Exemplo n.º 1
0
 public AstroUtils(int leapSeconds, IAscomDataStore store, ITraceLogger logger)
 {
     Utl          = new Util();
     Nov31        = new NOVAS31();
     Store        = store ?? (IAscomDataStore) new EntityStore();
     TL           = logger ?? new TraceLogger("", "Astrometry");
     TL.Enabled   = Store?.GetProfile <bool>("Utilities", "Trace Astro Utils", false) ?? false;
     UtcTaiOffset = Store?.GetProfile("Astrometry", "Leap Seconds", 36) ?? 36;
     TL.LogMessage("New", "AstroUtils created Utilities component OK");
     TL.LogMessage("New", $"Leap seconds: {UtcTaiOffset}");
     TL.LogMessage("New", "Finished initialisation OK");
 }
        internal static string ConditionPlatformVersion(string PlatformVersion, IAscomDataStore Profile, TraceLogger TL)
        {
            string str = PlatformVersion;

            if (Profile != null)
            {
                try
                {
                    string withoutExtension = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName);
                    TL?.LogMessage("ConditionPlatformVersion", "  ModuleFileName: \"" + withoutExtension + "\" \"" + Process.GetCurrentProcess().MainModule.FileName + "\"");
                    //if (Operators.CompareString(Strings.Left(withoutExtension.ToUpper(), 3), "IS-", false) == 0)
                    if (withoutExtension.ToUpper().StartsWith("IS-"))
                    {
                        TL?.LogMessage("ConditionPlatformVersion", "    Inno installer temporary executable detected, searching for parent process!");
                        TL?.LogMessage("ConditionPlatformVersion", "    Old Module Filename: " + withoutExtension);
                        PerformanceCounter performanceCounter = new PerformanceCounter("Process", "Creating Process ID", Process.GetCurrentProcess().ProcessName);
                        withoutExtension = Path.GetFileNameWithoutExtension(Process.GetProcessById(checked ((int)Math.Round((double)performanceCounter.NextValue()))).MainModule.FileName);
                        TL?.LogMessage("ConditionPlatformVersion", "    New Module Filename: " + withoutExtension);
                        performanceCounter.Close();
                        performanceCounter.Dispose();
                    }
                    SortedList <string, string> sortedList1 = Profile.EnumProfile("ForcePlatformVersion");
                    IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator1 = null;
                    try
                    {
                        enumerator1 = sortedList1.GetEnumerator();
                        while (enumerator1.MoveNext())
                        {
                            System.Collections.Generic.KeyValuePair <string, string> current = enumerator1.Current;
                            TL?.LogMessage("ConditionPlatformVersion", "  ForcedFileName: \"" + current.Key + "\" \"" + current.Value + "\" \"" + Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)) + "\" \"" + Strings.UCase(Path.GetFileName(current.Key)) + "\" \"" + Strings.UCase(current.Key) + "\" \"" + current.Key + "\" \"" + Strings.UCase(withoutExtension) + "\"");
                            string Left = !current.Key.Contains(".") ? current.Key : Path.GetFileNameWithoutExtension(current.Key);
                            if (Operators.CompareString(Left, "", false) != 0 && Strings.UCase(withoutExtension).StartsWith(Strings.UCase(Left)))
                            {
                                str = current.Value;
                                TL?.LogMessage("ConditionPlatformVersion", "  Matched file: \"" + withoutExtension + "\" \"" + Left + "\"");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator1 != null)
                        {
                            enumerator1.Dispose();
                        }
                    }
                    SortedList <string, string> sortedList2 = Profile.EnumProfile("ForcePlatformVersionSeparator");
                    IEnumerator <System.Collections.Generic.KeyValuePair <string, string> > enumerator2 = null;
                    try
                    {
                        enumerator2 = sortedList2.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            System.Collections.Generic.KeyValuePair <string, string> current = enumerator2.Current;
                            TL?.LogMessage("ConditionPlatformVersion", "  ForcedFileName: \"" + current.Key + "\" \"" + current.Value + "\" \"" + Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)) + "\" \"" + Strings.UCase(Path.GetFileName(current.Key)) + "\" \"" + Strings.UCase(current.Key) + "\" \"" + current.Key + "\" \"" + Strings.UCase(withoutExtension) + "\"");
                            if (!current.Key.Contains("."))
                            {
                            }

                            if (Operators.CompareString(Strings.UCase(Path.GetFileNameWithoutExtension(current.Key)), Strings.UCase(withoutExtension), false) == 0)
                            {
                                if (string.IsNullOrEmpty(current.Value))
                                {
                                    str = str.Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
                                    TL?.LogMessage("ConditionPlatformVersion", "  String IsNullOrEmpty: \"" + str + "\"");
                                }
                                else
                                {
                                    str = str.Replace(".", current.Value);
                                    TL?.LogMessage("ConditionPlatformVersion", "  String Is: \"" + current.Value + "\" \"" + str + "\"");
                                }
                                TL?.LogMessage("ConditionPlatformVersion", "  Matched file: \"" + withoutExtension + "\" \"" + current.Key + "\"");
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator2 != null)
                        {
                            enumerator2.Dispose();
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ProjectData.SetProjectError(ex);
                    Exception exception = ex;
                    TL?.LogMessageCrLf("ConditionPlatformVersion", "Exception: " + exception.ToString());
                    EventLogCode.LogEvent("ConditionPlatformVersion", "Exception: ", EventLogEntryType.Error, GlobalConstants.EventLogErrors.VB6HelperProfileException, exception.ToString());
                    //ProjectData.ClearProjectError();
                }
            }
            TL?.LogMessage("ConditionPlatformVersion", "  Returning: \"" + str + "\"");
            return(str);
        }