当前位置: 首页>>代码示例>>C#>>正文


C# ISettings.Commit方法代码示例

本文整理汇总了C#中ISettings.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# ISettings.Commit方法的具体用法?C# ISettings.Commit怎么用?C# ISettings.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISettings的用法示例。


在下文中一共展示了ISettings.Commit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: internalMain

        static void internalMain(string[] args)
        {
            bool success = ProgramArguments.TryParse(args, out arguments);

            if (!success) {
                arguments = new ProgramArguments(); // Get a new instance with default values.
            }

            if (arguments.CleanupUpdate || EnvironmentUtils.IsMonoRuntime()) {
                if (!EnvironmentUtils.IsMonoRuntime()) {
                    // Wait one second to allow the other instance to exit.
                    Thread.Sleep(1000);
                }
                // Remove the old executable file.
                if (File.Exists(String.Format("{0}.tmp", AssemblyUtils.GetApplicationPath()))) {
                    File.Delete(String.Format("{0}.tmp", AssemblyUtils.GetApplicationPath()));
                }
            }

            if (!arguments.AllowMultipleInstances) {
                var assembly = typeof(Program).Assembly;
                GuidAttribute guidAttribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
                bool applicationInstanceIsNotRunning;
                mutex = new Mutex(false, String.Format("{0}{1}", Application.ProductName, guidAttribute.Value), out applicationInstanceIsNotRunning);
                if (!applicationInstanceIsNotRunning) {
                    MessageBox.Show(String.Format("An instance of this program is already running."), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Load settings.
            String settingsFilePath = String.Format("{0}{1}{2}", Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath), Path.DirectorySeparatorChar, Program.SettingsFileName);
            try {
                if (!File.Exists(settingsFilePath)) {
                    try {
                        XMLSettings.CreateFile(settingsFilePath);
                    }
                    catch (Exception createSettingsFileException) {
                        MessageBox.Show(String.Format("Cannot create settings file {0}.\n\nError details: {1}", settingsFilePath, createSettingsFileException.Message), "uRADMonitorX", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                settings = XMLSettings.LoadFromFile(settingsFilePath);
                // Fixes an issue with data log directory name on Linux due to trailing slash.
                settings.DataLogDirectoryPath = settings.DataLogDirectoryPath.TrimEnd('\\');
                settings.Commit();
            }
            catch (Exception loadSettingsFileException) {
                MessageBox.Show(String.Format("Cannot load settings from file {0}.\n\nError details: {1}", settingsFilePath, loadSettingsFileException.Message), "uRADMonitorX", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var loggerFilePath = getLoggerPath(settings.LogDirectoryPath, Program.LoggerFileName, false);
            var dataLoggerFilePath = getLoggerPath(settings.DataLoggingToSeparateFile ? settings.DataLogDirectoryPath : settings.LogDirectoryPath, Program.DataLoggerFileName, settings.IsLoggingEnabled && settings.IsDataLoggingEnabled && settings.DataLoggingToSeparateFile);

            LoggerManager.GetInstance().Add(Program.LoggerName,
                                            new ThreadSafeLogger(
                                                new Logger(
                                                    new ReconfigurableFileAppender(loggerFilePath),
                                                    new DateTimeFormatter()
                                                ) {
                                                    Enabled = settings.IsLoggingEnabled
                                                }
                                            ));
            LoggerManager.GetInstance().Add(Program.DataLoggerName,
                                          new ThreadSafeLogger(
                                                new Logger(
                                                    new NLogDailyFileAppender(dataLoggerFilePath),
                                                    new DateTimeFormatter()
                                                ) {
                                                    Enabled = settings.IsLoggingEnabled &&
                                                    settings.IsDataLoggingEnabled &&
                                                    settings.DataLoggingToSeparateFile
                                                }
                                            ));
            logger = LoggerManager.GetInstance().GetLogger(Program.LoggerName);

            IDeviceDataReaderFactory deviceDataReaderFactory = new DeviceDataHttpReaderFactory(settings);

            if (!arguments.IgnoreRegisteringAtWindowsStartup && !EnvironmentUtils.IsUnix()) {
                registerAtWindowsStartup();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            FormMain formMain = new FormMain(deviceDataReaderFactory, settings, logger);
            formMain.SettingsChangedEventHandler += new SettingsChangedEventHandler(formMain_SettingsChangedEventHandler);

            Application.Run(formMain);
        }
开发者ID:cristianst85,项目名称:uRADMonitorX,代码行数:91,代码来源:Program.cs


注:本文中的ISettings.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。