public void Load(IPersistable persistable) { using (BinaryReader reader = new BinaryReader(File.Open(_savePath, FileMode.Open))) { persistable.Load(new GameDataReader(reader)); } }
void LoadDataFromPath(string path) { SetupPersistenceForPath(path); customPersistenceData.Load(); ReadProperties(); ContainsUnsavedChanges = false; }
private void LoadSettings(Story story) { var xml = Storage.RestoreStorySettings(story); breakpointPersistence.Load(xml); gameScriptPersistence.Load(xml); routinePersistence.Load(xml); }
internal static void LoadNotNull(this IPersistable obj, SettingsStorage settings, string name) { var value = settings.GetValue <SettingsStorage>(name); if (value != null) { obj.Load(value); } }
public void Load(IPersistable entry) { DataSettings settings = entry.GetDataSettings(); if (settings.PersistanceType == PersistanceType.ReadOnly || settings.PersistanceType == PersistanceType.ReadWrite) { string uniqueID = settings.UniqueID; if (!string.IsNullOrEmpty(uniqueID) && _data.ContainsKey(uniqueID)) { entry.Load(_data[uniqueID]); } } }
public void Undo(IPersistable persistable) { if (_history.Count == 0) { return; } string previous = _history.Pop(); using (Stream stream = GenerateStreamFromString(previous)) { persistable.Load(new GameDataReader(new BinaryReader(stream))); } }
public void Load(IPersistable o, string filename) { var path = Path.Combine(_saveFolderPath, filename); if (!File.Exists(path)) { return; } var data = File.ReadAllBytes(path); MemoryStream ms = new MemoryStream(data); var reader = new BinaryReader(ms); o.Load(new GameDataReader(reader, -reader.ReadInt32())); }
static void Main(string[] args) { var person = new Person(); person.Save(); ISaveable s = person; s.Save(); // note Load method is not available on interface instance IPersistable p = (IPersistable)person; Console.WriteLine(p.Save()); Console.WriteLine(p.Load()); // note Load method is not available on interface instance Console.ReadLine(); }
protected virtual void WeaveOnException(IList <AspectData> allAspects, Instruction instructionCallStart, Instruction instructionCallEnd, Instruction instructionAfterCall, IPersistable returnValue) { var realInstructionAfterCall = instructionAfterCall ?? instructionCallEnd.Next; var tryLeaveInstruction = Instruction.Create(OpCodes.Leave, realInstructionAfterCall); _ilProcessor.InsertAfter(instructionCallEnd, tryLeaveInstruction); var exception = _creator.SaveThrownException(); var exceptionHandlerCurrent = exception.InsertAfter(tryLeaveInstruction, _ilProcessor); var pushException = _creator.LoadValueOnStack(exception); exceptionHandlerCurrent = pushException.InsertAfter(exceptionHandlerCurrent, _ilProcessor); var setExceptionFromStack = _creator.SetMethodExecutionArgsExceptionFromStack(ExecutionArgs); exceptionHandlerCurrent = setExceptionFromStack.InsertAfter(exceptionHandlerCurrent, _ilProcessor); var returnAfterHandling = new InstructionBlockChain(); if (returnValue != null) { returnAfterHandling.Add(returnValue.Load(false, false)); } returnAfterHandling.Add(new InstructionBlock("Return", Instruction.Create(OpCodes.Ret))); var indices = allAspects .Select((asp, index) => new { asp, index }) .Where(x => (x.asp.AspectMethods & AspectMethods.OnException) != 0) .Select(x => x.index) .Reverse() .ToList(); foreach (var index in indices) { var onExceptionAspect = allAspects[index]; if (HasMultipleAspects) { var load = _creator.LoadMethodExecutionArgsTagFromPersistable(ExecutionArgs, onExceptionAspect.TagPersistable); exceptionHandlerCurrent = load.InsertAfter(exceptionHandlerCurrent, _ilProcessor); } var callAspectOnException = _creator.CallAspectOnException(onExceptionAspect, ExecutionArgs); var nop = new InstructionBlock("Nop", Instruction.Create(OpCodes.Nop)); var callOnExitsAndReturn = new InstructionBlockChain(); for (var i = index - 1; i >= 0; --i) { var jthAspect = allAspects[i]; if ((jthAspect.AspectMethods & AspectMethods.OnExit) == 0) { continue; } if (HasMultipleAspects) { callOnExitsAndReturn.Add(_creator.LoadMethodExecutionArgsTagFromPersistable(ExecutionArgs, jthAspect.TagPersistable)); } callOnExitsAndReturn.Add(_creator.CallAspectOnExit(jthAspect, ExecutionArgs)); } if (returnValue != null) { callOnExitsAndReturn.Add(_creator.ReadReturnValue(ExecutionArgs, returnValue)); } callOnExitsAndReturn.Add(new InstructionBlock("Leave", Instruction.Create(OpCodes.Leave_S, returnAfterHandling.First))); callAspectOnException.Add(_creator.IfFlowBehaviorIsAnyOf(ExecutionArgs, nop.First, callOnExitsAndReturn, 1, 3)); callAspectOnException.Add(nop); callAspectOnException.InsertAfter(exceptionHandlerCurrent, _ilProcessor); exceptionHandlerCurrent = callAspectOnException.Last; } var flowBehaviorHandler = new InstructionBlockChain(); flowBehaviorHandler.Add(new InstructionBlock("throw", Instruction.Create(OpCodes.Rethrow))); flowBehaviorHandler.Add(new InstructionBlock("Leave", Instruction.Create(OpCodes.Leave_S, realInstructionAfterCall))); flowBehaviorHandler.InsertAfter(exceptionHandlerCurrent, _ilProcessor); returnAfterHandling.InsertAfter(flowBehaviorHandler.Last, _ilProcessor); _method.Body.ExceptionHandlers.Add(new ExceptionHandler(ExceptionHandlerType.Catch) { CatchType = _creator.GetExceptionTypeReference(), TryStart = instructionCallStart, TryEnd = tryLeaveInstruction.Next, HandlerStart = tryLeaveInstruction.Next, HandlerEnd = flowBehaviorHandler.Last.Next }); }
private void WeaveOnEntry(IPersistable returnValue) { var aspectsWithOnEntry = _aspects .Select((asp, index) => new { aspect = asp, index }) .Where(x => (x.aspect.AspectMethods & AspectMethods.OnEntry) != 0) .ToList(); foreach (var entry in aspectsWithOnEntry) { var aspect = entry.aspect; var call = _creator.CallAspectOnEntry(aspect, ExecutionArgs); AddToSetup(call); if (HasMultipleAspects) { AddToSetup(_creator.SaveMethodExecutionArgsTagToPersistable(ExecutionArgs, aspect.TagPersistable)); } var nopChain = new InstructionBlockChain(); nopChain.Add(new InstructionBlock(null, Instruction.Create(OpCodes.Nop))); var flowChain = new InstructionBlockChain(); var onExitChain = new InstructionBlockChain(); if (_method.ReturnType.IsByReference) { var notSupportedExceptionCtorString = _module.ImportReference( _creator.GetExceptionTypeReference <NotSupportedException>() .Resolve().Methods .FirstOrDefault(m => m.IsConstructor && m.Parameters.Count == 1 && m.Parameters[0].ParameterType.FullName == "System.String")); onExitChain.Add(new InstructionBlock("Throw NotSupported", Instruction.Create(OpCodes.Ldstr, "Weaving early return from a method with a byref return type is not supported."), Instruction.Create(OpCodes.Newobj, notSupportedExceptionCtorString), Instruction.Create(OpCodes.Throw))); } else { for (var i = entry.index - 1; i >= 0; --i) { var onExitAspect = _aspects[i]; if ((onExitAspect.AspectMethods & AspectMethods.OnExit) == 0) { continue; } if (HasMultipleAspects) { onExitChain.Add(_creator.LoadMethodExecutionArgsTagFromPersistable(ExecutionArgs, onExitAspect.TagPersistable)); } onExitChain.Add(_creator.CallAspectOnExit(onExitAspect, ExecutionArgs)); } } if (returnValue != null) { onExitChain.Add(_creator.ReadReturnValue(ExecutionArgs, returnValue)); onExitChain.Add(returnValue.Load(false, false)); } onExitChain.Add(new InstructionBlock("Return", Instruction.Create(OpCodes.Ret))); flowChain.Add(_creator.IfFlowBehaviorIsAnyOf(ExecutionArgs, nopChain.First, onExitChain, 3)); flowChain.Add(nopChain); AddToSetup(flowChain); } }