internal void SetString(string name, string value) { Log.Write(String.Format("config: writing {0}={1} to driver {2}\n", name, value, m_driverId)); try { m_profile.WriteValue(m_driverId, name, value); } catch (Exception ex) { Log.Write(String.Format("config: WriteValue raised an exception: {0}\n", ex.ToString())); } }
private void cmdOK_Click(object sender, EventArgs e) // OK button event handler { wisedome.wisedomeshutter.ShutterWebClientEnabled = checkBoxShutterUseWebClient.Checked; wisedome.wisedomeshutter._ipAddress = textBoxShutterIpAddress.Text.Trim(); wisedome.wisedomeshutter._highestValue = Convert.ToInt32(textBoxShutterHighestValue.Text); wisedome.wisedomeshutter._lowestValue = Convert.ToInt32(textBoxShutterLowestValue.Text); wisedome._autoCalibrate = checkBoxAutoCalibrate.Checked; wisedome.SyncVentWithShutter = checkBoxSyncVent.Checked; wisedome.WriteProfile(); using (ASCOM.Utilities.Profile driverProfile = new ASCOM.Utilities.Profile()) { driverProfile.DeviceType = "Telescope"; driverProfile.WriteValue(Const.wiseTelescopeDriverID, Const.ProfileName.Dome_MinimalTrackingMovement, textBoxMinimalStep.Text); } Close(); }
// // Do everything to register this for COM. Never use REGASM on // this exe assembly! It would create InProcServer32 entries // which would prevent proper activation! // // Using the list of COM object types generated during dynamic // assembly loading, it registers each one for COM as served by our // exe/local server, as well as registering it for ASCOM. It also // adds DCOM info for the local server itself, so it can be activated // via an outbound connection from TheSky. // private static void RegisterObjects() { if (!IsAdministrator) { ElevateSelf("/register"); return; } // If reached here, we're running elevated Assembly assy = Assembly.GetExecutingAssembly(); Attribute attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyTitleAttribute)); string assyTitle = ((AssemblyTitleAttribute)attr).Title; attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyDescriptionAttribute)); string assyDescription = ((AssemblyDescriptionAttribute)attr).Description; TL.LogMessage("RegisterObjects", $"ASsembly description: {assyDescription}"); // Set the local server's DCOM/AppID information try { // Set HKCR\APPID\appid using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + s_appId)) { key.SetValue(null, assyDescription); key.SetValue("AppID", s_appId); key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord); TL.LogMessage("RegisterObjects", $"Set APPID: {assyDescription} {s_appId} Authentication level: 1"); } // Set HKCR\APPID\exename.ext using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)))) { key.SetValue("AppID", s_appId); } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex.ToString(), LOCAL_SERVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop); TL.LogMessageCrLf("RegisterObjects", $"Exception while registering AppID: {ex.ToString()}"); return; } finally { } TL.LogMessage("RegisterObjects", "Registering types"); // COM register each of the driver assemblies foreach (Type type in s_ComObjectTypes) { TL.LogMessage("RegisterObjects", string.Format("Processing type: {0}, is a COM object: {1}", type.FullName, type.IsCOMObject)); bool bFail = false; try { // Set HKCR\CLSID\clsid string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); TL.LogMessage("RegisterObjects", $"ProgID: {progid} CLSID: {clsid} "); // Generate device type from the Class name string deviceType = type.Name; using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid))) { key.SetValue(null, progid); key.SetValue("AppId", s_appId); using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) { key2.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); } using (RegistryKey key2 = key.CreateSubKey("ProgId")) { key2.SetValue(null, progid); } key.CreateSubKey("Programmable"); using (RegistryKey key2 = key.CreateSubKey("LocalServer32")) { key2.SetValue(null, Application.ExecutablePath); } } // Set HKCR\APPID\clsid for TheSkyX DCOM using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + clsid)) { key.SetValue(null, assyDescription); key.SetValue("AppID", clsid); key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord); } // Set HKCR\CLSID\progid using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid)) { key.SetValue(null, assyTitle); using (RegistryKey key2 = key.CreateSubKey("CLSID")) { key2.SetValue(null, clsid); } } // Register the driver in the ASCOM Profile if it is not already registered assy = type.Assembly; // Pull the display name from the ServedClassName attribute. attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer"; using (var profile = new ASCOM.Utilities.Profile()) { profile.DeviceType = deviceType; TL.LogMessage("RegisterObjects", $"About to Check whether {progid} of device type: {deviceType} is registered. IsRegistered: {profile.IsRegistered(progid)}"); if (!profile.IsRegistered(progid)) // Device is not ASCOM registered so register it and set some initial values so that the driver will appear valid to the dynamic device manager { TL.LogMessage("RegisterObjects", $"ProgID: {progid} profile is not registered, setting default values "); profile.Register(progid, chooserName); profile.WriteValue(progid, SharedConstants.IPADDRESS_PROFILENAME, SharedConstants.IPADDRESS_DEFAULT); profile.WriteValue(progid, SharedConstants.PORTNUMBER_PROFILENAME, SharedConstants.PORTNUMBER_DEFAULT.ToString()); profile.WriteValue(progid, SharedConstants.REMOTE_DEVICE_NUMBER_PROFILENAME, SharedConstants.REMOTE_DEVICE_NUMBER_DEFAULT.ToString()); profile.WriteValue(progid, SharedConstants.UNIQUEID_PROFILENAME, SharedConstants.UNIQUEID_DEFAULT); } else { TL.LogMessage("RegisterObjects", $"ProgID: {progid} profile is already registered."); } } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex.ToString(), LOCAL_SERVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop); TL.LogMessageCrLf("RegisterObjects", $"Exception while registering objects: {ex.ToString()}"); bFail = true; } finally { } if (bFail) { break; } } }