Ejemplo n.º 1
0
        public string SetRoles(Application app, Guid userId)
        {
            Contract.Requires <ArgumentNullException>(null != app);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != app.Identifier);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != userId);

            using (new PerformanceMonitor())
            {
                var userInfo = this.userTable.QueryBy(app.Identifier.ToString(), userId.ToString());

                if (null != userInfo)
                {
                    IList <RoleRow> roles = new List <RoleRow>(2);
                    if (userInfo.Email.ToUpperInvariant().EndsWith("@agilebusinesscloud.com".ToUpperInvariant()))
                    {
                        userInfo.RoleValue = (int)RoleType.Manager;
                        var staff = new RoleRow(app.Identifier)
                        {
                            UserIdentifier = userInfo.Id,
                            Name           = "staff",
                        };

                        roles.Add(staff);
                    }

                    var member = new RoleRow(app.Identifier)
                    {
                        UserIdentifier = userInfo.Id,
                        Name           = "member",
                    };

                    roles.Add(member);

                    var roleTable = new AzureTable <RoleRow>(ServerConfiguration.Default, new RoleRowValidator());
                    roleTable.AddEntity(roles);

                    var preference = new UserPreference()
                    {
                        Application = app,
                        User        = userInfo.Convert(),
                        MaximumAllowedApplications = 1,
                    };

                    var userCore = new UserCore();
                    userCore.Save(preference);

                    userInfo.EmailValidated = true;
                    userInfo.LastActivityOn = DateTime.UtcNow;
                    this.userTable.AddOrUpdateEntity(userInfo);

                    return(userInfo.Email);
                }
                else
                {
                    Logging.Log("Email validation key not found.");
                }

                return(null);
            }
        }
Ejemplo n.º 2
0
        public void AddEntityQueryPartition()
        {
            Random random = new Random();
            var    table  = new AzureTable <Entity>(CloudStorageAccount.DevelopmentStorageAccount);

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

            table.AddEntity(entity);

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

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

            Assert.AreEqual <int>(1, items.Count);
            var first = returned.FirstOrDefault();

            Assert.AreEqual <string>(entity.PartitionKey, first.PartitionKey);
            Assert.AreEqual <string>(entity.RowKey, first.RowKey);
            Assert.AreEqual <int>(entity.ToTest, first.ToTest);
        }
Ejemplo n.º 3
0
        public void SaveConfigurationNullsUserAndToken()
        {
            var user      = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(user);
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core   = new ApplicationCore();
            var config = this.Config(userApp.ApplicationId);

            var u = new User()
            {
                Identifier = userApp.UserId,
            };
            var a = new Application()
            {
                Identifier = user.ApplicationId,
            };
            var editor = new UserApplication()
            {
                User        = u,
                Application = a,
            };
            var returned = core.Save(config, editor);

            Assert.IsNotNull(returned);
            Assert.IsNull(returned.Token);
        }
        public void Query()
        {
            var table = new AzureTable <MessageData>(CloudStorageAccount.DevelopmentStorageAccount);

            var appId = Guid.NewGuid();

            for (int i = 0; i < 4; i++)
            {
                var data = new MessageData(appId);
                data.Fill();

                table.AddEntity(data);
            }

            var query = new LogQuery()
            {
                ApplicationIdentifier = appId,
                From = DateTime.UtcNow.AddMinutes(-1),
                To   = DateTime.UtcNow.AddMilliseconds(1),
                Top  = 1,
            };

            var messages = table.Query <MessageData>(query).ToList();

            Assert.IsNotNull(messages, "Message data should not be null.");
            Assert.AreEqual <int>(1, messages.Count(), "1 Message Should be contained.");

            query.Top = 3;

            messages = table.Query <MessageData>(query).ToList();
            Assert.IsNotNull(messages, "Message data should not be null.");
            Assert.AreEqual <int>(3, messages.Count(), "3 Message Should be contained.");
        }
Ejemplo n.º 5
0
        public void QueryByRowSmallRandom()
        {
            var table = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());

            table.EnsureExist();
            var row      = Guid.NewGuid().ToString();
            var entities = new List <EntityWithDataStore>(1010);
            var random   = new Random();
            var count    = random.Next(1, 100);

            Parallel.For(
                0,
                count + 5,
                (i, loopState) =>
            {
                var entity = new EntityWithDataStore()
                {
                    RowKey       = row,
                    PartitionKey = Guid.NewGuid().ToString(),
                };
                table.AddEntity(entity);
            });

            var returned = table.QueryByRow(row, count).ToList();

            Assert.AreEqual <int>(count, returned.Count);
        }
