public DocumentEditorViewModel(IDocumentEditor documentEditor, IExporter exporter)
        {
            Ensure.ArgumentNotNull(documentEditor, "documentEditor");
            Ensure.ArgumentNotNull(exporter, "exporter");

            _documentEditor = documentEditor;
            _fontSize = DefaultFontSize;
            _documentEditor.New();
            _document = new TextDocument();
            _exporter = exporter;
        }
		public async Task CloseDocumentEditor (IDocumentEditor editor, bool unbindUI, bool deleteThumbnail, bool reloadThumbnail)
		{
			var docRef = editor.DocumentReference;
			if (docRef == null)
				return;
			
			var doc = docRef.Document;
			if (doc == null)
				return;

			Debug.WriteLine ("CLOSE " + docRef.File.Path);

			if (!doc.IsOpen)
				return;
			docRef.IsNew = false;

			Settings.LastDocumentPath = "";

			try {
				await docRef.Close ();

				editor.UnbindDocument ();
				if (unbindUI) {
					editor.UnbindUI ();
				}

				InvalidateThumbnail (docRef.File, deleteThumbnail:deleteThumbnail, reloadThumbnail:reloadThumbnail);

			} catch (Exception ex) {
				Debug.WriteLine (ex);
			}
		}
		static async Task BindEditorAsync (IDocumentEditor newEditor)
		{
			var docRef = newEditor.DocumentReference;
			if (!docRef.IsOpen) {
				await docRef.Open ();
			}
			newEditor.BindDocument ();
		}
 private static void OnEditUut( IDocumentEditor source, Document document, UUTDescription obj,
     bool saveDocumentOnCompletion)
 {
     bool ret = false;
     EditDocumentDelegate handler = EditUUT;
     if (handler != null) handler( source, document, obj, saveDocumentOnCompletion );
 }
 private static void OnEditTestStation( IDocumentEditor source, Document document, TestStationDescription11 obj,
     bool saveDocumentOnCompletion)
 {
     EditDocumentDelegate handler = EditTestStation;
     if (handler != null) handler( source, document, obj, saveDocumentOnCompletion );
 }
 private static void OnEditTestAdapter( IDocumentEditor source, Document document, TestAdapterDescription1 obj,
     bool saveDocumentOnCompletion)
 {
     bool ret = false;
     EditDocumentDelegate handler = EditTestAdapter;
     if (handler != null) handler( source, document, obj, saveDocumentOnCompletion );
 }
        public static bool EditDocument( IDocumentEditor source, Document _document, string uuid, string documentContent,
            bool saveDocumentOnCompletion)
        {
            bool documentSaved = false;
            Document document = GetDocument( uuid );
            if (document != null)
            {
                string content = Encoding.UTF8.GetString( _document.DocumentContent );

                switch (document.DocumentType)
                {
                    case dbDocument.DocumentType.INSTRUMENT_DESCRIPTION:
                    {
                        InstrumentDescription obj =
                            InstrumentDescription.Deserialize( content );
                        OnEditInstrument( source, document, obj, saveDocumentOnCompletion );
                        break;
                    }
                    case dbDocument.DocumentType.TEST_ADAPTER_DESCRIPTION:
                    {
                        TestAdapterDescription1 obj =
                            TestAdapterDescription1.Deserialize( content );
                        OnEditTestAdapter( source, document, obj, saveDocumentOnCompletion );
                        break;
                    }
                    case dbDocument.DocumentType.TEST_STATION_DESCRIPTION:
                    {
                        TestStationDescription11 obj =
                            TestStationDescription11.Deserialize( content );
                        OnEditTestStation( source, document, obj, saveDocumentOnCompletion );
                        break;
                    }
                    case dbDocument.DocumentType.UUT_DESCRIPTION:
                    {
                        UUTDescription obj =
                            UUTDescription.Deserialize( content );
                        OnEditUut( source, document, obj, saveDocumentOnCompletion );
                        break;
                    }
                    default:
                    {
                        MessageBox.Show(
                            string.Format( "There is currently no editor available for document type \"{0}\".",
                                           document.DocumentType ) );
                        break;
                    }
                }
            }

            return documentSaved;
        }