Ejemplo n.º 1
0
        internal EmulatorStorageAccount UpdateAccount(string accountName, bool?secondaryReadEnabled)
        {
            EmulatorStorageAccount emulatorStorageAccount;

            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
            {
                using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    IEnumerable <Account> accounts =
                        from a in dbContext.Accounts
                        where a.Name == accountName
                        select a;
                    if (accounts == null || accounts.Count <Account>() == 0)
                    {
                        throw new EmulatorException(EmulatorErrorCode.AccountNotFound);
                    }
                    Account account  = accounts.Single <Account>();
                    Account account1 = account;
                    bool?   nullable = secondaryReadEnabled;
                    account1.SecondaryReadEnabled = (nullable.HasValue ? nullable.GetValueOrDefault() : account.SecondaryReadEnabled);
                    emulatorStorageAccount        = new EmulatorStorageAccount(account.Name, Convert.ToBase64String(account.SecretKey), Convert.ToBase64String(account.SecondaryKey), account.SecondaryReadEnabled);
                    dbContext.SubmitChanges();
                    transactionScope.Complete();
                }
            }
            return(emulatorStorageAccount);
        }
Ejemplo n.º 2
0
        internal EmulatorStorageAccount CreateAccount(string accountName, string primaryKey, string secondaryKey, bool secondaryReadEnabled)
        {
            Account account;

            byte[] numArray  = (primaryKey == null ? StorageContext.GenerateKey() : Convert.FromBase64String(primaryKey));
            byte[] numArray1 = (secondaryKey == null ? StorageContext.GenerateKey() : Convert.FromBase64String(secondaryKey));
            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
            {
                using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    IEnumerable <Account> accounts =
                        from a in dbContext.Accounts
                        where a.Name == accountName
                        select a;
                    if (accounts != null && accounts.Count <Account>() > 0)
                    {
                        throw new EmulatorException(EmulatorErrorCode.AccountAlreadyExists);
                    }
                    IEnumerable <DeletedAccount> deletedAccounts =
                        from a in dbContext.DeletedAccounts
                        where a.Name == accountName
                        select a;
                    if (deletedAccounts != null && deletedAccounts.Count <DeletedAccount>() > 0)
                    {
                        DeletedAccount deletedAccount = deletedAccounts.Single <DeletedAccount>();
                        if ((deletedAccount.DeletionTime + Constants.AccountRecreationTimeLimit) > DateTime.UtcNow)
                        {
                            throw new EmulatorException(EmulatorErrorCode.NeedToWaitForAccountDeletion);
                        }
                        dbContext.DeletedAccounts.DeleteOnSubmit(deletedAccount);
                    }
                    Account account1 = new Account()
                    {
                        Name                 = accountName,
                        SecretKey            = numArray,
                        SecondaryKey         = numArray1,
                        SecondaryReadEnabled = secondaryReadEnabled
                    };
                    account = account1;
                    dbContext.Accounts.InsertOnSubmit(account);
                    dbContext.SubmitChanges();
                    transactionScope.Complete();
                }
            }
            EmulatorStorageAccount emulatorStorageAccount = new EmulatorStorageAccount(account.Name, Convert.ToBase64String(account.SecretKey), Convert.ToBase64String(account.SecondaryKey), account.SecondaryReadEnabled);

            return(emulatorStorageAccount);
        }
Ejemplo n.º 3
0
        internal IEnumerable <EmulatorStorageAccount> ListAccounts()
        {
            List <Account> list;

            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
            {
                IEnumerable <Account> accounts =
                    from a in dbContext.Accounts
                    select a;
                list = accounts.ToList <Account>();
            }
            List <EmulatorStorageAccount> emulatorStorageAccounts = new List <EmulatorStorageAccount>();

            foreach (Account account in list)
            {
                EmulatorStorageAccount emulatorStorageAccount = new EmulatorStorageAccount(account.Name, Convert.ToBase64String(account.SecretKey), Convert.ToBase64String(account.SecondaryKey), account.SecondaryReadEnabled);
                emulatorStorageAccounts.Add(emulatorStorageAccount);
            }
            return(emulatorStorageAccounts);
        }
Ejemplo n.º 4
0
        internal EmulatorStorageAccount GetAccount(string accountName)
        {
            EmulatorStorageAccount emulatorStorageAccount;

            using (DevelopmentStorageDbDataContext dbContext = DevelopmentStorageDbDataContext.GetDbContext())
            {
                IEnumerable <Account> accounts =
                    from a in dbContext.Accounts
                    where a.Name == accountName
                    select a;
                if (accounts == null || accounts.Count <Account>() == 0)
                {
                    throw new EmulatorException(EmulatorErrorCode.AccountNotFound);
                }
                Account account = accounts.Single <Account>();
                EmulatorStorageAccount emulatorStorageAccount1 = new EmulatorStorageAccount(account.Name, Convert.ToBase64String(account.SecretKey), Convert.ToBase64String(account.SecondaryKey), account.SecondaryReadEnabled);
                emulatorStorageAccount = emulatorStorageAccount1;
            }
            return(emulatorStorageAccount);
        }