Beispiel #1
0
 public XMLAccess(bool p_IgnoreTest)
 {
     this.disposedValue = false;
     this.TL            = new TraceLogger("", "XMLAccess");
     this.TL.Enabled    = RegistryCommonCode.GetBool("Trace XMLAccess", false);
     VersionCode.RunningVersions(this.TL);
     this.sw           = new Stopwatch();
     this.swSupport    = new Stopwatch();
     this.FileStore    = (IFileStoreProvider) new AllUsersFileSystemProvider();
     this.ProfileMutex = new Mutex(false, "ASCOMProfileMutex");
     if (p_IgnoreTest)
     {
         return;
     }
     try
     {
         if (!this.FileStore.get_Exists("\\Profile.xml"))
         {
             throw new ProfileNotFoundException("Utilities Error Base key does not exist");
         }
         this.GetProfile("\\", "PlatformVersion");
     }
     catch (Exception ex)
     {
         //ProjectData.SetProjectError(ex);
         this.TL.LogMessageCrLf("XMLAccess.New Unexpected exception:", ex.ToString());
         throw;
     }
 }
        public static bool GetBool(string p_Name, bool p_DefaultValue)
        {
            string      methSig     = $"GetBool({p_Name},{p_DefaultValue})";
            RegistryKey currentUser = Registry.CurrentUser;

            TraceLogger.Debug($"{methSig}: RegistryKey[CurrentUser]='{currentUser?.Name??"NULL"}'");
            currentUser.CreateSubKey("Software\\ASCOM\\Utilities");
            RegistryKey registryKey = currentUser.OpenSubKey("Software\\ASCOM\\Utilities", true);

            TraceLogger.Debug($"{methSig}: RegistryKey[Utilities]='{registryKey?.Name ?? "NULL"}'");
            bool flag = false;

            try
            {
                if (registryKey.GetValueKind(p_Name) == RegistryValueKind.String)
                {
                    string keyValue = registryKey.GetValue(p_Name).ToString();
                    TraceLogger.Debug($"{methSig}: RegistryKey[Utilities.{p_Name}]='{keyValue ?? "NULL"}'");
                    flag = Conversions.ToBoolean(keyValue);
                }
            }
            catch (IOException ex1)
            {
                TraceLogger.Debug($"Exception1: Get RegistryValue: {ex1.GetType().Name}");
                TraceLogger.Debug(ex1.ToString());
                //ProjectData.SetProjectError((Exception) ex1);
                try
                {
                    RegistryCommonCode.SetName(p_Name, p_DefaultValue.ToString());
                    flag = p_DefaultValue;
                }
                catch (Exception ex2)
                {
                    TraceLogger.Debug($"Exception2: SetName: {ex2.GetType().Name}");
                    TraceLogger.Debug(ex2.ToString());
                    //ProjectData.SetProjectError(ex2);
                    flag = p_DefaultValue;
                    //ProjectData.ClearProjectError();
                }
                //ProjectData.ClearProjectError();
            }
            catch (Exception ex)
            {
                TraceLogger.Debug($"Exception: Get RegistryValue: {ex.GetType().Name}");
                TraceLogger.Debug(ex.ToString());
                //ProjectData.SetProjectError(ex);
                flag = p_DefaultValue;
                //ProjectData.ClearProjectError();
            }
            registryKey.Flush();
            registryKey.Close();
            currentUser.Flush();
            currentUser.Close();
            return(flag);
        }
