private TroyPortMonitorConfiguration ConfigPort(KeyValuePair <string, string> kvp) { string configPath = kvp.Value.ToString(); printToFilePath = GetPathFromRegistry(kvp.Key); var tpmc = new TroyPortMonitorConfiguration(); DirectoryInfo dirInfo = new DirectoryInfo(configPath); if (!dirInfo.Exists) { EventLog.WriteEntry("TROY SecurePort Monitor", configPath + " does not exist", EventLogEntryType.Error); } else { //Read port monitor configuraton file ReadPortMonitorConfiguration(kvp.Key, configPath, printToFilePath, out tpmc); var keyName = new DirectoryInfo(printToFilePath).Name; string fileName = "TroyDataCaptureConfiguration.xml"; if (!File.Exists(configPath + fileName)) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error: Unable to open the Data Capture XML file. File name = " + configPath + fileName, EventLogEntryType.Error); } else { XmlSerializer dser = new XmlSerializer(typeof(DataCaptureList)); FileStream fs = new FileStream(configPath + "TroyDataCaptureConfiguration.xml", FileMode.Open, FileAccess.Read, FileShare.Read); DataCaptureList dcl = (DataCaptureList)dser.Deserialize(fs); fs.Close(); portDataCap.Add(keyName, dcl); SetupFontConfig(dcl, keyName, tpmc); } fileName = "TroyPrinterMap.xml"; if (!File.Exists(configPath + fileName)) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error: Unable to open the Printer Map XML file. File name = " + configPath + fileName, EventLogEntryType.Error); } else { XmlSerializer dser = new XmlSerializer(typeof(TroyPrinterMap)); FileStream fs = new FileStream(configPath + fileName, FileMode.Open, FileAccess.Read, FileShare.Read); TroyPrinterMap tpm = (TroyPrinterMap)dser.Deserialize(fs); fs.Close(); portPrintMap.Add(keyName, tpm); } fileName = "TroyPantographConfiguration.xml"; if (File.Exists(configPath + fileName)) { XmlSerializer dser = new XmlSerializer(typeof(PantographConfiguration)); FileStream fs = new FileStream(configPath + fileName, FileMode.Open, FileAccess.Read, FileShare.Read); PantographConfiguration temp = (PantographConfiguration)dser.Deserialize(fs); fs.Close(); portPantoConfig.Add(keyName, temp); } } return(tpmc); }
private void SetupFontConfig(DataCaptureList dcl, string dirName, TroyPortMonitorConfiguration tpmc) { try { Dictionary <string, string> fontgs = new Dictionary <string, string>(); XmlSerializer dsers = new XmlSerializer(typeof(TroyFontGlyphMapList)); FileStream fss = new FileStream(serviceConfigFilePath + "TroyFontGlyphConfiguration.xml", FileMode.Open, FileAccess.Read, FileShare.Read); tfgml = (TroyFontGlyphMapList)dsers.Deserialize(fss); fss.Close(); foreach (TroyFontGlyphMap tfgm in tfgml.FontGlyphMapList) { fontgs.Add(tfgm.FontName, tfgm.FontGlyphFileName); } bool PlainText = false; bool TroyFont = false; bool PjlData = false; bool DynamicPrint = false; TroyFontConfiguration tfc = new TroyFontConfiguration(); List <string> UsedFontNames = new List <string>(); TroyFontInfo tfi; if (tpmc.UseConfigurableDataCapture) { foreach (TroyDataCaptureConfiguration dcc in dcl.DataCaptureConfigurationList) { switch (dcc.DataCapture) { case DataCaptureType.PjlHeader: PjlData = true; break; case DataCaptureType.PlainText: PlainText = true; break; case DataCaptureType.TroyFonts: TroyFont = true; break; } if (dcc.DataUse == DataUseType.PrinterMap) { DynamicPrint = true; } if ((dcc.DataCapture == DataCaptureType.StandardFonts) && (dcc.FontNames.Count > 0)) { foreach (string fn in dcc.FontNames) { if (UsedFontNames.Contains(fn)) { foreach (TroyFontInfo ti in tfc.TroyFontInfoList) { if (ti.FontName == fn) { switch (dcc.DataUse) { case DataUseType.PassThrough: ti.UseForPassThrough = true; break; case DataUseType.PrinterMap: ti.UseForPrinterMap = true; break; case DataUseType.TroyMark: ti.UseForTroyMark = true; ti.UseAllDataForTm = dcc.UseAllData; break; case DataUseType.MicroPrint: ti.UseForMicroPrint = true; ti.UseAllDataForMp = dcc.UseAllData; break; } if (!ti.RemoveData) { ti.RemoveData = dcc.RemoveData; } break; } } } else { if (fontgs.ContainsKey(fn)) { UsedFontNames.Add(fn); tfi = new TroyFontInfo(); tfi.FontName = fn; tfi.FontType = "Data Capture"; tfi.GlyphMapFile = fontgs[fn]; tfi.LoadGlyphToCharMap(serviceConfigFilePath + "Data\\" + tfi.GlyphMapFile); tfi.RemoveData = dcc.RemoveData; switch (dcc.DataUse) { case DataUseType.PassThrough: tfi.UseForPassThrough = true; break; case DataUseType.PrinterMap: tfi.UseForPrinterMap = true; break; case DataUseType.TroyMark: tfi.UseForTroyMark = true; tfi.UseAllDataForTm = dcc.UseAllData; break; case DataUseType.MicroPrint: tfi.UseForMicroPrint = true; tfi.UseAllDataForMp = dcc.UseAllData; break; } tfc.TroyFontInfoList.Add(tfi); } else { //Error, can not find glyph } } } } } } else if (tpmc.UseSecureRxSetup) { if (tpmc.SecureRxFonts != "") { foreach (string str in tpmc.SecureRxFonts.Split(',')) { tfi = new TroyFontInfo(); tfi.FontName = str; if (tpmc.SaveFontDataAsTokens) { tfi.FontType = "Data Tokens"; } else { tfi.FontType = "Data Capture"; } tfi.GlyphMapFile = "StandardGlyphMap.csv"; tfi.LoadGlyphToCharMap(serviceConfigFilePath + "Data\\" + tfi.GlyphMapFile); tfi.RemoveData = false; tfi.UseForTroyMark = true; tfc.TroyFontInfoList.Add(tfi); } } else if (tpmc.PlainTextData) { PlainText = true; } } else { } DataCaptureFlags dcf = new DataCaptureFlags(); dcf.EnableLookForTroyFontCalls = TroyFont; dcf.EnablePjlHeaderCapture = PjlData; dcf.EnablePlainTextCapture = PlainText; dcf.DynamicPrinterConfig = DynamicPrint; portDataCapFlags.Add(dirName, dcf); portFonts.Add(dirName, tfc); } catch (Exception ex) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error in SetupFontConfig. Error: " + ex.Message, EventLogEntryType.Error); } }
public static PrintJobThread setupPrintJob(string fullname) { string fullnamePath = extractPath(fullname); PrintJobThread printJob = new PrintJobThread(); printJob.printFileName = fullname; FileInfo fi = new FileInfo(fullname); string dirName = fi.Directory.Name; TroyPortMonitorConfiguration tpmc = portConfigs[dirName]; if (tpmc != null) { printJob.pmConfig = tpmc; } else { Exception ex1 = new Exception("Error: Could not find Configuration for directory " + dirName); throw ex1; } var pml = portLogs[dirName]; if (pml != null) { printJob.pmLogging = pml; } DataCaptureList dcl = portDataCap[dirName]; if (dcl != null) { printJob.dCapConfig = dcl; } TroyPrinterMap pm = portPrintMap[dirName]; if (pm != null) { printJob.printerMap = pm; } TroyFontConfiguration tfc = portFonts[dirName]; if (tfc != null) { printJob.fontConfigs = tfc; } DataCaptureFlags dcf = portDataCapFlags[dirName]; if (dcf != null) { printJob.dataCapFlags = dcf; } PantographConfiguration pgc = portPantoConfig[dirName]; if (pgc != null) { printJob.pantoConfig = pgc; } printJob.insertPjl = InsertPjl; printJob.SoftwarePantograph = UsingSoftwarePantograph; printJob.SoftwareTroyMark = UsingSoftwareTroymark; return(printJob); }
private static void fileWatcherService_Changed(object source, FileSystemEventArgs e) { try { PrintJobThread printJob = new PrintJobThread(); printJob.printFileName = e.FullPath; FileInfo getPath = new FileInfo(e.FullPath); string filePath = getPath.DirectoryName.ToString(); if ((filePath.Length > 0) && (!filePath.EndsWith("\\"))) { filePath += "\\"; } TroyPortMonitorConfiguration tpmc = portConfigs[filePath]; if (tpmc != null) { printJob.pmConfig = tpmc; } else { Exception ex1 = new Exception("Error: Could not find Configuration for file path " + filePath); throw ex1; } portMonLogging = portLogs[filePath]; if (portLogs != null) { printJob.pmLogging = portMonLogging; } DataCaptureList customConfiguration = portDataCap[filePath]; if (customConfiguration != null) { printJob.dCapConfig = customConfiguration; } TroyPrinterMap tpm = portPrintMap[filePath]; if (tpm != null) { printJob.printerMap = tpm; } TroyFontConfiguration tfc = portFonts[filePath]; if (tfc != null) { printJob.fontConfigs = tfc; } DataCaptureFlags dcf = dataCapFlags[filePath]; if (dcf != null) { printJob.dataCapFlags = dcf; } PantographConfiguration pgc = portPantoConfig[filePath]; if (pgc != null) { printJob.pantoConfig = pgc; } printJob.insertPjl = InsertPjl; //printJob.LicenseStatus = ls; printJob.SoftwarePantograph = UsingSoftwarePantograph; printJob.SoftwareTroyMark = UsingSoftwareTroymark; Thread printJobThread = new Thread(new ThreadStart(printJob.PrintJobReceived)); printJobThread.Name = e.Name + " thread"; printJobThread.IsBackground = true; printJobThread.Priority = ThreadPriority.Normal; printJobThread.Start(); } catch (Exception ex) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error in fileWatcherService_Changed. Error: " + ex.Message, EventLogEntryType.Error); } }
private void SetupFileWatchers() { try { printToFilePath = ""; string configPath; FileSystemWatcher fileWatcher; TroyPortMonitorConfiguration tpmc = null; DataCaptureList dcl = null; foreach (KeyValuePair <string, string> kvp in portsForFileWatcher) { printToFilePath = GetPathFromRegistry(kvp.Key); if (kvp.Value == "") { configPath = ""; } //Default is the print to file path + the config folder else if (kvp.Value.ToUpper() == "DEFAULT") { configPath = printToFilePath + "Config\\"; } else { configPath = kvp.Value.ToString(); } string Extension = ""; if (configPath != "") { if (!configPath.EndsWith("\\")) { configPath += "\\"; } DirectoryInfo dirInfo = new DirectoryInfo(configPath); if (!dirInfo.Exists) { } else { //Read port monitor configuraton file tpmc = new TroyPortMonitorConfiguration(); ReadPortMonitorConfiguration(kvp.Key, configPath, printToFilePath, out Extension, out tpmc); string fileName = "TroyDataCaptureConfiguration.xml"; if (!File.Exists(configPath + fileName)) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error: Unable to open the Data Capture XML file. File name = " + configPath + fileName, EventLogEntryType.Error); } else { XmlSerializer dser = new XmlSerializer(typeof(DataCaptureList)); FileStream fs = new FileStream(configPath + "TroyDataCaptureConfiguration.xml", FileMode.Open, FileAccess.Read, FileShare.Read); dcl = (DataCaptureList)dser.Deserialize(fs); fs.Close(); portDataCap.Add(printToFilePath, dcl); SetupFontConfig(dcl, printToFilePath, tpmc); } fileName = "TroyPrinterMap.xml"; if (!File.Exists(configPath + fileName)) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error: Unable to open the Printer Map XML file. File name = " + configPath + fileName, EventLogEntryType.Error); } else { XmlSerializer dser = new XmlSerializer(typeof(TroyPrinterMap)); FileStream fs = new FileStream(configPath + fileName, FileMode.Open, FileAccess.Read, FileShare.Read); TroyPrinterMap tpm = (TroyPrinterMap)dser.Deserialize(fs); fs.Close(); portPrintMap.Add(printToFilePath, tpm); } fileName = "TroyPantographConfiguration.xml"; if (File.Exists(configPath + fileName)) { XmlSerializer dser = new XmlSerializer(typeof(PantographConfiguration)); FileStream fs = new FileStream(configPath + fileName, FileMode.Open, FileAccess.Read, FileShare.Read); PantographConfiguration temp = (PantographConfiguration)dser.Deserialize(fs); fs.Close(); portPantoConfig.Add(printToFilePath, temp); } } } DirectoryInfo dirCheck = new DirectoryInfo(printToFilePath); if (!dirCheck.Exists) { dirCheck.Create(); } else { if (!ReprintFiles) { foreach (FileInfo file in dirCheck.GetFiles("*." + Extension)) { file.Delete(); } foreach (FileInfo file2 in dirCheck.GetFiles("*.bak")) { file2.Delete(); } foreach (FileInfo file2 in dirCheck.GetFiles("*.enc")) { file2.Delete(); } } } fileWatcher = new FileSystemWatcher(); fileWatcher.InternalBufferSize = 12288; fileWatcher.Path = printToFilePath; fileWatcher.NotifyFilter = NotifyFilters.FileName; fileWatcher.Filter = "*." + Extension; fileWatcher.IncludeSubdirectories = false; //EVENTS HANDLERS (Note: Only one event handler is needed for both events) fileWatcher.Changed += new FileSystemEventHandler(fileWatcherService_Changed); fileWatcher.Created += new FileSystemEventHandler(fileWatcherService_Changed); //ENABLE fileWatcher.EnableRaisingEvents = true; fileWatchers.Add(fileWatcher); if (ReprintFiles) { if (tpmc != null) { foreach (FileInfo file in dirCheck.GetFiles("*." + tpmc.FileExtension)) { PrintJobThread printJob = new PrintJobThread(); printJob.printFileName = file.FullName; printJob.pmConfig = tpmc; printJob.pmLogging = portMonLogging; TroyPrinterMap tpm = portPrintMap[printToFilePath]; if (tpm != null) { printJob.printerMap = tpm; } TroyFontConfiguration tfc = portFonts[printToFilePath]; if (tfc != null) { printJob.fontConfigs = tfc; } //TroyFontConfiguration tfc2 = portFonts2[printToFilePath]; //if (tfc2 != null) //{ // printJob.fontConfigs2 = tfc2; //} if (dcl != null) { printJob.dCapConfig = dcl; } DataCaptureFlags dcf = dataCapFlags[printToFilePath]; if (dcf != null) { printJob.dataCapFlags = dcf; } //printJob.LicenseStatus = ls; printJob.SoftwarePantograph = UsingSoftwarePantograph; printJob.SoftwareTroyMark = UsingSoftwareTroymark; Thread printJobThread = new Thread(new ThreadStart(printJob.PrintJobReceived)); printJobThread.Name = file.Name + " thread"; printJobThread.IsBackground = true; printJobThread.Priority = ThreadPriority.Normal; printJobThread.Start(); Thread.Sleep(200); } } } } } catch (Exception ex) { EventLog.WriteEntry("TROY SecurePort Monitor", "Error in SetupFileWatchers. Error: " + ex.Message, EventLogEntryType.Error); throw ex; } finally { #if (DEBUG) Console.WriteLine("waiting..."); Console.Read(); #endif } }