예제 #1
0
        /// <summary>
        /// Exports a server to a export file.
        /// </summary>
        private static Export.RegisteredServer Export(RegisteredDotNetOpcServer server)
        {
            Export.RegisteredServer _serverToExport = new Export.RegisteredServer();
            _serverToExport.Clsid  = server.CLSID.ToString();
            _serverToExport.ProgId = server.ProgId;
            if (server.Description != server.ProgId)
            {
                _serverToExport.Description = server.Description;
            }
            _serverToExport.WrapperClsid = server.WrapperCLSID.ProgIDFromCLSID().Item1;
            _serverToExport.ServerClsid  = server.ServerCLSID.ProgIDFromCLSID().Item1;
            // export parameters.
            _serverToExport.Parameter = new Export.Parameter[server.Parameters.Count];
            int index = 0;

            foreach (KeyValuePair <string, string> entry in server.Parameters)
            {
                Export.Parameter parameter = new Export.Parameter();
                parameter.Name  = entry.Key;
                parameter.Value = entry.Value;
                _serverToExport.Parameter[index++] = parameter;
            }
            // return exported server.
            return(_serverToExport);
        }
예제 #2
0
        /// <summary>
        /// Imports a server from an export file.
        /// </summary>
        /// <param name="serverToImport">The server to import.</param>
        /// <returns>RegisteredDotNetOpcServer.</returns>
        private static RegisteredDotNetOpcServer Import(Export.RegisteredServer serverToImport)
        {
            RegisteredDotNetOpcServer server = new RegisteredDotNetOpcServer();

            // assign clsid if none specified.
            if (String.IsNullOrEmpty(serverToImport.Clsid))
            {
                server.CLSID = Utils.CLSIDFromProgID(serverToImport.ProgId);
                if (server.CLSID == Guid.Empty)
                {
                    server.CLSID = Guid.NewGuid();
                }
            }
            else
            {
                server.CLSID = new Guid(serverToImport.Clsid);
            }
            // get prog id and description.
            server.ProgId      = serverToImport.ProgId;
            server.Description = serverToImport.Description;
            // parse wrapper clsid/prog id.
            try
            {
                server.WrapperCLSID = new Guid(serverToImport.WrapperClsid);
            }
            catch
            {
                server.WrapperCLSID = Utils.CLSIDFromProgID(serverToImport.WrapperClsid);
            }
            // parse wrapped server clsid/prog id.
            try
            {
                server.ServerCLSID = new Guid(serverToImport.ServerClsid);
            }
            catch
            {
                server.ServerCLSID = Utils.CLSIDFromProgID(serverToImport.ServerClsid);
            }
            // read parameters.
            server.Parameters.Clear();
            if (!CommonDefinitions.IsEmpty(serverToImport.Parameter))
            {
                for (int ii = 0; ii < serverToImport.Parameter.Length; ii++)
                {
                    Export.Parameter parameter = serverToImport.Parameter[ii];
                    if (parameter != null && !String.IsNullOrEmpty(parameter.Name))
                    {
                        server.Parameters.Add(parameter.Name, parameter.Value);
                    }
                }
            }
            // return new server.
            return(server);
        }