Beispiel #3
0
        public Timer()
        {
            this.Tick         += new Timer.TickEventHandler(this.Timer_Tick);
            this.disposedValue = false;
            this.TL            = new TraceLogger("", "Timer");
            this.TraceEnabled  = RegistryCommonCode.GetBool("Trace Timer", false);
            this.TL.Enabled    = this.TraceEnabled;
            this.TL.LogMessage("New", "Started on thread: " + Thread.CurrentThread.ManagedThreadId.ToString());
            this.FormTimer = new System.Windows.Forms.Timer();
            this.TL.LogMessage("New", "Created FormTimer");
            this.FormTimer.Enabled  = false;
            this.FormTimer.Interval = 1000;
            this.TL.LogMessage("New", "Set FormTimer interval");
            this.TimersTimer = new System.Timers.Timer();
            this.TL.LogMessage("New", "Created TimersTimer");
            this.TimersTimer.Enabled  = false;
            this.TimersTimer.Interval = 1000.0;
            this.TL.LogMessage("New", "Set TimersTimer interval");
            try
            {
                this.TL.LogMessage("New", "Process FileName \"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
                PEReader peReader = new PEReader(Process.GetCurrentProcess().MainModule.FileName, this.TL);
                this.TL.LogMessage("New", "SubSystem " + peReader.SubSystem().ToString());
                switch (peReader.SubSystem())
                {
                case PEReader.SubSystemType.WINDOWS_GUI:
                    this.IsForm = true;
                    break;

                case PEReader.SubSystemType.WINDOWS_CUI:
                    this.IsForm = false;
                    break;

                default:
                    this.IsForm = false;
                    break;
                }
                this.IsForm = !this.ForceTimer(this.IsForm);
                this.TL.LogMessage("New", "IsForm: " + Conversions.ToString(this.IsForm));
            }
            catch (Exception ex)
            {
                //ProjectData.SetProjectError(ex);
                Exception exception = ex;
                this.TL.LogMessageCrLf("New Exception", exception.ToString());
                EventLogCode.LogEvent("Timer:New", "Exception", EventLogEntryType.Error, GlobalConstants.EventLogErrors.TimerSetupException, exception.ToString());
                //ProjectData.ClearProjectError();
            }
        }
Beispiel #4
0
 void IAccess.MigrateProfile(string CurrentPlatformVersion)
 {
     try
     {
         this.GetProfileMutex("MigrateProfile", "");
         this.sw.Reset();
         this.sw.Start();
         this.TL.LogMessage("MigrateProfile", "");
         bool enabled = this.TL.Enabled;
         this.TL.Enabled = true;
         VersionCode.RunningVersions(this.TL);
         this.TL.LogMessage("MigrateProfile", "Migrating keys");
         if (!this.FileStore.get_Exists("\\Profile.xml"))
         {
             this.FileStore.CreateDirectory("\\", this.TL);
             this.CreateKey("\\");
             this.TL.LogMessage("MigrateProfile", "Successfully created root directory and root key");
         }
         else
         {
             this.TL.LogMessage("MigrateProfile", "Root directory already exists");
         }
         this.TL.LogMessage("MigrateProfile", "Setting security ACLs on ASCOM root directory ");
         this.FileStore.SetSecurityACLs(this.TL);
         this.TL.LogMessage("MigrateProfile", "Copying Profile from Registry");
         RegistryKey p_FromKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ASCOM");
         if (p_FromKey == null)
         {
             throw new ProfileNotFoundException("Cannot find ASCOM Profile in HKLM\\SOFTWARE\\ASCOM Is Platform 5 installed?");
         }
         this.TL.LogMessage("MigrateProfile", "FromKey Opened OK: " + p_FromKey.Name + ", SubKeyCount: " + p_FromKey.SubKeyCount.ToString() + ", ValueCount: " + p_FromKey.ValueCount.ToString());
         this.MigrateKey(p_FromKey, "");
         this.TL.LogMessage("MigrateProfile", "Successfully migrated keys");
         p_FromKey.Close();
         this.TL.Enabled = RegistryCommonCode.GetBool("Trace XMLAccess", false);
         this.sw.Stop();
         this.TL.LogMessage("  ElapsedTime", "  " + Conversions.ToString(this.sw.ElapsedMilliseconds) + " milliseconds");
         this.TL.Enabled = enabled;
     }
     catch (Exception ex)
     {
         //ProjectData.SetProjectError(ex);
         this.TL.LogMessageCrLf("MigrateProfile", "Exception: " + ex.ToString());
         throw;
     }
 }
        public static DateTime GetDate(string p_Name, DateTime p_DefaultValue)
        {
            RegistryKey currentUser = Registry.CurrentUser;

            currentUser.CreateSubKey("Software\\ASCOM\\Utilities");
            RegistryKey registryKey = currentUser.OpenSubKey("Software\\ASCOM\\Utilities", true);
            DateTime    dateTime    = default(DateTime);

            try
            {
                if (registryKey.GetValueKind(p_Name) == RegistryValueKind.String)
                {
                    dateTime = Conversions.ToDate(registryKey.GetValue(p_Name));
                }
            }
            catch (IOException ex1)
            {
                //ProjectData.SetProjectError((Exception) ex1);
                try
                {
                    RegistryCommonCode.SetName(p_Name, p_DefaultValue.ToString());
                    dateTime = p_DefaultValue;
                }
                catch (Exception ex2)
                {
                    //ProjectData.SetProjectError(ex2);
                    dateTime = p_DefaultValue;
                    //ProjectData.ClearProjectError();
                }
                //ProjectData.ClearProjectError();
            }
            catch (Exception ex)
            {
                //ProjectData.SetProjectError(ex);
                dateTime = p_DefaultValue;
                //ProjectData.ClearProjectError();
            }
            registryKey.Flush();
            registryKey.Close();
            currentUser.Flush();
            currentUser.Close();
            return(dateTime);
        }
        public static Serial.WaitType GetWaitType(string p_Name, Serial.WaitType p_DefaultValue)
        {
            RegistryKey currentUser = Registry.CurrentUser;

            currentUser.CreateSubKey("Software\\ASCOM\\Utilities");
            RegistryKey registryKey = currentUser.OpenSubKey("Software\\ASCOM\\Utilities", true);

            Serial.WaitType waitType = Serial.WaitType.Sleep;
            try
            {
                if (registryKey.GetValueKind(p_Name) == RegistryValueKind.String)
                {
                    waitType = (Serial.WaitType)Conversions.ToInteger(Enum.Parse(typeof(Serial.WaitType), registryKey.GetValue(p_Name).ToString()));
                }
            }
            catch (IOException ex1)
            {
                //ProjectData.SetProjectError((Exception) ex1);
                try
                {
                    RegistryCommonCode.SetName(p_Name, p_DefaultValue.ToString());
                    waitType = p_DefaultValue;
                }
                catch (Exception ex2)
                {
                    //ProjectData.SetProjectError(ex2);
                    waitType = p_DefaultValue;
                    //ProjectData.ClearProjectError();
                }
                //ProjectData.ClearProjectError();
            }
            catch (Exception ex)
            {
                //ProjectData.SetProjectError(ex);
                waitType = p_DefaultValue;
                //ProjectData.ClearProjectError();
            }
            registryKey.Flush();
            registryKey.Close();
            currentUser.Flush();
            currentUser.Close();
            return(waitType);
        }
        public static string GetString(string p_Name, string p_DefaultValue)
        {
            string      str         = "";
            RegistryKey currentUser = Registry.CurrentUser;

            currentUser.CreateSubKey("Software\\ASCOM\\Utilities");
            RegistryKey registryKey = currentUser.OpenSubKey("Software\\ASCOM\\Utilities", true);

            try
            {
                if (registryKey.GetValueKind(p_Name) == RegistryValueKind.String)
                {
                    str = registryKey.GetValue(p_Name).ToString();
                }
            }
            catch (IOException ex1)
            {
                //ProjectData.SetProjectError((Exception) ex1);
                try
                {
                    RegistryCommonCode.SetName(p_Name, p_DefaultValue.ToString());
                    str = p_DefaultValue;
                }
                catch (Exception ex2)
                {
                    //ProjectData.SetProjectError(ex2);
                    str = p_DefaultValue;
                    //ProjectData.ClearProjectError();
                }
                //ProjectData.ClearProjectError();
            }
            catch (Exception ex)
            {
                //ProjectData.SetProjectError(ex);
                str = p_DefaultValue;
                //ProjectData.ClearProjectError();
            }
            registryKey.Flush();
            registryKey.Close();
            currentUser.Flush();
            currentUser.Close();
            return(str);
        }