Ejemplo n.º 6
0
        public void ApplicationInfoRoundTrip()
        {
            var table = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);
            var user  = new UserData(string.Format("{0}@temp.com", Guid.NewGuid()), "na", Guid.NewGuid().ToString());

            table.AddEntity(user);

            var core = new ApplicationCore();
            var data = this.Information();

            data.Identifier = Abc.Underpinning.Application.Identifier;
            var u = new User()
            {
                Identifier = user.Id,
            };
            var app = new Application()
            {
                Identifier = Guid.NewGuid(),
            };
            var editor = new UserApplication()
            {
                User        = u,
                Application = app,
            };
            var userApp = new ApplicationInformation()
            {
                Identifier = Application.Default.Identifier,
            };
            var saved = core.Save(data, editor, userApp);

            Assert.IsNotNull(saved);
            Assert.AreEqual <string>(data.Description, saved.Description);
            Assert.AreEqual <string>(data.Name, saved.Name);
            Assert.AreEqual <Guid>(data.Identifier, saved.Identifier);
        }
        public void RegisterManager()
        {
            var started = DateTime.UtcNow;
            var table = new AzureTable<UserData>(CloudStorageAccount.DevelopmentStorageAccount);
            var user = new UserData(string.Format("{0}@agilebusinesscloud.com", Guid.NewGuid()), Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
            table.AddEntity(user);

            var target = new AccountController();

            var returned = table.QueryBy(user.PartitionKey, user.RowKey);
            Assert.IsNotNull(returned);
            Assert.AreEqual<DateTime>(returned.CreatedOn, user.CreatedOn);
            Assert.AreEqual<DateTime>(returned.LastLoggedInOn, user.LastLoggedInOn);
            Assert.AreEqual<DateTime>(returned.LastActivityOn.Date, user.LastActivityOn.Date);
            Assert.AreEqual<DateTime>(returned.PasswordLastChangedOn, user.PasswordLastChangedOn);
            Assert.AreEqual<string>(returned.Email, user.Email);
            Assert.AreEqual<string>(returned.OpenId, user.OpenId);
            Assert.AreEqual<string>(returned.UserName, user.UserName);
            Assert.AreEqual<int>(returned.RoleValue, user.RoleValue);
            Assert.AreEqual<bool>(returned.IsApproved, user.IsApproved);
            Assert.AreEqual<bool>(returned.IsLockedOut, user.IsLockedOut);
            Assert.AreEqual<bool>(returned.EmailValidated, user.EmailValidated);
            Assert.AreEqual<string>(returned.EmailValidationKey, user.EmailValidationKey);
            Assert.AreEqual<DateTime>(returned.LastLockedOutOn.Date, user.LastLockedOutOn.Date);

            Assert.IsTrue(returned.EmailValidated);
            Assert.AreEqual<int>((int)RoleType.Client, returned.RoleValue);
        }
Ejemplo n.º 8
0
        public void AddEntitiesValidationThrows()
        {
            var table = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());

            table.EnsureExist();
            var entities = new List <EntityWithDataStore>();
            var entity   = new EntityWithDataStore()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString(),
                ToTest       = 11
            };

            entities.Add(entity);
            entity = new EntityWithDataStore()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString(),
                ToTest       = -100
            };
            entities.Add(entity);
            entity = new EntityWithDataStore()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString(),
                ToTest       = 22
            };
            entities.Add(entity);
            table.AddEntity(entities);
        }
Ejemplo n.º 9
0
        public ContactGroup Save(ContactGroup contact)
        {
            Contract.Requires <ArgumentNullException>(null != contact);
            Contract.Requires <ArgumentNullException>(null != contact.Owner);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != contact.Identifier);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != contact.Owner.Identifier);

            using (new PerformanceMonitor())
            {
                var row   = contact.Convert();
                var table = new AzureTable <ContactGroupRow>(ServerConfiguration.Default, new ContactGroupRowValidator());
                var data  = table.QueryBy(row.PartitionKey, row.RowKey);

                if (null == data)
                {
                    table.AddEntity(row);
                }
                else
                {
                    data.Name = row.Name;
                    table.AddOrUpdateEntity(data);

                    row = data;
                }

                return(row.Convert());
            }
        }
