예제 #1
0
        public void Initialize()
        {
            var dispatcher = new WPFDispatcher(Application.Current.Dispatcher);

            // Initialize Settings
            var settingsImpl = new SettingsImpl((string)null);

            settings_ = new Settings(settingsImpl, dispatcher);

            // Load settings from file if it exists
            if (File.Exists(PluginInfo.SettingsFilePath))
            {
                try {
                    using (var fs = new FileStream(PluginInfo.SettingsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        var serializer = new DataContractSettingsSerializer();
                        serializer.Deserialize(fs, settingsImpl);
                    }
                }
                catch (Exception ex) {
                    Logger.Error("Failed to load settings from file.", ex);
                    if (ex.IsCritical())
                    {
                        throw;
                    }
                }
            }

            // Initialize settings auto expoter
            expoter_ = new SettingsAutoExpoter(
                PluginInfo.SettingsFilePath, PluginInfo.SettingsFilePath + ".temp",
                settingsImpl, new DataContractSettingsSerializer());
        }
예제 #2
0
        protected override void RegisterTypes(IUnityContainer unityContainer)
        {
            var container = new SettingsContainer("AnizanHelper", Models.Settings.KnownTypes);

            var settings = new Models.Settings(container);

            unityContainer.RegisterInstance(settings);

            var serializer = new DataContractSettingsSerializer();

            try
            {
                var settingsFilePath = Path.Combine(AppInfo.Current.StartupDirectory, Constants.SettingsFileName);
                if (File.Exists(settingsFilePath))
                {
                    using (var fs = new FileStream(settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        serializer.Deserialize(fs, container);
                    }
                }
            }
            catch
            {
                MessageBox.Show(App.Current.MainWindow, "設定の読込に失敗しました。\nデフォルトの設定を利用します。", "エラー", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            var autoSaverService = new SettingsAutoSaverService(
                container,
                serializer,
                TimeSpan.FromMilliseconds(250));

            this.ServiceManager.Register(autoSaverService);
        }
        private void KanColleClient_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (KanColleClient.Current.Homeport != null)
            {
                KanColleClient.Current.PropertyChanged -= KanColleClient_PropertyChanged;

                var admiral    = KanColleClient.Current.Homeport.Admiral;
                var dispatcher = new WPFDispatcher(Application.Current.Dispatcher);

                // Initialize Settings
                var settingsImpl = new SettingsImpl((string)null);
                settings_ = new Settings(settingsImpl, dispatcher);

                // Load settings from file if it exists
                if (File.Exists(PluginInfo.SettingsFilePath))
                {
                    try {
                        using (var fs = new FileStream(PluginInfo.SettingsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                            var serializer = new DataContractSettingsSerializer();
                            serializer.Deserialize(fs, settingsImpl);
                        }
                    }
                    catch (Exception ex) {
                        Logger.Error("Failed to load settings from file.", ex);
                        if (ex.IsCritical())
                        {
                            throw;
                        }
                    }
                }

                // Initialize settings auto expoter
                expoter_ = new SettingsAutoExpoter(
                    PluginInfo.SettingsFilePath, PluginInfo.SettingsFilePath + ".temp",
                    settingsImpl, new DataContractSettingsSerializer());

                viewModel_ = new ViewModels.KanburaTimerToolViewModel(
                    KanColleClient.Current,
                    settings_,
                    dispatcher);

                viewModel_.StartMonitoring();
            }
        }
        public void Initialize()
        {
            var dispatcher = new WPFDispatcher(Application.Current.Dispatcher);

            // Initialize Settings
            var settingsImpl = new SettingsImpl((string)null);
            settings_ = new Settings(settingsImpl, dispatcher);

            // Load settings from file if it exists
            if (File.Exists(PluginInfo.SettingsFilePath)) {
                try {
                    using (var fs = new FileStream(PluginInfo.SettingsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        var serializer = new DataContractSettingsSerializer();
                        serializer.Deserialize(fs, settingsImpl);
                    }
                }
                catch (Exception ex) {
                    Logger.Error("Failed to load settings from file.", ex);
                    if (ex.IsCritical()) { throw; }
                }
            }

            // Initialize settings auto expoter
            expoter_ = new SettingsAutoExpoter(
                PluginInfo.SettingsFilePath, PluginInfo.SettingsFilePath + ".temp",
                settingsImpl, new DataContractSettingsSerializer());
        }