Пример #1
0
        protected override object Apply(string oprName, BaseModel m)
        {
            var       mnplOpr = (ManipulationOperation)FactoryBusinessOperation.CreateBusinessOperationObject(oprName);
            BaseModel o       = mnplOpr.Apply(m);

            return(o);
        }
Пример #2
0
        protected override object Apply(string oprName, BaseModel m)
        {
            var  isExistOpr = (IsExistOperation)FactoryBusinessOperation.CreateBusinessOperationObject(oprName);
            bool isExist    = isExistOpr.Apply(m);

            return(isExist);
        }
        protected override int Execute()
        {
            Hashtable args   = GetArguments();
            string    serial = args["serial"].ToString();
            string    pin    = args["pin"].ToString();
            string    ip     = args["ip"].ToString();

            INoSqlContext ctx = GetNoSqlContextWithAuthen("firebase");

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory());
            CreateRegistration opr = (CreateRegistration)FactoryBusinessOperation.CreateBusinessOperationObject("CreateRegistration");

            MRegistration param = new MRegistration();

            param.IP           = ip;
            param.Pin          = pin;
            param.SerialNumber = serial;

            try
            {
                opr.Apply(param);
                Console.WriteLine("Done register barcode [{0}] [{1}]", serial, pin);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e.Message);
            }

            return(0);
        }
Пример #4
0
        private void processAll()
        {
            Hashtable   args    = GetArguments();
            string      basedir = args["basedir"].ToString();
            ILogger     logger  = GetLogger();
            SaveProduct opr     = (SaveProduct)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProduct");
            CTable      t       = XmlToCTable();

            ArrayList products = t.GetChildArray("Products");

            foreach (CTable pd in products)
            {
                MProduct mpd = new MProduct();
                mpd.Code        = pd.GetFieldValue("Code");
                mpd.Rating      = Int32.Parse(pd.GetFieldValue("Rating"));
                mpd.ProductType = pd.GetFieldValue("ProductType");
                mpd.Price       = Double.Parse(pd.GetFieldValue("Price"));
                mpd.NameColor   = pd.GetFieldValue("NameColor");
                mpd.NameBgColor = pd.GetFieldValue("NameBgColor");

                string[] imgPaths = { basedir, pd.GetFieldValue("Image1LocalPath") };
                mpd.Image1LocalPath = Path.Combine(imgPaths);

                processDescriptions(pd, mpd);
                processCompositionGroups(pd, mpd);
                processPerformances(pd, mpd);

                LogUtils.LogInformation(logger, "Adding product : [{0}]", mpd.Code);
                opr.Apply(mpd);
            }
        }
        protected override object Apply(string oprName, BaseModel m)
        {
            var       getInfoOpr = (GetInfoOperation)FactoryBusinessOperation.CreateBusinessOperationObject(oprName);
            BaseModel o          = getInfoOpr.Apply(m);

            return(o);
        }
        public void UpdateExisting()
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            MMetric existing = new MMetric();

            existing.Key   = "PageViews";
            existing.Value = 5;
            ctx.SetReturnObjectByKey <MMetric>(existing);

            var opt = (IBusinessOperationManipulate <MMetric>)FactoryBusinessOperation.CreateBusinessOperationObject("IncreaseAndRetrieveMetric");

            MMetric dat = new MMetric();

            dat.Key   = "PageViews";
            dat.Value = 5;

            try
            {
                int result = opt.Apply(dat);
                Assert.AreEqual(10, result);
            }
            catch (Exception)
            {
                Assert.Fail("Exception should not be thrown here!!!");
            }
        }
Пример #7
0
        public virtual CreateBarcode GetCreateBarcodeOperation()
        {
            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory());
            CreateBarcode opr = (CreateBarcode)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode");

            return(opr);
        }
