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 int Execute() { Hashtable args = GetArguments(); string serial = args["serial"].ToString(); string pin = args["pin"].ToString(); INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); FactoryBusinessOperation.SetNoSqlContext(ctx); FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory()); ResetRegistration opr = (ResetRegistration)FactoryBusinessOperation.CreateBusinessOperationObject("ResetRegistration"); MRegistration param = new MRegistration(); param.Pin = pin; param.SerialNumber = serial; try { opr.Apply(param); Console.WriteLine("Done reset barcode [{0}] [{1}]", serial, pin); } catch (Exception e) { Console.WriteLine("Error : {0}", e.Message); } return(0); }
public OnixControllerBase(BaseDbContext ctx, string api, string pk, Type t) { pkName = pk; modelType = t; apiName = api; FactoryBusinessOperation.SetDatabaseContext(ctx); }
public virtual CreateBarcode GetCreateBarcodeOperation() { FactoryBusinessOperation.SetNoSqlContext(ctx); FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory()); CreateBarcode opr = (CreateBarcode)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode"); return(opr); }
public BaseTest() { FactoryBusinessOperation.ClearRegisteredItems(); FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList()); FactoryCacheContext.ClearRegisteredItems(); FactoryCacheContext.RegisterCaches(BusinessErpCaches.GetInstance().ExportedServicesList()); }
public static void LoadBusinessOperations() { if (!isLoad) { var servicesList = BusinessErpOperations.GetInstance().ExportedServicesList(); FactoryBusinessOperation.RegisterBusinessOperations(servicesList); isLoad = true; } }
protected OnixErpDbContext CreateOnixDbContext() { DbCredential crd = new DbCredential("", 9999, "", "", "", "sqlite_inmem"); ctx = new OnixErpDbContext(crd); ctx.Database.EnsureCreated(); FactoryBusinessOperation.SetDatabaseContext(ctx); return(ctx); }
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 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 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); }
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 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!!!"); } }
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 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); } }
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!!!"); }
public void GenericExceptionTest(string db, string provider) { Assembly asm = Assembly.GetExecutingAssembly(); CreateOnixDbContext(db, provider); FactoryBusinessOperation.RegisterBusinessOperation(asm, "OperationMocked", "Its.Onix.Erp.Businesses.Commons.OperationMocked"); var opr = CreateManipulateOperation("OperationMocked"); try { opr.Apply(null); Assert.Fail("InvalidOperationException should be thrown here!!!"); } catch (InvalidOperationException) { Assert.Pass(); } }
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); }
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); }
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 } }
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 !!!"); }
//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); }
protected override int Execute() { INoSqlContext ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext"); FactoryBusinessOperation.SetNoSqlContext(ctx); IStorageContext storageCtx = GetStorageContextWithAuthen("FirebaseStorageContext"); FactoryBusinessOperation.SetStorageContext(storageCtx); try { processAll(); } catch (Exception e) { Console.WriteLine("Error : {0}", e.StackTrace); } return(0); }
public Startup(IConfiguration configuration) { var loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Its", LogLevel.Warning) .AddConsole(); }); string host = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST"); string dbname = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME"); string user = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER"); string password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD"); crd = new DbCredential(host, 5432, dbname, user, password, "pgsql"); Configuration = configuration; FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList()); FactoryBusinessOperation.SetLoggerFactory(loggerFactory); }
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 } }