コード例 #1
0
        public void Store_factoryBuyConditionPolicy()
        {
            setup();

            String         details = " ( 2 , 2, 5 , 10 , 20 , 0 )";
            PurchasePolicy bcp     = store.factoryBuyConditionPolicy(1, details.Split(',').Length - 1, 0, details.Split(','), -1);


            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 1));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too few products");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too much products");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 2));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too cheap");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 3));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "too expensive");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 2));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(true, bcp.CheckCondition(cart, null), "proper");
        }
コード例 #2
0
        public Tuple <bool, string> UpdatePurchasePolicy(User user, PurchasePolicy purchasePolicy)
        {
            Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());

            if (!owners.Contains(user.Name) && !managers.Contains(user.Name))
            {
                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreErrorMessage.notAOwnerOrManagerErrMsg);
                return(new Tuple <bool, string>(false, CommonStr.StoreErrorMessage.notAOwnerOrManagerErrMsg));
            }

            if (managers.Contains(user.Name))
            {
                if (!user.getUserPermission(Id, CommonStr.MangerPermission.PurachsePolicy))
                {
                    Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreErrorMessage.ManagerNoPermissionErrMsg);
                    return(new Tuple <bool, string>(false, CommonStr.StoreErrorMessage.ManagerNoPermissionErrMsg));
                }
            }

            Tuple <bool, string> policycheck = IsValidPurchasePolicy(purchasePolicy);

            if (!policycheck.Item1)
            {
                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreErrorMessage.DiscountPolicyErrMessage);
                return(policycheck);
            }

            PurchasePolicy = purchasePolicy;
            //DB update Purchase Policy
            DbManager.Instance.UpdatePurchasePolicy(purchasePolicy, this, true);
            return(new Tuple <bool, string>(true, ""));
        }
コード例 #3
0
ファイル: IfThenCondition.cs プロジェクト: MaorSagi/wsep192
 public IfThenCondition(int id, PurchasePolicy ifCond, PurchasePolicy thenCond, LogicalConnections act)
 {
     this.id       = id;
     this.ifCond   = ifCond ?? throw new ArgumentNullException(nameof(ifCond));
     this.thenCond = thenCond ?? throw new ArgumentNullException(nameof(thenCond));
     this.act      = act;
 }
コード例 #4
0
        public void Store_addComplexPurchasePolicy_addComplexPurchasePolicy_inventoryConditionPolicy()
        {
            setup();
            String         details = " ( 2 , 2, 5 , 10 , 20 , 0 )";
            PurchasePolicy bcp     = store.addComplexPurchasePolicy(0, details);
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 1));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too few products");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too much products");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 2));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "Too cheap");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 3));
            Assert.AreEqual(false, bcp.CheckCondition(cart, null), "too expensive");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 2));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(true, bcp.CheckCondition(cart, null), "proper");
        }
コード例 #5
0
 public bool addChild(PurchasePolicy child)
 {
     if (!children.Contains(child))
     {
         children.Add(child);
         return(true);
     }
     return(false);
 }
コード例 #6
0
 public Store(int storeId, string storeName, string storeOwnerName)
 {
     products       = new List <Product>();
     buyingPolicy   = new BuyingPolicy();
     purchasePolicy = new PurchasePolicy();
     salesPolicy    = new SalesPolicy();
     storeOwners    = new List <string>();
     storeOwners.Add(storeOwnerName);
     storeID = storeId;
 }
コード例 #7
0
        public Tuple <bool, string> CheckIsValidBasket(PurchaseBasket basket)
        {
            Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());

            //checks if the basket accomodate the store's purchase policy
            if (!PurchasePolicy.IsEligiblePurchase(basket))
            {
                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreErrorMessage.BasketNotAcceptPurchasePolicy);
                return(new Tuple <bool, string>(false, CommonStr.StoreErrorMessage.BasketNotAcceptPurchasePolicy));
            }
            return(Inventory.isValidBasket(basket.Products));
        }
