Esempio n. 1
0
 public SBInventoryBaseController()
 {
     _seasonFactory       = new SeasonFactory();
     _categoryFactory     = new CategoriesFactory();
     _printerFactory      = new PrinterFactory();
     _categoryFactoryInte = new InteCategoriesFactory();
 }
Esempio n. 2
0
        public void Init()
        {
            Metric.Config.WithHttpEndpoint("http://localhost:2581/").WithSystemCounters();

            //XXX use config to get this info
            var registryFactory = LogRegistryFactory.Create();

            var parserFactory = LogParserFactory.GetParserForFileExtension("xml");

            IPrinterFactory printerFactory;

            if (config.ExtraConfigs != null && config.ExtraConfigs.ContainsKey("printToFile") && !string.IsNullOrWhiteSpace(config.ExtraConfigs["printToFile"]))
            {
                // Note: this just sets a default. Configs can change the file
                printerFactory = PrinterFactory.CrateFileFactory(config.ExtraConfigs["printToFile"]);
            }
            else
            {
                printerFactory = PrinterFactory.CrateConsoleFactory();
            }

            registry = registryFactory.Create();

            logFileParser = parserFactory.Create(registry, config);
            printer       = printerFactory.Create(registry, config);
        }
Esempio n. 3
0
        private void button5_Click(object sender, EventArgs e)
        {
            // StringBuilder sw = new StringBuilder();
            // sw.Append("       S0011234567892asdfghj");
            // sw.Append("订单编号1:" );
            // sw.Append("订单编号2:" );
            // sw.Append("订单编号3:" );
            // sw.Append("订单编号4:" );

            printDocument = new PrintDocument();
            string printerName = printDocument.PrinterSettings.PrinterName;
            var    currPrinter = PrinterFactory.GetPrinter("printerName", PaperWidth.Paper76mm);

            currPrinter.PrintWaitInfoTicket(new WaitInfoV1d0(), "测试餐厅");
            //currPrinter.PrintText("排队序号S001");
            // currPrinter.NewRow();
            // currPrinter.PrintText("序号:");
            // currPrinter.NewRow();
            // currPrinter.PrintText("前面还有00位");
            // currPrinter.NewRow();
            // currPrinter.PrintText("排队时间:" + DateTime.Now.ToString("yyyyMMdd hh:mm:ss"));
            //// currPrinter.PrintLine();
            // //currPrinter.Finish();
            // currPrinter.Finish();
        }
Esempio n. 4
0
 internal ConsoleOutputConfiguration(ConsoleColor foregroundColor, ConsoleColor backgroundColor)
 {
     ForegroundColor = foregroundColor;
     BackgroundColor = backgroundColor;
     OutputType      = OutputType.Console;
     Printer         = new PrinterFactory().CreateConsolePrinter(foregroundColor, backgroundColor);
 }
Esempio n. 5
0
        public PrinterManager(IRepository repository, ILogger logger)
        {
            this.repository = repository ?? throw new ArgumentNullException(nameof(repository));
            this.logger     = logger ?? throw new ArgumentNullException(nameof(logger));

            repository.Save(PrinterFactory.CreateCanonPrinter());
            repository.Save(PrinterFactory.CreateEpsonPrinter());
        }
Esempio n. 6
0
 public void PrintDocumentToFile(String Filename, String Type, String Template, Int64 documentId, String connectionstring)
 {
     datacollection = new DataSet();
     port           = new FilePort(Filename);
     printer        = PrinterFactory.getPrinter(Type);
     port.SetDocumentName("CDS DOC " + documentId);
     job = printer.getDefaultJobProperties();
     PrintDocumentFromTemplate(Template, documentId, connectionstring);
     printer.endJob();
 }
Esempio n. 7
0
        public APIResult QureyOrderState([FromBody] PrintParameter parameter)
        {
            if (string.IsNullOrEmpty(parameter.OrderID))
            {
                return(Error("OrderID参数不能为空"));
            }
            PrinterBase @base  = PrinterFactory.Create(PrinterType.FEIE);//)
            string      result = @base.QureyOrderState(parameter.OrderID);

            return(Success(result));
        }
Esempio n. 8
0
        public void PrintImageTest()
        {
            var printer = PrinterFactory.GetPrinter("Microsoft XPS Document Writer", PaperWidth.Paper80mm);

            printer.PrintText("一二三四五六七八", width: 0.3f);
            printer.PrintText("一二三四五六七八", width: 0.2f, offset: 0.4f);
            printer.NewRow();
            printer.PrintText("我是新的行");
            printer.NewRow();
            printer.Finish();
        }
Esempio n. 9
0
        public void PrinterFactoryProducesConsole()
        {
            var factory = PrinterFactory.CrateConsoleFactory();

            Assert.That(factory, Is.Not.Null);

            var printer = factory.Create(mockLogRegistry, logConfig);

            Assert.That(printer, Is.Not.Null);
            Assert.That(printer, Is.TypeOf <Printers.Internal.ConsolePrinter>());
        }
