Exemplo n.º 1
0
        public async Task <FeatureDetail> CreateFeature(string name, FeatureUpdateParams prms)
        {
            var sessionInfo = idInfo_.GetSessionInfo();

            if (!sessionInfo.IsUser)
            {
                throw new AccessDeniedException($"Login required");
            }

            if (newGates_)
            {
                var entry = new FeatureEntry()
                {
                    Name     = name,
                    Issuer   = sessionInfo.AccountId,
                    Disabled = true,
                };

                entry.Update(prms);

                try
                {
                    var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Insert(entry.To <FeatureEntryTableEntity>()));

                    var newEntry = (FeatureEntryTableEntity)tableResult.Result;
                    return(newEntry.To <FeatureEntry>().ToFeatureDetail());
                }
                catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created");
                }
            }
            else
            {
                var entry = new LegacyFeatureEntry()
                {
                    PartitionKey = FeatureGateStore.GatePartitionKey,
                    Name         = name,
                    Issuer       = sessionInfo.AccountId,
                    Disabled     = true,
                };

                entry.Update(prms);

                try
                {
                    TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Insert(entry));

                    var newEntry = (LegacyFeatureEntry)tableResult.Result;
                    return(newEntry.ToFeatureDetail());
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created");
                }
            }
        }
Exemplo n.º 2
0
        public async Task <FeatureDetail> UpdateFeature(string name, FeatureUpdateParams prms)
        {
            if (newGates_)
            {
                var          table = featureStore_.Value.Storage;
                FeatureEntry entry = (await table.RetrieveAsync <FeatureEntryTableEntity>(FeatureGateStore.GatePartitionKey, name)).To <FeatureEntry>();
                if (entry == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }

                entry.Update(prms);

                try
                {
                    var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Replace(entry.To <FeatureEntryTableEntity>()));

                    var newEntry = (FeatureEntryTableEntity)tableResult.Result;
                    return(newEntry.To <FeatureEntry>().ToFeatureDetail());
                }
                catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to update feature, already removed or modified");
                }
            }
            else
            {
                var table = featureStore_.Value.GatesTable;
                var entry = await table.GetRowAsync <LegacyFeatureEntry>(FeatureGateStore.GatePartitionKey, name);

                if (entry == null)
                {
                    throw new ItemNotFoundException($"Feature gate [{name}] not found");
                }

                entry.Update(prms);

                try
                {
                    TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Replace(entry));

                    var newEntry = (LegacyFeatureEntry)tableResult.Result;
                    return(newEntry.ToFeatureDetail());
                }
                catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409)
                {
                    throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to update feature, already removed or modified");
                }
            }
        }