コード例 #8
0
        public override bool deleteChildren(PurchasePolicy purchasePolicy, MarketDbContext context)
        {
            bool leftremoved  = purchasePolicy.DeletePolicyRecursiveFromNotActivePolicies(PolicyLeftID, context);
            bool rightremoved = purchasePolicy.DeletePolicyRecursiveFromNotActivePolicies(PolicyRightID, context);
            bool resultDelete = leftremoved && rightremoved;

            if (resultDelete)
            {
                this.ChildrenPolicies = new List <APurchasePolicy>();
            }
            return(leftremoved && rightremoved);
        }
コード例 #9
0
 // will return true iff <param> purchasePolicy is a malformed policy, i.e failed
 // to parse, i.e if it is instance of ProductPurchasePolicy with negative precondition.
 public static bool CheckPurchasePolicy(PurchasePolicy purchasePolicy)
 {
     try
     {
         ProductPurchasePolicy productPurchasePolicy = ((ProductPurchasePolicy)purchasePolicy);
         return(productPurchasePolicy.PreCondition.PreConditionNumber < 0 ? false : true);
     }
     catch (Exception)
     {
         return(true);
     }
 }
コード例 #10
0
        public void Store_factoryLogicalCondition_complex()
        {
            setup();
            // true if buy p1 between 0-10 and the min inventory 5 or buy p2 between 0-10 and the min inventory 5
            String         details = "(5 ,( 5 , ( 0 , " + "p1" + " , 0 , 10 , 0 ) , ( 1 ," + "p1" + ", 5 , 0 ) , 0 , 0), ( 5 , ( 0 , " + "p2" + " , 0 , 10 , 0 ) , ( 1 ," + "p2" + ", 5 , 0 ) , 0 , 0) , 1 , 0 )";
            PurchasePolicy lcp     = store.factoryLogicalCondition(1, details.Split(',').Length - 1, 0, details.Split(','), 0);

            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, -1));

            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p1-Failure on condition is not satisfactory a");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, -1));
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p1-Failure on condition is not satisfactory b");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, -1));
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p1-then failure - the then condition are not satisfied");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, -1));

            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "p1-All conditions are to be satisfied");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, -1));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p2-Failure on condition is not satisfactory a");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 11));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p2-Failure on condition is not satisfactory b");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 6));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, lcp.CheckCondition(cart, null), "p2-then failure - the then condition are not satisfied");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 5));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "p2-All conditions are to be satisfied");

            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 5));
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, lcp.CheckCondition(cart, null), "Both-All conditions are to be satisfied");
        }
コード例 #11
0
        public void Store_addComplexPurchasePolicy_inventoryConditionPolicy()
        {
            setup();
            String         details = " ( 1 , 1, 5 , 0 )";
            PurchasePolicy icp     = store.addComplexPurchasePolicy(0, details);
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, pcp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, pcp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            Assert.AreEqual(false, pcp.CheckCondition(cart, null));
        }
