public bool Memorize() { if (!ShouldMemorize) { return(false); } //Delete index: current to end //If there are 3 and now on index 2, index 3 to 0 -> don't delete //If there are 3 and now on index 1, index 2 to 1 -> delete int startIndex = curIndex + 1; int removeCount = infos.Count - 1 - curIndex; // Debug.WriteLine("RemoveRange({0}, {1})", startIndex, removeCount); infos.RemoveRange(startIndex, removeCount); if (UndoBufferCount > 0 && infos.Count > UndoBufferCount) { removeCount = infos.Count - UndoBufferCount; infos.RemoveRange(0, removeCount); } //Replication of the model after changing its properties are stored. EDOModel newModel = EDOSerializer.Clone(curModel); infos.Add(new UndoInfo(newModel, stateProvider.SaveState())); curIndex = infos.Count - 1; // Debug.WriteLine("model's count=" + models.Count + " curIndex=" + curIndex); // Debug.Assert(curIndex == models.Count - 1); // points at the bottom end OnModelChanged(); return(true); }
public static bool IsNotSame(EDOModel model1, EDOModel model2) { string hash1 = ComputeHash(model1); string hash2 = ComputeHash(model2); return(hash1 != hash2); }
public static EDOModel LoadFile(string pathName) { if (string.IsNullOrEmpty(pathName)) { return(null); } EDOModel edoModel = null; try { if (IsGroupFile(pathName)) { edoModel = LoadAll(pathName); } else { edoModel = LoadStudyUnit(pathName); } } catch (Exception ex) { //Error occured MessageBox.Show(Resources.ErrorOccurred + ":" + ex.Message); } return(edoModel); }
public UndoManager() { infos = new List <UndoInfo>(); curIndex = -1; curModel = null; stateProvider = null; IsEnabled = true; transactions = new List <UndoTransaction>(); }
private static EDOModel LoadStudyUnit(string pathName) { StudyUnit studyUnit = DoLoadStudyUnit(pathName); EDOModel newEdoModel = new EDOModel(); newEdoModel.StudyUnits.Add(studyUnit); return(newEdoModel); }
public void Init(EDOModel edoModel, IStatefullVM stateProvider) { this.curModel = edoModel; this.stateProvider = stateProvider; curIndex = -1; IsEnabled = true; infos.Clear(); transactions.Clear(); Memorize(); }
public SelectStudyUnitWindowVM(EDOModel fromModel, EDOModel toModel, StudyUnit curStudyUnit, DDIImportOption importOption) { this.fromModel = fromModel; this.toModel = toModel; fromStudyUnits = new ObservableCollection <StudyUnit>(fromModel.StudyUnits); this.FromStudyUnit = fromModel.StudyUnits.FirstOrDefault(); toStudyUnits = new ObservableCollection <StudyUnit>(toModel.StudyUnits); this.ToStudyUnit = curStudyUnit; this.importOption = importOption; }
public UndoInfo Redo() { if (!CanRedo) { return(null); } Debug.Assert(curIndex < infos.Count - 1); curIndex++; UndoInfo info = infos[curIndex].Copy(); curModel = info.Model; return(info); }
public static EDOModel Clone(EDOModel edoModel) { XmlSerializer serializer = new XmlSerializer(typeof(EDOModel)); MemoryStream ms = new MemoryStream(); serializer.Serialize(ms, edoModel); ms.Position = 0; object result = serializer.Deserialize(ms); EDOModel newEdoModel = (EDOModel)result; CopyPath(edoModel, newEdoModel); return(newEdoModel); }
public UndoInfo Undo() { if (!CanUndo) { return(null); } Debug.Assert(curIndex > 0); curIndex--; UndoInfo info = infos[curIndex].Copy(); curModel = info.Model; return(info); }
public bool ReplaceMemorize() { if (!ShouldMemorize) { return(false); } //replace the model of the last model of the current. EDOModel newModel = EDOSerializer.Clone(curModel); UndoInfo info = new UndoInfo(newModel, stateProvider.SaveState()); infos[curIndex] = info; OnModelChanged(); return(true); }
public static string ComputeHash(EDOModel model) { XmlSerializer serializer = new XmlSerializer(typeof(EDOModel)); MemoryStream ms = new MemoryStream(); serializer.Serialize(ms, model); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); ms.Position = 0; var bs = md5.ComputeHash(ms); ms.Close(); return(BitConverter.ToString(bs).ToLower().Replace("-", "")); }
private static void CopyPath(EDOModel fromModel, EDOModel toModel) { if (fromModel != null && toModel != null) { if (fromModel.Group != null && toModel.Group != null) { toModel.Group.PathName = fromModel.Group.PathName; } for (int i = 0; i < fromModel.StudyUnits.Count && i < toModel.StudyUnits.Count; i++) { StudyUnit fromStudyUnit = fromModel.StudyUnits[i]; StudyUnit toStudyUnit = toModel.StudyUnits[i]; toStudyUnit.PathName = fromStudyUnit.PathName; } } }
public static void SaveDebug(string path, EDOModel model) { try { Debug.Assert(!string.IsNullOrEmpty(path)); XmlSerializer serializer = new XmlSerializer(typeof(EDOModel)); FileStream fs = new FileStream(path, FileMode.Create); serializer.Serialize(fs, model); fs.Close(); } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); throw ex; } }
private static EDOModel LoadAll(string pathName) { Group group = Load <Group>(pathName); if (group == null) { return(null); } List <StudyUnit> studyUnits = new List <StudyUnit>(); List <string> absPaths = group.StudyUnitAbsPathNames; List <string> usingPaths = new List <string>(); foreach (string absPath in absPaths) { if (usingPaths.Contains(absPath)) { //Skipped save this file because the name of it is used by other file. MessageBox.Show(Resources.UsedFileNameAndSkip); continue; } StudyUnit studyUnit = DoLoadStudyUnit(absPath); if (studyUnit != null) { studyUnits.Add(studyUnit); usingPaths.Add(absPath); } } if (studyUnits.Count == 0) { return(null); } EDOModel edoModel = new EDOModel(); edoModel.Group = group; foreach (StudyUnit studyUnit in studyUnits) { edoModel.StudyUnits.Add(studyUnit); } return(edoModel); }
public UndoInfo(EDOModel edoModel, VMState state) { this.edoModel = edoModel; this.state = state; }