/// <inheritdoc />
        public void Dispose()
        {
            using (Dictionary <string, IPreferenceStore> .ValueCollection.Enumerator storeItr = _preferenceStoreTable.Values.GetEnumerator()) {
                while (storeItr.MoveNext())
                {
                    IPreferenceStore store = storeItr.Current;
                    if (store == null)
                    {
                        continue;
                    }

                    try {
                        store.Flush();
                    } catch (Exception ex) {
                        _log.Error("Error on flushing store. Reason: {0}", ex);
                    }
                }
            }

            _preferenceStoreTable.Clear();
        }
Exemple #2
0
        /// <summary>
        /// Memorizes the state of the given <paramref name="mainWindow"/> and writes all data
        /// into a specific preference store. If the given <paramref name="mainWindow"/> is NULL, nothing
        /// will happen.
        /// </summary>
        /// <param name="mainWindow">Window which state is to memorize</param>
        private void MemorizeWindowState(IMainWindow mainWindow)
        {
            if (mainWindow == null)
            {
                return;
            }
            int windowState  = (int)mainWindow.WindowState;
            int windowWidth  = mainWindow.Width;
            int windowHeight = mainWindow.Height;
            int windowTop    = mainWindow.TopLocation;
            int windowLeft   = mainWindow.LeftLocation;

            try {
                IPreferenceStore preferenceStore = GetPreferenceStore();
                preferenceStore.SetValue(WindowStateKey, windowState);
                preferenceStore.SetValue(WindowWidthKey, windowWidth);
                preferenceStore.SetValue(WindowHeightKey, windowHeight);
                preferenceStore.SetValue(WindowTopKey, windowTop);
                preferenceStore.SetValue(WindowLeftKey, windowLeft);
                preferenceStore.Flush();
            } catch (Exception ex) {
                _log.Error("Error on memorizing window state.", ex);
            }
        }
Exemple #3
0
        /// <summary>
        /// Restores the state of the given <paramref name="mainWindow"/> based on the values that
        /// have been saved into a specific preference store before. If there aren't stored settings,
        /// a default value set is used. If the given <paramref name="mainWindow"/> is NULL, nothing
        /// will happen.
        /// </summary>
        /// <param name="mainWindow">Window to restore</param>
        private void RestoreWindowState(IMainWindow mainWindow)
        {
            if (mainWindow == null)
            {
                return;
            }

            try {
                IPreferenceStore preferenceStore = GetPreferenceStore();
                int windowState  = preferenceStore.GetValue(WindowStateKey, (int)EWindowState.Normal);
                int windowWidth  = preferenceStore.GetValue(WindowWidthKey, 800);
                int windowHeight = preferenceStore.GetValue(WindowHeightKey, 600);
                int windowTop    = preferenceStore.GetValue(WindowTopKey, 0);
                int windowLeft   = preferenceStore.GetValue(WindowLeftKey, 0);

                mainWindow.WindowState  = (EWindowState)windowState;
                mainWindow.Width        = windowWidth;
                mainWindow.Height       = windowHeight;
                mainWindow.TopLocation  = windowTop;
                mainWindow.LeftLocation = windowLeft;
            } catch (Exception ex) {
                _log.Error("Error on restoring window state.", ex);
            }
        }