Ejemplo n.º 10
0
        private string SetupData()
        {
            var table = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount);

            table.EnsureExist();
            var partition = Guid.NewGuid().ToString();
            var entities  = new List <EntityWithDataStore>(1010);

            Parallel.For(
                0,
                1010,
                (i, loopState) =>
            {
                var entity = new EntityWithDataStore()
                {
                    RowKey       = Guid.NewGuid().ToString(),
                    PartitionKey = partition,
                    Hex          = StringHelper.ValidString(),
                    Index        = i,
                };
                table.AddEntity(entity);
            });

            return(partition);
        }
Ejemplo n.º 11
0
        public void UserApplicationRoundTrip()
        {
            var user = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var e    = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());

            e.EmailValidated = true;
            e.RoleValue      = (int)RoleType.Manager;
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(new[] { e, user });
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core   = new ApplicationCore();
            var data   = this.UserApplication(userApp.ApplicationId);
            var editor = this.UserApplication(userApp.ApplicationId);

            editor.User = e.Convert();

            var saved = core.Save(data, editor);

            Assert.AreEqual <Guid>(data.Application.Identifier, saved.Application.Identifier);
            Assert.AreEqual <Guid>(data.User.Identifier, saved.User.Identifier);

            var get = core.Get(data);

            Assert.AreEqual <Guid>(data.Application.Identifier, get.Application.Identifier);
            Assert.AreEqual <Guid>(data.User.Identifier, get.User.Identifier);
        }
Ejemplo n.º 12
0
        public static PayPalPaymentConfirmation ProcessResponse(PayPalPaymentConfirmation payment)
        {
            Contract.Requires <ArgumentNullException>(null != payment);

            if (string.IsNullOrWhiteSpace(payment.Response))
            {
                log.Log("Empty response returned from PayPal.");
            }
            else if (payment.Response.StartsWith("SUCCESS", StringComparison.InvariantCultureIgnoreCase))
            {
                payment.Successful = true;

                payment = PaymentCore.ProcessSuccessfulResponse(payment);

                var preferenceTable = new AzureTable <UserPreferenceRow>(ServerConfiguration.Default);
                var preference      = preferenceTable.QueryBy(payment.Application.Identifier.ToString(), payment.User.Identifier.ToString());

                preference = preference ?? new UserPreferenceRow(payment.Application.Identifier, payment.User.Identifier);

                preference.MaxiumAllowedApplications = preference.MaxiumAllowedApplications.HasValue ? preference.MaxiumAllowedApplications + 1 : 1;
                preferenceTable.AddOrUpdateEntity(preference);
            }
            else
            {
                payment.Successful = false;

                log.Log("Error Accepting payment response.");
            }

            var table = new AzureTable <PayPalPaymentConfirmationRow>(ServerConfiguration.Default);

            table.AddEntity(payment.Convert());

            return(payment);
        }
Ejemplo n.º 13
0
        public void DeleteByPartitionMultiple()
        {
            var random = new Random();
            var table  = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());

            table.EnsureExist();
            var partition = Guid.NewGuid().ToString();
            int multiple  = random.Next(1, 10);

            for (int i = 0; i < multiple; i++)
            {
                var entity = new EntityWithDataStore()
                {
                    RowKey       = Guid.NewGuid().ToString(),
                    PartitionKey = partition,
                    ToTest       = random.Next()
                };
                table.AddEntity(entity);
            }

            var items = table.QueryByPartition(partition);

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

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

            table.DeleteByPartition(partition);
            items = table.QueryByPartition(partition);
            Assert.IsNotNull(items);
            list = items.ToList();
            Assert.AreEqual <int>(0, list.Count());
        }
