public async Task AutoSave()
        {
            if (!IsDirty)
            {
                return;
            }
            if (Document == null)
            {
                var    index = 1;
                string path;
                do
                {
                    path = Path.Combine(_workingDirectory, DocumentViewModel.GetAutoSaveName("Program" + index++));
                } while (File.Exists(path));
                Document = DocumentViewModel.CreateAutoSave(MainViewModel, path);
            }

            await SaveDocument(Document.IsAutoSave?Document.Path
                               // ReSharper disable once AssignNullToNotNullAttribute
                               : Path.Combine(Path.GetDirectoryName(Document.Path), DocumentViewModel.GetAutoSaveName(Document.Name))).ConfigureAwait(false);
        }
        private void LoadDockLayout()
        {
            var layout = _viewModel.Settings.DockLayout;

            if (string.IsNullOrEmpty(layout))
            {
                return;
            }

            var layoutSerializer = new XmlLayoutSerializer(DockingManager);

            layoutSerializer.LayoutSerializationCallback += (s, e) =>
            {
                var contentId = e.Model.ContentId;

                if (string.IsNullOrEmpty(contentId) || e.Content != null)
                {
                    return;
                }

                if (File.Exists(contentId))
                {
                    var document = DocumentViewModel.FromPath(contentId);
                    _viewModel.OpenDocument(document);
                }

                e.Cancel = true;
            };

            var reader = new StringReader(layout);

            try
            {
                layoutSerializer.Deserialize(reader);
            }
            catch
            {
                // ignored
            }
        }
        public OpenDocumentViewModel(MainViewModel mainViewModel, DocumentViewModel document)
        {
            Document      = document;
            MainViewModel = mainViewModel;
            NuGet         = new NuGetDocumentViewModel(mainViewModel.NuGet);
            _dispatcher   = Dispatcher.CurrentDispatcher;

            var roslynHost = mainViewModel.RoslynHost;

            IsDirty = document?.IsAutoSave == true;

            _workingDirectory = Document != null
                ? Path.GetDirectoryName(Document.Path)
                : MainViewModel.DocumentRoot.Path;

            Platform       = Platform.X86;
            _executionHost = new ExecutionHost(GetHostExeName(), _workingDirectory,
                                               roslynHost.DefaultReferences.OfType <PortableExecutableReference>().Select(x => x.FilePath),
                                               roslynHost.DefaultImports, mainViewModel.NuGetConfiguration, mainViewModel.ChildProcessManager);

            SaveCommand        = new DelegateCommand(() => Save(promptSave: false));
            RunCommand         = new DelegateCommand(Run, () => !IsRunning);
            RestartHostCommand = new DelegateCommand(RestartHost);
        }
 private static string OrderByName(DocumentViewModel x)
 {
     return(Regex.Replace(x.Name, "[0-9]+", m => m.Value.PadLeft(100, '0')));
 }
Exemple #5
0
 public IEnumerable <OpenDocumentViewModel> LoadAutoSaves(string root)
 {
     return(Directory.EnumerateFiles(root, DocumentViewModel.GetAutoSaveName("*"), SearchOption.AllDirectories)
            .Select(x => new OpenDocumentViewModel(this, DocumentViewModel.CreateAutoSave(this, x))));
 }
Exemple #6
0
 private IEnumerable <OpenDocumentViewModel> LoadAutoSavedDocuments(string root)
 {
     return(EnumerateFilesWithCatch(root, DocumentViewModel.GetAutoSaveName("*")).Select(x =>
                                                                                         new OpenDocumentViewModel(this, DocumentViewModel.CreateAutoSave(x))));
 }