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

Save() public method

Saves the specified file path.
public Save ( string filePath ) : void
filePath string The file path. Uses the original source file path if not provided.
return void
        public void Save(string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                if (m_sourceFile == null)
                {
                    filePath = Utils.GetAbsoluteDirectoryPath("%LocalApplicationData%\\OPC Foundation\\Applications\\", false, false, true);
                    filePath += m_displayName;
                    filePath += "*.xml";
                }
                else
                {
                    filePath = m_sourceFile.FullName;
                }
            }

            using (Stream ostrm = File.Open(filePath, FileMode.Create))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ManagedApplication));
                serializer.WriteObject(ostrm, this);
            }

            m_sourceFile = new FileInfo(filePath);
        }

Usage Example

コード例 #1
0
        /// <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::Save