コード例 #12
0
        public void Store_factoryinventoryConditionPolicy()
        {
            setup();
            String         details = " ( 1 , p1, 5 , 0 )";
            PurchasePolicy icp     = store.factoryinventoryConditionPolicy(1, details.Split(',').Length - 1, 0, details.Split(','), -1);
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(true, icp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, icp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            Assert.AreEqual(false, icp.CheckCondition(cart, null));
        }
コード例 #13
0
        public void init()
        {
            WebServices.DAL.CleanDB cDB = new WebServices.DAL.CleanDB();
            cDB.emptyDB();
            configuration.DB_MODE = testing;
            PPDB = new PurchasePolicyDB(testing);
            li   = new LinkedList <PurchasePolicy>();
            PurchasePolicy temp = new PurchasePolicy();

            temp.TypeOfPolicy     = 1;
            temp.ProductName      = "milk";
            temp.StoreId          = 1;
            temp.Category         = "";
            temp.ProductInStoreId = 1;
            temp.Country          = "";
            PPDB.Add(temp);
        }
コード例 #14
0
 public void AddPurchasePolicy()
 {
     try
     {
         PurchasePolicy toAdd = new PurchasePolicy();
         toAdd.TypeOfPolicy     = 1;
         toAdd.ProductName      = "meat";
         toAdd.StoreId          = 1;
         toAdd.Category         = "";
         toAdd.ProductInStoreId = 2;
         toAdd.Country          = "ISRAEL";
         PPDB.Add(toAdd);
         li = PPDB.Get();
         Assert.AreEqual(li.Count, 2);
     }
     catch (Exception e)
     { Assert.AreEqual(true, false, "there was a connection error to the testing db"); }
 }
コード例 #15
0
 public ComplexPurchasePolicy(string type, PurchasePolicy p1, PurchasePolicy p2)
 {
     if (type == "xor")
     {
         this.type = Type.xor;
     }
     else if (type == "or")
     {
         this.type = Type.or;
     }
     else
     {
         this.type = Type.and;
     }
     this.p1       = p1;
     this.p2       = p2;
     this.policyID = DBStore.getInstance().getNextPolicyID();
 }
コード例 #16
0
 public ComplexPurchasePolicy(string type, PurchasePolicy p1, PurchasePolicy p2, int policyID)
 {
     if (type == "xor")
     {
         this.type = Type.xor;
     }
     if (type == "or")
     {
         this.type = Type.or;
     }
     else
     {
         this.type = Type.and;
     }
     this.p1       = p1;
     this.p2       = p2;
     this.policyID = policyID;
 }
コード例 #17
0
        public void Store_factoryProductConditionPolicy()
        {
            setup();
            String details = "";

            details += " ( 0 , " + "p1" + " , 0 , 10 , 0 )";
            PurchasePolicy pcp = store.factoryProductConditionPolicy(1, details.Split(',').Length - 1, 0, details.Split(','), -1);
            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, pcp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, pcp.CheckCondition(cart, null));
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            Assert.AreEqual(false, pcp.CheckCondition(cart, null));
        }
コード例 #18
0
 public void RemovePurchasePolicy()
 {
     try
     {
         PurchasePolicy temp = new PurchasePolicy();
         temp.TypeOfPolicy     = 1;
         temp.ProductName      = "milk";
         temp.StoreId          = 1;
         temp.Category         = "";
         temp.ProductInStoreId = 1;
         temp.Country          = "";
         PPDB.Remove(temp);
         li = PPDB.Get();
         Assert.AreEqual(li.Count, 0);
     }
     catch (Exception e)
     { Assert.AreEqual(true, false, "there was a connection error to the testing db"); }
 }
コード例 #19
0
        public PurchasePolicyData ToPurchasePolicyData(PurchasePolicy policyData)
        {
            if (policyData.GetType() == typeof(ProductPurchasePolicy))
            {
                int policyProdutId = ((ProductPurchasePolicy)policyData).ProductId;
                int preCondition   = ((ProductPurchasePolicy)policyData).PreCondition.PreConditionNumber;
                return(new PurchasePolicyProductData(preCondition, policyProdutId));
            }

            else if (policyData.GetType() == typeof(BasketPurchasePolicy))
            {
                int preCondition = ((BasketPurchasePolicy)policyData).PreCondition.PreConditionNumber;
                return(new PurchasePolicyBasketData(preCondition));
            }

            else if (policyData.GetType() == typeof(SystemPurchasePolicy))
            {
                int storeId      = ((SystemPurchasePolicy)policyData).StoreId;
                int preCondition = ((SystemPurchasePolicy)policyData).PreCondition.PreConditionNumber;
                return(new PurchasePolicySystemData(preCondition, storeId));
            }

            else if (policyData.GetType() == typeof(UserPurchasePolicy))
            {
                int preCondition = ((UserPurchasePolicy)policyData).PreCondition.PreConditionNumber;
                return(new PurchasePolicyUserData(preCondition));
            }

            else if (policyData.GetType() == typeof(CompundPurchasePolicy))
            {
                int mergetype = ((CompundPurchasePolicy)policyData).mergeType;
                List <PurchasePolicy>     policies = ((CompundPurchasePolicy)policyData).getChildren();
                List <PurchasePolicyData> retList  = new List <PurchasePolicyData>();
                foreach (PurchasePolicy policy in policies)
                {
                    PurchasePolicyData newPolicyData = ToPurchasePolicyData(policy);
                    retList.Add(newPolicyData);
                }
                return(new CompoundPurchasePolicyData(mergetype, retList));
            }
            return(new PurchasePolicyData()); // not reached
        }
