Пример #1
0
        private void SetupDialogForm_Load(object sender, EventArgs e)
        {
            string portName;

            using (ASCOM.Utilities.Profile p = new ASCOM.Utilities.Profile())
            {
                p.DeviceType = "Focuser";
                portName     = p.GetValue(Focuser.driverId, "ComPort");
                if (p.GetValue(Focuser.driverId, "TempDisp").Equals("C"))
                {
                    radioCelcius.Checked = true;
                }
                else
                {
                    radioCelcius.Checked = false;
                }
                textBoxRpm.Text = p.GetValue(Focuser.driverId, "RPM");
                if (!(textBoxRpm.Text.Length > 0))
                {
                    textBoxRpm.Text = "75";
                }
            }

            foreach (string s in SerialPort.GetPortNames())
            {
                cbComPort.Items.Add(s);
            }

            cbComPort.SelectedItem = portName;
        }
Пример #2
0
        private void RefreshDome()
        {
            if (!panelDome.Visible)
            {
                return;
            }

            if (labelDomeSlavedConfValue.Text == string.Empty)
            {
                using (ASCOM.Utilities.Profile driverProfile = new ASCOM.Utilities.Profile())
                {
                    driverProfile.DeviceType = "Telescope";
                    bool confDomeSlaved = Convert.ToBoolean(driverProfile.GetValue("ASCOM.Wise40.Telescope", "Enslave Dome", string.Empty, "false"));

                    labelDomeSlavedConfValue.Text = confDomeSlaved ? "Enslaved" : "Not enslaved" + " while tracking";
                }
            }

            if (wisedome.Connected)
            {
                string shutterStatus;
                groupBoxDome.Text = string.Format(" {0} v{1} ", wisedome.Name, wisedome.DriverVersion);

                labelDomeAzimuthValue.Text = wisedome.Calibrated ? wisedome.Azimuth.ToNiceString() : "not calibrated";
                labelDomeStatusValue.Text  = wisedome.Status;

                switch (wisedome.ShutterStatus)
                {
                case ShutterState.shutterClosed:
                    shutterStatus = "Closed";
                    break;

                case ShutterState.shutterClosing:
                    shutterStatus = "Closing";
                    break;

                case ShutterState.shutterOpen:
                    shutterStatus = "Open";
                    break;

                case ShutterState.shutterOpening:
                    shutterStatus = "Opening";
                    break;

                default:
                    shutterStatus = "Unknown";
                    break;
                }
                labelDomeShutterStatusValue.Text = shutterStatus;
            }
            else
            {
                groupBoxDome.Text = " Dome (not connected) ";

                labelDomeAzimuthValue.Text       = string.Empty;
                labelDomeStatusValue.Text        = string.Empty;
                labelDomeShutterStatusValue.Text = string.Empty;
            }
        }
Пример #3
0
 public void Dispose()
 {
     if (profile != null)
     {
         profile.Dispose();
         profile = null;
     }
     GC.SuppressFinalize(this);
 }
        //
        // 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) { }
            }
        }
Пример #5
0
        private string DeviceName(string deviceType, string driverId)
        {
            if (driverId.Length == 0)
            {
                return(String.Empty);
            }

            using (ASCOM.Utilities.Profile profile = new ASCOM.Utilities.Profile())
            {
                profile.DeviceType = deviceType;
                return(profile.GetValue(driverId, string.Empty, string.Empty, driverId));
            }
        }
Пример #6
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 = "FilterWheel";
                if (bRegister)
                {
                    P.Register(WiseFilterWheel.DriverID, WiseFilterWheel.Description);
                }
                else
                {
                    P.Unregister(WiseFilterWheel.DriverID);
                }
            }
        }
Пример #7
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 = DRIVER_DEVICE_TYPE;
         if (bRegister)
         {
             P.Register(DRIVER_ID, DRIVER_DESCRIPTION);
         }
         else
         {
             P.Unregister(DRIVER_ID);
         }
     }
 }
Пример #8
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>
 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);
         }
     }
 }
Пример #9
0
        public static List <IWeatherData> GetWeatherDataSources(IProfileService profileService)
        {
            var l            = new List <IWeatherData>();
            var ascomDevices = new ASCOM.Utilities.Profile();

            foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("ObservingConditions"))
            {
                try {
                    AscomObservingConditions obsdev = new AscomObservingConditions(device.Key, device.Value);
                    l.Add(obsdev);
                } catch (Exception) {
                }
            }
            return(l);
        }
Пример #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 = "ObservingConditions";
                if (bRegister)
                {
                    P.Register(Const.wiseBoltwoodDriverID, WiseBoltwood.driverDescription);
                }
                else
                {
                    P.Unregister(Const.wiseBoltwoodDriverID);
                }
            }
        }
