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

AddTable() public method

Adds a table to mobile services
public AddTable ( string tableName, Types defaultPermission = Types.MobileServices.Roles.Application ) : void
tableName string the name of the table
defaultPermission Types Sets the default permission for the table scripts
return void
        public void AddTable(string tableName, Types.MobileServices.Roles defaultPermission = Types.MobileServices.Roles.Application)
        {
            if(String.IsNullOrEmpty(tableName))
                throw new FluentManagementException("unable to add table with an empty name", "CreateMobileServicesTableCommand");
            var permission = defaultPermission.ToString().ToLower();
            var dictionary = BuildCrudDictionary(new List<string> {permission, permission, permission, permission});
            dictionary["name"] = tableName;
            EnsureMobileServicesName();
            var config = JsonConvert.SerializeObject(dictionary);
            var command = new CreateMobileServiceTableCommand(MobileServiceName, tableName, config)
                              {
                                  SubscriptionId = SubscriptionId,
                                  Certificate = ManagementCertificate
                              };
            command.Execute();
        }

Usage Example

Esempio n. 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();
        }