コード例 #20
0
        public void Store_addComplexPurchasePolicy_factoryUserConditionPolicy()
        {
            setup();

            String         details = " ( 3 , Tel Aviv , 1, 0 )";
            PurchasePolicy ucp     = store.addComplexPurchasePolicy(1, details);

            UserDetailes user = new UserDetailes("", false);

            Assert.AreEqual(false, ucp.CheckCondition(null, user), "Registeration and Adress check fail");

            user.Isregister = true;
            Assert.AreEqual(false, ucp.CheckCondition(null, user), "The adress check fail");

            user.Isregister = false;
            user.Adress     = "Tel Aviv";
            Assert.AreEqual(false, ucp.CheckCondition(null, user), "The registeretion check fail");

            user.Isregister = true;
            Assert.AreEqual(true, ucp.CheckCondition(null, user), "Registeration and Adress check fail");
        }
 internal void tearDown()
 {
     try
     {
         dataUsers.RemoveRange(dataUsers.ToList());
         adminUsers.RemoveRange(adminUsers.ToList());
         states.RemoveRange(states.ToList());
         statistics.RemoveRange(statistics.ToList());
         productInCarts.RemoveRange(productInCarts.ToList());
         membersShoppingBaskets.RemoveRange(membersShoppingBaskets.ToList());
         membersShoppingCarts.RemoveRange(membersShoppingCarts.ToList());
         appointers.RemoveRange(appointers.ToList());
         Prem.RemoveRange(Prem.ToList());
         managers.RemoveRange(managers.ToList());
         products.RemoveRange(products.ToList());
         addresses.RemoveRange(addresses.ToList());
         BidsManager.RemoveRange(BidsManager.ToList());
         transactionStatuses.RemoveRange(transactionStatuses.ToList());
         deliveryStatuses.RemoveRange(deliveryStatuses.ToList());
         purchasedProducts.RemoveRange(purchasedProducts.ToList());
         productHistoryDatas.RemoveRange(productHistoryDatas.ToList());
         paymentStatuses.RemoveRange(paymentStatuses.ToList());
         stores.RemoveRange(stores.ToList());
         PurchasePolicy.RemoveRange(PurchasePolicy.ToList());
         categories.RemoveRange(categories.ToList());
         marketRulesRequestType1.RemoveRange(marketRulesRequestType1.ToList());
         marketRulesRequestType2.RemoveRange(marketRulesRequestType2.ToList());
         marketRulesRequestType3.RemoveRange(marketRulesRequestType3.ToList());
         marketRulesRequestType4.RemoveRange(marketRulesRequestType4.ToList());
         marketRulesRequestType5.RemoveRange(marketRulesRequestType5.ToList());
         marketRulesRequestType6.RemoveRange(marketRulesRequestType6.ToList());
         marketRulesRequestType7.RemoveRange(marketRulesRequestType7.ToList());
         marketRulesRequestType8.RemoveRange(marketRulesRequestType8.ToList());
         SaveChanges();
     }
     catch (Exception e)
     {
     }
 }
コード例 #22
0
        public void Store_addComplexPurchasePolicy_factoryIfThenCondition()
        {
            setup();
            String         details = "( 4 , ( 0 , " + "p1" + " , 0 , 10 , 0 ) , ( 1 , p1, 5 , 0 ) , 0 )";
            PurchasePolicy itcp    = store.addComplexPurchasePolicy(0, details);

            List <KeyValuePair <ProductInStore, int> > cart = new List <KeyValuePair <ProductInStore, int> >();

            cart.Add(new KeyValuePair <ProductInStore, int>(ps2, 1));
            Assert.AreEqual(true, itcp.CheckCondition(cart, null), "The empty case - the product is not related to the purchase policy");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, -1));
            Assert.AreEqual(false, itcp.CheckCondition(cart, null), "Failure on condition is not satisfactory a");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 11));
            Assert.AreEqual(false, itcp.CheckCondition(cart, null), "Failure on condition is not satisfactory b");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 6));
            Assert.AreEqual(false, itcp.CheckCondition(cart, null), "then failure - the then condition are not satisfied");
            cart = new List <KeyValuePair <ProductInStore, int> >();
            cart.Add(new KeyValuePair <ProductInStore, int>(ps1, 5));
            Assert.AreEqual(true, itcp.CheckCondition(cart, null), "All conditions are to be satisfied");
        }
