Example #1
0
        public void ArgumentParsingTest(string appName, string generateFlag)
        {
            ConsoleAppBase app = (ConsoleAppBase)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);
            if (!generateFlag.Equals(""))
            {
                app.AddArgument("generate", generateFlag);
                h.Add("generate", generateFlag);
            }

            Hashtable values = app.GetArguments();

            foreach (string key in values.Keys)
            {
                string value = (string)values[key];
                Assert.AreEqual(h[key].ToString(), value, "Arguments parsing incorrect!!!");
            }

            //Assert.AreEqual(h.Count, values.Count, "Number of argument parsed is incorrect!!!");

            //Test to cover code coverage
            app.DumpParameter();
        }
        public void ExecuteTest()
        {
            ConsoleAppBase app = (ConsoleAppBase)FactoryConsoleApplication.CreateConsoleApplicationObject("BarcodeMigrate");

            MBarcode existingData = new MBarcode();

            Mock <INoSqlContext> mockCtx = new Mock <INoSqlContext>();

            mockCtx.Setup(foo => foo.GetObjectByKey <MBarcode>("barcodes/8/0/5/2/1/5/8059699639/2154237147")).Returns(existingData);
            INoSqlContext ctx = mockCtx.Object;

            app.SetNoSqlContext(ctx);

            ILogger logger = new Mock <ILogger>().Object;

            app.SetLogger(logger);

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            createInputFile((String)h["infile"]);

            int result = app.Run();

            Assert.AreEqual(0, result);
        }
        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);
        }
Example #4
0
        public virtual CreateBarcode GetCreateBarcodeOperation()
        {
            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory());
            CreateBarcode opr = (CreateBarcode)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode");

            return(opr);
        }
Example #5
0
        public void GenerateBarcodeTest(string appName, int quantity, bool callFunc, bool generateFlag)
        {
            byte[] bytes = CreateDummyBitmap();

            var mockedConverter = new Mock <IHtmlConverter>();

            mockedConverter.Setup(p => p.FromHtmlString(It.IsAny <string>())).Returns(bytes);

            LabelGenerator generator = new LabelGenerator();

            generator.SetHtmlConverter(mockedConverter.Object);

            generatedCount = 0;

            BarcodeGeneratorApplication app = (BarcodeGeneratorApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            app.SetLabelGnerator(generator);
            app.SetFilePerFolder(10);
            app.SetProgressPerImage(2);
            if (callFunc)
            {
                app.SetUpdateProgressFunc(BarcodeGenerateProgressUpdate);
            }

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            //Update the same key if already exist
            app.AddArgument("outpath", Path.GetTempPath());
            app.AddArgument("quantity", quantity.ToString());

            imgGenerateFlag = false;
            if (generateFlag)
            {
                imgGenerateFlag = true;
                app.AddArgument("generate", "Y");
            }

            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            app.SetNoSqlContext(ctx);

            app.Run();

            if (callFunc)
            {
                Assert.AreEqual(quantity, generatedCount, "Generated file count is wrong!!!");
            }
        }
Example #6
0
        public void ResetBarcodeTest(string appName)
        {
            ResetBarcodeApplication app = (ResetBarcodeApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);
            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            app.SetNoSqlContext(ctx);

            //To cover test coverage
            app.GetLogger();

            app.Run();
            Assert.True(true);
        }
Example #7
0
        public void ImportProductFailedTest(string appName)
        {
            ImportProductApplication app = (ImportProductApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);
            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            string[] paths      = { tempPath, fileName };
            string   importFile = Path.Combine(paths);

            createFailedXML(importFile);

            INoSqlContext ctx = new Mock <INoSqlContext>().Object;

            app.SetNoSqlContext(ctx);

            app.Run();
            Assert.True(true);
        }
Example #8
0
        public void ResetBarcodeTest(string appName, bool IsActivated)
        {
            ResetBarcodeApplication app = (ResetBarcodeApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);
            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            MockedNoSqlContext ctx = new MockedNoSqlContext();

            MBarcode barcode = new MBarcode();

            barcode.IsActivated = IsActivated;
            ctx.SetReturnObjectByKey(barcode);
            app.SetNoSqlContext(ctx);

            //To cover test coverage
            app.GetLogger();

            app.Run();
            Assert.True(true);
        }
Example #9
0
        public void ArgumentParsingTest(string appName)
        {
            QRGeneratorApplication app = (QRGeneratorApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            Hashtable values = app.GetArguments();

            foreach (string key in values.Keys)
            {
                string value = (string)values[key];
                Assert.AreEqual(h[key].ToString(), value, "Arguments parsing incorrect!!!");
            }

            Assert.AreEqual(h.Count, values.Count, "Number of argument parsed is incorrect!!!");

            //Test to cover code coverage
            app.DumpParameter();
        }
Example #10
0
        public void Setup()
        {
            FactoryConsoleApplication.SetLoggerFactory(new Mock <ILoggerFactory>().Object);
            h = new Hashtable()
            {
                { "host", "xxxx.firebase.com" },
                { "key", "firebase_key" },
                { "infile", fileName },
                { "basedir", tempPath },
                { "user", "pjame" },
                { "password", "faked_password" },
            };

            args = new string[]
            {
                string.Format("--h={0}", h["host"]),
                string.Format("--k={0}", h["key"]),
                string.Format("--infile={0}", h["infile"]),
                string.Format("--basedir={0}", h["basedir"]),
                string.Format("--user={0}", h["user"]),
                string.Format("--password={0}", h["password"]),
            };
        }
Example #11
0
        public static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.WriteLine("Missing application name!!!");
                return;
            }

            FactoryBusinessOperation.ClearRegisteredItems();
            FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList());

            FactoryCacheContext.ClearRegisteredItems();
            FactoryCacheContext.RegisterCaches(BusinessErpCaches.GetInstance().ExportedServicesList());

            string appName = args[0];

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddSerilog());

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var loggerFactory   = serviceProvider.GetService <ILoggerFactory>();

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .CreateLogger();

            FactoryConsoleApplication.SetLoggerFactory(loggerFactory);
            IApplication app = FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            app.Run();
        }