Пример #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)
        {
            using (var P = new ASCOM.Utilities.Profile())
            {
                P.DeviceType = "ObservingConditions";
                if (bRegister)
                {
                    P.Register(OpenWeatherMap.driverID, driverDescription);
                }
                else
                {
                    P.Unregister(OpenWeatherMap.driverID);
                }
            }
        }
Пример #12
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    if (Profile != null)
                    {
                        Profile.Dispose();
                        Profile = null;
                    }
                }

                disposedValue = true;
            }
        }
Пример #13
0
        public static List <ITelescope> GetTelescopes(IProfileService profileService)
        {
            var l = new List <ITelescope>();

            using (var ascomDevices = new ASCOM.Utilities.Profile()) {
                foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("Telescope"))
                {
                    try {
                        AscomTelescope telescope = new AscomTelescope(device.Key, device.Value, profileService);
                        l.Add(telescope);
                    } catch (Exception) {
                        //only add telescopes which are supported. e.g. x86 drivers will not work in x64
                    }
                }
                return(l);
            }
        }
        public ParkHomeAndStartupForm()
        {
            InitializeComponent();

            // Draw the combobox in combobox style rather than comboboxlist style
            cmbStartupMode.DrawMode  = DrawMode.OwnerDrawVariable;
            cmbStartupMode.DrawItem += DropDownListComboBox_DrawItem;

            // Set invalid input event handlers
            txtStartAzimuth.TextChanged  += Textbox_TextChanged;
            txtStartAltitude.TextChanged += Textbox_TextChanged;
            txtParkAzimuth.TextChanged   += Textbox_TextChanged;
            txtParkAltitude.TextChanged  += Textbox_TextChanged;
            TxtHomeAzimuth.TextChanged   += Textbox_TextChanged;
            TxtHomeAltitude.TextChanged  += Textbox_TextChanged;

            txtStartAzimuth.Validating  += TextBox_Validating;
            txtStartAltitude.Validating += TextBox_Validating;
            txtParkAzimuth.Validating   += TextBox_Validating;
            txtParkAltitude.Validating  += TextBox_Validating;
            TxtHomeAzimuth.Validating   += TextBox_Validating;
            TxtHomeAltitude.Validating  += TextBox_Validating;

            // Populate startup options list
            foreach (string option in TelescopeHardware.StartupOptions)
            {
                cmbStartupMode.Items.Add(option);
            }

            string startupOption;

            using (ASCOM.Utilities.Profile profile = new ASCOM.Utilities.Profile())
            {
                startupOption = profile.GetValue(SharedResources.PROGRAM_ID, "StartUpMode", "", TelescopeHardware.StartupOptions[0]);
            }

            cmbStartupMode.SelectedItem = startupOption;

            // Populate the form text boxes
            txtStartAzimuth.Text  = TelescopeHardware.StartCoordinates.X.ToString();
            txtStartAltitude.Text = TelescopeHardware.StartCoordinates.Y.ToString();
            txtParkAzimuth.Text   = TelescopeHardware.ParkAzimuth.ToString();
            txtParkAltitude.Text  = TelescopeHardware.ParkAltitude.ToString();
            TxtHomeAzimuth.Text   = TelescopeHardware.HomePosition.X.ToString();
            TxtHomeAltitude.Text  = TelescopeHardware.HomePosition.Y.ToString();
        }
Пример #15
0
        public static List <IRotator> GetRotators(IProfileService profileService)
        {
            var l = new List <IRotator>();

            using (var ascomDevices = new ASCOM.Utilities.Profile()) {
                foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("Rotator"))
                {
                    try {
                        AscomRotator rotator = new AscomRotator(device.Key, device.Value);
                        l.Add(rotator);
                    } catch (Exception) {
                        //only add filter wheels which are supported. e.g. x86 drivers will not work in x64
                    }
                }
                return(l);
            }
        }
Пример #16
0
        public static List <ICamera> GetCameras(IProfileService profileService)
        {
            var l = new List <ICamera>();

            using (var ascomDevices = new ASCOM.Utilities.Profile()) {
                foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("Camera"))
                {
                    try {
                        AscomCamera cam = new AscomCamera(device.Key, device.Value + " (ASCOM)", profileService);
                        Logger.Trace(string.Format("Adding {0}", cam.Name));
                        l.Add(cam);
                    } catch (Exception) {
                        //only add cameras which are supported. e.g. x86 drivers will not work in x64
                    }
                }
                return(l);
            }
        }
