コード例 #1
0
        internal async Task <PackageTag> AddPackageVersionAsync(string name, string tag, string versionChanges, string fileHash)
        {
            var tableStorage = new AzureTableStorageProvider(storageAccount);

            if (name == Package.PACKAGES_PARTITION_NAME)
            {
                throw new ArgumentException($"{name} is reserved");
            }

            Package package = new Package(name, tag, fileHash);

            tableStorage.Upsert(PackagesTableName, package); // save as Packages | name@tag

            List <PackageTag> allTags = await GetAllEntitiesFromPartitionAsync <PackageTag>(PackagesTableName, name);

            if (allTags.Any())
            {
                if (allTags.Any(t => t.Tag == tag) && allTags.First().Tag != tag) //tag already exist and it is not last
                {
                    throw new ArgumentException($"Tag {tag} already exist and it is not last");
                }
                else if (allTags.First().Tag == tag)
                {
                    IEnumerable <PackageChange> packageChanges = await GetAllEntitiesFromPartitionAsync <PackageChange>(PackagesFileChangesTableName, name);

                    foreach (var prevChange in packageChanges.Where(c => c.Tag == tag))
                    {
                        tableStorage.Delete(PackagesFileChangesTableName, prevChange);
                    }
                    tableStorage.Delete(PackagesTableName, allTags.First());
                }
            }

            PackageTag packageVersion = new PackageTag(name, tag, fileHash);

            tableStorage.Upsert(PackagesTableName, packageVersion); //save as name | timestamp (tag, hash)

            JObject versionInfoJO = JObject.Parse(versionChanges);

            foreach (var fileEntry in versionInfoJO["files"])
            {
                string path       = fileEntry["path"].Value <string>();
                string hash       = fileEntry["hash"].Value <string>();
                string changeType = fileEntry["editType"].Value <string>();
                tableStorage.Add(PackagesFileChangesTableName, new PackageChange(name, tag, path, hash, changeType));
            }

            await tableStorage.SaveAsync();

            return(packageVersion);
        }
コード例 #2
0
        public async Task Upsert_101EntitiesInTheSamePartition_ShouldSucceed()
        {
            string partitionKey  = "123";
            int    expectedCount = 101;

            for (int i = 0; i < expectedCount; i++)
            {
                var item = new DecoratedItem
                {
                    Id   = partitionKey,
                    Name = i.ToString(CultureInfo.InvariantCulture)
                };
                _tableStorageProvider.Upsert(_tableName, item);
            }


            await _tableStorageProvider.SaveAsync(Execute.InBatches);


            IEnumerable <DecoratedItem> items = (await _tableStorageProvider.CreateQuery <DecoratedItem>(_tableName).PartitionKeyEquals(partitionKey).Async()).ToList();

            Assert.AreEqual(expectedCount, items.Count());
        }
コード例 #3
0
ファイル: SaveAtomicallyTest.cs プロジェクト: Zero-GHub/hyde
        public async Task SaveAsync_MultipleOperationTypesOnSamePartitionAndNoConflicts_OperationsSucceed()
        {
            _tableStorageProvider.Add(_tableName, new DecoratedItem {
                Id = "123", Name = "Eve", Age = 34
            });
            await _tableStorageProvider.SaveAsync();

            _tableStorageProvider.Add(_tableName, new DecoratedItem {
                Id = "123", Name = "Ed", Age = 7
            });
            _tableStorageProvider.Upsert(_tableName, new DecoratedItem {
                Id = "123", Name = "Eve", Age = 42
            });
            await _tableStorageProvider.SaveAsync(Execute.Atomically);

            Assert.AreEqual(7, (await _tableStorageProvider.GetAsync <DecoratedItem>(_tableName, "123", "Ed")).Age);
            Assert.AreEqual(42, (await _tableStorageProvider.GetAsync <DecoratedItem>(_tableName, "123", "Eve")).Age);
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: BLesnau/Byldit
        public ActionResult Index(SubmitEmail model)
        {
            if (ModelState.IsValid)
            {
                var connectionString     = GlobalConfig.GetString("BylditStorageAccountConnectionString");
                var storageAccount       = CloudStorageAccount.Parse(connectionString);
                var tableStorageProvider = new AzureTableStorageProvider(new CloudStorageAccountAdapter(storageAccount));
                var emailTableName       = GlobalConfig.GetString("SubmitEmailTableName");

                storageAccount.CreateCloudTableClient().GetTableReference(emailTableName).CreateIfNotExists();

                tableStorageProvider.Upsert(emailTableName, model);
                tableStorageProvider.Save();

                model.Submitted = true;
            }

            return(View(model));
        }