public void StartService(string[] args) { try { //Call the routine to read the main configuration xml file for the service ReadMainConfiguration(); 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(); //Setup the file watchers for each defined port SetupFileWatchers(); } catch (Exception ex) { //portMonLogging.LogError("Fatal Error in Service Start. " + ex.Message, EventLogEntryType.Error, true); EventLog.WriteEntry("Error in Troy Port Monitor Service: " + ex.Message, EventLogEntryType.Error); ServiceStop serviceStop = new ServiceStop(this.ServiceName); Thread workerThread = new Thread(new ThreadStart(serviceStop.Start)); workerThread.Name = "Troy Service ServiceStop thread"; workerThread.Start(); } }
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); } }