Beispiel #1
0
        private bool ReadPortMonitorConfiguration(string portMonName, string configPath, string printToFilePath, out TroyPortMonitorConfiguration tpmc)
        {
            tpmc = null;
            try
            {
                string fileName = configPath + "TroyPortMonitorConfiguration.xml";
                var    dirName  = new DirectoryInfo(printToFilePath).Name;

                var dser1 = new XmlSerializer(typeof(TroyPortMonitorConfiguration));
                var fs1   = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                tpmc = (TroyPortMonitorConfiguration)dser1.Deserialize(fs1);

                fs1.Close();
                tpmc.PrintFilePath = printToFilePath;

                portMonLogging = new PortMonLogging();

                portMonLogging.LogErrorsToEventLog = tpmc.LogErrorsToEventLog;
                portMonLogging.EnableTraceLog      = tpmc.EnableTraceLog;

                if (tpmc.DebugBackupFilesPath.ToUpper() == "DEFAULT")
                {
                    tpmc.DebugBackupFilesPath = printToFilePath + "Backup\\";
                }
                if (tpmc.DebugBackupFilesPath.Length > 0)
                {
                    if (!tpmc.DebugBackupFilesPath.EndsWith("\\"))
                    {
                        tpmc.DebugBackupFilesPath += "\\";
                    }
                    Directory.CreateDirectory(tpmc.DebugBackupFilesPath);
                }

                if (tpmc.ErrorLogPath.ToUpper() == "DEFAULT")
                {
                    tpmc.ErrorLogPath = printToFilePath + "Error Log\\";
                }
                if (tpmc.ErrorLogPath.Length > 0)
                {
                    portMonLogging.LogToErrorFile = true;
                    if (!tpmc.ErrorLogPath.EndsWith("\\"))
                    {
                        tpmc.ErrorLogPath += "\\";
                    }
                    Directory.CreateDirectory(tpmc.ErrorLogPath);
                    portMonLogging.ErrorLogFilePath = tpmc.ErrorLogPath;
                    portMonLogging.InitializeErrorLog();
                    if (tpmc.EnableTraceLog)
                    {
                        portMonLogging.TraceLogPath = tpmc.ErrorLogPath;
                        portMonLogging.InitializeTraceLog();
                    }
                }

                portMonLogging.EnableMessageBoxes = tpmc.EnableMessageBoxes;

                portLogs.Add(dirName, portMonLogging);

                portConfigs.Add(dirName, tpmc);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fatal Error!  Error In ReadPortMonitorConfiguration. " + ex.Message.ToString(), "TROY Port Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                return(false);
            }
        }
        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);
            }
        }