/// <summary> /// Create main window form /// </summary> public mainWin() { Printers.init(); tools.SetAllowUnsafeHeaderParsing20(); log.Info("GUI Initialization start..."); InitializeComponent(); log.Info("Loading config start..."); Program.config = new Config(err => { log.Error(err, "Config loading error."); }); log.Info("Cheking update..."); updateInit(); log.Info("Tray icon initialization..."); trayIconInit(); log.Info("Configuring GUI..."); aboutTabInit(); this.Shown += mainWin_Shown; WinAutoSize.apply(this, new Control[] { printersTable, jobsTable.table }); }
public static void init() { Printers.init(); log.Info("Loading config start..."); Program.config = new Config(err => { log.Error(err, "Config loading error."); }); //pingPongPipe(); //printers(); //jobsList(); //jobPrint(); //ConfigReload(); //JobsServerState(); server = new NamedPipeServer <string>(Pipe.name); server.ClientConnected += server_ClientConnected; server.ClientMessage += server_ClientMessage; server.ClientDisconnected += server_ClientDisconnected; server.Error += server_Error; server.Start(); if (Program.config.channel.Length != 0) { srvConnect(Program.config.channel); } msgTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); msgTimer.Interval = 100; msgTimer.Enabled = true; configWatch(); }
public void init() { this.url = new Uri(file); this.docType = DocumentTypes.ToDocumentType(this.document).type; if (printerName.Length > 0) { this.printer = Printers.fromName(this.printerName); } }
/// <summary> /// Job listener /// </summary> /// <param name="channel"></param> /// <param name="onJob"></param> /// <returns></returns> public static Listener init(string channel, Action <Exception, Job> onJob) { return(new Listener(channel, newJobEvent, (dynamic msg) => { // Msg validation if (msgValidate(msg)) { // Searching printers for this job List <Printer> printers = Printers.findPrinters((string)msg.document, (int)msg.location, (int)msg.register); if (printers.Count == 0) { log.Info("Skipped job: document: {0}, file: {1}, location: {2}, type: {3}, autoprinted: {4}, register: {5}", (string)msg.document, (string)msg.file, (int)msg.location, (string)msg.type, (bool)msg.autoprinted, (int)msg.register ); return; } foreach (Printer printer in printers) { // Job cration Job job = new Job( (string)msg.document, (string)msg.file, (int)msg.location, (string)msg.type, (bool)msg.autoprinted, (int)msg.register ); job.Processing(); // Setting job printers job.printer = printer; // New job callback (not sure if it corret and better via event) onJob(null, job); // New job event if (jobAdded != null) { jobAdded(null, job); } job.download((err1) => { if (err1 == null) { if (jobDownloaded != null) { jobDownloaded(null, job); } job.print((err2) => { if (err2 == null) { if (jobPrinted != null) { jobPrinted(null, job); } } else { job.err = err2; log.Error("File printing error. File: \"{0}\"; Error details:\n{1}", job.localFilePath, err2); } }); } else { job.err = err1; log.Error("File download error. File: \"{0}\"; Error details:\n{1}", job.file, err1); } }); } } else { onJob(new Exception("Wrong job format. Get: " + msg.ToString()), null); } })); }
// ------------------------------------------------------------------- /// <summary> /// Generate printers UI /// </summary> public void createPrintersUI() { printersTable.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single; try { Printers.get(); } catch (Exception e1) { MessageBox.Show("Error while loading printers local config. Config will be wiped. Error is: " + e1.Message.ToString()); try { Program.config.save(); Printers.get(); } catch (Exception e2) { MessageBox.Show("Great Scott! Unexpected error was expected and catched. Application will exit. Error is:" + e2.Message.ToString()); Application.Exit(); } } // Clear column styles (in other case columns will have wrong width) printersTable.ColumnStyles.Clear(); // Printers table header // Adding first column header printersTable.Controls.Add(new tabelLabel("Printers:"), 0, 0); int column = 1; foreach (Printer p in Program.config.printers) { printersTable.ColumnCount++; printersTable.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); // Printer label printersTable.Controls.Add(new pLabel(p), column++, 0); // Printer qty //printersTable.ColumnCount++; //printersTable.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); //column++; } printersTable.RowStyles.Clear(); printersTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); int row = 1; column = 0; printersTable.RowCount++; printersTable.Controls.Add(new tabelLabel("Documents"), column++, row); foreach (Printer p in Program.config.printers) { printersTable.Controls.Add(new tabelLabel("Enabled | Quantity | Print from triggers"), column++, row); } foreach (DocumentType type in DocumentTypes.list) { column = 0; printersTable.RowCount++; printersTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); // Add header label printersTable.Controls.Add(new tabelLabel(type.title), column++, ++row); foreach (Printer p in Program.config.printers) { printersTable.Controls.Add(new PrinterDocumentControl(type, p), column, row); column++; } } column = 0; printersTable.RowCount++; printersTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); printersTable.Controls.Add(new tabelLabel("Print method"), column++, ++row); foreach (Printer p in Program.config.printers) { printersTable.Controls.Add(new PrintEngineDD(p), column++, row); } column = 0; printersTable.RowCount++; printersTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); printersTable.Controls.Add(new tabelLabel("Register"), column++, ++row); RegisterDD rdd; foreach (Printer p in Program.config.printers) { rdd = new RegisterDD(p, Program.config.registers); registersDD.Add(rdd); printersTable.Controls.Add(rdd, column++, row); } // // Adding rest columns and headers //int column = 1; //foreach (PrintType type in PrintTypes.list) //{ // // Add colmn // printersTable.ColumnCount++; // // Set column style // printersTable.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); // // Add header label // printersTable.Controls.Add(new tabelLabel(type.title), column++, 0); //} //// Adding rows //int row = 1; //foreach (Printer p in Program.config.printers) //{ // // Row creating // printersTable.RowCount++; // printersTable.RowStyles.Add(new RowStyle(SizeType.AutoSize)); // // Printer label // printersTable.Controls.Add(new pLabel(p), 0, row); // // Prnter checkboxes // column = 1; // foreach (PrintType t in PrintTypes.list) // { // printersTable.Controls.Add(new pCheckBox(t.type, p) { }, column, row); // } // row++; //} //MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); //MessageBox.Show(Path.GetTempPath()); }