Example #1
0
        /// <summary>
        /// Save a Device Rule to the server. This may be either a new rule or an update to an existing rule.
        /// </summary>
        /// <param name="updateContainer"></param>
        /// <returns></returns>
        public async Task <TableStorageResponse <DeviceRule> > SaveDeviceRuleAsync(DeviceRule updatedRule)
        {
            DeviceRuleTableEntity incomingEntity =
                new DeviceRuleTableEntity(updatedRule.DeviceID, updatedRule.RuleId)
            {
                DataField  = updatedRule.DataField,
                Threshold  = (double)updatedRule.Threshold,
                Enabled    = updatedRule.EnabledState,
                RuleOutput = updatedRule.RuleOutput
            };

            if (!string.IsNullOrWhiteSpace(updatedRule.Etag))
            {
                incomingEntity.ETag = updatedRule.Etag;
            }

            TableStorageResponse <DeviceRule> result =
                await AzureTableStorageHelper.DoTableInsertOrReplace <DeviceRule, DeviceRuleTableEntity>(incomingEntity, BuildRuleFromTableEntity,
                                                                                                         _storageAccountConnectionString, _deviceRulesNormalizedTableName);

            // Build up a new blob to push up
            List <DeviceRuleBlobEntity> blobList = await BuildBlobEntityListFromTableRows();

            await PersistRulesToBlobStorageAsync(blobList);

            return(result);
        }
Example #2
0
        public async Task <TableStorageResponse <UserSetting> > SetUserSettingValueAsync(UserSetting setting)
        {
            var incomingEntity =
                new UserSettingTableEntity()
            {
                PartitionKey = _settingsTablePartitionKey,
                RowKey       = setting.Key,
                SettingValue = setting.Value
            };

            if (!string.IsNullOrWhiteSpace(setting.Etag))
            {
                incomingEntity.ETag = setting.Etag;
            }

            TableStorageResponse <UserSetting> result = await AzureTableStorageHelper.DoTableInsertOrReplace <UserSetting, UserSettingTableEntity>(incomingEntity, (tableEntity) =>
            {
                if (tableEntity == null)
                {
                    return(null);
                }

                var updatedSetting = new UserSetting()
                {
                    Key   = tableEntity.RowKey,
                    Value = tableEntity.SettingValue,
                    Etag  = tableEntity.ETag
                };

                return(updatedSetting);
            }, _storageAccountConnectionString, _settingsTableName);

            return(result);
        }