Пример #8
0
        public virtual JsonResult GetInfo(int id)
        {
            var opr = (GetInfoOperation)FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            BaseModel m        = GetModel(id, "");
            var       response = opr.Apply(m);
            var       result   = new JsonResult(response);

            return(result);
        }
        public JsonResult Delete(int id)
        {
            var opr = (ManipulationOperation)FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            BaseModel m        = GetModel(id, "");
            BaseModel response = opr.Apply(m);
            var       result   = new JsonResult(response);

            return(result);
        }
        public virtual JsonResult Get()
        {
            var opr = (GetListOperation)FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            var qrp      = new QueryRequestParam();
            var response = opr.Apply(qrp);

            var result = new JsonResult(response);

            return(result);
        }
        public string ExecuteGetListOperation(string oprName, Hashtable args)
        {
            var opr = (GetListOperation)FactoryBusinessOperation.CreateBusinessOperationObject(oprName);

            string jsonFile = args["if"].ToString();
            string content  = File.ReadAllText(jsonFile);

            var qrp = (QueryRequestParam)JsonConvert.DeserializeObject <QueryRequestParam>(content);

            QueryResponseParam response = opr.Apply(qrp);

            string json = JsonConvert.SerializeObject(response, Formatting.Indented);

            return(json);
        }
Пример #12
0
        public void DeleteProductAnyCaseTest()
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            var opt = (IBusinessOperationManipulate <MProduct>)FactoryBusinessOperation.CreateBusinessOperationObject("DeleteProduct");

            MProduct pd = new MProduct();

            pd.Code = "MockedCode";
            pd.Key  = "FAKED_NOTFOUNDKEY";

            var result = opt.Apply(pd);

            Assert.AreEqual(1, result, "Row affected should be returned !!!");
        }
        public void CreateRegistrationWithCodeNotFoundTest(bool barcodeFound, bool isActivated, string keyword)
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            if (barcodeFound)
            {
                MBarcode bc = new MBarcode();
                bc.IsActivated = isActivated;
                ctx.SetReturnObjectByKey(bc);
            }

            var opt = (IBusinessOperationManipulate <MRegistration>)FactoryBusinessOperation.CreateBusinessOperationObject("CreateRegistration");

            MRegistration rg = new MRegistration();

            rg.Pin          = "9999999999";
            rg.SerialNumber = "ABCDEFGHIJKLM";
            rg.IP           = "192.168.0.1";

            bool shouldThrow = !barcodeFound || isActivated;

            if (shouldThrow)
            {
                try
                {
                    opt.Apply(rg);
                    Assert.Fail("Exception should be thrown here!!!");
                }
                catch (Exception ex)
                {
                    string msg          = ex.Message;
                    bool   foundKeyword = msg.Contains(keyword);
                    Assert.AreEqual(true, foundKeyword, "Should get [{0}] error!!!", keyword);
                }
            }
            else
            {
                //Found barcode and not yet activated
                opt.Apply(rg);

                //Status wrote back to input parameter
                Assert.AreEqual("SUCCESS", rg.Status);
            }
        }
Пример #14
0
        public void GenericGetProductListTest(string code)
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationQuery <MContent>)FactoryBusinessOperation.CreateBusinessOperationObject("GetContentList");

            try
            {
                opt.Apply(null, null);
            }
            catch (Exception)
            {
                Assert.Fail("Exception should not be thrown here!!!");
            }
        }
Пример #15
0
        public virtual JsonResult Update(int id, [FromForm] FormSubmitParam prm = null)
        {
            var opr = (ManipulationOperation)FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            string content = "";

            if ((prm != null) && (!String.IsNullOrEmpty(prm.JsonContent)))
            {
                content = prm.JsonContent;
            }

            BaseModel m        = GetModel(id, content);
            var       response = opr.Apply(m);
            var       result   = new JsonResult(response);

            return(result);
        }
        public void Apply()
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationQuery <MMetricWrapper>)FactoryBusinessOperation.CreateBusinessOperationObject("RetrieveMetric");

            try
            {
                opt.Apply(null, null);
            }
            catch (Exception)
            {
                Assert.Fail("Exception should not be thrown here!!!");
            }
        }
        public void GetProductTypeNotFoundTest()
        {
            MProductType       prdReturned = null;
            MockedNoSqlContext ctx         = new MockedNoSqlContext();

            ctx.SetReturnObjectByKey(prdReturned);

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo");

            MProductType pd = new MProductType();

            pd.Code = "MockedCode";

            var result = opt.Apply(pd);

            Assert.AreEqual(null, result, "Product type not found should return null!!!");
        }