Пример #17
0
        private void GetTelescopes()
        {
            using (var ascomDevices = new ASCOM.Utilities.Profile()) {
                foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("Telescope"))
                {
                    try {
                        AscomTelescope cam = new AscomTelescope(device.Key, device.Value, profileService);
                        Devices.Add(cam);
                    } catch (Exception) {
                        //only add telescopes which are supported. e.g. x86 drivers will not work in x64
                    }
                }

                if (Devices.Count > 0)
                {
                    var selected = (from device in Devices where device.Id == profileService.ActiveProfile.TelescopeSettings.Id select device).First();
                    SelectedDevice = selected;
                }
            }
        }
        private void BtnOK_Click(object sender, EventArgs e)
        {
            TelescopeHardware.StartCoordinates.X = double.Parse(txtStartAzimuth.Text);
            TelescopeHardware.StartCoordinates.Y = double.Parse(txtStartAltitude.Text);
            TelescopeHardware.ParkAzimuth        = double.Parse(txtParkAzimuth.Text);
            TelescopeHardware.ParkAltitude       = double.Parse(txtParkAltitude.Text);
            TelescopeHardware.HomePosition.X     = double.Parse(TxtHomeAzimuth.Text);
            TelescopeHardware.HomePosition.Y     = double.Parse(TxtHomeAltitude.Text);
            using (ASCOM.Utilities.Profile profile = new ASCOM.Utilities.Profile())
            {
                profile.WriteValue(SharedResources.PROGRAM_ID, "HomeAzimuth", TelescopeHardware.HomePosition.X.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "HomeAltitude", TelescopeHardware.HomePosition.Y.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "ParkAzimuth", TelescopeHardware.ParkAzimuth.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "ParkAltitude", TelescopeHardware.ParkAltitude.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "StartAzimuthConfigured", TelescopeHardware.StartCoordinates.X.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "StartAltitudeConfigured", TelescopeHardware.StartCoordinates.Y.ToString(CultureInfo.InvariantCulture));
                profile.WriteValue(SharedResources.PROGRAM_ID, "StartUpMode", cmbStartupMode.Text);
            }

            this.Close();
        }
Пример #19
0
        private void SetupDialogForm_Load(object sender, EventArgs e)
        {
            string portName;
            using (ASCOM.Utilities.Profile p = new ASCOM.Utilities.Profile())
            {
                p.DeviceType = "Focuser";
                portName = p.GetValue(Focuser.driverId, "ComPort");
                if (p.GetValue(Focuser.driverId, "TempDisp").Equals("C"))
                    radioCelcius.Checked = true;
                else
                    radioCelcius.Checked = false;
                textBoxRpm.Text = p.GetValue(Focuser.driverId, "RPM");
                if (!(textBoxRpm.Text.Length > 0))
                    textBoxRpm.Text = "75";
            }

            foreach (string s in SerialPort.GetPortNames())
            {
                cbComPort.Items.Add(s);
            }

            cbComPort.SelectedItem = portName;
        }
Пример #20
0
        public void init()
        {
            if (_initialized)
            {
                return;
            }

            using (ASCOM.Utilities.Profile driverProfile = new ASCOM.Utilities.Profile()
            {
                DeviceType = "FilterWheel"
            })
            {
                string port = driverProfile.GetValue(Const.wiseFilterWheelDriverID, "Port", string.Empty, "COM7");
                if (System.IO.Ports.SerialPort.GetPortNames().Contains(port))
                {
                    _serialPortName = port;
                    _serialPort     = new System.IO.Ports.SerialPort(_serialPortName, _serialPortSpeed);
                    communicationCompleteHandler += onCommunicationComplete;
                }
            }

            _initialized = true;
        }
Пример #21
0
        private void GetCameras()
        {
            using (var ascomDevices = new ASCOM.Utilities.Profile()) {
                foreach (ASCOM.Utilities.KeyValuePair device in ascomDevices.RegisteredDevices("Camera"))
                {
                    try {
                        AscomCamera cam = new AscomCamera(device.Key, "ASCOM --- " + device.Value, profileService);
                        Devices.Add(cam);
                    } catch (Exception) {
                        //only add cameras which are supported. e.g. x86 drivers will not work in x64
                    }
                }
            }
            for (int i = 0; i < ASICameras.Count; i++)
            {
                var cam = ASICameras.GetCamera(i, profileService);
                if (!string.IsNullOrEmpty(cam.Name))
                {
                    Devices.Add(cam);
                }
            }

            /*IntPtr cameraList;
             * uint err = EDSDK.EdsGetCameraList(out cameraList);
             * if (err == EDSDK.EDS_ERR_OK) {
             *  int count;
             *  err = EDSDK.EdsGetChildCount(cameraList, out count);
             *
             *  for(int i = 0; i < count; i++) {
             *      IntPtr cam;
             *      err = EDSDK.EdsGetChildAtIndex(cameraList, i, out cam);
             *
             *      EDSDK.EdsDeviceInfo info;
             *      err = EDSDK.EdsGetDeviceInfo(cam, out info);
             *
             *      Devices.Add(new EDCamera(cam, info));*/
            /*err = EDSDK.EdsOpenSession(cam);
             *
             * IntPtr saveTo = (IntPtr)EDSDK.EdsSaveTo.Host;
             * err = EDSDK.EdsSetPropertyData(cam, EDSDK.PropID_SaveTo, 0, 4, saveTo);
             *
             * EDSDK.EdsCapacity capacity = new EDSDK.EdsCapacity();
             * capacity.NumberOfFreeClusters = 0x7FFFFFFF;
             * capacity.BytesPerSector = 0x1000;
             * capacity.Reset = 1;
             * err = EDSDK.EdsSetCapacity(cam, capacity);
             *
             * err = EDSDK.EdsSendCommand(cam, EDSDK.CameraCommand_TakePicture, 0);
             *
             * err = EDSDK.EdsCloseSession(cam);*/
            /* }
             * }*/

            if (Devices.Count > 0)
            {
                var items = (from device in Devices where device.Id == profileService.ActiveProfile.CameraSettings.Id select device);
                if (items.Count() > 0)
                {
                    SelectedDevice = items.First();
                }
                else
                {
                    SelectedDevice = Devices.First();
                }
            }
        }
