示例#1
0
        //
        // Remove all traces of this from the registry.
        //
        // **TODO** If the above does AppID/DCOM stuff, this would have
        // to remove that stuff too.
        //
        private static void UnregisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/unregister");
                return;
            }
            //
            // Local server's DCOM/AppID information
            //
            Registry.ClassesRoot.DeleteSubKey("APPID\\" + m_sAppId, false);
            Registry.ClassesRoot.DeleteSubKey("APPID\\" +
                                              Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1), false);

            //
            // For each of the driver assemblies
            //
            foreach (Type type in m_ComObjectTypes)
            {
                string clsid  = Marshal.GenerateGuidForType(type).ToString("B");
                string progid = Marshal.GenerateProgIdForType(type);
                //
                // Best efforts
                //
                //
                // HKCR\progid
                //
                Registry.ClassesRoot.DeleteSubKey(progid + "\\CLSID", false);
                Registry.ClassesRoot.DeleteSubKey(progid, false);
                //
                // HKCR\CLSID\clsid
                //
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories\\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}", false);
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Implemented Categories", false);
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\ProgId", false);
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\LocalServer32", false);
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid + "\\Programmable", false);
                Registry.ClassesRoot.DeleteSubKey("CLSID\\" + clsid, false);
                try
                {
                    //
                    // ASCOM
                    //
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = progid.Substring(progid.LastIndexOf('.') + 1);
                        P.Unregister(progid);
                        //try										// In case Helper becomes native .NET
                        //{
                        //    Marshal.ReleaseComObject(P);
                        //}
                        //catch (Exception) { }
                    }
                }
                catch (Exception) { }
            }
        }
示例#2
0
        //
        // Remove all traces of this from the registry.
        //
        // **TODO** If the above does AppID/DCOM stuff, this would have
        // to remove that stuff too.
        //
        private static void UnregisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/unregister");
                return;
            }

            //
            // Local server's DCOM/AppID information
            //
            Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false);
            Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}",
                                                            Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false);

            //
            // For each of the driver assemblies
            //
            foreach (Type type in s_ComObjectTypes)
            {
                string clsid      = Marshal.GenerateGuidForType(type).ToString("B");
                string progid     = Marshal.GenerateProgIdForType(type);
                string deviceType = type.Name;
                //
                // Best efforts
                //
                //
                // HKCR\progid
                //
                Registry.ClassesRoot.DeleteSubKey(String.Format("{0}\\CLSID", progid), false);
                Registry.ClassesRoot.DeleteSubKey(progid, false);
                //
                // HKCR\CLSID\clsid
                //
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\ProgId", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\LocalServer32", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Programmable", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}", clsid), false);
                try
                {
                    //
                    // ASCOM
                    //
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Unregister(progid);
                    }
                }
                catch (Exception) { }
            }
        }
示例#3
0
 private static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile()) {
         P.DeviceType = "Camera";
         if (bRegister)
         {
             P.Register(driverID, driverName);
         }
         else
         {
             P.Unregister(driverID);
         }
     }
 }
示例#4
0
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="register">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool register)
 {
     using (var profile = new ASCOM.Utilities.Profile())
     {
         profile.DeviceType = "Telescope";
         if (register)
         {
             profile.Register(driverID, driverDescription);
         }
         else
         {
             profile.Unregister(driverID);
         }
     }
 }
示例#5
0
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = "Telescope";
         if (bRegister)
         {
             P.Register(Common.DriverId, Common.DriverDescription);
         }
         else
         {
             P.Unregister(Common.DriverId);
         }
     }
 }
示例#6
0
        //INTERFACECODEINSERTIONPOINT
        #region Private properties and methods
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "TEMPLATEDEVICECLASS";
                if (bRegister)
                {
                    P.Register(driverID, driverDescription);
                }
                else
                {
                    P.Unregister(driverID);
                }
            }
        }
