Пример #1
0
        public async Task <ActionResult> Settings(string tabId, int parentId, IFormCollection collection)
        {
            var db    = DbService.ReadSettingsForUpdate();
            var model = EntityViewModel.Create <DbViewModel>(db, tabId, parentId);

            await TryUpdateModelAsync(model);

            if (ModelState.IsValid)
            {
                if (model.Data.RecordActions)
                {
                    if (model.OverrideRecordsFile)
                    {
                        var currentDbVersion = _appInfoRepository.GetCurrentDbVersion();
                        XmlDbUpdateSerializerHelpers.ErasePreviouslyRecordedActions(CommonHelpers.GetBackendUrl(HttpContext), currentDbVersion);
                    }

                    if (model.OverrideRecordsUser || model.Data.SingleUserId == null)
                    {
                        model.Data.SingleUserId = QPContext.CurrentUserId;
                    }
                }
                else
                {
                    model.Data.SingleUserId = null;
                }

                model.Data = DbService.UpdateSettings(model.Data);

                return(Redirect("Settings", new { successfulActionCode = ActionCode.UpdateDbSettings }));
            }

            return(await JsonHtml("Settings", model));
        }
Пример #2
0
        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("<?"));
        }
Пример #3
0
        public ActionResult Settings(string tabId, int parentId, FormCollection collection)
        {
            var db    = DbService.ReadSettingsForUpdate();
            var model = EntityViewModel.Create <DbViewModel>(db, tabId, parentId);

            TryUpdateModel(model);
            model.Validate(ModelState);
            if (ModelState.IsValid)
            {
                object message         = null;
                var    needSendMessage = false;
                if (model.Data.RecordActions)
                {
                    if (model.OverrideRecordsFile)
                    {
                        var currentDbVersion = _appInfoRepository.GetCurrentDbVersion();
                        XmlDbUpdateSerializerHelpers.ErasePreviouslyRecordedActions(CommonHelpers.GetBackendUrl(HttpContext), currentDbVersion);
                    }

                    if (model.OverrideRecordsUser || model.Data.SingleUserId == null)
                    {
                        model.Data.SingleUserId = QPContext.CurrentUserId;
                        needSendMessage         = true;
                        message = new
                        {
                            userId   = QPContext.CurrentUserId,
                            userName = QPContext.CurrentUserName
                        };
                    }
                }
                else
                {
                    needSendMessage         = true;
                    model.Data.SingleUserId = null;
                }

                model.Data = DbService.UpdateSettings(model.Data);
                if (needSendMessage)
                {
                    _communicationService.Send("singleusermode", message);
                }

                return(Redirect("Settings", new { successfulActionCode = ActionCode.UpdateDbSettings }));
            }

            return(JsonHtml("Settings", model));
        }
Пример #4
0
        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();
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
        }