Пример #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 = "Dome";
         if (bRegister)
         {
             P.Register(driverID, driverDescription);
         }
         else
         {
             P.Unregister(driverID);
         }
     }
 }
        //
        // 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);
                }
                //
                // 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(),
                                "OpenAstroTracker", 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(),
                                    "OpenAstroTracker", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    bFail = true;
                }
                finally
                {
                }
                if (bFail)
                {
                    break;
                }
            }
        }
Пример #24
0
 public void Open()
 {
     Profile = new ASCOM.Utilities.Profile();
 }
Пример #25
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(bool rerunningAsElevated = false)
        {
            if (rerunningAsElevated)
            {
                if (!IsElevated)
                {
                    MessageBox.Show("Unable to gain elevated privileges to register the Device Hub.\n\n"
                                    + "Possible fixes are to enable User Account Control and/or add your user account\n"
                                    + "to the local Administrators group. Then re-install the Device Hub",
                                    "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);

                    return;
                }
            }
            else
            {
                if (!IsElevated)
                {
                    // Here we want to elevate a copy of ourselves, unless we are running under the VS Debugger.

                    RerunAsAdministrator("/regElevated");

                    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\\" + _appId))
                {
                    key.SetValue(null, assyDescription);
                    key.SetValue("AppID", _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 ...
                }

                // HKCR\APPID\exename.ext

                using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}",
                                                                                         GetExecutableFileName())))
                {
                    key.SetValue("AppID", _appId);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
                                "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);

                return;
            }

            // For each of the driver assemblies

            foreach (Type type in _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", _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"))
                        {
                            string path = GetExecutablePath();
                            key2.SetValue(null, path);
                        }
                    }

                    // 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(),
                                    "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);
                    bFail = true;
                }
                finally
                { }

                if (bFail)
                {
                    break;
                }
            }
        }
Пример #26
0
        // Remove all traces of this from the registry.

        private static void UnregisterObjects(bool rerunningAsElevated = false)
        {
            if (rerunningAsElevated)
            {
                if (!IsElevated)
                {
                    MessageBox.Show("Unable to gain elevated privileges to unregister the Device Hub.\n\n"
                                    + "If User Account Control is disabled, please enable it before uninstalling the Device Hub",
                                    "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop);

                    return;
                }
            }
            else
            {
                if (!IsElevated)
                {
                    // Here we want to elevate a copy of ourselves, unless we are running under the VS Debugger.

                    RerunAsAdministrator("/unregElevated");

                    return;
                }
            }

            // Local server's DCOM/AppID information

            Registry.ClassesRoot.DeleteSubKey(String.Format("APPID\\{0}", _appId), false);
            Registry.ClassesRoot.DeleteSubKey(String.Format("APPID\\{0}", GetExecutableFileName()), false);

            // For each of the driver assemblies

            foreach (Type type in _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) { }
            }
        }
Пример #27
0
 //
 // Register or unregister driver for ASCOM. This is harmless if already
 // registered or unregistered.
 //
 private static void RegUnregASCOM(bool bRegister)
 {
     ASCOM.Utilities.Profile P = new ASCOM.Utilities.Profile();
     P.DeviceType = "Focuser";					//  Requires Helper 5.0.3 or later
     if (bRegister)
         P.Register(s_csDriverID, s_csDriverDescription);
     else
         P.Unregister(s_csDriverID);
     try										// In case Helper becomes native .NET
     {
         Marshal.ReleaseComObject(P);
     }
     catch (Exception) { }
     P = null;
 }