示例#1
0
        private void OnLoadRecentFileExecute(RecentFile recentFileData)
        {
            SetLoadingStatus(true);
            Task<IVisualisableTypeWithAssociations> task = this.fileManager.LoadFromRecentFileAsync(recentFileData);
            if (task == null)
            {
                SetLoadingStatus(false);
                return;
            }

            if (task.IsCompleted)
            {
                OnTypeFinishedLoading(task.Result);
            } else
            {
                task.ContinueWith(finishedTask => OnTypeFinishedLoading(finishedTask.Result));
            }
        }
示例#2
0
        public void SaveRecentFile()
        {
            if (string.IsNullOrEmpty(AssemblyFileName))
            {
                return;
            }

            var newRecentFile = new RecentFile { FileName = AssemblyFileName, TypeName = this.currentType, When = this.when };

            RecentFile existing = RecentlyUsedFiles.SingleOrDefault(x => x.FileName == newRecentFile.FileName && x.TypeName == newRecentFile.TypeName);
            if (existing != null)
            {
                RecentlyUsedFiles.Remove(existing);
            }

            RecentlyUsedFiles.Insert(0, newRecentFile);

            // Save to xml file
            string serialised = XamlServices.Save(RecentlyUsedFiles.ToList());
            try
            {
                File.WriteAllText(FullFileName, serialised);
            } catch (IOException ex)
            {
                this.userPrompt.Show(ex, Resources.RecentFilesXml_SaveRecentFile);
            }
        }
示例#3
0
 private void HandleLoadRecentFileException(RecentFile recentFileData, Exception ex)
 {
     Logger.Instance.WriteEntry("Exception occured in ShellController.LoadFromRecentFileAsync\n" + ex);
     this.messenger.Send(new RecentFileDeleteMessage(recentFileData));
     this.UserPrompt.Show(Resources.ModelBuilder_BuildType_Bad_file_and_or_type_in_Recently_Used_File_List_cannot_load_this_type);
 }
示例#4
0
 public void SetLastAccessed(RecentFile file)
 {
     RecentFile item = RecentlyUsedFiles.SingleOrDefault(x => x.FileName == file.FileName && x.TypeName == file.TypeName);
     if (item != null)
     {
         item.When = DateTime.Now;
         AssemblyFileName = file.FileName;
     }
 }
示例#5
0
        public Task<IVisualisableTypeWithAssociations> LoadFromRecentFileAsync(RecentFile recentFileData)
        {
            Type type;
            if (recentFileData == null)
            {
                throw new ArgumentNullResourceException("recentFileData", Resources.General_Given_Parameter_Cannot_Be_Null);
            }

            try
            {
                type = this.ModelBuilder.BuildType(recentFileData.FileName, recentFileData.TypeName);
            }
            catch (ArgumentException ex)
            {
                this.HandleLoadRecentFileException(recentFileData, ex);
                return null;
            }
            catch (FileLoadException ex)
            {
                this.HandleLoadRecentFileException(recentFileData, ex);
                return null;
            }
            catch (TypeLoadException ex)
            {
                this.HandleLoadRecentFileException(recentFileData, ex);
                return null;
            }

            if (type == null)
            {
                return null;
            }

            this.RecentFiles.SetLastAccessed(recentFileData);
            this.RecentFiles.SaveRecentFile();
            return this.LoadTypeAsync(type);
        }