/// <summary>
 /// Constructs a command to create a mobile service
 /// </summary>
 internal CreateMobileServiceTableScriptCommand(string serviceName, string tableName, CrudOperation operation, string config)
 {
     OperationId = "mobileservices";
     ServiceType = "services";
     Name = serviceName;
     TableName = tableName;
     Config = config;
     HttpVerb = HttpVerbPut;
     ContentType = "text/plain";
     HttpCommand = String.Format("mobileservices/{0}/tables/{1}/scripts/{2}/code", serviceName.ToLower(), tableName.ToLower(), operation.ToString().ToLower());
 }
예제 #2
0
        /// <summary>
        /// Adds a script for a crud operation to the table
        /// </summary>
        /// <param name="operationType">The type of operation</param>
        /// <param name="tableName">The name of the WAMS table</param>
        /// <param name="script">The script to add</param>
        /// <param name="permission">The permissions of the script to upload</param>
        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();
        }
        /// <summary>
        /// Adds a script for a crud operation to the table
        /// </summary>
        /// <param name="operationType">The type of operation</param>
        /// <param name="tableName">The name of the WAMS table</param>
        /// <param name="script">The script to add</param>
        /// <param name="permission">The permissions of the script to upload</param>
        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();
        }
예제 #4
0
 /// <summary>
 /// Constructs a command to create a mobile service
 /// </summary>
 internal CreateMobileServiceTableScriptCommand(string serviceName, string tableName, CrudOperation operation, string config)
 {
     OperationId = "mobileservices";
     ServiceType = "services";
     Name        = serviceName;
     TableName   = tableName;
     Config      = config;
     HttpVerb    = HttpVerbPut;
     ContentType = "text/plain";
     HttpCommand = String.Format("mobileservices/{0}/tables/{1}/scripts/{2}/code", serviceName.ToLower(), tableName.ToLower(), operation.ToString().ToLower());
 }