Ejemplo n.º 14
0
        public void GetConfigurationItems()
        {
            var user      = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(user);
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core    = new ApplicationCore();
            var config1 = this.Config(userApp.ApplicationId);

            var config2 = this.Config(userApp.ApplicationId);
            var u       = new Abc.Services.Contracts.User()
            {
                Identifier = userApp.UserId,
            };
            var a = new Abc.Services.Contracts.Application()
            {
                Identifier = user.ApplicationId,
            };
            var editor = new Abc.Services.Contracts.UserApplication()
            {
                User        = u,
                Application = a,
            };

            core.Save(config1, editor);
            core.Save(config2, editor);

            var query = new Abc.Services.Contracts.Configuration()
            {
                Token = config1.Token,
            };

            var returned = core.Get(query);

            Assert.IsNotNull(returned);
            var item1 = (from data in returned
                         where data.Key == config1.Key &&
                         data.Value == config1.Value
                         select data).First();

            Assert.AreEqual <string>(config1.Key, item1.Key);
            Assert.AreEqual <string>(config1.Value, item1.Value);

            var item2 = (from data in returned
                         where data.Key == config2.Key &&
                         data.Value == config2.Value
                         select data).First();

            Assert.AreEqual <string>(config2.Key, item2.Key);
            Assert.AreEqual <string>(config2.Value, item2.Value);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Execute
        /// </summary>
        protected override void Execute(object state)
        {
            using (new PerformanceMonitor())
            {
                try
                {
                    var item = new DataManagerLog(this.GetType());

                    var table  = new AzureTable <DataManagerLog>(ServerConfiguration.Default);
                    var latest = (from data in table.QueryByPartition(item.PartitionKey).ToList()
                                  orderby data.StartTime
                                  select data).FirstOrDefault();

                    // Check if there's any task to execute
                    var performTask = null == latest || (latest.CompletionTime.HasValue ?
                                                         DateTime.UtcNow.Subtract(latest.CompletionTime.Value) >= period || !latest.Successful :
                                                         DateTime.UtcNow.Subtract(latest.StartTime) >= retryInterval);

                    if (performTask)
                    {
                        log.Log(string.Format("{0} Task Started.", DateTime.UtcNow));

                        item.StartTime = DateTime.UtcNow;

                        table.AddEntity(item);

                        // Start the backup
                        try
                        {
                            this.Execute();
                            item.Successful = true;
                        }
                        catch (Exception ex)
                        {
                            log.Log(ex, EventTypes.Critical, (int)ServiceFault.Unknown);
                            item.Successful = false;
                        }
                        finally
                        {
                            item.CompletionTime = DateTime.UtcNow;
                        }

                        // Update entry in table
                        table.AddOrUpdateEntity(item);
                        log.Log(string.Format("{0} Task Completed. Success: {1}", DateTime.UtcNow, item.Successful));
                    }
                    else
                    {
                        log.Log(string.Format("{0} No Action Required.", DateTime.UtcNow));
                    }
                }
                catch (Exception ex)
                {
                    log.Log(ex, EventTypes.Error, (int)ServiceFault.Unknown);
                }
            }
        }
Ejemplo n.º 17
0
        public void GetUsersDeepLoad()
        {
            var table = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);
            var user  = table.QueryByPartition(Settings.ApplicationIdentifier.ToString()).FirstOrDefault();

            if (null == user)
            {
                user = new UserData(string.Format("{0}@temp.com", Guid.NewGuid()), "na", Guid.NewGuid().ToBase64());
                table.AddEntity(user);
            }

            var companyTable = new AzureTable <CompanyRow>(CloudStorageAccount.DevelopmentStorageAccount);
            var companyRow   = new CompanyRow(user.Id)
            {
                Name = Guid.NewGuid().ToBase64(),
            };

            companyTable.AddEntity(companyRow);
            var roleTable = new AzureTable <RoleRow>(CloudStorageAccount.DevelopmentStorageAccount);
            var roleRow   = new RoleRow(Settings.ApplicationIdentifier)
            {
                UserIdentifier = user.Id,
                Name           = Guid.NewGuid().ToBase64(),
            };

            roleTable.AddEntity(roleRow);

            var core  = new ApplicationCore();
            var users = core.GetUsers(Application.Current, true);

            Assert.IsNotNull(users);
            Assert.IsTrue(0 < users.Count());
            var returned = (from data in users
                            where data.Identifier == user.Id &&
                            data.Companies != null &&
                            data.Roles != null
                            select data).FirstOrDefault();

            Assert.IsNotNull(returned);
            Assert.AreEqual <Guid>(user.Id, returned.Identifier);
            Assert.AreEqual <string>(user.UserName, returned.UserName);
            Assert.IsNotNull(returned.Companies);
            var company = (from data in returned.Companies
                           where data.Identifier == companyRow.Identifier
                           select data).First();

            Assert.AreEqual <Guid>(companyRow.Identifier, company.Identifier);
            Assert.AreEqual <string>(companyRow.Name, company.Name);
            Assert.IsNotNull(returned.Roles);

            var role = (from data in returned.Roles
                        where data == roleRow.Name
                        select data).First();

            Assert.AreEqual <string>(roleRow.Name, role);
        }