コード例 #23
0
        public Tuple <bool, string> UpdatePurchasePolicy(int storeId, string userName, string purchasePolicy)
        {
            //throw new NotImplementedException();
            Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod());
            User user = userManager.GetAtiveUser(userName);

            if (user == null)
            {
                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreMangmentErrorMessage.userNotFoundErrMsg);
                return(new Tuple <bool, string>(false, CommonStr.StoreMangmentErrorMessage.userNotFoundErrMsg));
            }
            if (!stores.ContainsKey(storeId))
            {
                Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod(), CommonStr.StoreMangmentErrorMessage.nonExistingStoreErrMessage);
                return(new Tuple <bool, string>(false, CommonStr.StoreMangmentErrorMessage.nonExistingStoreErrMessage));
            }
            PurchasePolicy parsedPurchase = PurchasePolicyParser.Parse(purchasePolicy);

            if (!PurchasePolicyParser.CheckPurchasePolicy(parsedPurchase))
            {
                return(new Tuple <bool, string>(false, CommonStr.StoreMangmentErrorMessage.PurchasePolicyParsedFailed));
            }
            return(stores[storeId].UpdatePurchasePolicy(user, parsedPurchase));
        }
コード例 #24
0
ファイル: APurchasePolicy.cs プロジェクト: benshyuv/Workshop
 public abstract bool deleteChildren(PurchasePolicy purchasePolicy, MarketDbContext context);
コード例 #25
0
 public bool removeChild(PurchasePolicy child)
 {
     return(children.Remove(child));
 }
