Exemple #1
0
        static ChoEnvironmentSettings()
        {
            ChoConfigurationManager.Refresh();
            _appConfigFileWatcher = new ChoConfigurationChangeFileWatcher("AppConfigFileWatcher", ChoConfigurationManager.ApplicationConfigurationFilePath);
            _appConfigFileWatcher.DoNotUseGlobalQueue = true;

            _appConfigFileWatcher.SetConfigurationChangedEventHandler("OnEnvironmentChanged", (sender, e) =>
            {
                // ChoAppFrxSettings.RefreshSection();
                //ChoCommandLineParserSettings.RefreshSection();
                CheckNChangeEnvironment();
            });

            if (ChoApplication.OnInitialize != null)
            {
                ChoApplication.OnInitialize(ChoAppFrxSettings.Me);
            }

            Environment = ChoAppFrxSettings.Me.AppEnvironment.NTrim();
            _sharedEnvironmentConfigFilePath = ChoSharedEnvironmentManager.SharedEnvironmentConfigFilePath;
            _appFrxFilePath = ChoSharedEnvironmentManager.AppFrxFilePath;

            LoadSharedEnvironmentManager();
            _appConfigFileWatcher.StartWatching();
        }
 public override void GetConfig(bool refresh, ChoConfigSectionObjectMap configSectionObjectMap)
 {
     _configSection = ChoConfigurationManager.GetConfig(ConfigElementName, refresh) as IChoConfigSectionable;
     if (_configSection != null)
     {
         _configSection.Init(configSectionObjectMap);
     }
 }
        protected override void OnAfterCommandLineArgObjectLoaded(string[] commandLineArgs)
        {
            ChoShellExtensionActionMode?sem = GetShellExtensionActionMode();

            if (DisplayAvailProperties || DisplayAvailTypeParsersNFormatters)
            {
                if (DisplayAvailProperties)
                {
                    ChoApplication.DisplayMsg(ChoPropertyManagerSettings.Me.GetHelpText(), null, ConsoleColor.Yellow);
                }
                if (DisplayAvailTypeParsersNFormatters)
                {
                    ChoApplication.DisplayMsg(ChoTypesManager.GetHelpText(), null, ConsoleColor.Green);
                }
                if (!ConfigObjectTypeName.IsNullOrWhiteSpace())
                {
                    ChoApplication.DisplayMsg(ChoConfigurationManager.GetHelpText(ChoType.GetType(ConfigObjectTypeName)), null, ConsoleColor.Green);
                }
                Environment.Exit(0);
            }
            else if (!ConfigObjectTypeName.IsNullOrWhiteSpace())
            {
                ChoApplication.DisplayMsg(ChoConfigurationManager.GetHelpText(ChoType.GetType(ConfigObjectTypeName)), null, ConsoleColor.Green);
                Environment.Exit(0);
            }
            else if (sem != null)
            {
                if (sem.Value == ChoShellExtensionActionMode.Register)
                {
                    ChoShellExtension.Register();
                    ChoTrace.WriteLine("Shell Extensions registered successfully.");

                    ChoShellFileAssociation.Register();
                    ChoTrace.WriteLine("File Associations registered successfully.");

                    Environment.Exit(0);
                }
                else if (sem.Value == ChoShellExtensionActionMode.Unregister)
                {
                    ChoShellExtension.Unregister();
                    ChoTrace.WriteLine("Shell Extensions unregistered successfully.");

                    ChoShellFileAssociation.Unregister();
                    ChoTrace.WriteLine("File Associations unregistered successfully.");

                    Environment.Exit(0);
                }
            }

            if (ChoShellExtension.ExecuteShellExtensionMethodIfAnySpecified(commandLineArgs))
            {
                ChoTrace.WriteLine("Shell Extension ran successfully.");
                Environment.Exit(0);
            }

            base.OnAfterCommandLineArgObjectLoaded(commandLineArgs);
        }
Exemple #4
0
        public ChoFileXmlSerializer(XmlNode node) : base(node)
        {
            ConfigSectionName = node.Name;
            _configPath       = ChoConfigurationManager.GetConfigFile(node);

            if (_configPath == null || !File.Exists(_configPath))
            {
                ErrMsg = String.Format("{0} not exists.", _configPath);
            }
        }
        private NameValueCollection LoadConfigSection(XmlNode section, string configPath)
        {
            if (configPath != null && configPath.Length > 0 && configPath != ChoConfigurationManager.AppConfigFilePath)
            {
                ConfigXmlDocument doc = new ConfigXmlDocument();
                doc.Load(configPath);

                if (doc.DocumentElement.Name != section.Name)
                {
                    throw new ChoConfigurationException(String.Format("Invalid {0} root element found in {1} config file. Expected {2}",
                                                                      doc.DocumentElement.Name, configPath, section.Name), doc.DocumentElement);
                }

                base.ExpandIncludes(doc.DocumentElement, configPath);

                return(ChoConfigurationManager.GetNameValueCollection(null, doc.DocumentElement,
                                                                      KeyAttributeName, ValueAttributeName));
            }
            else
            {
                return(ChoConfigurationManager.GetNameValueCollection(null, section,
                                                                      KeyAttributeName, ValueAttributeName));
            }
        }
