/// <summary> /// Loads the document from a given file name. /// </summary> /// <param name="fileName">Filename from which to load the document data.</param> /// <param name="isReload">True if the document is reloading.</param> public virtual void Load(string fileName, bool isReload) { Reset(); if (isReload) { OnDocumentReloading(new EventArgs()); } else { OnDocumentLoading(new EventArgs()); } //currentModelFileName = fileName; Microsoft.VisualStudio.Modeling.Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load Model", true); ModelData.DoSendModelEvents = false; try { LoadDocument(fileName, isReload); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); this.SerializationResult.AddMessage(new SerializationMessage(ModelValidationMessageIds.SerializationLoadErrorId, ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); } ModelData.DoSendModelEvents = true; // clear undo manager stack if (!this.ModelData.Store.TransactionActive) { this.ModelData.UndoManager.Flush(); } this.ModelData.RaiseUndoRedoChangeEvents(); this.IsDirty = false; OnPropertyChanged("CanUndo"); OnPropertyChanged("CanRedo"); if (isReload) { OnDocumentReloaded(new EventArgs()); } else { OnDocumentLoaded(new EventArgs()); } }
/// <summary> /// Saves the document to a given file name. This serialization is treated as temporarly and as such does /// not change the default saving location of the current domain model. /// </summary> /// <param name="fileName">Filename to save the document data to.</param> public virtual void SaveTemporarly(string fileName) { Microsoft.VisualStudio.Modeling.Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Save Model Temporarly", true); try { SaveDocumentTemporarly(fileName); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); this.SerializationResult.AddMessage(new SerializationMessage(ModelValidationMessageIds.SerializationSaveErrorId, ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); } }
/// <summary> /// Loads the document from a given file name. This will not replace the currently loaded domain model neither will it send events. /// </summary> /// <param name="fileName">Filename from which to load the document data.</param> public virtual Microsoft.VisualStudio.Modeling.ModelElement LoadInternal(string fileName) { Microsoft.VisualStudio.Modeling.Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Load Model Internal", true); try { Microsoft.VisualStudio.Modeling.ModelElement modelElement = LoadDocumentInternal(fileName); transaction.Commit(); return(modelElement); } catch (Exception ex) { transaction.Rollback(); this.SerializationResult.AddMessage(new SerializationMessage(ModelValidationMessageIds.SerializationLoadErrorId, ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); return(null); } }
/// <summary> /// Saves the document to a given file name. /// </summary> /// <param name="fileName">Filename to save the document data to.</param> public virtual void Save(string fileName) { OnDocumentSaving(new EventArgs()); Microsoft.VisualStudio.Modeling.Transaction transaction = this.ModelData.Store.TransactionManager.BeginTransaction("Save Model", true); try { SaveDocument(fileName); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); this.SerializationResult.AddMessage(new SerializationMessage(ModelValidationMessageIds.SerializationSaveErrorId, ModelValidationViolationType.Error, ex.Message, fileName, 0, 0)); } this.IsDirty = false; OnDocumentSaved(new EventArgs()); }
private void cmdCancel_Click(object sender, EventArgs e) { _transaction.Rollback(); this.DialogResult = DialogResult.Cancel; this.Close(); }