Exemple #1
0
 private AutoSaveIndex GetCurrentAutoSaveIndex()
 {
     _masterAutoSaveIndex.TryGetValue(CurrentProcessId, out AutoSaveIndex index);
     if (index == null)
     {
         index = AutoSaveIndex.Create();
         _masterAutoSaveIndex.Add(CurrentProcessId, index);
     }
     return(index);
 }
Exemple #2
0
        // this gets called from a timer, so it's already running off the UI thread, so this IO should not be blocking
        private void SaveIndex(AutoSaveIndex index)
        {
            JsonSerializer serializer = new JsonSerializer();

            using (StreamWriter sw = new StreamWriter(AutoSaveIndexFile(index)))
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, index);
                }
        }
Exemple #3
0
        public async static Task Save(DocumentTabViewModel tabs)
        {
            try
            {
                // exit here if no tabs are open
                if (tabs.Items.Count == 0)
                {
                    return;
                }

                var currentProcessId = Process.GetCurrentProcess().Id;

                AutoSaveIndex index;
                _masterAutoSaveIndex.TryGetValue(currentProcessId, out index);
                if (index == null)
                {
                    index = new AutoSaveIndex();
                    _masterAutoSaveIndex.Add(currentProcessId, index);
                }

                foreach (DocumentViewModel tab in tabs.Items)
                {
                    if (tab.IsDirty)
                    {
                        index.Add(tab);
                    }

                    // don't autosave if the document has not changed since last save
                    // or if IsDirty is false meaning that the file has been manually saved
                    if (tab.IsDirty || tab.LastAutoSaveUtcTime < tab.LastModifiedUtcTime)
                    {
                        await tab.AutoSave();
                    }
                }
                SaveIndex(index);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "{class} {method} {message}", "AutoSaver", "Save", ex.Message);
            }
        }
Exemple #4
0
 internal string AutoSaveIndexFile(AutoSaveIndex index)
 {
     return(Path.Combine(ApplicationPaths.AutoSavePath, index.IndexFile));
 }
Exemple #5
0
 internal static string AutoSaveIndexFile(AutoSaveIndex index)
 {
     return(Path.Combine(Environment.ExpandEnvironmentVariables(Constants.AutoSaveFolder), index.IndexFile));
 }