public void GetXmlDbUpdateRecordedAction_WhenSerializingForLogging_ShouldNotIncludeXmlDeclaration(string currentDbVersion, string backendUrl) { // Fixture setup var actionToRecord = _fixture.Create <XmlDbUpdateRecordedAction>(); // Exercise system string resultXml; using (new NonQpEnvironmentContext(null)) { resultXml = XmlDbUpdateSerializerHelpers.SerializeAction(actionToRecord, currentDbVersion, backendUrl, true).ToNormalizedString(true); } // Verify outcome Assert.False(resultXml.StartsWith("<?")); }
public void GetXmlDbUpdateRecordedAction_WhenSerializingForLogging_ShouldNotIncludeRootElement(string currentDbVersion, string backendUrl) { // Fixture setup var actionToRecord = _fixture.Create <XmlDbUpdateRecordedAction>(); // Exercise system IEnumerable <XElement> actualElements; using (new NonQpEnvironmentContext(null)) { var resultXmlDocument = XmlDbUpdateSerializerHelpers.SerializeAction(actionToRecord, currentDbVersion, backendUrl, true); actualElements = resultXmlDocument.XPathSelectElements("/actions"); } // Verify outcome actualElements.Should().BeNullOrEmpty(); }
public void GetXmlDbUpdateRecordedAction_WhenSerializing_ShouldIncludeFormElements(string currentDbVersion, string backendUrl) { // Fixture setup var actionToRecord = _fixture.Create <XmlDbUpdateRecordedAction>(); var expectedElementsCount = actionToRecord.Form.Count; // Exercise system int actualElementsCount; using (new NonQpEnvironmentContext(null)) { var resultXmlDocument = XmlDbUpdateSerializerHelpers.SerializeAction(actionToRecord, currentDbVersion, backendUrl); actualElementsCount = resultXmlDocument.XPathSelectElements("//action/field").Count(); } // Verify outcome Assert.Equal(expectedElementsCount, actualElementsCount); }
private void ReplayActionsFromXml(IEnumerable <XElement> actionElements, string currentDbVersion, string backendUrl, int updateId) { foreach (var xmlAction in actionElements) { XmlDbUpdateRecordedAction action; var xmlActionString = xmlAction.ToNormalizedString(SaveOptions.DisableFormatting, true); try { action = XmlDbUpdateSerializerHelpers.DeserializeAction(xmlAction); } catch (Exception ex) { var throwEx = new XmlDbUpdateReplayActionException("Error while deserializing xml action string.", ex); throwEx.Data.Add(LoggerData.XmlDbUpdateExceptionXmlActionStringData, xmlActionString.ToJsonLog()); throw throwEx; } var logEntry = new XmlDbUpdateActionsLogModel { UserId = _userId, Applied = DateTime.Now, ParentId = action.ParentId, UpdateId = updateId, SourceXml = xmlActionString, Hash = HashHelpers.CalculateMd5Hash(xmlActionString) }; if (_dbLogService.IsActionAlreadyReplayed(logEntry.Hash)) { Logger.Log.Warn($"XmlDbUpdateAction conflict: Current action already applied and exist at database. Entry: {logEntry.ToJsonLog()}"); continue; } var xmlActionStringLog = xmlAction.RemoveDescendants().ToString(SaveOptions.DisableFormatting); Logger.Log.Debug($"-> Begin replaying action [{logEntry.Hash}]: -> {xmlActionStringLog}"); var replayedAction = ReplayAction(action, backendUrl); Logger.Log.Debug($"End replaying action [{logEntry.Hash}]: {xmlActionStringLog}"); logEntry.Ids = string.Join(",", replayedAction.Ids); logEntry.ResultXml = XmlDbUpdateSerializerHelpers.SerializeAction(replayedAction, currentDbVersion, backendUrl, true).ToNormalizedString(SaveOptions.DisableFormatting, true); _dbLogService.InsertActionLogEntry(logEntry); } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { try { var isValid = filterContext.Exception == null && filterContext.Controller.ViewData.ModelState.IsValid && !QPController.IsError(filterContext.HttpContext); if (isValid && DbRepository.Get().RecordActions) { var currentDbVersion = new ApplicationInfoRepository().GetCurrentDbVersion(); var actionToSerialize = XmlDbUpdateHttpContextHelpers.CreateXmlDbUpdateActionFromHttpContext(filterContext.HttpContext, _code ?? BackendActionContext.Current.ActionCode, _ignoreForm); XmlDbUpdateSerializerHelpers .SerializeAction(actionToSerialize, currentDbVersion, CommonHelpers.GetBackendUrl(filterContext.HttpContext)) .Save(QPContext.GetRecordXmlFilePath(), SaveOptions.None); } } catch (Exception ex) { throw new Exception("There was an error while recording xml actions", ex); } base.OnActionExecuted(filterContext); }