Esempio n. 10
0
        public APIResult QueryPrinterStatus([FromBody] PrintParameter parameter)
        {
            if (string.IsNullOrEmpty(parameter.SN))
            {
                return(Error("Sn参数不能为空"));
            }
            PrinterBase @base  = PrinterFactory.Create(PrinterType.FEIE);//)
            string      result = @base.QueryPrinterStatus(parameter.SN);

            return(Success(result));
            // return new EmptyResult();
        }
Esempio n. 11
0
 private static void Add(PrinterFactory factory)
 {
     try
     {
         printerManager.Add(factory.CreatePrinter());
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e);
         System.Console.ReadKey();
     }
 }
Esempio n. 12
0
        public void TextStringAlignmentTest()
        {
            var printer = PrinterFactory.GetPrinter("Microsoft XPS Document Writer", PaperWidth.Paper80mm);

            printer.PrintText("正", Printer.Models.FontSize.Huge);
            printer.NewRow();
            printer.PrintText("正");
            printer.NewRow();
            printer.PrintText("正", Printer.Models.FontSize.micro);
            printer.NewRow();
            printer.Finish();
        }
Esempio n. 13
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            CtcSettings.Initialize(executionData);

            // create activity data
            DiscoveryActivityData activityData = executionData.GetMetadata <DiscoveryActivityData>(CtcMetadataConverter.Converters);
            PrinterFamilies       family       = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), activityData.ProductFamily);

            // create instance of ews adapter
            EwsWrapper.Instance().Create(family, activityData.ProductName, activityData.IPv4Address, Path.Combine(activityData.SitemapPath,
                                                                                                                  activityData.SitemapsVersion), BrowserModel.Firefox);

            //create instance of SNMP wrapper
            SnmpWrapper.Instance().Create(activityData.IPv4Address);

            //create instance of Telnet wrapper
            TelnetWrapper.Instance().Create(activityData.IPv4Address);

            EwsWrapper.Instance().Start();

            EwsWrapper.Instance().WakeUpPrinter();

            EwsWrapper.Instance().SetAdvancedOptions();

            EwsWrapper.Instance().EnableSnmpv1v2ReadWriteAccess();

            BonjourServiceInstallation();

            Printer.Printer printer = PrinterFactory.Create(activityData.ProductFamily, activityData.IPv4Address);
            activityData.PrinterMacAddress = printer.MacAddress.Replace(":", string.Empty);

            // create network discovery tests
            if (null == _networkDiscoveryTests)
            {
                _networkDiscoveryTests = new DiscoveryTests(activityData);
            }

            foreach (int testNumber in activityData.SelectedTests)
            {
                try
                {
                    ExecutionServices.SessionRuntime.AsInternal().WaitIfPaused();
                    _networkDiscoveryTests.RunTest(executionData, testNumber, IPAddress.Parse(activityData.IPv4Address), (ProductFamilies)Enum.Parse(typeof(ProductFamilies), activityData.ProductFamily));
                }
                catch (Exception e)
                {
                    TraceFactory.Logger.Info("Error while executing test:{0}  \n ".FormatWith(testNumber, e.Message));
                }
            }

            return(new PluginExecutionResult(PluginResult.Passed));
        }
Esempio n. 14
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            CtcSettings.Initialize(executionData);

            // create activity data
            FirewallActivityData activityData = executionData.GetMetadata <FirewallActivityData>(CtcMetadataConverter.Converters);
            PrinterFamilies      family       = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), activityData.ProductFamily);

            // Instance for EWS adapter and Start WebDriver
            EwsWrapper.Instance().Create(family, activityData.ProductName, activityData.IPv4Address, Path.Combine(activityData.SitemapPath, activityData.SitemapsVersion), BrowserModel.Firefox);
            EwsWrapper.Instance().Start();
            EwsWrapper.Instance().WakeUpPrinter();
            EwsWrapper.Instance().SetWSDiscovery(true);
            EwsWrapper.Instance().SetDHCPv6OnStartup(true);
            EwsWrapper.Instance().EnableSnmpv1v2ReadWriteAccess();

            // Get All IPv6 Addresses

            Printer.Printer printer = PrinterFactory.Create(family, IPAddress.Parse(activityData.IPv4Address));
            activityData.IPv6LinkLocalAddress = printer.IPv6LinkLocalAddress?.ToString() ?? string.Empty;
            activityData.IPv6StatefulAddress  = printer.IPv6StateFullAddress?.ToString() ?? string.Empty;
            activityData.IPv6StatelessAddress = printer.IPv6StatelessAddresses.Count == 0 ? string.Empty : printer.IPv6StatelessAddresses[0].ToString();

            // Instance for SNMP wrapper
            SnmpWrapper.Instance().Create(activityData.IPv4Address);

            // Instance for Telnet wrapper
            TelnetWrapper.Instance().Create(activityData.IPv4Address);

            // Instance for Firewall Tests
            if (null == _tests)
            {
                _tests = new FirewallTests(activityData);
            }

            foreach (int testNumber in activityData.SelectedTests)
            {
                try
                {
                    ExecutionServices.SessionRuntime.AsInternal().WaitIfPaused();
                    _tests.RunTest(executionData, testNumber, IPAddress.Parse(activityData.IPv4Address), (ProductFamilies)Enum.Parse(typeof(ProductFamilies), activityData.ProductFamily));
                }
                catch (Exception exception)
                {
                    TraceFactory.Logger.Info("Error while executing test {0} with exception {1}. \n".FormatWith(testNumber, exception.Message));
                }
            }

            EwsWrapper.Instance().Stop();

            return(new PluginExecutionResult(PluginResult.Passed));
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            PrinterFactory printerFactory = new PrinterFactory();
            IPrinter       printer1       = printerFactory.NewPrinter("Epson");
            IPrinter       printer2       = printerFactory.NewPrinter("HP");

            printer1.ShouldBeType <EpsonPrinter>();
            printer2.ShouldBeType <HpPrinter>();
            new Action(() => printerFactory.NewPrinter("Other")).ShouldThrow <NotFoundException>();

            Console.WriteLine("Test done");
            Console.ReadKey(false);
        }