Example #12
0
        public void GenerateQrTest(string appName)
        {
            byte[] bytes = CreateDummyBitmap();

            var mockedConverter = new Mock <IHtmlConverter>();

            mockedConverter.Setup(p => p.FromHtmlString(It.IsAny <string>())).Returns(bytes);

            QRGenerator generator = new QRGenerator();

            generator.SetHtmlConverter(mockedConverter.Object);

            QRGeneratorApplication app = (QRGeneratorApplication)FactoryConsoleApplication.CreateConsoleApplicationObject(appName);

            app.SetQrGnerator(generator);

            OptionSet opt = app.CreateOptionSet();

            opt.Parse(args);

            //Update the same key if already exist
            app.AddArgument("outpath", Path.GetTempPath());
            app.Run();
        }
        protected override int Execute()
        {
            logger = GetLogger();

            Hashtable args       = GetArguments();
            string    payloadUrl = args["url"].ToString();
            string    batch      = args["batch"].ToString();
            string    prof       = args["profile"].ToString();
            string    outputPath = args["outpath"].ToString();

            string generate = (string)args["generate"];

            if (generate == null)
            {
                generate = "";
            }

            bool imageGenerate = generate.Equals("Y");

            BarcodeProfileBase prf = (BarcodeProfileBase)BarcodeProfileFactory.CreateBarcodeProfileObject(prof);
            INoSqlContext      ctx = GetNoSqlContextWithAuthen("FirebaseNoSqlContext");

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

            int quantity = Int32.Parse(args["quantity"].ToString());

            MBarcode param = new MBarcode();

            param.BatchNo = batch;
            param.Url     = payloadUrl;

            string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss");

            generator.TemplateFile = prf.TemplateFile;
            generator.Setup();

            CreateExportFile(prof, param, outputPath, timeStamp);

            for (int i = 1; i <= quantity; i++)
            {
                string chunk   = ((i - 1) / imgPerFolder).ToString().PadLeft(6, '0');
                string urlPath = string.Format("{0}_{1}_{2}/{3}", prof, param.BatchNo, timeStamp, chunk);
                string dir     = string.Format("{0}/{1}", outputPath, urlPath);

                if (!Directory.Exists(dir) && imageGenerate)
                {
                    Directory.CreateDirectory(dir);
                }

                param.Path           = urlPath;
                param.CompanyWebSite = prf.CompanyWebSite;
                param.Barcode        = prf.Barcode;
                param.Product        = prf.Product;
                MBarcode bc = opr.Apply(param);

                string fileName = string.Format("{0}/{1}-{2}.png", dir, bc.SerialNumber, bc.Pin);
                if (imageGenerate)
                {
                    generator.RenderToFile(bc, fileName);
                }

                progressFunc(bc, dir);
                WriteExportFile(prf, bc, param);

                if ((i % progressPerImage) == 0)
                {
                    int remain = quantity - i;
                    LogUtils.LogInformation(logger, "Generated {0} barcodes, {1} barcodes to go...", i, remain);
                }
            }

            CloseExportFiles();

            generator.Cleanup();
            LogUtils.LogInformation(logger, "Done generating {0} barcodes.", quantity);

            int shipped = UpdateTotalShipped(quantity);

            LogUtils.LogInformation(logger, "Updated shipped number to {0}.", shipped);


            return(0);
        }