示例#7
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "Dome";
                if (bRegister)
                {
                    P.Register(driverID, driverDescriptionShort);
                }
                else
                {
                    P.Unregister(driverID);
                }
            }
        }
示例#8
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "CoverCalibrator";
                if (bRegister)
                {
                    P.Register(DRIVER_PROGID, DRIVER_DESCRIPTION);
                }
                else
                {
                    //P.Unregister(driverID);
                }
            }
        }
示例#9
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "ObservingConditions";
                if (bRegister)
                {
                    P.Register(VantagePro.DriverId, VantagePro.DriverDescription);
                }
                else
                {
                    P.Unregister(VantagePro.DriverId);
                }
            }
        }
示例#10
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "Telescope";
                if (bRegister)
                {
                    P.Register(Const.wiseTelescopeDriverID, WiseTele.driverDescription);
                }
                else
                {
                    P.Unregister(Const.wiseTelescopeDriverID);
                }
            }
        }
示例#11
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            string desc = string.Format("ASCOM Wise40.SafeToOpen v0.2");

            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "SafetyMonitor";
                if (bRegister)
                {
                    P.Register(driverID, desc);
                }
                else
                {
                    P.Unregister(driverID);
                }
            }
        }
示例#12
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "Focuser";
                if (bRegister)
                {
                    Version version     = new Version("0.2");
                    string  description = string.Format("ASCOM Wise40.Focuser v{0}", version);
                    P.Register(WiseFocuser.DriverId, description);
                }
                else
                {
                    P.Unregister(WiseFocuser.DriverId);
                }
            }
        }
示例#13
0
        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();
        }
示例#14
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered.
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "Telescope";
                if (bRegister)
                {
                    P.Register(driverID, driverDescription);
                }
                else
                {
                    try
                    {
                        P.Unregister(driverID);
                    }
                    catch (DriverNotRegisteredException) { }
                }
            }
        }
示例#15
0
        public DomeSetupDialogForm()
        {
            InitializeComponent();

            wisedome.ReadProfile();
            checkBoxAutoCalibrate.Checked       = wisedome._autoCalibrate;
            checkBoxSyncVent.Checked            = wisedome.SyncVentWithShutter;
            textBoxShutterIpAddress.Text        = wisedome.wisedomeshutter._ipAddress;
            textBoxShutterHighestValue.Text     = wisedome.wisedomeshutter._highestValue.ToString();
            textBoxShutterLowestValue.Text      = wisedome.wisedomeshutter._lowestValue.ToString();
            checkBoxShutterUseWebClient.Checked = wisedome.wisedomeshutter.ShutterWebClientEnabled;

            using (ASCOM.Utilities.Profile driverProfile = new ASCOM.Utilities.Profile())
            {
                driverProfile.DeviceType = "Telescope";
                minimalStep = Convert.ToDouble(driverProfile.GetValue(Const.wiseTelescopeDriverID,
                                                                      Const.ProfileName.Dome_MinimalTrackingMovement, string.Empty, "2.0"));
                textBoxMinimalStep.Text = minimalStep.ToString();
            }
        }
示例#16
0
        public Configuration(UInt16 whichController, UInt16 whichCamera)
        {
            Log.Write(String.Format("Configuration({0}, {1}) starts\n", whichController, whichCamera));

            m_profile            = new ASCOM.Utilities.Profile();
            m_profile.DeviceType = DEVICE_TYPE;

            // Note that this picks main camera configuraitons for guide cameras too -
            // there are currently no configuration values for guide cameras

            m_driverId = String.Format("ASCOM.SXMain{0}.{1}", whichController, DEVICE_TYPE);

            Log.Write(String.Format("Configuration() computes driverId={0}\n", m_driverId));

            m_whichController = whichController;
            m_whichCamera     = whichCamera;

            if (enableLogging && !Log.enabled)
            {
                Log.enabled = true;
                Log.Write("Configuration() has enabled logging\n");
            }
        }