Ejemplo n.º 18
0
        public void AddEntityInvalidRowKey()
        {
            var table  = new AzureTable <Entity>(CloudStorageAccount.DevelopmentStorageAccount);
            var entity = new Entity()
            {
                RowKey       = StringHelper.NullEmptyWhiteSpace(),
                PartitionKey = StringHelper.ValidString()
            };

            table.AddEntity(entity);
        }
Ejemplo n.º 19
0
        public void AddEntityNullPartitionKey()
        {
            var table  = new AzureTable <Entity>(CloudStorageAccount.DevelopmentStorageAccount);
            var entity = new Entity()
            {
                PartitionKey = null,
                RowKey       = StringHelper.ValidString()
            };

            table.AddEntity(entity);
        }
Ejemplo n.º 20
0
        public void AddEntityValidationThrows()
        {
            var table  = new AzureTable <EntityWithDataStore>(CloudStorageAccount.DevelopmentStorageAccount, new TestStoreValidator());
            var entity = new EntityWithDataStore()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString(),
                ToTest       = -1
            };

            table.AddEntity(entity);
        }
Ejemplo n.º 21
0
        public Configuration Save(Configuration configuration, UserApplication editor)
        {
            Contract.Requires(null != configuration);
            Contract.Requires(null != configuration.Token);
            Contract.Requires(null != editor);
            Contract.Requires(Guid.Empty != configuration.Token.ApplicationId);
            Contract.Requires(Guid.Empty != editor.User.Identifier);
            Contract.Requires(Guid.Empty != editor.Application.Identifier);
            Contract.Requires(!string.IsNullOrWhiteSpace(configuration.Value));
            Contract.Requires(!string.IsNullOrWhiteSpace(configuration.Key));

            using (new PerformanceMonitor())
            {
                var app = new Abc.Services.Contracts.Application()
                {
                    Identifier = configuration.Token.ApplicationId,
                };

                if (!this.UserIsAssociated(editor, app))
                {
                    throw new SecurityException("Editor is not associated with Application.");
                }

                var table  = new AzureTable <ApplicationConfiguration>(ServerConfiguration.Default);
                var save   = configuration.Convert();
                var exists = table.QueryBy(save.PartitionKey, save.RowKey);

                save.LastUpdatedBy = editor.User.Identifier;
                save.LastUpdatedOn = DateTime.UtcNow;
                if (null == exists)
                {
                    save.CreatedBy = editor.User.Identifier;
                    save.CreatedOn = DateTime.UtcNow;
                    table.AddEntity(save);
                }
                else
                {
                    save.CreatedOn = exists.CreatedOn;
                    save.CreatedBy = exists.CreatedBy;
                    table.AddOrUpdateEntity(save);
                }

                return(new Configuration()
                {
                    Key = configuration.Key,
                    Value = configuration.Value,
                });
            }
        }
Ejemplo n.º 22
0
        public UserApplication Save(UserApplication data, UserApplication editor)
        {
            Contract.Requires <ArgumentNullException>(null != data);
            Contract.Requires <ArgumentNullException>(null != editor);
            Contract.Requires <ArgumentNullException>(null != editor.Application);
            Contract.Requires <ArgumentNullException>(null != editor.User);
            Contract.Requires <ArgumentNullException>(null != data.Application);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != data.Application.Identifier);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.User.Identifier);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != editor.Application.Identifier);

            Contract.Ensures(Contract.Result <UserApplication>() != null);

            using (new PerformanceMonitor())
            {
                if (!this.UserIsAssociated(editor, data.Application))
                {
                    throw new SecurityException("Editor is not associated with Application.");
                }

                var table = new AzureTable <UserApplicationData>(ServerConfiguration.Default, new UserApplicationValidation());

                var existing = table.QueryBy(data.User.Identifier.ToString(), data.Application.Identifier.ToString());

                if (null == existing)
                {
                    existing               = data.Convert();
                    existing.CreatedOn     = DateTime.UtcNow;
                    existing.LastUpdatedOn = DateTime.UtcNow;
                    existing.CreatedBy     = editor.User.Identifier;
                    existing.LastUpdatedBy = editor.User.Identifier;
                    table.AddEntity(existing);
                }
                else
                {
                    var createdBy = existing.CreatedBy;
                    var createdOn = existing.CreatedOn;
                    existing               = data.Convert();
                    existing.CreatedBy     = createdBy;
                    existing.CreatedOn     = createdOn;
                    existing.LastUpdatedOn = DateTime.UtcNow;
                    existing.LastUpdatedBy = editor.User.Identifier;

                    table.AddOrUpdateEntity(existing);
                }

                return(data);
            }
        }