Пример #18
0
        public void CreateBarcodeWithMigrationModeTest(string serial, string pin, string payload)
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var      opt = (IBusinessOperationGetInfo <MBarcode>)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode");
            MBarcode bc  = new MBarcode();

            bc.SerialNumber = serial;
            bc.Pin          = pin;
            bc.PayloadUrl   = payload;

            MBarcode barcode1 = opt.Apply(bc);

            Assert.AreEqual(serial, barcode1.SerialNumber, "SerialNumber must be the same!!!");
            Assert.AreEqual(pin, barcode1.Pin, "Pin must be the same!!!");
            Assert.AreEqual(payload, barcode1.PayloadUrl, "Payload URL must be the same!!!");
        }
        protected override int Execute()
        {
            ILogger logger = GetLogger();
            CTable  t      = XmlToCTable();

            INoSqlContext ctx = GetNoSqlContextWithAuthen("firebase");

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            SaveProductType opr = (SaveProductType)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProductType");

            try
            {
                ArrayList types = t.GetChildArray("ProductTypes");
                foreach (CTable pt in types)
                {
                    MProductType mpt = new MProductType();
                    mpt.Code = pt.GetFieldValue("Code");

                    ArrayList descs = pt.GetChildArray("Descriptions");
                    foreach (CTable desc in descs)
                    {
                        MGenericDescription mdc = new MGenericDescription();
                        mdc.Language         = desc.GetFieldValue("Language");
                        mdc.Name             = desc.GetFieldValue("Name");
                        mdc.ShortDescription = desc.GetFieldValue("ShortDescription");
                        mdc.LongDescription1 = desc.GetFieldValue("LongDescription");

                        mpt.Descriptions.Add(mdc.Language, mdc);
                        LogUtils.LogInformation(logger, "Adding product type : [{0}] [{1}]", mpt.Code, mdc.Name);
                    }

                    opr.Apply(mpt);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e.Message);
            }

            return(0);
        }
Пример #20
0
        protected override int Execute()
        {
            ILogger logger = GetLogger();
            CTable  t      = XmlToCTable();

            INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext");

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            SaveContent opr = (SaveContent)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            try
            {
                ArrayList types = t.GetChildArray("Contents");
                foreach (CTable pt in types)
                {
                    MContent mc = new MContent();
                    mc.Name          = pt.GetFieldValue("Name");
                    mc.Type          = pt.GetFieldValue("Type");
                    mc.LastMaintDate = DateTime.Now;
                    ArrayList values = pt.GetChildArray("Values");

                    foreach (CTable value in values)
                    {
                        mc.Values = new Dictionary <string, string>();
                        foreach (CField field in value.GetTableFields())
                        {
                            mc.Values[field.GetName()] = field.GetValue();
                        }
                        LogUtils.LogInformation(logger, "Adding content : [{0}][{1}]", mc.Type, mc.Name);
                    }

                    opr.Apply(mc);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error : {0}", e);
            }

            return(0);
        }
Пример #21
0
        public void SaveTest()
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationManipulate <MContactUs>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContactUs");

            MContactUs dat = new MContactUs();

            try
            {
                int result = opt.Apply(dat);
                Assert.AreEqual(result, 0);
            }
            catch (Exception)
            {
                //Do nothing
            }
        }
Пример #22
0
        public void SaveProductTypeByAddingTheNewOneTest()
        {
            MProductType prdReturned = null;

            MockedNoSqlContext ctx = new MockedNoSqlContext();

            ctx.SetReturnObjectByKey(prdReturned);

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProductType");

            MProductType pd = new MProductType();

            pd.Code = "MockedCode";

            var result = opt.Apply(pd);

            Assert.AreEqual(null, result, "Expected null to return !!!");
        }
