Пример #1
0
        private static void Init()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddSerilog());
            var serviceProvider = serviceCollection.BuildServiceProvider();

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

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

            FactoryApplication.SetLoggerFactory(loggerFactory);

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

            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");
            DbCredential crd      = new DbCredential(host, 5432, dbname, user, password, "pgsql");

            OnixErpDbContext ctx = new OnixErpDbContext(crd);

            ctx.SetLoggerFactory(loggerFactory);
            FactoryBusinessOperation.SetDatabaseContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(loggerFactory);

            Assembly asm = Assembly.GetExecutingAssembly();

            FactoryDbContext.RegisterDbContext(asm, "OnixErpDbContextPgSql", "OnixBusinessErpApp.OnixErpDbContextPgSql");
        }
Пример #2
0
        private static void SetupFactory(ILoggerFactory logFactory)
        {
            string host     = Environment.GetEnvironmentVariable("MAGNUM_FIREBASE_URL");
            string key      = Environment.GetEnvironmentVariable("MAGNUM_FIREBASE_KEY");
            string user     = Environment.GetEnvironmentVariable("MAGNUM_DB_USERNAME");
            string password = Environment.GetEnvironmentVariable("MAGNUM_DB_PASSWORD");
            string bucket   = Environment.GetEnvironmentVariable("MAGNUM_FIREBASE_BUCKET");

            Microsoft.Extensions.Logging.ILogger logger = logFactory.CreateLogger <FirebaseNoSqlContext>();

            FirebaseNoSqlContext ctx = new FirebaseNoSqlContext();

            ctx.SetLogger(logger);
            ctx.Authenticate(host, key, user, password);

            var storageCtx = new FirebaseStorageContext();

            storageCtx.Authenticate(bucket, key, user, password);

            FactoryBusinessOperation.SetStorageContext(storageCtx);
            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(logFactory);
            FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList());

            FactoryCacheContext.RegisterCaches(BusinessErpCaches.GetInstance().ExportedServicesList());
            FactoryCacheContext.SetLoggerFactory(logFactory);
        }
        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
        public virtual CreateBarcode GetCreateBarcodeOperation()
        {
            FactoryBusinessOperation.SetNoSqlContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(FactoryConsoleApplication.GetLoggerFactory());
            CreateBarcode opr = (CreateBarcode)FactoryBusinessOperation.CreateBusinessOperationObject("CreateBarcode");

            return(opr);
        }
        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);
        }
        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);
        }