Ejemplo n.º 23
0
        public void GetConvertable()
        {
            var data = new MessageData(Guid.NewGuid());

            data.Fill();

            var table = new AzureTable <MessageData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(data);
            var msg = table.Get <MessageDisplay, MessageData>(data.PartitionKey, data.RowKey);

            Assert.AreEqual <Guid>(data.Id, msg.Identifier);
            Assert.AreEqual <Guid>(data.ApplicationId, msg.Token.ApplicationId);
            Assert.AreEqual <string>(data.MachineName, msg.MachineName);
        }
Ejemplo n.º 24
0
        public void RoundTripConfiguration()
        {
            var table = new AzureTable <ApplicationConfiguration>(ServerConfiguration.Default);
            var data  = new ApplicationConfiguration(Guid.NewGuid(), Guid.NewGuid().ToString())
            {
                Value = Guid.NewGuid().ToString(),
            };

            table.AddEntity(data);

            var adaptor = new TableAdaptor(data.ApplicationId);

            adaptor.Load(null);
            Assert.AreEqual <string>(data.Value, adaptor.Configuration[data.RowKey]);
        }
Ejemplo n.º 25
0
        public void GetConfigurationItem()
        {
            var user      = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var userTable = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            userTable.AddEntity(user);
            var userApp = new UserApplicationData(user.Id, user.ApplicationId)
            {
                Active = true
            };
            var table = new AzureTable <UserApplicationData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userApp);

            var core   = new ApplicationCore();
            var config = this.Config(userApp.ApplicationId);
            var u      = new Abc.Services.Contracts.User()
            {
                Identifier = userApp.UserId,
            };
            var a = new Abc.Services.Contracts.Application()
            {
                Identifier = user.ApplicationId,
            };
            var editor = new Abc.Services.Contracts.UserApplication()
            {
                User        = u,
                Application = a,
            };

            core.Save(config, editor);

            var query = new Abc.Services.Contracts.Configuration()
            {
                Token = config.Token,
                Key   = config.Key,
            };

            var returned = core.Get(query);

            Assert.IsNotNull(returned);
            Assert.AreEqual <int>(1, returned.Count());
            var item = returned.ToArray()[0];

            Assert.AreEqual <string>(config.Key, item.Key);
            Assert.AreEqual <string>(config.Value, item.Value);
        }
Ejemplo n.º 26
0
        public Guid Send(BinaryEmail email)
        {
            Contract.Requires <ArgumentNullException>(null != email);

            Contract.Requires <ArgumentOutOfRangeException>(!string.IsNullOrWhiteSpace(email.Sender));
            Contract.Requires <ArgumentOutOfRangeException>(!string.IsNullOrWhiteSpace(email.Recipient));

            Contract.Requires <ArgumentOutOfRangeException>(null != email.RawMessage);

            MailGun.Send(email.Sender, email.Recipient, email.RawMessage);

            var table = new AzureTable <BinaryEmailData>(ServerConfiguration.Default);
            var data  = email.Convert();

            table.AddEntity(data);

            return(data.Id);
        }
Ejemplo n.º 27
0
        public void GetUser()
        {
            var data  = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var table = new AzureTable <UserData>(ServerConfiguration.Default);

            table.AddEntity(data);

            var core    = new UserCore();
            var userApp = this.UserApp();

            userApp.User.Identifier        = data.Id;
            userApp.Application.Identifier = data.ApplicationId;
            var user = core.Get(userApp);

            Assert.AreEqual <Guid>(data.Id, user.Identifier);
            Assert.AreEqual <string>(data.Email, user.Email);
            Assert.AreEqual <string>(data.UserName, user.UserName);
        }