Esempio n. 16
0
        public void PrintDocument(String Printer, String Type, String Template, Int64 documentId, String connectionstring)
        {
            datacollection = new DataSet();
            port           = new WindowsPrinter(Printer);
            printer        = PrinterFactory.getPrinter(Type);
            port.SetDocumentName("CDS DOC " + documentId);
            job = printer.getDefaultJobProperties();

            job.draftQuality = true;
            job.pitch        = 10;
            //job.paperSize = PaperSize.LETTER;

            PrintDocumentFromTemplate(Template, documentId, connectionstring);

            printer.endJob();
        }
Esempio n. 17
0
        public APIResult QueryOrderInfoByDate([FromBody] PrintParameter parameter)

        {
            if (string.IsNullOrEmpty(parameter.SN))
            {
                return(Error("Sn参数不能为空"));
            }
            if (string.IsNullOrEmpty(parameter.Date))
            {
                parameter.Date = DateTime.Now.ToString("yyyy-MM-dd");
            }
            PrinterBase @base  = PrinterFactory.Create(PrinterType.FEIE);//)
            string      result = @base.QueryOrderInfoByDate(parameter.SN, parameter.Date);

            return(Success(result));
            // return new EmptyResult();
        }
        /// <summary>
        /// Print all files in specified folder
        /// </summary>
        /// <param name="ipAddress">IP Address of Printer</param>
        /// <param name="printProtocol"><see cref=" Printer.Printer.PrintProtocol"/></param>
        /// <param name="portNo">Port number for installation</param>
        /// <param name="testNo">Test number</param>
        /// <returns>true if all files printed successfully, false otherwise</returns>
        public bool ComplexPrinting(string ipAddress, Printer.Printer.PrintProtocol printProtocol, int portNo, int testNo)
        {
            string[] files = Directory.GetFiles(_activityData.DocumentsPath);
            if (null == files || 0 == files.Length)
            {
                TraceFactory.Logger.Info("Complex Printing failed. No files available.");
                return(false);
            }

            string hostname = string.Empty;

            if (Printer.Printer.PrintProtocol.IPPS.Equals(printProtocol))
            {
                if (!CtcUtility.IPPS_Prerequisite(IPAddress.Parse(ipAddress), out hostname))
                {
                    TraceFactory.Logger.Info("Failed to perform pre-requisites for IPPS.");
                    return(false);
                }
            }

            PrinterFamilies family = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), Enum <ProductFamilies> .Value(_activityData.ProductFamily));

            Printer.Printer printer = PrinterFactory.Create(family, IPAddress.Parse(ipAddress));

            if (printer.Install(IPAddress.Parse(ipAddress), printProtocol, _activityData.DriverPackagePath, _activityData.DriverModel, portNo, hostname))
            {
                printer.Print(CtcUtility.CreateFile("Test {0} started.".FormatWith(testNo)));
                // Subscribing for Print Queue Event
                printer.PrintQueueError += printer_PrintQueueError;

                if (!printer.Print(files))
                {
                    TraceFactory.Logger.Info("Complex Printing failed. All jobs didn't print.");
                    return(false);
                }
            }
            else
            {
                TraceFactory.Logger.Info("Complex Printing failed.");
                return(false);
            }

            TraceFactory.Logger.Info("All jobs for Complex Printing printed successfully.");
            return(true);
        }
