コード例 #1
0
        public MainWindow()
        {
            InitializeComponent();
            var savingDirectory = ServiceLocator.Instance.SaveLocation;

            persistingFilename       = Path.Combine(savingDirectory, "MainWindow");
            persistingRecentFileName = Path.Combine(savingDirectory, "RecentFiles");
            var fileName = Path.ChangeExtension(persistingFilename, ".json");

            var settings = PersistingSettings.Load(fileName);

            // Restore persisted window placement if provided
            if (settings?.WindowPlacementInfo != null)
            {
                RestoreWindowPosition(settings.WindowPlacementInfo);
            }

            if (settings?.UserPreferences != null)
            {
                // TODO: is this already set?
                Preferences = settings.UserPreferences;
            }

            // Get recently opened files
            GetRecentlyOpenedFiles();
        }
コード例 #2
0
        private static PersistingSettings DeserializeFromV1(string fileContents)
        {
            Trace.WriteLine("DeserializeFromV1");

            PersistingSettings wrapper = null;

            try
            {
                wrapper = new PersistingSettings
                {
                    WindowPlacementInfo = JsonHelper.DeserializeFromString <WindowPlacementInfo>(fileContents),
                };
            }
            catch (Exception e)
            {
                Trace.TraceError($"Deserialize error: {e.Message}");
            }

            return(wrapper);
        }
コード例 #3
0
        private void OnClosed(object sender, CancelEventArgs e)
        {
            var windowInfo = new WindowPlacementInfo
            {
                Height      = (int)Height,
                Top         = (int)Top,
                Left        = (int)Left,
                Width       = (int)Width,
                WindowState = WindowState,
            };

            var filename = Path.ChangeExtension(persistingFilename, ".json");

            PersistingSettings.Save(filename, windowInfo, Preferences);

            var recentFileInfo = new RecentFileInfo {
                RecentFilePaths = RecentFiles.ToList()
            };

            JsonHelper.SerializeToFile(recentFileInfo, Path.ChangeExtension(persistingRecentFileName, ".json"));
        }
コード例 #4
0
        internal static void Save(string fileName, WindowPlacementInfo placementInfo, IUserPreferences userPreferences)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(fileName));
            }

            var wrapper = new PersistingSettings
            {
                WindowPlacementInfo = placementInfo,
                UserPreferences     = userPreferences,
            };

            try
            {
                JsonHelper.SerializeToFile(wrapper, fileName);
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to write persistence file: {e.Message}");
            }
        }