Ejemplo n.º 28
0
        public void Validate()
        {
            var emailValidationKey = StringHelper.ValidString();
            var app      = Application.Default;
            var email    = StringHelper.ValidString();
            var userData = new UserData(email, StringHelper.ValidString(), StringHelper.ValidString())
            {
                EmailValidationKey = emailValidationKey,
            };

            var table = new AzureTable <UserData>(CloudStorageAccount.DevelopmentStorageAccount);

            table.AddEntity(userData);

            var core          = new UserCore();
            var returnedEmail = core.SetRoles(app, userData.Id);

            Assert.AreEqual <string>(email, returnedEmail);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Blog Entry
        /// </summary>
        /// <param name="entry">Blog Entry</param>
        /// <returns>Blog Entry</returns>
        public BlogEntry Store(BlogEntry entry)
        {
            Contract.Requires <ArgumentNullException>(null != entry);
            Contract.Requires <ArgumentException>(Guid.Empty != entry.SectionIdentifier);
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(entry.Title));
            Contract.Requires <ArgumentException>(!string.IsNullOrWhiteSpace(entry.Content));

            Contract.Ensures(Contract.Result <BlogEntry>() != null);

            using (new PerformanceMonitor())
            {
                entry.Identifier = this.source.InsertText(entry.Content);

                var table = new AzureTable <BlogRow>(ServerConfiguration.Default);
                table.AddEntity(entry.Convert());
            }

            return(entry);
        }
Ejemplo n.º 30
0
        public void AddEntitiesEntityNull()
        {
            var table    = new AzureTable <Entity>(CloudStorageAccount.DevelopmentStorageAccount);
            var entities = new List <Entity>();
            var entity   = new Entity()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString()
            };

            entities.Add(entity);
            entities.Add(null);
            entity = new Entity()
            {
                PartitionKey = StringHelper.ValidString(),
                RowKey       = StringHelper.ValidString()
            };
            entities.Add(entity);
            table.AddEntity(entities);
        }
Ejemplo n.º 31
0
        public override void Run()
        {
            CloudStorageAccount.SetConfigurationSettingPublisher(
              (name, publisher) =>
              {
                  var connectionString = RoleEnvironment.GetConfigurationSettingValue(name);
                  publisher(connectionString);
              }
            );

            var account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            AzureQueue<NewCustomerCommand> queue = new AzureQueue<NewCustomerCommand>(account);
            queue.EnsureExist();

            while (true)
            {
            try
            {
                var message = queue.GetMessage();
                if (message != null)
                {
                    AzureTable<Customer> table = new AzureTable<Customer>(account);
                    var guiid= Guid.NewGuid().ToString();
                    table.AddEntity( new Customer
                    {
                        Id = Guid.NewGuid().ToString(),
                        PartitionKey = guiid,
                        RowKey = message.FirstName,
                        FirstName = message.FirstName,
                        LastName=message.LastName,
                        Address=message.Address,
                        Phone=message.Phone,
                        Email=message.Email
                    });
                    queue.DeleteMessage(message);
                }
            }
            catch { }
            Thread.Sleep(5000);
            }
        }
        private static IEnumerable<WebSiteRow> CreateAndSaveWebSiteRows(AzureTable<WebSiteRow> table, int count)
        {
            var sites = new List<WebSiteRow>();

            for (int k = 0; k < count; k++)
            {
                sites.Add(CreateWebSiteRow());
            }

            table.AddEntity(sites);

            return sites;
        }
 private static CertificateRow CreateAndSaveCertificateRow(AzureTable<CertificateRow> table)
 {
     CertificateRow info = CreateCertificateRow();
     table.AddEntity(info);
     return info;
 }
 private static WebSiteRow CreateAndSaveWebSiteRow(AzureTable<WebSiteRow> table)
 {
     WebSiteRow site = CreateWebSiteRow();
     table.AddEntity(site);
     return site;
 }
        private static IEnumerable<CertificateRow> CreateAndSaveCertificateRows(AzureTable<CertificateRow> table, int count)
        {
            List<CertificateRow> infos = new List<CertificateRow>();

            for (int k = 0; k < count; k++)
            {
                infos.Add(CreateCertificateRow());
            }

            table.AddEntity(infos);

            return infos;
        }