private void ProceedWithChrono(IInvocation invocation, string sessionId) { var mode = clientService.GetSessionMode(sessionId); if (mode == ChronoSessionMode.Play) { if (invocation.Method.ReturnType == typeof(void)) { invocation.Proceed(); } else { var key = $"{invocation.TargetType.FullName}.{invocation.Method.Name}"; var snapshot = clientService.FindLastSnapshotByKey(sessionId, key); var stringValue = snapshot.Value; var value = JsonConvert.DeserializeObject(stringValue, invocation.Method.ReturnType); invocation.ReturnValue = value; } } if (mode == ChronoSessionMode.Record) { var begin = DateTime.Now; invocation.Proceed(); var key = $"{invocation.TargetType.FullName}.{invocation.Method.Name}"; var parameterDictionary = invocation.Method.GetParameters().ToDictionary(x => x.Name, x => invocation.Arguments[x.Position]); var parameters = JsonConvert.SerializeObject(parameterDictionary); var snapshot = new ChronoSnapshot { Id = Guid.NewGuid().ToString(), Key = key, SessionId = sessionId, Parameters = parameters, Begin = begin, End = DateTime.Now }; if (invocation.Method.ReturnType != typeof(void)) { var value = JsonConvert.SerializeObject(invocation.ReturnValue); snapshot.Value = value; } clientService.Save(snapshot); } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { var mode = ClientService.GetSessionMode(SessionId); if (mode == ChronoSessionMode.Play) { var actionName = filterContext.ActionDescriptor.ActionName; var controllername = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var key = $"{controllername}.{actionName}"; var state = ClientService.FindLastSnapshotByKey(SessionId, key); var stringValue = state.Value; var viewResult = (ViewResult)filterContext.Result; var converter = new ViewResultJsonConverter(filterContext.Controller, viewResult.Model.GetType()); var value = JsonConvert.DeserializeObject <ViewResult>(stringValue, converter); value.ViewEngineCollection = viewResult.ViewEngineCollection; filterContext.Result = value; } if (mode == ChronoSessionMode.Record) { var actionName = filterContext.ActionDescriptor.ActionName; var controllername = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; var key = $"{controllername}.{actionName}"; var value = JsonConvert.SerializeObject(filterContext.Result); var snapshot = new ChronoSnapshot { Id = Guid.NewGuid().ToString(), Key = key, Value = value, SessionId = SessionId, Begin = Start, End = DateTime.Now }; ClientService.Save(snapshot); } }
public void Save(ChronoSnapshot chronoSnapshot) { var snapshot = snapshotDataMapper.Map(chronoSnapshot); storage.Add(snapshot); }
public void Save(ChronoSnapshot chronoSnapshot) { ChronoHostContext.Current.ClientService.Save(chronoSnapshot); }