SetExecutableFile() public method

Sets the executable file.
public SetExecutableFile ( string filePath ) : void
filePath string The file path.
return void
        /// <summary>
        /// Loads the applications from disk.
        /// </summary>
        public void LoadApplications()
        {
            ApplicationToManageCB.Items.Clear();

            // add the recent files.
            foreach (string filePath in Utils.GetRecentFileList(m_groupName))
            {
                AddApplicationToManage(new FileInfo(filePath));
            }

            // load the config files for any OPC applications.
            string configDir = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications", false, false, true);

            if (configDir != null)
            {
                foreach (FileInfo fileInfo in new DirectoryInfo(configDir).GetFiles("*.xml"))
                {
                    AddApplicationToManage(fileInfo);
                }
            }

            // add the standard applications.
            foreach (string fileName in s_StandardApplications)
            {
                string filePath = Utils.FindInstalledFile(fileName);

                if (!String.IsNullOrEmpty(filePath))
                {
                    ManagedApplication application = new ManagedApplication();
                    application.SetExecutableFile(filePath);

                    bool found = false;

                    foreach (ManagedApplication item in ApplicationToManageCB.Items)
                    {
                        if (item.ExecutablePath != null)
                        {
                            if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        application.Save(configDir + "\\" + application.DisplayName + ".xml");
                        AddApplicationToManage(application);
                    }
                }
            }

            // select the first item.
            if (ApplicationToManageCB.Items.Count > 0)
            {
                ApplicationToManageCB.SelectedIndex = 0;
            }
        }
Esempio n. 2
0
        private void NewApplicationBTN_Click(object sender, EventArgs e)
        {
            try
            {
                // set current directory.
                if (m_currentDirectory == null)
                {
                    m_currentDirectory = Utils.GetAbsoluteDirectoryPath("%ProgramFiles%", false, false);
                }

                // open file dialog.
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.CheckFileExists  = true;
                dialog.CheckPathExists  = true;
                dialog.DefaultExt       = ".exe";
                dialog.Filter           = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*";
                dialog.Multiselect      = false;
                dialog.ValidateNames    = true;
                dialog.Title            = "Select Wrapper Executable File";
                dialog.FileName         = null;
                dialog.InitialDirectory = m_currentDirectory;
                dialog.RestoreDirectory = true;

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FileInfo executableFile = new FileInfo(dialog.FileName);
                m_currentDirectory = executableFile.Directory.FullName;

                ManagedApplication application = new ManagedApplication();
                application.SetExecutableFile(executableFile.FullName);

                for (int ii = 0; ii < ApplicationToManageCB.Items.Count; ii++)
                {
                    ManagedApplication item = ApplicationToManageCB.Items[ii] as ManagedApplication;

                    if (item != null)
                    {
                        if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            ApplicationToManageCB.SelectedIndex = ii;
                            return;
                        }
                    }
                }

                ApplicationToManageCB.SelectedIndex = ApplicationToManageCB.Items.Add(application);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        private void ExecutableBTN_Click(object sender, EventArgs e)
        {
            try
            {
                // get current executable file.
                if (!String.IsNullOrEmpty(ExecutableFileTB.Text))
                {
                    FileInfo filePath = new FileInfo(ExecutableFileTB.Text);

                    if (filePath.Exists)
                    {
                        m_currentDirectory = filePath.Directory.FullName;
                    }
                }

                // set current directory.
                if (m_currentDirectory == null)
                {
                    m_currentDirectory = Utils.GetAbsoluteDirectoryPath("%ProgramFiles%", false, false);
                }

                // open file dialog.
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.CheckFileExists  = true;
                dialog.CheckPathExists  = true;
                dialog.DefaultExt       = ".exe";
                dialog.Filter           = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*";
                dialog.Multiselect      = false;
                dialog.ValidateNames    = true;
                dialog.Title            = "Select Application Executable File";
                dialog.FileName         = null;
                dialog.InitialDirectory = m_currentDirectory;
                dialog.RestoreDirectory = true;

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FileInfo executableFile = new FileInfo(dialog.FileName);
                m_currentDirectory    = executableFile.Directory.FullName;
                ExecutableFileTB.Text = executableFile.FullName;

                m_application.SetExecutableFile(executableFile.FullName);

                // update the control.
                Update(m_application);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
Esempio n. 4
0
        private void ApplicationToManageCB_DropDown(object sender, EventArgs e)
        {
            try
            {
                ApplicationToManageCB.Items.Clear();

                List <string> applications = Utils.GetRecentFileList("COM Wrappers");

                for (int ii = 0; ii < applications.Count; ii++)
                {
                    if (File.Exists(applications[ii]))
                    {
                        ManagedApplication application = new ManagedApplication();
                        application.SetExecutableFile(applications[ii]);
                        ApplicationToManageCB.Items.Add(application);
                    }
                }

                if (ApplicationToManageCB.Items.Count == 0)
                {
                    // find the wrapper.
                    string path = Utils.FindInstalledFile("Opc.Ua.ComServerWrapper.exe");

                    if (path != null)
                    {
                        ManagedApplication application = new ManagedApplication();
                        application.SetExecutableFile(path);
                        ApplicationToManageCB.Items.Add(application);
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        private void ApplicationToManageCB_DropDown(object sender, EventArgs e)
        {
            try
            {
                ApplicationToManageCB.Items.Clear();

                List<string> applications = Utils.GetRecentFileList("COM Wrappers");

                for (int ii = 0; ii < applications.Count; ii++)
                {
                    if (File.Exists(applications[ii]))
                    {
                        ManagedApplication application = new ManagedApplication();
                        application.SetExecutableFile(applications[ii]);
                        ApplicationToManageCB.Items.Add(application);
                    }
                }

                if (ApplicationToManageCB.Items.Count == 0)
                {
                    // find the wrapper.
                    string path = Utils.FindInstalledFile("Opc.Ua.ComServerWrapper.exe");

                    if (path != null)
                    {
                        ManagedApplication application = new ManagedApplication();
                        application.SetExecutableFile(path);
                        ApplicationToManageCB.Items.Add(application);
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        private void NewApplicationBTN_Click(object sender, EventArgs e)
        {
            try
            {
                // set current directory.
                if (m_currentDirectory == null)
                {
                    m_currentDirectory = Utils.GetAbsoluteDirectoryPath("%ProgramFiles%", false, false);
                }

                // open file dialog.
                OpenFileDialog dialog = new OpenFileDialog();

                dialog.CheckFileExists = true;
                dialog.CheckPathExists = true;
                dialog.DefaultExt = ".exe";
                dialog.Filter = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*";
                dialog.Multiselect = false;
                dialog.ValidateNames = true;
                dialog.Title = "Select Wrapper Executable File";
                dialog.FileName = null;
                dialog.InitialDirectory = m_currentDirectory;
                dialog.RestoreDirectory = true;

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FileInfo executableFile = new FileInfo(dialog.FileName);
                m_currentDirectory = executableFile.Directory.FullName;

                ManagedApplication application = new ManagedApplication();
                application.SetExecutableFile(executableFile.FullName);

                for (int ii = 0; ii < ApplicationToManageCB.Items.Count; ii++)
                {
                    ManagedApplication item = ApplicationToManageCB.Items[ii] as ManagedApplication;

                    if (item != null)
                    {
                        if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            ApplicationToManageCB.SelectedIndex = ii;
                            return;
                        }
                    }
                }

                ApplicationToManageCB.SelectedIndex = ApplicationToManageCB.Items.Add(application);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <summary>
        /// Loads the applications from disk.
        /// </summary>
        public void LoadApplications()
        {
            ApplicationToManageCB.Items.Clear();

            // add the recent files.
            foreach (string filePath in Utils.GetRecentFileList(m_groupName))
            {
                AddApplicationToManage(new FileInfo(filePath));
            }

            // load the config files for any OPC applications.
            string configDir = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications", false, false, true);

            if (configDir != null)
            {
                foreach (FileInfo fileInfo in new DirectoryInfo(configDir).GetFiles("*.xml"))
                {
                    AddApplicationToManage(fileInfo);
                }
            }

            // add the standard applications.
            foreach (string fileName in s_StandardApplications)
            {
                string filePath = Utils.FindInstalledFile(fileName);

                if (!String.IsNullOrEmpty(filePath))
                {
                    ManagedApplication application = new ManagedApplication();
                    application.SetExecutableFile(filePath);

                    bool found = false;

                    foreach (ManagedApplication item in ApplicationToManageCB.Items)
                    {
                        if (item.ExecutablePath != null)
                        {
                            if (String.Compare(item.ExecutablePath, application.ExecutablePath, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found)
                    {
                        application.Save(configDir + "\\" + application.DisplayName + ".xml");
                        AddApplicationToManage(application);
                    }
                }
            }

            // select the first item.
            if (ApplicationToManageCB.Items.Count > 0)
            {
                ApplicationToManageCB.SelectedIndex = 0;
            }
        }
Esempio n. 8
0
        private void RegisterWithDiscoveryServerBTN_Click(object sender, EventArgs e)
        {
            try
            {
                const string caption = "Register with Discovery Server";

                ManagedApplication application = ManageApplicationSecurityCTRL.GetSelectedApplication();

                if (application == null)
                {
                    return;
                }

                application.Reload();

                if (application.Certificate == null)
                {
                    MessageBox.Show(this, "Certificate is not specified.", caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // find discovery server.
                string path = Utils.FindInstalledFile("Opc.Ua.DiscoveryServer.exe");

                if (path == null)
                {
                    MessageBox.Show("Could not find the discovery server. Please confirm that it is installed.", caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ManagedApplication lds = new ManagedApplication();
                lds.SetExecutableFile(path);

                if (!SetupTrustRelationship(application, lds))
                {
                    return;
                }

                MessageBox.Show("The Local Discovery Server now trusts the application.", caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }