Esempio n. 1
0
        /// <summary>
        /// Save Profile Page
        /// </summary>
        /// <param name="page">Page</param>
        /// <returns>Profile Page</returns>
        public ProfilePage Save(ProfilePage page)
        {
            Contract.Requires <ArgumentNullException>(null != page);
            Contract.Requires <ArgumentException>(Guid.Empty != page.ApplicationIdentifier);
            Contract.Requires <ArgumentException>(Guid.Empty != page.OwnerIdentifier);
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(page.Handle));

            var row = page.Convert();

            var            table      = new AzureTable <UserProfileRow>(ServerConfiguration.Default);
            UserProfileRow oldProfile = null;
            UserProfileRow newProfile = null;

            try
            {
                oldProfile = table.QueryBy(row.PartitionKey, page.ExistingHandle.ToLowerInvariant());
            }
            catch (Exception ex)
            {
                Logging.Log(ex, EventTypes.Warning, (int)ServiceFault.ProfileDoesntExist);
            }

            try
            {
                newProfile = table.QueryBy(row.PartitionKey, page.Handle.ToLowerInvariant());
            }
            catch (Exception ex)
            {
                Logging.Log(ex, EventTypes.Warning, (int)ServiceFault.ProfileDoesntExist);
            }

            if (null == newProfile)
            {
                table.AddEntity(row);
            }
            else if (newProfile.OwnerIdentifier == row.OwnerIdentifier)
            {
                table.AddOrUpdateEntity(row);
            }
            else
            {
                throw new InvalidOperationException("User doesn't own profile");
            }

            if (null != oldProfile)
            {
                if (oldProfile.OwnerIdentifier == row.OwnerIdentifier)
                {
                    table.DeleteBy(oldProfile.PartitionKey, oldProfile.RowKey);
                }
                else
                {
                    throw new InvalidOperationException("User doesn't own profile");
                }
            }

            return(page);
        }
Esempio n. 2
0
        public void DeleteByMultiple()
        {
            var random = new Random();
            var table  = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());

            table.EnsureExist();
            var partition = Guid.NewGuid().ToString();
            var entity1   = new EntityWithDataStore()
            {
                RowKey       = Guid.NewGuid().ToString(),
                PartitionKey = partition,
                ToTest       = random.Next()
            };

            table.AddEntity(entity1);
            var entity2 = new EntityWithDataStore()
            {
                RowKey       = Guid.NewGuid().ToString(),
                PartitionKey = partition,
                ToTest       = random.Next()
            };

            table.AddEntity(entity2);

            var items = table.QueryByPartition(partition);

            Assert.IsNotNull(items);
            var list = items.ToList();

            Assert.AreEqual <int>(2, list.Count());

            table.DeleteBy(entity1.PartitionKey, entity1.RowKey);
            items = table.QueryByPartition(partition);
            Assert.IsNotNull(items);
            list = items.ToList();
            Assert.AreEqual <int>(1, list.Count());

            table.DeleteBy(entity2.PartitionKey, entity2.RowKey);

            items = table.QueryByPartition(partition);
            list  = items.ToList();
            Assert.AreEqual <int>(0, list.Count());
        }
Esempio n. 3
0
        public void DeleteBySingle()
        {
            var random = new Random();
            var table  = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());

            table.EnsureExist();
            var entity = new EntityWithDataStore()
            {
                RowKey       = Guid.NewGuid().ToString(),
                PartitionKey = Guid.NewGuid().ToString(),
                ToTest       = random.Next()
            };

            table.AddEntity(entity);

            table.DeleteBy(entity.PartitionKey, entity.RowKey);

            var returned = table.QueryByPartition(entity.PartitionKey);

            Assert.IsNotNull(returned);
            var list = returned.ToList();

            Assert.AreEqual <int>(0, list.Count());
        }
Esempio n. 4
0
        public void DeleteByInvalidRowKey()
        {
            var table = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount);

            table.DeleteBy(StringHelper.ValidString(), StringHelper.NullEmptyWhiteSpace());
        }
Esempio n. 5
0
        public void DeleteByNullPartitionKey()
        {
            var table = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount);

            table.DeleteBy(null, StringHelper.ValidString());
        }