Esempio n. 1
0
        /// <summary>
        /// Used to return the mobile service application details
        /// </summary>
        protected override void ResponseCallback(System.Net.HttpWebResponse webResponse)
        {
            var dictionary = Parse(webResponse, BaseParser.GetMobileServiceTablePermissionsParser, new GetMobileServiceTablePermissionsParser(null));

            if (dictionary != null && dictionary.Count != 4)
            {
                throw new FluentManagementException("Incorrect values returned or service does not exist", ToString());
            }
            InsertPermission = (Types.MobileServices.Roles)Enum.Parse(typeof(Types.MobileServices.Roles), dictionary["Insert"]);
            ReadPermission   = (Types.MobileServices.Roles)Enum.Parse(typeof(Types.MobileServices.Roles), dictionary["Read"]);
            UpdatePermission = (Types.MobileServices.Roles)Enum.Parse(typeof(Types.MobileServices.Roles), dictionary["Update"]);
            DeletePermission = (Types.MobileServices.Roles)Enum.Parse(typeof(Types.MobileServices.Roles), dictionary["Delete"]);

            SitAndWait.Set();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a table to mobile services
        /// </summary>
        /// <param name="tableName">the name of the table</param>
        /// <param name="defaultPermission">Sets the default permission for the table scripts</param>
        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();
        }
Esempio n. 3
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();
        }