/// <summary> /// Converts the object to a displayable string. /// </summary> public override string ToString() { if (!String.IsNullOrEmpty(ProgId)) { return(ProgId); } if (CLSID == Guid.Empty) { return("(unknown)"); } return(CLSID.ToString()); }
/// <summary> /// Registers this instance as a COM server with the specified CLSID. /// </summary> public void Register() { DotNetOpcServer _server = new DotNetOpcServer(ServerCLSID); if (_server.Specifications == Specifications.None) { throw new ApplicationException("The .NET server does not implement any OPC specifications."); } DotNetOpcServerWrapper _wrapper = new DotNetOpcServerWrapper(WrapperCLSID); if (_wrapper.Specifications == Specifications.None) { throw new ApplicationException("The .NET server wrapper does not implement any OPC interfaces."); } // determine the intersection of between the specs supported by the wrapper and the specs supported by the server. Specifications specifications = _wrapper.Specifications & _server.Specifications; if (specifications == Specifications.None) { throw new ApplicationException("The .NET server wrapper does not implement any OPC interfaces supported by the .NET server."); } // verify url and prog id. string _progId = ProgId; if (WrapperCLSID == Guid.Empty || String.IsNullOrEmpty(_progId)) { throw new ApplicationException("Proxy does not have a valid wrapper clsid or prog id."); } // verify wrapper path. string _wrapperPath = WrapperCLSID.GetExecutablePath(); if (_wrapperPath == null) { throw new ApplicationException("OPC server wrapper is not registered on this machine."); } // remove existing CLSID. Guid _existingClsid = Utils.CLSIDFromProgID(_progId); if (_existingClsid != CLSID) { Utils.UnregisterComServer(_existingClsid); } string _CLSIDKey = String.Format(@"CLSID\{{{0}}}", CLSID.ToString().ToUpper()); // create new entries. RegistryKey _key = Registry.ClassesRoot.CreateSubKey(_CLSIDKey); if (_key == null) { throw new ApplicationException("Could not create key: " + _CLSIDKey); } // save description. if (String.IsNullOrEmpty(m_description)) { m_description = _progId; } _key.SetValue(null, m_description); try { // create local server key. RegistryKey _subkey = _key.CreateSubKey("LocalServer32"); if (_subkey == null) { throw new ApplicationException("Could not create key: LocalServer32"); } _subkey.SetValue(null, _wrapperPath); _subkey.SetValue("WrapperClsid", String.Format("{{{0}}}", WrapperCLSID)); _subkey.Close(); // create prog id key. _subkey = _key.CreateSubKey("ProgId"); if (_subkey == null) { throw new ApplicationException("Could not create key: ProgId"); } _subkey.SetValue(null, _progId); _subkey.Close(); // create endpoint key. _subkey = _key.CreateSubKey(WrappedServerSubKey); if (_subkey == null) { throw new ApplicationException("Could not create key: " + WrappedServerSubKey); } // add parameters. try { _subkey.SetValue(null, String.Format("{{{0}}}", ServerCLSID)); // remove unused parameters. foreach (string name in _subkey.GetValueNames()) { if (!String.IsNullOrEmpty(name) && !m_parameters.ContainsKey(name)) { _subkey.DeleteValue(name, false); } } // add new parameters. foreach (KeyValuePair <string, string> entry in m_parameters) { if (!String.IsNullOrEmpty(entry.Key)) { _subkey.SetValue(entry.Key, entry.Value); } } } finally { _subkey.Close(); } } finally { _key.Close(); } // create prog id key. _key = Registry.ClassesRoot.CreateSubKey(_progId); if (_key == null) { throw new ApplicationException("Could not create key: " + _progId); } try { // create clsid key. RegistryKey _subkey = _key.CreateSubKey("CLSID"); if (_subkey == null) { throw new ApplicationException("Could not create key: CLSID"); } _subkey.SetValue(null, String.Format("{{{0}}}", CLSID.ToString().ToUpper())); _subkey.Close(); // create the OPC key use with DA 2.0 servers. if ((specifications & Specifications.DA2) != 0) { _subkey = _key.CreateSubKey("OPC"); if (_subkey == null) { throw new ApplicationException("Could not create key: OPC"); } _subkey.Close(); } } finally { _key.Close(); } // register as wrapper server. Utils.RegisterClassInCategory(CLSID, CommonDefinitions.CATID_RegisteredDotNetOpcServers, "OPC Wrapped COM Server Proxy"); // register in OPC component categories. if ((specifications & Specifications.DA2) != 0) { Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Da.CATID_OPCDAServer20).GUID); } if ((specifications & Specifications.DA3) != 0) { Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Da.CATID_OPCDAServer30).GUID); } if ((specifications & Specifications.AE) != 0) { Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Ae.CATID_OPCAEServer10).GUID); } if ((specifications & Specifications.HDA) != 0) { Utils.RegisterClassInCategory(CLSID, typeof(OpcRcw.Hda.CATID_OPCHDAServer10).GUID); } }
protected override void ProcessRecord() { if (!Environment.UserInteractive) throw new InvalidOperationException("Non-Interactive mode detected. OneDrive Status can only be checked interactively"); if (UacHelper.IsProcessElevated) throw new InvalidOperationException("PowerShell is running in Administrator mode. OneDrive status cannot be checked in elevated privileges"); WriteLog.ShouldLog = IncludeLog; if (IncludeLog) WriteVerbose("Log file is being saved @ "+WriteLog.FileName); if (dllPath == null) { CopyDLL(); } OdSyncStatusWS os = new OdSyncStatusWS(); List<StatusDetail> statuses = new List<StatusDetail>(); // Just Get the Path if(!String.IsNullOrEmpty(ByPath)) { if(CLSID == Guid.Empty) WriteObject(os.GetStatus(ByPath).ToString()); else { WriteObject(Native.API.IsCertainType(ByPath, CLSID)); } return; } var statusCol = os.GetStatus(); foreach(var status in statusCol) { if (String.IsNullOrEmpty(Type) || status.ServiceType.ToLower().Contains(Type.ToLower().Replace("*", ""))) { if(CLSID != Guid.Empty) { status.StatusString = Native.API.IsCertainType(status.LocalPath, CLSID) ? "GuidFound "+CLSID.ToString("B") : "GuidNotFound " + CLSID.ToString("B"); } statuses.Add(status); } } WriteObject(statuses.ToArray()); }
// private bool disposedValue; protected override void ProcessRecord() { base.ProcessRecord(); if (!Environment.UserInteractive && ParameterSetName != OnDemandString) { throw new InvalidOperationException("Non-Interactive mode detected. OneDrive Status can only be checked interactively unless -OnDemandOnly is specified"); } if (UacHelper.IsProcessElevated && ParameterSetName != OnDemandString) { throw new InvalidOperationException("PowerShell is running in Administrator mode. OneDrive status cannot be checked in elevated privileges"); } OdSyncStatusWS.OnDemandOnly = onDemandOnly; WriteLog.ShouldLog = includeLog; if (includeLog) { WriteVerbose("Log file is being saved @ " + WriteLog.FileName); } if (onDemandOnly) { WriteVerbose("On Demand Only check"); WriteLog.WriteInformationEvent("On Demand Only option selected"); } if (showDllPath) { WriteVerbose("Show DLL folder is enabled"); } if (dllPath == null) { CopyDLL(); } if (showDllPath) { Host.UI.WriteLine($"The temporary DLL path is '{Path.Combine(dllPath, dllName)}'"); } OdSyncStatusWS os = new OdSyncStatusWS(); List <StatusDetail> statuses = new List <StatusDetail>(); // Just Get the Path if (!String.IsNullOrEmpty(ByPath)) { WriteLog.WriteInformationEvent($"Path being tested is '{ByPath}'"); if (CLSID == Guid.Empty) { WriteObject(os.GetStatus(ByPath).ToString()); } else { WriteObject(Native.API.IsCertainType(ByPath, CLSID)); } return; } var statusCol = os.GetStatus(); foreach (var status in statusCol) { if (String.IsNullOrEmpty(Type) || status.ServiceType.ToLower().Contains(Type.ToLower().Replace("*", ""))) { WriteLog.WriteInformationEvent($"Guid Type being tested is '{CLSID}'"); if (CLSID != Guid.Empty) { status.StatusString = Native.API.IsCertainType(status.LocalPath, CLSID) ? "GuidFound " + CLSID.ToString("B") : "GuidNotFound " + CLSID.ToString("B"); } statuses.Add(status); } } WriteObject(statuses.ToArray()); }