示例#17
0
        private void ConnectForm_Load(object sender, EventArgs e)
        {
            ArrayList DeviceTypes = new ArrayList();

            cmbDeviceType.SelectedIndexChanged += new EventHandler(cmbDeviceType_SelectedIndexChanged); // Add an event handler for devicetype combo box
            this.Resize += new EventHandler(ConnectForm_Resize);                                        // Add an event handler for form resize.

            try
            {
                Util = new ASCOM.Utilities.Util();

                // Get the currently define device types
                ASCOM.Utilities.Profile Profile = new ASCOM.Utilities.Profile();
                DeviceTypes = Profile.RegisteredDeviceTypes;
                Profile.Dispose();

                DefaultDevices = new SortedList <string, string>(); // Initialise the sorted array of default drivers for each device type
                foreach (string DeviceType in DeviceTypes)          // Populate the sorted array and the UI combo boxwith the default driver values
                {
                    cmbDeviceType.Items.Add(DeviceType);
                    switch (DeviceType.ToUpperInvariant())
                    {
                    case "TELESCOPE":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_TELESCOPE);
                        break;

                    case "FOCUSER":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_FOCUSER);
                        break;

                    case "FILTERWHEEL":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_FILTER_WHEEL);
                        break;

                    case "ROTATOR":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_ROTATOR);
                        break;

                    case "DOME":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_DOME);
                        break;

                    case "CAMERA":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_CAMERA);
                        break;

                    case "VIDEO":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_VIDEO);
                        break;

                    case "SWITCH":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_SWITCH);
                        break;

                    case "SAFETYMONITOR":
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), DEFAULT_DEVICE_SAFETY_MONITOR);
                        break;

                    default:
                        DefaultDevices.Add(DeviceType.ToUpperInvariant(), "");
                        break;
                    }
                }

                CurrentDevice              = DEFAULT_DEVICE_TELESCOPE; // Initialise current value variables and UI display
                CurrentDeviceType          = DEFAULT_DEVICE_TYPE;
                cmbDeviceType.SelectedItem = CurrentDeviceType;
                txtDevice.Text             = CurrentDevice;

                // Supply an appropriate title for the form depending on the OS and application bitness
                if (Environment.Is64BitOperatingSystem) // 64bit OS
                {
                    if (Environment.Is64BitProcess)     // 64bit process
                    {
                        this.Text = "Device Connection Tester - 64bit OS - Operating in 64bit mode";
                    }
                    else // 32bit process
                    {
                        this.Text = "Device Connection Tester - 64bit OS - Operating in 32bit mode";
                    }
                }
                else // 32bit OS
                {
                    this.Text = "Device Connection Tester - 32bit OS";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#18
0
 /// <summary>
 /// Registering switch as ASCOM device
 /// </summary>
 public void RegisterSettings()
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = "Switch";
         P.Register(IP9212_switch_id, IP9212_switch_description);
     }
 }
示例#19
0
        // here are some useful properties and methods that can be used as required
        // to help with driver development

        #region ASCOM Registration

        // Register or unregister driver for ASCOM. This is harmless if already
        // registered or unregistered. 
        //
        /// <summary>
        /// Register or unregister the driver with the ASCOM Platform.
        /// This is harmless if the driver is already registered/unregistered.
        /// </summary>
        /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
        private static void RegUnregASCOM(bool bRegister)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "Dome";
                if (bRegister)
                {
                    P.Register(driverID, driverDescription);
                }
                else
                {
                    P.Unregister(driverID);
                }
                try
                {
                    Marshal.ReleaseComObject(P);
                    //P = null;
                }
                catch { }
            }
            
        }
