Elastacloud.AzureManagement.Fluent.Clients.MobileServiceClient.AddTableScript C# (CSharp) Method

AddTableScript() public method

Adds a script for a crud operation to the table
public AddTableScript ( CrudOperation operationType, string tableName, string script, Types permission ) : void
operationType CrudOperation The type of operation
tableName string The name of the WAMS table
script string The script to add
permission Types The permissions of the script to upload
return void
        public void AddTableScript(CrudOperation operationType, string tableName, string script, Types.MobileServices.Roles permission)
        {
            if (String.IsNullOrEmpty(tableName))
                throw new FluentManagementException("unable to add table with an empty name", "CreateMobileServicesTableScriptCommand");
            EnsureMobileServicesName();
            Refresh();
            // then create the script
            var command = new CreateMobileServiceTableScriptCommand(MobileServiceName, tableName, operationType, script)
            {
                SubscriptionId = SubscriptionId,
                Certificate = ManagementCertificate
            };
            command.Execute();
            // update the script with the new permissions
            var table = Tables.FirstOrDefault(a => a.TableName == tableName);
            var values = new List<string> { table.InsertPermission.ToString(), table.UpdatePermission.ToString(), table.ReadPermission.ToString(), table.DeletePermission.ToString()};
            // TODO: speak to MSFT about this - the cmdlets have a bug and all of the permissions need to be added for them to update more than a single one

            var dictionary = BuildCrudDictionary(values);
            dictionary[operationType.ToString().ToLower()] = permission.ToString().ToLower();

            // updates the script table service permissions
            var config = JsonConvert.SerializeObject(dictionary);
            var updateCommand = new UpdateMobileServiceTablePermissionsCommand(MobileServiceName, tableName, config)
                              {
                                  SubscriptionId = SubscriptionId,
                                  Certificate = ManagementCertificate
                              };
            updateCommand.Execute();
            Refresh();
        }

Usage Example

Example #1
0
        public void Execute()
        {
            System.Console.WriteLine("Update mobile service");
            System.Console.WriteLine("=====================");
            var client = new MobileServiceClient(_subscriptionId, _certificate, _mobileServiceName);
            if(!client.Tables.Exists(a => a.TableName == "Speakers"))
                client.AddTable("Speakers");
            client.AddTableScript(CrudOperation.Insert, "Speakers", Resources.insert_js, Types.MobileServices.Roles.Public);
            client.FacebookClientId = "test";
            client.FacebookClientSecret = "test";
            client.GoogleClientId = "test";
            client.GoogleClientSecret = "test";
            client.TwitterClientId = "test";
            client.TwitterClientSecret = "test";
            client.DynamicSchemaEnabled = true;
            client.MicrosoftAccountClientId = "test";
            client.MicrosoftAccountClientSecret = "test";
            client.Update();

            System.Console.WriteLine("Application key: {0}", client.ApplicationKey);
            System.Console.WriteLine("Application url: {0}", client.ApplicationUrl);
            System.Console.WriteLine("Description: {0}", client.Description);
            System.Console.WriteLine("Location: {0}", client.Location);
            System.Console.WriteLine("Master key: {0}", client.MasterKey);
            System.Console.WriteLine("Mobile service Db name: {0}", client.MobileServiceDbName);
            System.Console.WriteLine("Mobile service server name: {0}", client.MobileServiceSqlName);
            System.Console.WriteLine("Sql Azure Db name: {0}", client.SqlAzureDbName);
            System.Console.WriteLine("Sql Azure server name: {0}", client.SqlAzureServerName);
            System.Console.WriteLine("Mobile service state: {0}", client.MobileServiceState.ToString());

            foreach (var table in client.Tables)
            {
                System.Console.WriteLine("==================================================");
                System.Console.WriteLine("Table name: {0}", table.TableName);
                System.Console.WriteLine("Size: {0} bytes", table.SizeInBytes);
                System.Console.WriteLine("Row count: {0}", table.NumberOfRecords);
                System.Console.WriteLine("No of indexes: {0}", table.NumberOfIndexes);
                System.Console.WriteLine("Read permission: {0}", table.ReadPermission);
                System.Console.WriteLine("Insert permission: {0}", table.InsertPermission);
                System.Console.WriteLine("Delete permission: {0}", table.DeletePermission);
                System.Console.WriteLine("Update permission: {0}", table.UpdatePermission);
                System.Console.WriteLine("==================================================");
            }

            var logs = client.Logs;
            System.Console.WriteLine("There are {0} log entries", logs.Count);
            System.Console.WriteLine("There are {0} error log entries", logs.Where(a => a.Type == LogLevelType.Error));
            System.Console.WriteLine("There are {0} warning log entries", logs.Where(a => a.Type == LogLevelType.Warning));
            System.Console.WriteLine("There are {0} information log entries", logs.Where(a => a.Type == LogLevelType.Information));
            client.RegenerateKeys();
            client.Restart();
        }