Esempio n. 1
0
        public void testAssertWithSubclassWithParent3()
        {
            Console.WriteLine("\nstart testAssertWithSubclassWithParent3");
            Rete engine = new Rete();

            engine.declareObject(typeof(IAccount), "account");
            engine.declareObject(typeof(BackupAccount), null, "account");
            engine.declareObject(typeof(DeletedAccount), null, typeof(BackupAccount));
            Assert.IsNotNull(engine);
            DeletedAccount acc1 = new DeletedAccount();

            acc1.AccountId   = "1234";
            acc1.AccountType = "new";
            acc1.First       = "fName";
            acc1.Last        = "lName";
            acc1.Middle      = "m";
            acc1.OfficeCode  = "MA";
            acc1.RegionCode  = "NE";
            acc1.Status      = "active";
            acc1.Title       = "MR";
            acc1.Username    = "******";
            try
            {
                engine.assertObject(acc1, null, false, true);
                Assert.IsTrue(true);
                Assert.AreEqual(1, engine.ObjectCount);
                Console.WriteLine("Number of facts: " + engine.ObjectCount);
                engine.printWorkingMemory(true, true);
            }
            catch (AssertException e)
            {
                Console.WriteLine(e.Message);
            }
            engine.close();
        }
Esempio 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);
        }
Esempio n. 3
0
 internal bool DeleteAccount(string accountName)
 {
     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);
             }
             foreach (StorageEmulatorConfigAccount value in StorageEmulatorConfigCache.Configuration.Accounts.Values)
             {
                 if (!value.Name.Equals(accountName))
                 {
                     continue;
                 }
                 throw new EmulatorException(EmulatorErrorCode.CannotDeleteDefaultAccount);
             }
             DeletedAccount deletedAccount = new DeletedAccount()
             {
                 Name         = accountName,
                 DeletionTime = DateTime.UtcNow
             };
             DeletedAccount deletedAccount1 = deletedAccount;
             dbContext.Accounts.DeleteOnSubmit(accounts.Single <Account>());
             dbContext.DeletedAccounts.InsertOnSubmit(deletedAccount1);
             dbContext.SubmitChanges();
             transactionScope.Complete();
         }
     }
     return(true);
 }