示例#20
0
        //
        // 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 outboiud 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;

            //
            // Local server's DCOM/AppID information
            //
            try
            {
                //
                // 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);
                    key.SetValue("RunAs", "Interactive User", RegistryValueKind.String); // Added to ensure that only one copy of the local server runs if the user uses both elevated and non-elevated clients concurrently
                }
                //
                // 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(),
                                "$safeprojectname$", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
            }

            //
            // For each of the driver assemblies
            //
            foreach (Type type in s_ComObjectTypes)
            {
                bool bFail = false;
                try
                {
                    //
                    // HKCR\CLSID\clsid
                    //
                    string clsid  = Marshal.GenerateGuidForType(type).ToString("B");
                    string progid = Marshal.GenerateProgIdForType(type);
                    //PWGS 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);                                             // Could be assyTitle/Desc??, but .NET components show ProgId here
                        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);
                        }
                    }
                    //
                    // HKCR\CLSID\progid
                    //
                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid))
                    {
                        key.SetValue(null, assyTitle);
                        using (RegistryKey key2 = key.CreateSubKey("CLSID"))
                        {
                            key2.SetValue(null, clsid);
                        }
                    }
                    //
                    // ASCOM
                    //
                    assy = type.Assembly;

                    // Pull the display name from the ServedClassName attribute.
                    attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); //PWGS Changed to search type for attribute rather than assembly
                    string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer";
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Register(progid, chooserName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                    "$safeprojectname$", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    bFail = true;
                }
                finally
                {
                }
                if (bFail)
                {
                    break;
                }
            }
        }
示例#21
0
        //
        // 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 outboiud connection from TheSky.
        //
        private static void RegisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/register");
                return;
            }
            //MessageBox.Show("after elevate");
            //
            // 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;
            //MessageBox.Show("assyDescription: " + assyDescription);
            //
            // Local server's DCOM/AppID information
            //
            try
            {
                //
                // 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);
                }
                //
                // 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(),
                        "Pictavore_Server", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
                //MessageBox.Show("finally");
            }

            //
            // For each of the driver assemblies
            //
            foreach (Type type in s_ComObjectTypes)
            {
                bool bFail = false;
                try
                {
                    //
                    // HKCR\CLSID\clsid
                    //
                    //MessageBox.Show("before marshal");
                    string clsid = Marshal.GenerateGuidForType(type).ToString("B");
                    string progid = Marshal.GenerateProgIdForType(type);
                    //PWGS Generate device type from the Class name
                    string deviceType = type.Name;
                    //MessageBox.Show(clsid + "\n" + progid + "\n" + deviceType);

                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid)))
                    {
                        key.SetValue(null, progid);						// Could be assyTitle/Desc??, but .NET components show ProgId here
                        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);
                        }
                    }
                    //
                    // HKCR\CLSID\progid
                    //
                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid))
                    {
                        key.SetValue(null, assyTitle);
                        using (RegistryKey key2 = key.CreateSubKey("CLSID"))
                        {
                            key2.SetValue(null, clsid);
                        }
                    }
                    //
                    // ASCOM
                    //
                    assy = type.Assembly;

                    // Pull the display name from the ServedClassName attribute.
                    attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); //PWGS Changed to search type for attribute rather than assembly
                    string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer";
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Register(progid, chooserName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                            "Pictavore_Server", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    bFail = true;
                }
                finally
                {
                }
                if (bFail) break;
            }
        }
示例#22
0
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered. 
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="bRegister">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool bRegister)
 {
     using (var P = new ASCOM.Utilities.Profile())
     {
         P.DeviceType = "Camera";
         if (bRegister)
         {
             P.Register(driverID, driverDescription);
         }
         else
         {
             P.Unregister(driverID);
         }
     }
 }
