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

Load() public static method

Loads the specified file path.
public static Load ( string filePath ) : ManagedApplication
filePath string The file path.
return ManagedApplication
        public static ManagedApplication Load(string filePath)
        {
            using (Stream istrm = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite))
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ManagedApplication));
                ManagedApplication application = (ManagedApplication)serializer.ReadObject(istrm);
                application.m_sourceFile = new FileInfo(filePath);

                if (String.IsNullOrEmpty(application.DisplayName))
                {
                    string name = application.m_sourceFile.Name;
                    int index = name.LastIndexOf('.');

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

                    application.DisplayName = name;
                }

                application.LoadSdkConfigFile();
                return application;
            }
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Adds an application to manage to the drop down menu.
        /// </summary>
        private int AddApplicationToManage(FileInfo fileInfo)
        {
            // ignore files that don't exist.
            if (fileInfo == null || !fileInfo.Exists)
            {
                return(ApplicationToManageCB.SelectedIndex);
            }

            try
            {
                ManagedApplication application = ManagedApplication.Load(fileInfo.FullName);

                if (application == null)
                {
                    return(ApplicationToManageCB.SelectedIndex);
                }

                // add to list.
                return(AddApplicationToManage(application));
            }

            // ignore errors.
            catch (Exception)
            {
                return(ApplicationToManageCB.SelectedIndex);
            }
        }