コード例 #26
0
        public static PurchasePolicy Parse(string text)
        {
            bool simplePolicy = prefixes.Any(prefix => text.StartsWith(prefix));

            if (simplePolicy)
            {
                if (productPurchasePolicyMinRegex.IsMatch(text)) // (p_min:precondition:productId:minAmount)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    int      productId    = Convert.ToInt32(constructs[2]);
                    int      minAmount    = Convert.ToInt32(constructs[3]);
                    return(new ProductPurchasePolicy(new PurchasePreCondition(precondition), productId, minAmount));
                }
                else if (productPurchasePolicyMaxRegex.IsMatch(text)) // (p_max:precondition:productId:maxAmount)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    int      productId    = Convert.ToInt32(constructs[2]);
                    int      maxAmount    = Convert.ToInt32(constructs[3]);
                    return(new ProductPurchasePolicy(maxAmount, new PurchasePreCondition(precondition), productId));
                }
                else if (basketPurchasePolicyRegex.IsMatch(text)) // (b:precondition)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    return(new BasketPurchasePolicy(new PurchasePreCondition(precondition)));
                }
                else if (basketPurchasePolicyMaxBasketRegex.IsMatch(text)) // (b_maxBasket:precondition:maxBasketPrice)
                {
                    string[] constructs     = text.Split(':');
                    int      precondition   = Convert.ToInt32(constructs[1]);
                    double   maxBasketPrice = Convert.ToDouble(constructs[2]);
                    return(new BasketPurchasePolicy(new PurchasePreCondition(precondition), maxBasketPrice));
                }
                else if (basketPurchasePolicyMinBasketRegex.IsMatch(text)) // (b_minBasket:precondition:minBasketPrice)
                {
                    string[] constructs     = text.Split(':');
                    int      precondition   = Convert.ToInt32(constructs[1]);
                    double   minBasketPrice = Convert.ToDouble(constructs[2]);
                    return(new BasketPurchasePolicy(minBasketPrice, new PurchasePreCondition(precondition)));
                }
                else if (basketPurchasePolicyMaxItemsRegex.IsMatch(text)) // (b_maxItems:precondition:maxItems)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    int      maxItems     = Convert.ToInt32(constructs[2]);
                    return(new BasketPurchasePolicy(new PurchasePreCondition(precondition), maxItems));
                }
                else if (basketPurchasePolicyMinItemsRegex.IsMatch(text)) // (b_minItems:precondition:minItems)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    int      minItems     = Convert.ToInt32(constructs[2]);
                    return(new BasketPurchasePolicy(minItems, new PurchasePreCondition(precondition)));
                }
                else if (systemPurchasePolicyRegex.IsMatch(text)) // (s:preCondition:storeID)
                {
                    string[] constructs   = text.Split(':');
                    int      preCondition = Convert.ToInt32(constructs[1]);
                    int      storeID      = Convert.ToInt32(constructs[2]);
                    return(new SystemPurchasePolicy(new PurchasePreCondition(preCondition), storeID));
                }
                else if (userPurchasePolicyRegex.IsMatch(text)) // (u:precondition)
                {
                    string[] constructs   = text.Split(':');
                    int      precondition = Convert.ToInt32(constructs[1]);
                    //string username = constructs[2];
                    return(new UserPurchasePolicy(new PurchasePreCondition(precondition)));
                }
            }
            else // compound purchase policy
            {
                int      counter    = 0;
                string   curr       = "";
                string[] constructs = Regex.Split(text, "(XOR|OR|AND)");
                if (constructs.Length <= 1)
                {
                    return(new ProductPurchasePolicy(new PurchasePreCondition(-1), -1, -1));
                }
                string opStr = constructs[1];
                int    op    = opStr == "XOR" ? 0 : opStr == "OR" ? 1 : opStr == "AND" ? 2 : -1;
                if (op == -1)
                {
                    return(new ProductPurchasePolicy(new PurchasePreCondition(-3), -3, -3));
                }
                string        restText = text.Substring(opStr.Length + 2, text.Length - 1 - opStr.Length - 2);
                List <string> policies = new List <string>();
                for (int i = 0; i < restText.Length; i++)
                {
                    if (restText[i] == '(')
                    {
                        if (counter == 0) // shift from 0 to 1 -> new element
                        {
                            curr = "";
                        }
                        counter++;
                    }
                    else if (restText[i] == ')')
                    {
                        if (counter == 1) // shift from 1 to 0 -> finish the current element
                        {
                            curr += restText[i];
                            policies.Add(curr);
                            curr = "";
                        }
                        counter--;
                    }
                    else if (restText[i] == ' ' && counter == 0)
                    {
                        if (!policies.Contains(curr) && curr != "")
                        {
                            policies.Add(curr);
                            curr = "";
                        }
                    }
                    if (!(counter == 0 || curr == ")"))
                    {
                        curr += restText[i];
                    }
                    if (counter == 0 && restText[i] != ')' && restText[i] != '(' && restText[i] != ' ')
                    {
                        curr += restText[i];
                    }
                }
                if (curr != "")
                {
                    policies.Add(curr);
                }
                if (counter != 0)
                {
                    return(new ProductPurchasePolicy(new PurchasePreCondition(-1), -1, -1));
                }

                List <PurchasePolicy> children = new List <PurchasePolicy>();

                foreach (string policy in policies)
                {
                    PurchasePolicy purchasePolicy = Parse(policy);
                    if (CheckPurchasePolicy(purchasePolicy) == false) // this indicates an error!
                    {
                        return(new ProductPurchasePolicy(new PurchasePreCondition(-2), -2, -2));
                    }
                    else
                    {
                        children.Add(purchasePolicy);
                    }
                }
                PurchasePolicy compoundPolicy = new CompundPurchasePolicy(op, children);
                return(compoundPolicy);
            }
            return(new ProductPurchasePolicy(new PurchasePreCondition(-4), -4, -4));
        }
コード例 #27
0
 public void remove(PurchasePolicy purchasePolicy)
 {
     children.Remove(purchasePolicy);
 }
コード例 #28
0
 public void add(PurchasePolicy purchasePolicy)
 {
     children.Add(purchasePolicy);
 }
コード例 #29
0
 public ManagerStub(Store store, User user, PurchasePolicy retPurchasePolicy, int permissions) : base(store, user, retPurchasePolicy)
 {
     permission = permissions;
 }
コード例 #30
0
 public RoleStub(Store store, User user, PurchasePolicy retVal) : base(store, user)
 {
     this.retPurchasePolicy = retVal;
 }