示例#23
0
        //
        // 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 outboiud connection from TheSky.
        //
        private static void RegisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/register");
                return;
            }
            //
            // If reached here, we're running elevated
            //
            //RegistryKey key = null;
            //RegistryKey key2 = null;
            //RegistryKey key3 = null;

            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;

            //
            // Local server's DCOM/AppID information
            //
            try
            {
                //
                // HKCR\APPID\appid
                //
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + m_sAppId))
                {
                    key.SetValue(null, assyDescription);
                    key.SetValue("AppID", m_sAppId);
                    key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord);
                }
                //
                // HKCR\APPID\exename.ext
                //
                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" +
                                                                           Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)))
                {
                    key.SetValue("AppID", m_sAppId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                "The PushToGo Driver", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            finally
            {
            }

            //
            // For each of the driver assemblies
            //
            foreach (Type type in m_ComObjectTypes)
            {
                bool bFail = false;
                try
                {
                    //
                    // HKCR\CLSID\clsid
                    //
                    string clsid      = Marshal.GenerateGuidForType(type).ToString("B");
                    string progid     = Marshal.GenerateProgIdForType(type);
                    string deviceType = type.Name;

                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\" + clsid))
                    {
                        key.SetValue(null, progid);                                             // Could be assyTitle/Desc??, but .NET components show ProgId here
                        key.SetValue("AppId", m_sAppId);
                        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);
                        }
                    }
                    //
                    // HKCR\CLSID\progid
                    //
                    using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progid))
                    {
                        key.SetValue(null, assyTitle);
                        using (RegistryKey key2 = key.CreateSubKey("CLSID"))
                        {
                            key2.SetValue(null, clsid);
                        }
                    }
                    //
                    // ASCOM
                    //
                    assy = type.Assembly;
                    //attr = Attribute.GetCustomAttribute(assy, typeof(AssemblyProductAttribute));
                    //string chooserName = ((AssemblyProductAttribute)attr).Product;

                    //Modified to pull from the custom Attribute ServedClassName
                    attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute));
                    string chooserName = ((ASCOM.ServedClassNameAttribute)attr).DisplayName ?? "telescope Simulator";

                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Register(progid, chooserName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                    "The PushToGo Driver", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    bFail = true;
                }
                finally
                {
                }
                if (bFail)
                {
                    break;
                }
            }
        }
示例#24
0
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 /// <summary>
 /// Register or unregister the driver with the ASCOM Platform.
 /// This is harmless if the driver is already registered/unregistered.
 /// </summary>
 /// <param name="register">If <c>true</c>, registers the driver, otherwise unregisters it.</param>
 private static void RegUnregASCOM(bool register)
 {
     using (var profile = new ASCOM.Utilities.Profile())
     {
         profile.DeviceType = "Telescope";
         if (register)
         {
             profile.Register(driverID, driverDescription);
         }
         else
         {
             profile.Unregister(driverID);
         }
     }
 }
示例#25
0
        //
        // Remove all traces of this from the registry.
        //
        // **TODO** If the above does AppID/DCOM stuff, this would have
        // to remove that stuff too.
        //
        private static void UnregisterObjects()
        {
            if (!IsAdministrator)
            {
                ElevateSelf("/unregister");
                return;
            }

            //
            // Local server's DCOM/AppID information
            //
            Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false);
            Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}",
                    Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false);

            //
            // For each of the driver assemblies
            //
            foreach (Type type in s_ComObjectTypes)
            {
                string clsid = Marshal.GenerateGuidForType(type).ToString("B");
                string progid = Marshal.GenerateProgIdForType(type);
                string deviceType = type.Name;
                //
                // Best efforts
                //
                //
                // HKCR\progid
                //
                Registry.ClassesRoot.DeleteSubKey(String.Format("{0}\\CLSID", progid), false);
                Registry.ClassesRoot.DeleteSubKey(progid, false);
                //
                // HKCR\CLSID\clsid
                //
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\ProgId", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\LocalServer32", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Programmable", clsid), false);
                Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}", clsid), false);
                try
                {
                    //
                    // ASCOM
                    //
                    using (var P = new ASCOM.Utilities.Profile())
                    {
                        P.DeviceType = deviceType;
                        P.Unregister(progid);
                    }
                }
                catch (Exception) { }
            }
        }
示例#26
0
        //
        // 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;
                }
            }
        }