Esempio n. 19
0
        public void FinishTest()
        {
            var printer = PrinterFactory.GetPrinter("Microsoft XPS Document Writer", PaperWidth.Paper80mm);

            printer.NewRow();
            printer.NewRow();
            printer.PrintText("永辉超市", Printer.Models.FontSize.Huge, StringAlignment.Center);
            printer.NewRow();
            printer.NewRow();
            printer.NewRow();
            printer.PrintText("操作员:张三");
            printer.PrintText(DateTime.Now.ToString("HH:mm:ss"), stringAlignment: StringAlignment.Far);
            printer.NewRow();
            printer.PrintLine();
            printer.NewRow();
            printer.PrintText("商品");
            printer.PrintText("单价", offset: 0.35f);
            printer.PrintText("数量", offset: 0.65f);
            printer.PrintText("总价", stringAlignment: StringAlignment.Far);
            printer.NewRow();
            printer.PrintLine();
            printer.NewRow();
            printer.PrintText("**长白山大萝卜,跳楼吐血大甩卖,不甜不要钱**", width: 0.35f);
            printer.PrintText("6.00", width: 0.2f, offset: 0.35f);
            printer.PrintText("2.00", width: 0.2f, offset: 0.65F);
            printer.PrintText("12.00", stringAlignment: StringAlignment.Far);
            printer.NewRow();
            printer.NewRow();
            printer.PrintText("大螃蟹", width: 0.35f);
            printer.PrintText("6.000000000001", width: 0.2f, offset: 0.35f);
            printer.PrintText("1", width: 0.2f, offset: 0.65F);
            printer.PrintText("6.000000000001", offset: 0.8f, width: 0.2f);
            printer.NewRow();
            printer.PrintLine();
            printer.NewRow();
            var bitmap = new Bitmap("qr.png");

            printer.PrintImage(bitmap, StringAlignment.Center);
            printer.NewRow();
            printer.PrintLine();
            printer.NewRow();
            printer.PrintText("感谢光临,欢迎下次再来!", stringAlignment: StringAlignment.Center);
            printer.NewRow();
            printer.Finish();
        }
Esempio n. 20
0
        private static Printer CreatePrinter()
        {
            var factory = new PrinterFactory();

            System.Console.WriteLine("Enter printer name");
            string name = System.Console.ReadLine();

            System.Console.WriteLine("Enter printer model");
            string model = System.Console.ReadLine();

            System.Console.WriteLine("Type:");
            string intype = System.Console.ReadLine();

            Enum.TryParse(intype, true, out PrinterTypes type);

            Printer printer = factory.Get(name, model, type);

            return(printer);
        }
Esempio n. 21
0
        private void btnGetSerial_Click(object sender, EventArgs e)
        {
            IFiscalPrinter fp = PrinterFactory.Create(Model);

            try
            {
                txtSerial.Text = fp.GetSerial(ComPort, Baud);
                if (txtSerial.Text.Length < 3 && !string.IsNullOrEmpty(txtSerial.Text))
                {
                    fp.getError(Convert.ToInt32(txtSerial.Text));
                }
                else
                {
                    savePrinterSettings();
                }
            }
            catch (Exception x) { MessageBox.Show(x.Message); }
            finally { fp.Dispose(); }
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            var printer = PrinterFactory.GetPrinter("Microsoft XPS Document Writer", PaperWidth.Paper80mm);

            var server = new WebSocketServer("ws://0.0.0.0:2399");

            server.Start(socket =>
            {
                socket.OnOpen = () =>
                {
                    Console.WriteLine("连接socket成功");
                };
                socket.OnClose = () =>
                {
                    Console.WriteLine("断开socket成功");
                };
                socket.OnMessage = msg =>
                {
                    var printData = JsonConvert.DeserializeObject <List <PrintUnit> >(msg);
                    foreach (var item in printData)
                    {
                        switch (item.Type)
                        {
                        case "text":
                            Console.WriteLine("打印文字");
                            printer.PrintText(item.Content);
                            break;

                        case "finish":
                            Console.WriteLine("结束打印输出文档");
                            printer.Finish();
                            break;

                        default:
                            break;
                        }
                    }
                };
            });

            Console.ReadKey();
        }
Esempio n. 23
0
        public void Add()
        {
            Console.WriteLine("\nEnter printer name");
            string name = Console.ReadLine();

            Console.WriteLine("Enter printer model");
            string model = Console.ReadLine();

            var printer = PrinterFactory.CreatePrinter(name, model);

            if (!this.repository.Contains(printer))
            {
                this.repository.Save(printer);
                Console.WriteLine("Printer added.");
            }
            else
            {
                Console.WriteLine("\nPrinter already exists.");
            }
        }
