/// <summary> /// STARTING POINT for Open Document /// /// Order of Operations /// 1.) MainViewModel.OnOpenDocument /// 2.) DocumentWindow.OpenFile /// 3.) MainViewModel.AddDocument /// </summary> public static void OpenDocument(string path, Action callback = null) { #region InvokeRequired if (View.InvokeRequired) { View.Invoke(new Action <string, Action>(OpenDocument), path, callback); return; } #endregion PerformanceService.StartEvent($"{PerformanceService.CONST_OpenDocument}{path}"); Log.WriteEnter(typeof(MainViewModel).FullName, MethodBase.GetCurrentMethod().Name); lock (_syncOpenDocument) { #region Check if already open if (!File.Exists(path)) { MessageBox.Show(string.Format("They system cannot find the file specified: \"{0}\"", path)); return; } var doc = FindDocument(path) as DocumentWindow; if (doc != null) { doc.DockHandler.Show(); var model = doc as DocumentWindow; if (model != null) { SetCurrent(model.ViewModel); } callback?.Invoke(); return; } #endregion #region Create DocumentWindow doc = new DocumentWindow { Text = Path.GetFileName(path) }; try { var model = new DocumentModel { Control = doc.PrepareDocument(path), File = XmlDal.CacheModel.GetFile(path) }; doc.ViewModel.View.StatusUpdate(StatusModel.Update("Loading")); doc.ViewModel.Model = model; model.File.Options = Options; model.File.DocumentModel = model; Documents.Add(doc.ViewModel); DocumentService.BuildDocument(model); } catch (Exception exception) { doc.Close(); MessageBox.Show(exception.Message); } #endregion #region Show if (View.DockPanel.DocumentStyle == DocumentStyle.SystemMdi) { doc.MdiParent = View as Form; doc.Show(); } else { doc.Show(View.DockPanel); } #endregion if (StartupComplete) { SetCurrent(doc.ViewModel); } callback?.Invoke(); PerformanceService.StopEvent($"{PerformanceService.CONST_OpenDocument}{path}"); Log.WriteExit(typeof(MainViewModel).FullName, MethodBase.GetCurrentMethod().Name); } }