Пример #23
0
        //Use POST method with the Get* operations with parameters to prevent the issue when deploy to Google Cloud Run
        //This is an example of issue - HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)
        public virtual JsonResult CreateWithParam([FromForm] FormSubmitParam prm = null)
        {
            object response = null;

            string content = "";

            if ((prm != null) && (!String.IsNullOrEmpty(prm.JsonContent)))
            {
                content = prm.JsonContent;
            }

            var opr = FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            BaseModel m = GetModel(null, content);

            response = (opr as ManipulationOperation).Apply(m);

            var result = new JsonResult(response);

            return(result);
        }
        public void GetProductTypeFoundTest(string code)
        {
            MProductType prdReturned = new MProductType();

            prdReturned.Code = code;

            MockedNoSqlContext ctx = new MockedNoSqlContext();

            ctx.SetReturnObjectByKey(prdReturned);

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo");

            MProductType pd = new MProductType();

            pd.Code = "MockedCode";

            var result = opt.Apply(pd);

            Assert.AreEqual(code, result.Code, "Return product type code should be [{0}]!!!", code);
        }
Пример #25
0
        public void SaveBlankObject()
        {
            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationManipulate <MContent>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveContent");

            MContent dat = new MContent();

            try
            {
                int result = opt.Apply(dat);
                Assert.Fail();
            }
            catch (Exception)
            {
                //Error should be thrown.
                Assert.Pass();
            }
        }
        public void GenericGetProductListTest(string code)
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationQuery <MProduct>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductList");

            MProduct pd = new MProduct();

            pd.Code = code;

            try
            {
                opt.Apply(pd, null);
            }
            catch (Exception)
            {
                Assert.Fail("Exception should not be thrown here!!!");
            }
        }
        public void GetProductTypeWithEmptyTest(string code)
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationGetInfo <MProductType>)FactoryBusinessOperation.CreateBusinessOperationObject("GetProductTypeInfo");

            MProductType pd = new MProductType();

            pd.Code = code;

            try
            {
                opt.Apply(pd);
                Assert.Fail("Exception should be thrown");
            }
            catch (Exception)
            {
                //Do nothing
            }
        }
Пример #28
0
        public void DeleteProductWithEmptyTest(string code)
        {
            MockedNoSqlContext ctx = new MockedNoSqlContext();

            FactoryBusinessOperation.SetNoSqlContext(ctx);

            var opt = (IBusinessOperationManipulate <MProduct>)FactoryBusinessOperation.CreateBusinessOperationObject("DeleteProduct");

            MProduct pd = new MProduct();

            pd.Code = code;

            try
            {
                opt.Apply(pd);
                Assert.Fail("Exception should be thrown");
            }
            catch (Exception)
            {
                //Do nothing
            }
        }
        //Use POST method with the Get* operations with parameters to prevent the issue when deploy to Google Cloud Run
        //This is an example of issue - HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)
        public virtual JsonResult GetWithParam([FromForm] FormSubmitParam prm = null)
        {
            object response = null;

            string content = "";

            if ((prm != null) && (!String.IsNullOrEmpty(prm.JsonContent)))
            {
                content = prm.JsonContent;
            }

            var opr = FactoryBusinessOperation.CreateBusinessOperationObject(ApiName);

            var qrp = new QueryRequestParam();

            qrp      = JsonConvert.DeserializeObject <QueryRequestParam>(content);
            response = (opr as GetListOperation).Apply(qrp);

            var result = new JsonResult(response);

            return(result);
        }
Пример #30
0
        public void SaveProductByAddingTheNewOneTest()
        {
            MProduct prdReturned = null;

            IStorageContext    storageCtx = new Mock <IStorageContext>().Object;
            MockedNoSqlContext ctx        = new MockedNoSqlContext();

            ctx.SetReturnObjectByKey(prdReturned);

            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetStorageContext(storageCtx);

            var opt = (IBusinessOperationGetInfo <MProduct>)FactoryBusinessOperation.CreateBusinessOperationObject("SaveProduct");

            MProduct pd = new MProduct();

            pd.Code = "MockedCode";
            pd.Key  = "FAKED_NOTFOUNDKEY";

            var result = opt.Apply(pd);

            Assert.AreEqual(null, result, "Expected null to return !!!");
        }