Esempio n. 24
0
        //kjo eshte vetem per kasat e vjetra kur ngel tastiera e bllokuar
        private void button4_Click(object sender, EventArgs e)
        {
            if (Model.Contains("W"))
            {
                return;
            }

            IFiscalPrinter fp     = PrinterFactory.Create(Model);
            int            answer = fp.OpenPort(Model, Key, ComPort, Baud);

            if (answer == 1)
            {
                fp.WriteLine("T,1,______,_,__;");

                if (activeKeyb)
                {
                    fp.WriteLine("F,1,______,_,__;");
                }
            }

            fp.Dispose();
        }
        /// <summary>
        /// Print all files in specified folder
        /// </summary>
        /// <param name="ipAddress">IP Address of Printer</param>
        /// <param name="testNo">Test number</param>
        /// <param name="isPassiveMode">Passive/ Active mode for FTP</param>
        /// <returns>true if all files printed successfully, false otherwise</returns>
        public bool ComplexPrinting(string ipAddress, int testNo, bool isPassiveMode = false)
        {
            string[] files = Directory.GetFiles(_activityData.DocumentsPath);
            if (null == files || 0 == files.Length)
            {
                TraceFactory.Logger.Info("Complex Printing failed. No files available.");
                return(false);
            }

            PrinterFamilies family = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), Enum <ProductFamilies> .Value(_activityData.ProductFamily));

            Printer.Printer printer = PrinterFactory.Create(family, IPAddress.Parse(ipAddress));

            if (printer.PrintWithFtp(IPAddress.Parse(ipAddress), string.Empty, string.Empty, files, isPassiveMode: isPassiveMode))
            {
                TraceFactory.Logger.Info("All jobs for Complex Printing printed successfully.");
                return(true);
            }
            else
            {
                TraceFactory.Logger.Info("Complex Printing failed. All jobs didn't print successfully.");
                return(false);
            }
        }
Esempio n. 26
0
        private void btnCheckKey_Click(object sender, EventArgs e)
        {
            savePrinterSettings();
            loadPrinterSettings();

            IFiscalPrinter fp = PrinterFactory.Create(Model);

            try
            {
                int answer = fp.OpenPort(Model, Key, ComPort, Baud);
                if (answer == 1)
                {
                    MessageBox.Show("Key Registered Sucessfully");
                    savePrinterSettings();
                }
                else
                {
                    //MessageBox.Show(getError(answer), "Kujdes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    MessageBox.Show(fp.getError(answer), "Cant Connect");
                }
            }
            catch { }
            finally { fp.Dispose(); }
        }
Esempio n. 27
0
        public void stert_Print()
        {
            int item    = 0;
            var printer = PrinterFactory.GetPrinter("XP-58", PaperWidth.Paper58mm);

            PrintQueueHelper.GetPrintQueueName();
            printer.NewRow();
            printer.NewRow();
            printer.PrintText(Title1.Text, FontSize.Huge, StringAlignment.Center);
            printer.NewRow();
            printer.NewRow();

            if (User.Text != "")
            {
                printer.NewRow();
                printer.PrintText(User.Text);
                printer.NewRow();
            }

            printer.PrintLine();
            printer.NewRow();
            printer.PrintText("商品");
            printer.PrintText("单价", offset: 0.35f);
            printer.PrintText("数量", offset: 0.65f);
            printer.PrintText("总价", stringAlignment: StringAlignment.Far);
            printer.NewRow();
            printer.PrintLine();

            if (num1.Value != 0)
            {
                printer.NewRow();
                printer.PrintText(item1.Text, width: 0.35f);
                printer.PrintText(up1.Value.ToString(), width: 0.2f, offset: 0.35f);
                printer.PrintText(num1.Value.ToString(), width: 0.2f, offset: 0.65F);
                printer.PrintText(price1.Text, stringAlignment: StringAlignment.Far);
                printer.NewRow();
                item++;
            }

            if (num2.Value != 0)
            {
                printer.NewRow();
                printer.PrintText(item2.Text, width: 0.35f);
                printer.PrintText(up2.Value.ToString(), width: 0.2f, offset: 0.35f);
                printer.PrintText(num2.Value.ToString(), width: 0.2f, offset: 0.65F);
                printer.PrintText(price2.Text, stringAlignment: StringAlignment.Far);
                printer.NewRow();
                item++;
            }
            if (num3.Value != 0)
            {
                printer.NewRow();
                printer.PrintText(item3.Text, width: 0.35f);
                printer.PrintText(up3.Value.ToString(), width: 0.2f, offset: 0.35f);
                printer.PrintText(num3.Value.ToString(), width: 0.2f, offset: 0.65F);
                printer.PrintText(price3.Text, stringAlignment: StringAlignment.Far);
                printer.NewRow();
                item++;
            }
            if (num4.Value != 0)
            {
                printer.NewRow();
                printer.PrintText(item4.Text, width: 0.35f);
                printer.PrintText(up4.Value.ToString(), width: 0.2f, offset: 0.35f);
                printer.PrintText(num4.Value.ToString(), width: 0.2f, offset: 0.65F);
                printer.PrintText(price4.Text, stringAlignment: StringAlignment.Far);
                printer.NewRow();
                item++;
            }
            if (num5.Value != 0)
            {
                printer.NewRow();
                printer.PrintText(item5.Text, width: 0.35f);
                printer.PrintText(up5.Value.ToString(), width: 0.2f, offset: 0.35f);
                printer.PrintText(num5.Value.ToString(), width: 0.2f, offset: 0.65F);
                printer.PrintText(price5.Text, stringAlignment: StringAlignment.Far);
                printer.NewRow();
                item++;
            }

            while (item < 5)
            {
                printer.NewRow();
                printer.NewRow();
                printer.NewRow();
                printer.NewRow();
                item++;
            }


            printer.PrintLine();
            printer.NewRow();
            printer.PrintText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), stringAlignment: StringAlignment.Near);
            printer.NewRow();
            printer.PrintText(EndText.Text, stringAlignment: StringAlignment.Near);
            printer.PrintText("合计: " + tp.Text, stringAlignment: StringAlignment.Far);
            printer.NewRow();
            printer.Finish();

            RawPrinterHelper.SendStringToPrinter("XP-58", Convert.ToString((char)29) + "V" + (char)1);
        }
