Opc.Ua.Configuration.ManagedApplication.SetExecutableFile C# (CSharp) Method

SetExecutableFile() public method

Sets the executable file.
public SetExecutableFile ( string filePath ) : void
filePath string The file path.
return void
        public void SetExecutableFile(string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                m_executablePath = null;
                return;
            }

            m_executablePath = filePath;
            m_configurationPath = null;
            m_isSdkCompatible = false;
            m_application = null;

            FileInfo executableFile = new FileInfo(m_executablePath);
            m_displayName = executableFile.Name.Substring(0, executableFile.Name.Length-4);

            FileInfo configFile = new FileInfo(executableFile.FullName + ".config");
            // Utils.Trace(1, "APPCONFIG={0}", configFile);

            if (configFile.Exists)
            {
                // save the .NET config file.
                m_configurationPath = configFile.FullName;

                // look for the UA SDK config file.
                string configurationPath = GetConfigFileFromAppConfig(configFile);
                // Utils.Trace(1, "UACONFIG={0}", configurationPath);

                if (configurationPath != null)
                {
                    m_configurationPath = configurationPath;
                }
                else
                {
                    m_configurationPath = configFile.FullName;
                }

                LoadSdkConfigFile();
            }

            // set display name.
            if (m_sourceFile == null || String.IsNullOrEmpty(m_displayName))
            {
                string name = executableFile.Name;
                int index = name.LastIndexOf('.');

                if (index > 0)
                {
                    name = name.Substring(0, index);
                }

                m_displayName = name;
            }
        }

Usage Example

        /// <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;
            }
        }
All Usage Examples Of Opc.Ua.Configuration.ManagedApplication::SetExecutableFile