Exemple #6
0
        private static void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }

            lock (_padLock)
            {
                if (_isInitialized)
                {
                    return;
                }

                _logBackupDay = DateTime.Today;

                InitializeAppInfo();

                if (!ServiceInstallation)
                {
                    if (ApplicationMode != ChoApplicationMode.Service &&
                        ApplicationMode != ChoApplicationMode.Web)
                    {
                        try
                        {
                            _rkAppRun = Registry.CurrentUser.OpenSubKey(RegRunSubKey, true);
                            if (_rkAppRun == null)
                            {
                                _rkAppRun = Registry.CurrentUser.CreateSubKey(RegRunSubKey);
                            }

                            RunAtSystemStartup(!ChoGlobalApplicationSettings.Me.ApplicationBehaviourSettings.RunAtStartup);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.TraceError(ex.ToString());
                        }

                        try
                        {
                            _rkAppRunOnce = Registry.CurrentUser.OpenSubKey(RegRunOnceSubKey, true);
                            if (_rkAppRunOnce == null)
                            {
                                _rkAppRunOnce = Registry.CurrentUser.CreateSubKey(RegRunOnceSubKey);
                            }

                            RunOnceAtSystemStartup(!ChoGlobalApplicationSettings.Me.ApplicationBehaviourSettings.RunOnceAtStartup);
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Trace.TraceError(ex.ToString());
                        }
                    }
                }

                ChoGuard.ArgumentNotNullOrEmpty(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath, "Application Config Path");

                try
                {
                    _elApplicationEventLog        = new EventLog("Application", Environment.MachineName, ChoGlobalApplicationSettings.Me.ApplicationName);
                    _elApplicationEventLog.Log    = "Application";
                    _elApplicationEventLog.Source = ChoGlobalApplicationSettings.Me.EventLogSourceName;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.TraceError(ex.ToString());
                }

                ApplicationConfigDirectory = Path.GetDirectoryName(ChoGlobalApplicationSettings.Me.ApplicationConfigFilePath);

                //Add default text trace listerner, if not defined in the configuration file
                Directory.CreateDirectory(ChoApplication.ApplicationLogDirectory);
                try
                {
                    if (_logFileName != ChoGlobalApplicationSettings.Me.LogSettings.LogFileName ||
                        _logDirectory != ChoApplication.ApplicationLogDirectory)
                    {
                        _logFileName  = ChoGlobalApplicationSettings.Me.LogSettings.LogFileName;
                        _logDirectory = ChoApplication.ApplicationLogDirectory;

                        ChoTextWriterTraceListener frxTextWriterTraceListener = new Cinchoo.Core.Diagnostics.ChoTextWriterTraceListener("Cinchoo",
                                                                                                                                        String.Format("BASEFILENAME={0};DIRECTORYNAME={1};FILEEXT={2}", ChoGlobalApplicationSettings.Me.LogSettings.LogFileName,
                                                                                                                                                      ChoApplication.ApplicationLogDirectory, ChoReservedFileExt.Txt));

                        if (_frxTextWriterTraceListener != null)
                        {
                            System.Diagnostics.Trace.Listeners.Remove(_frxTextWriterTraceListener);
                        }
                        else
                        {
                            ChoGlobalTimerServiceManager.Register("Logbackup", () =>
                            {
                                if (DateTime.Today != _logBackupDay)
                                {
                                    _logBackupDay = DateTime.Today;
                                    ChoTrace.Backup();
                                }
                            }, 60000);
                        }

                        _frxTextWriterTraceListener = frxTextWriterTraceListener;
                        System.Diagnostics.Trace.Listeners.Add(_frxTextWriterTraceListener);
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.TraceError(ex.ToString());
                }

                while (_queueTraceMsg.Count > 0)
                {
                    Tuple <bool?, string> tuple = _queueTraceMsg.Dequeue();
                    System.Diagnostics.Trace.WriteLineIf(tuple.Item1 == null ? ChoGlobalApplicationSettings.Me.TurnOnConsoleOutput : tuple.Item1.Value, tuple.Item2);
                }
                _isInitialized = true;

                ChoApplication.WriteToEventLog(ChoApplication.ToString());
                //ChoApplication.WriteToEventLog(ChoGlobalApplicationSettings.Me.ToString());

                //Initialize other Framework Settings
                ChoAssembly.Initialize();
                ChoConsole.Initialize();
                ChoConfigurationManager.Initialize();
            }
        }