Esempio n. 28
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            CtcSettings.Initialize(executionData);

            // create activity data
            DotOneXActivityData activityData = executionData.GetMetadata <DotOneXActivityData>(CtcMetadataConverter.Converters);
            PrinterFamilies     family       = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), activityData.ProductFamily);

            activityData.DotOneXUserName = DOT1X_USERNAME.FormatWith(activityData.RadiusServerType.ToString().ToLower(CultureInfo.CurrentCulture));
            activityData.DotOneXPassword = DOT1X_PASSWORD;
            activityData.SharedSecret    = SHARED_SECRET;
            activityData.PolicyName      = NETWORK_POLICY;

            bool continueTest = true;

            while (continueTest && !NetworkUtil.PingUntilTimeout(IPAddress.Parse(activityData.Ipv4Address), TimeSpan.FromSeconds(30)))
            {
                continueTest = DotOneXTemplates.ShowErrorPopUp("Printer: {0} is not available.\nPlease cold reset the printer.".FormatWith(activityData.Ipv4Address));
            }

            if (!continueTest)
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Printer: {0} is not available.\nPlease cold reset the printer.".FormatWith(activityData.Ipv4Address)));
            }

            // create instance of ews adapter
            EwsWrapper.Instance().Create(family, activityData.ProductName, activityData.Ipv4Address, Path.Combine(activityData.SitemapPath, activityData.SiteMapVersion), BrowserModel.Firefox);

            EwsWrapper.Instance().Start();

            EwsWrapper.Instance().WakeUpPrinter();

            EwsWrapper.Instance().EnableSnmpv1v2ReadWriteAccess();

            SnmpWrapper.Instance().Create(activityData.Ipv4Address);
            SnmpWrapper.Instance().SetCommunityName("public");

            TelnetWrapper.Instance().Create(activityData.Ipv4Address);

            //TODO: Migration issue even thought it is not migration issue why it is commented
            //EwsWrapper.Instance().SetWSDiscovery(true);

            Printer.Printer printer = PrinterFactory.Create(activityData.ProductFamily, activityData.Ipv4Address);
            activityData.MacAddress = printer.MacAddress;

            using (DhcpApplicationServiceClient dhcpClient = DhcpApplicationServiceClient.Create(activityData.DhcpServerIp))
            {
                string scope = dhcpClient.Channel.GetDhcpScopeIP(activityData.DhcpServerIp);
                dhcpClient.Channel.DeleteReservation(activityData.DhcpServerIp, scope, activityData.Ipv4Address, activityData.MacAddress);

                if (dhcpClient.Channel.CreateReservation(activityData.DhcpServerIp, scope, activityData.Ipv4Address, activityData.MacAddress, ReservationType.Both))
                {
                    TraceFactory.Logger.Info("Successfully created reservation for IP address: {0}, Mac address: {1} for {2}".FormatWith(activityData.Ipv4Address, activityData.MacAddress, ReservationType.Both));
                }
                else
                {
                    TraceFactory.Logger.Info("Failed to create reservation for IP address: {0}, Mac address: {1} for {2}".FormatWith(activityData.Ipv4Address, activityData.MacAddress, ReservationType.Both));
                    return(new PluginExecutionResult(PluginResult.Failed, "Failed to create reservation for IP address: {0}, Mac address: {1} for {2}".FormatWith(activityData.Ipv4Address, activityData.MacAddress, ReservationType.Both)));
                }
            }

            if (!ConfigureRadiusServer(activityData))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to configure radius server"));
            }

            if (!ConfigureSwitch(activityData))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to configure switch"));
            }

            activityData.SessionId = executionData.SessionId;

            if (null == _tests)
            {
                _tests = new DotOneXTests(activityData);
            }

            // Execute the selected tests
            foreach (int testNumber in activityData.SelectedTests)
            {
                try
                {
                    ExecutionServices.SessionRuntime.AsInternal().WaitIfPaused();
                    _tests.RunTest(executionData, testNumber, IPAddress.Parse(activityData.Ipv4Address), (ProductFamilies)Enum.Parse(typeof(ProductFamilies), activityData.ProductFamily));
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Fatal("Error while executing Test:{0} \n".FormatWith(testNumber, ex.Message));
                }
            }

            EwsWrapper.Instance().Stop();

            return(new PluginExecutionResult(PluginResult.Passed));
        }
