private void ReadMainConfiguration()
        {
            try
            {
                Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.LocalMachine;
                Microsoft.Win32.RegistryKey pmKey       = registryKey.OpenSubKey(REGISTRY_PATH_LOCATION, false);
                serviceConfigFilePath = pmKey.GetValue("MainConfigurationPath").ToString();
                if ((serviceConfigFilePath.Length > 0) && (!serviceConfigFilePath.EndsWith("\\")))
                {
                    serviceConfigFilePath += "\\";
                }

                string configFile = serviceConfigFilePath + "TroyPMServiceConfiguration.xml";

                if (File.Exists(configFile))
                {
                    //Deserialize the service configuration
                    XmlSerializer dser1 = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                    FileStream    fs    = new FileStream(configFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                    TroyPortMonitorServiceConfiguration tmsc = (TroyPortMonitorServiceConfiguration)dser1.Deserialize(fs);
                    fs.Close();

                    UsingSoftwarePantograph = tmsc.UserInterface.UseAsSecurePrint;
                    UsingSoftwareTroymark   = tmsc.UserInterface.UseAsSecurePrint;

                    ReprintFiles = tmsc.PrintJobsOnRestart;
                    InsertPjl    = tmsc.InsertPjlHeader;

                    foreach (TroySecurePort tsp in tmsc.PortList)
                    {
                        if ((tsp.ConfigurationPath.ToUpper() != "DEFAULT") &&
                            (tsp.ConfigurationPath.Length > 0) &&
                            (!tsp.ConfigurationPath.EndsWith("\\")))
                        {
                            tsp.ConfigurationPath += "\\";
                        }
                        if (portsForFileWatcher.ContainsKey(tsp.PortMonitorName))
                        {
                            MessageBox.Show("Error: Multiple Secure Ports defined for the same TROYPORT Port Monitor.  Port Monitor = " + tsp.PortMonitorName, "TROY Port Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                            EventLog.WriteEntry("TROY SecurePort Monitor", "Error: Multiple Port Monitor Service defined for the same Port Monitor.  Port Monitor = " + tsp.PortMonitorName, EventLogEntryType.Error);
                        }
                        else
                        {
                            portsForFileWatcher.Add(tsp.PortMonitorName, tsp.ConfigurationPath);
                        }
                    }
                }
                else
                {
                    Exception newEx = new Exception("Invalid File Path for Main Configuration File.  File: " + configFile);
                    throw newEx;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fatal Error!  Error In ReadMainConfiguation. " + ex.Message.ToString(), "TROY Port Monitor Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
                throw ex;
            }
        }
Beispiel #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if ((cboPortType.Text != CurrentPortType) ||
                (txtName.Text != PortName))
            {
                //Deserialize the service configuration
                string        serviceXmlFile = filePath + "TroyPMServiceConfiguration.xml";
                XmlSerializer dser1          = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                FileStream    fs             = new FileStream(serviceXmlFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                TroyPortMonitorServiceConfiguration tpmsc = (TroyPortMonitorServiceConfiguration)dser1.Deserialize(fs);
                fs.Close();

                foreach (TroySecurePort tsp in tpmsc.PortList)
                {
                    if (tsp.PortName == PortName)
                    {
                        string portMonName = tsp.PortMonitorName;
                        string portPath    = GetPortPath(portMonName);
                        if (portPath != "")
                        {
                            string portConfigPath = portPath + "Config\\";
                            if (cboPortType.Text != CurrentPortType)
                            {
                                string PortConfiguration = filePath + "Configuration\\" + cboPortType.Text;
                                if (Directory.Exists(PortConfiguration))
                                {
                                    DirectoryInfo filesCopy = new DirectoryInfo(PortConfiguration);
                                    foreach (FileInfo fInfo in filesCopy.GetFiles())
                                    {
                                        fInfo.CopyTo(portConfigPath + fInfo.Name, true);
                                    }
                                }
                            }
                        }
                        if (PortName != txtName.Text)
                        {
                            tsp.PortName = PortName;
                            XmlSerializer xser   = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                            TextWriter    writer = new StreamWriter(serviceXmlFile);
                            xser.Serialize(writer, tsp);
                            writer.Close();
                        }


                        break;
                    }
                }
            }
            this.Close();
        }
Beispiel #3
0
        private bool ReadMainPortConfig()
        {
            try
            {
                if (GetBasePath())
                {
                    //Check if the service configuration xml file exists.
                    string serviceXmlFile = baseFilePath + "TroyPMServiceConfiguration.xml";
                    if (!File.Exists(serviceXmlFile))
                    {
                        MessageBox.Show("Fatal Error.  File " + serviceXmlFile + " does not exist.  Can not continue.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }

                    //Deserialize the service configuration
                    XmlSerializer dser1 = new XmlSerializer(typeof(TroyPortMonitorServiceConfiguration));
                    FileStream    fs    = new FileStream(serviceXmlFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                    tpmsc_local = (TroyPortMonitorServiceConfiguration)dser1.Deserialize(fs);
                    fs.Close();

                    PrintSpoolerName = tpmsc_local.PrintSpoolerName;

                    UsingSoftwarePantograph = tpmsc_local.UserInterface.UseAsSecurePrint;
                    UsingSoftwareTroymark   = tpmsc_local.UserInterface.UseAsSecurePrint;

                    cboPortType.Items.Clear();
                    lblPortType.Enabled          = false;
                    cboPortType.Enabled          = false;
                    chkIncludeTypeInName.Enabled = false;
                    string        configurationFilePath = baseFilePath + "Configuration";
                    DirectoryInfo di        = new DirectoryInfo(configurationFilePath);
                    int           subdircnt = di.GetDirectories().Length;

                    if (subdircnt < 1)
                    {
                        //keep port type controls disabled
                        cboPortType.Text = @"";
                    }
                    else if (subdircnt > 0)
                    {
                        foreach (DirectoryInfo subdi in di.GetDirectories())
                        {
                            cboPortType.Items.Add(subdi.Name);
                        }
                        if (subdircnt == 1)
                        {
                            cboPortType.Text = cboPortType.Items[0].ToString();
                        }
                        else
                        {
                            lblPortType.Enabled          = true;
                            cboPortType.Enabled          = true;
                            chkIncludeTypeInName.Enabled = true;
                        }
                    }

                    //Loop through each port
                    string portString, portConfigPath, portMonName, portPath, dataPath = "";
                    foreach (TroySecurePort tsp in tpmsc_local.PortList)
                    {
                        portString = tsp.PortName;

                        portMonName    = tsp.PortMonitorName;
                        portConfigPath = tsp.ConfigurationPath;

                        troyPorts.Add(portString, portMonName);
                        configPaths.Add(portString, portConfigPath);
                    }

                    string defaultPortName;
                    for (int cntr = 1; cntr < MAX_NUMBER_OF_PORTS; cntr++)
                    {
                        defaultPortName = "Troy Secure Port " + cntr.ToString();
                        bool nextonefound = false;
                        foreach (KeyValuePair <string, string> kvp in troyPorts)
                        {
                            if (!kvp.Key.StartsWith(defaultPortName))
                            {
                                nextonefound = true;
                            }
                            else
                            {
                                nextonefound = false;
                                break;
                            }
                        }
                        if (nextonefound)
                        {
                            txtNewPortName.Text = defaultPortName;
                            if (chkIncludeTypeInName.Checked)
                            {
                                txtNewPortName.Text = txtNewPortName.Text + " (" + cboPortType.Text + ")";
                            }
                            currentPortNumber = cntr;
                            break;
                        }
                    }
                    return(true);
                }
                else
                {
                    MessageBox.Show("Error reading base path from Registry.", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Opening Port Monitor Configuration. Application will close. Path: " + filePath, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                MessageBox.Show(ex.Message, "Exception Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }