示例#1
0
        public static ChoIniFile OpenIniSection(string sectionName = null)
        {
            CheckInitCalled();

            if (sectionName == null)
            {
                return(IniFile);
            }
            else
            {
                return(ChoIniFile.New(IniFile.FilePath, sectionName));
            }
        }
        private void InitIsLockedCache(Type declaringType)
        {
            if (!_turnOnMetaDataCache)
            {
                return;
            }

            ChoIniFile iniFile = ChoIniFile.New(declaringType.FullName);

            if (!_isLockedCache.ContainsKey(declaringType))
            {
                lock (_padlock)
                {
                    if (!_isLockedCache.ContainsKey(declaringType))
                    {
                        _isLockedCache.Add(declaringType, iniFile.GetValue <bool>("IsLocked"));
                    }
                }
            }
        }
示例#3
0
        private void Save()
        {
            lock (_padLock)
            {
                try
                {
                    if (ChoIniFile.New(this.IniFilePath).GetValue <bool>("IsLocked", false))
                    {
                        return;
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(_iniFilePath));

                    string iniContents = String.Empty;
                    if (File.Exists(_iniFilePath))
                    {
                        iniContents = File.ReadAllText(_iniFilePath);
                    }

                    if (_sectionName.IsNullOrWhiteSpace())
                    {
                        iniContents = Regex.Replace(iniContents, @"^(?<ini>[^\[]*)", Matcher, RegexOptions.IgnoreCase);
                        File.WriteAllText(_iniFilePath, iniContents);
                    }
                    else
                    {
                        if (!Regex.IsMatch(iniContents, @"(?<ini>\[{0}\][^\[]*)".FormatString(_sectionName)))
                        {
                            iniContents += "{0}[{1}]{0}".FormatString(Environment.NewLine, _sectionName);
                        }

                        iniContents = Regex.Replace(iniContents, @"(?<ini>\[{0}\][^\[]*)".FormatString(_sectionName), Matcher, RegexOptions.IgnoreCase);
                        File.WriteAllText(_iniFilePath, iniContents);
                    }
                }
                catch (Exception ex)
                {
                    ChoETLLog.Error(ex.ToString());
                }
            }
        }
示例#4
0
        private static void _Initialize()
        {
            try
            {
                if (ChoETLFrxBootstrap.TraceLevel != null)
                {
                    TraceLevel = ChoETLFrxBootstrap.TraceLevel.Value;
                }
                if (ChoETLFrxBootstrap.Log != null)
                {
                    Log = ChoETLFrxBootstrap.Log;
                }

                if (ChoETLFrxBootstrap.ApplicationName.IsNullOrWhiteSpace())
                {
                    ChoETLFrxBootstrap.ApplicationName = ChoPath.EntryAssemblyName;
                }

                if (IniFile == null)
                {
                    IniFile = ChoIniFile.New(ChoPath.EntryAssemblyName);
                }

//#if !DEBUG
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//#endif
                AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
                if (GetConfigValue <bool>("TurnOnConsoleCtrlHandler", true))
                {
                    RegisterConsoleControlHandler();
                }

#if !NETSTANDARD2_0
                try
                {
                    _elApplicationEventLog        = new EventLog("Application", Environment.MachineName, ChoETLFrxBootstrap.ApplicationName);
                    _elApplicationEventLog.Log    = "Application";
                    _elApplicationEventLog.Source = ChoETLFrxBootstrap.ApplicationName;
                }
                catch (Exception ex)
                {
                    WriteLog(ChoETLFramework.TraceSwitch.TraceError, ex.ToString());
                }
#endif

                if (_traceLevel == null)
                {
#if DEBUG
                    _switch.Level = GetConfigValue <TraceLevel>("TraceLevel", TraceLevel.Verbose);
#else
                    _switch.Level = GetConfigValue <TraceLevel>("TraceLevel", TraceLevel.Off);
#endif
                }
                else
                {
                    _switch.Level = GetConfigValue <TraceLevel>("TraceLevel", _traceLevel.Value);
                }

                var x = GetConfigValue <string>("LogFileName", ChoETLFrxBootstrap.ApplicationName);
                if (ChoETLFramework.TraceLevel != TraceLevel.Off)
                {
                    ChoTextWriterTraceListener frxTextWriterTraceListener = new ChoTextWriterTraceListener("ChoETL",
                                                                                                           String.Format("BASEFILENAME={0};DIRECTORYNAME={1};FILEEXT={2};TIMESTAMP=false",
                                                                                                                         GetConfigValue <string>("LogFileName", ChoETLFrxBootstrap.LogFileName),
                                                                                                                         GetConfigValue <string>("LogFileDir", ChoETLFrxBootstrap.LogFolder), "log"));

                    if (_frxTextWriterTraceListener != null)
                    {
                        System.Diagnostics.Trace.Listeners.Remove(_frxTextWriterTraceListener);
                    }

                    _frxTextWriterTraceListener = frxTextWriterTraceListener;
                    System.Diagnostics.Trace.Listeners.Add(_frxTextWriterTraceListener);
                }
                GlobalProfile = new ChoProfile(ChoETLFramework.TraceSwitch.TraceVerbose, "Time taken to run the application...");

                if (ChoAppSettings.Configuration != null)
                {
                    ChoETLLog.Info("Configuration File Path: " + ChoAppSettings.Configuration.FilePath);
                }
            }
            catch (Exception ex)
            {
                if (!ChoETLFrxBootstrap.IsSandboxEnvironment)
                {
                    Exit(ex);
                }
            }
            finally
            {
            }
        }
 private ChoIniFile GetIniSection(Type type, string sectionName)
 {
     return(ChoIniFile.New(type.FullName, sectionName));
 }