Esempio n. 29
0
        public static void PrintOrder(this PrintDbContext printDbContext, ShopDbContext db, ShopOrder shopOrder, string shopname)
        {
            try
            {
                if (shopOrder == null)
                {
                    throw new Exception("订单错误");
                }
                List <ShopOrderItem> items = db.Query <ShopOrderItem>()
                                             .Where(m => !m.IsDel)
                                             .Where(m => m.ShopOrderId == shopOrder.Id)
                                             .ToList();
                if (items.Count == 0)
                {
                    return;
                }
                List <OrderInfo> orderInfo = items.Select(s => new OrderInfo()
                {
                    Name  = $"{s.CommodityName}({s.SkuSummary})",
                    Price = Math.Round(s.SalePrice / 100d, 2),
                    Count = s.Count
                }).ToList();
                string stringorderlist = JsonConvert.SerializeObject(orderInfo);

                List <Printer> printers = printDbContext.Query <Printer>()
                                          .Where(s => !s.IsDel)
                                          .Where(s => s.ShopID == shopOrder.ShopId && s.IsEnable).ToList();
                if (printers.Count == 0)
                {
                    return;
                }

                PrintParameter parameter = GetPrintParameter(db, shopOrder);
                parameter.ShopName = shopname;
                parameter.List     = orderInfo;

                foreach (var item in printers)
                {
                    //StringBuilder postData = new StringBuilder("sn=" + item.SN);
                    parameter.SN    = item.SN;
                    parameter.Times = item.Times + "";
                    PrintModel model = printDbContext.Query <PrintModel>().FirstOrDefault(s => s.ID == item.ModelID);
                    if (model == null)
                    {
                        model = printDbContext.Set <PrintModel>().Find(2);
                    }
                    parameter.ModelContent = model.ModelContent;
                    PrinterBase @base = PrinterFactory.Create(item.PrinterType);//)
                    string      temp  = @base.PrinterRequest(parameter, item);
                    #region 数据库操作
                    PrintRecord record = new PrintRecord();
                    //处理接口返回数据
                    Dictionary <string, object> dic = JsonConvert.DeserializeObject <Dictionary <string, object> >(temp);
                    //实体赋值
                    record.SN         = item.SN;
                    record.OrderID    = @base.GetOrderID(temp);// dic.ContainsKey("data") && dic["msg"].Equals("ok") ? dic["data"].ToString() : "未能成功打印";
                    record.Title      = parameter.Title;
                    record.OrderList  = stringorderlist;
                    record.TotalMoney = (float)parameter.TotalMoney;
                    record.Address    = parameter.Address;
                    record.OrderName  = parameter.OrderName;
                    record.Mobile     = parameter.Mobile;
                    record.OrderTime  = Convert.ToDateTime(parameter.OrderTime);
                    record.QRAddress  = parameter.QRAddress;
                    record.Remark     = shopOrder.Remark;
                    printDbContext.AddTo(record);
                    #endregion
                }
                shopOrder.IsPrint = true;
            }
            catch (Exception e)
            {
                //_logger.LogError("打印机错误:{0}", e.Message);
            }
        }
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            CtcSettings.Initialize(executionData);

            WebProxyActivityData activityData = executionData.GetMetadata <WebProxyActivityData>(CtcMetadataConverter.Converters);

            #region Scenario Prerequisites

            //Check the Windows Server Service is up and running on all servers
            CtcUtility.StartService("WindowsServerService", activityData.PrimaryDHCPServerIPAddress);
            CtcUtility.StartService("WindowsServerService", activityData.UnsecureWebProxyServerIPAddress);
            CtcUtility.StartService("WindowsServerService", activityData.SecureWebProxyServerIPAddress);
            CtcUtility.StartService("WindowsServerService", activityData.WPADServerIPAddress);

            //Add WPAD entry and Domain Name on the DHCP Server
            DhcpApplicationServiceClient serviceFunction = DhcpApplicationServiceClient.Create(activityData.PrimaryDHCPServerIPAddress);
            activityData.PrimaryDHCPScopeIPAddress = serviceFunction.Channel.GetDhcpScopeIP(activityData.PrimaryDHCPServerIPAddress);
            serviceFunction.Channel.SetWPADServer(activityData.PrimaryDHCPServerIPAddress, activityData.PrimaryDHCPScopeIPAddress, activityData.cURLPathIPAddress);
            activityData.DomainName = "lfpctc.com";

            string recordType = "A";
            serviceFunction.Channel.SetDomainName(activityData.PrimaryDHCPServerIPAddress, activityData.PrimaryDHCPScopeIPAddress, activityData.DomainName);

            // Retrieving hostnames of all servers

            SystemConfigurationClient secureProxy = SystemConfigurationClient.Create(activityData.SecureWebProxyServerIPAddress);
            activityData.SecureWebProxyServerHostName = secureProxy.Channel.GetHostName();
            TraceFactory.Logger.Info("Secure Web Proxy hostname is {0}".FormatWith(activityData.SecureWebProxyServerHostName));

            SystemConfigurationClient unsecureProxy = SystemConfigurationClient.Create(activityData.UnsecureWebProxyServerIPAddress);
            activityData.UnsecureWebProxyServerHostName = unsecureProxy.Channel.GetHostName();
            TraceFactory.Logger.Info("Unsecure Web Proxy hostname is {0}".FormatWith(activityData.UnsecureWebProxyServerHostName));

            SystemConfigurationClient wpadServer = SystemConfigurationClient.Create(activityData.WPADServerIPAddress);
            activityData.WPADServerHostName = wpadServer.Channel.GetHostName();
            TraceFactory.Logger.Info("WPAD hostname is {0}".FormatWith(activityData.WPADServerHostName));

            //Add DNS entry for all servers on the DHCP/DNS server
            DnsApplicationServiceClient dnsClient = DnsApplicationServiceClient.Create(activityData.PrimaryDHCPServerIPAddress);
            dnsClient.Channel.AddDomain(activityData.DomainName);
            dnsClient.Channel.AddRecord(activityData.DomainName, activityData.SecureWebProxyServerHostName, recordType, activityData.SecureWebProxyServerIPAddress);
            dnsClient.Channel.AddRecord(activityData.DomainName, activityData.UnsecureWebProxyServerHostName, recordType, activityData.UnsecureWebProxyServerIPAddress);
            dnsClient.Channel.AddRecord(activityData.DomainName, activityData.WPADServerHostName, recordType, activityData.WPADServerIPAddress);

            string curlFqdn = string.Concat(activityData.WPADServerHostName, activityData.DomainName);
            activityData.cURLPathFQDN             = string.Concat("http://", curlFqdn, ":80/wpad.dat");
            activityData.SecureWebProxyServerFQDN = string.Concat(activityData.SecureWebProxyServerHostName, activityData.DomainName);

            TraceFactory.Logger.Info(activityData.cURLPathFQDN);
            TraceFactory.Logger.Info(activityData.SecureWebProxyServerFQDN);

            PrinterFamilies family  = (PrinterFamilies)Enum.Parse(typeof(PrinterFamilies), activityData.ProductFamily);
            Printer         printer = PrinterFactory.Create(family, IPAddress.Parse(activityData.WiredIPv4Address));

            // create instance of ews adapter
            EwsWrapper.Instance().Create(family, activityData.ProductName, activityData.WiredIPv4Address, Path.Combine(activityData.SitemapPath, activityData.SiteMapVersion), BrowserModel.Firefox);
            EwsWrapper.Instance().Start();

            //Create instance of SNMP Wrapper
            SnmpWrapper.Instance().Create(activityData.WiredIPv4Address);

            //Create instance of Telnet Wrapper
            TelnetWrapper.Instance().Create(activityData.WiredIPv4Address);

            //Wake up the printer and disable sleep mode
            EwsWrapper.Instance().WakeUpPrinter();
            printer.KeepAwake();

            EwsWrapper.Instance().EnableSnmpv1v2ReadWriteAccess();

            #endregion
            if (null == _webProxyTests)
            {
                _webProxyTests = new WebProxyTests(activityData);
            }

            // assign the session id to activity data
            activityData.SessionId = executionData.SessionId;

            foreach (int testNumber in activityData.SelectedTests)
            {
                try
                {
                    ExecutionServices.SessionRuntime.AsInternal().WaitIfPaused();
                    _webProxyTests.RunTest(executionData, testNumber, IPAddress.Parse(activityData.WiredIPv4Address), (ProductFamilies)Enum.Parse(typeof(ProductFamilies), activityData.ProductFamily));
                }
                catch (Exception generalException)
                {
                    TraceFactory.Logger.Info("Test {0} failed with error: {1}".FormatWith(testNumber, generalException.Message));
                }
            }

            EwsWrapper.Instance().Stop();

            return(new PluginExecutionResult(PluginResult.Passed));
        }