/// <summary> /// run validation /// </summary> /// <returns></returns> internal bool Validate() { PxValidator ppValidator = new PxValidator(); PxDocument PxDoc = ppValidator.ParsePxFile(DTO.MtrInput); if (!ppValidator.ParseValidatorResult.IsValid) { Response.error = Error.GetValidationFailure(ppValidator.ParseValidatorResult.Errors); return(false); } MatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? ""); if (MatrixData.MainSpec.requiresResponse) { this.RequiresResponse = true; return(false); } MatrixValidator matrixValidator = new MatrixValidator(); if (!matrixValidator.Validate(MatrixData, false)) { Response.error = Error.GetValidationFailure(matrixValidator.MatrixValidatorResult.Errors); return(false); } return(true); }
private void ValidateMatrix(Complex[,] matrix, string methodName, string paramName) { string modelName = _model != null ? _model.Name : "root"; if (!MatrixValidator.IsUnitary2x2(matrix)) { StringBuilder sb = new StringBuilder("\n"); sb.Append(modelName).Append(".").Append(methodName).Append(": "); sb.Append("The matrix is not unitary 2x2."); throw new ArgumentException(sb.ToString(), paramName); } }
private static string ProcessMatrixExpression(string expression, bool debugMode) { if (debugMode) { TextProc.WriteProcess("preprocessing"); } expression = ConstantsValidator.ValidateMatrixExpression(expression); if (expression.Length == 0) { return("error (length)"); } if (!CharValidator.Validate(CharValidator.ExpressionType.Matrix, expression, debugMode)) { return("error (chars)"); } if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Round, expression, debugMode)) { return("error (brackets)"); } if (!BracketsValidator.Validate(BracketsValidator.BracketsTypes.Square, expression, debugMode)) { return("error (brackets)"); } if (!PointersValidator.Validate('.', expression, debugMode)) { return("error (pointers)"); } if (!SequenceValidator.ValidateMatrixExpression(expression, debugMode)) { return("error (sequence)"); } if (debugMode) { TextProc.WriteProcess("processing"); } var separatedExpression = MatrixProcessor.GetExpressionSeparated(expression, debugMode); if (!MatrixValidator.Validate(separatedExpression, debugMode)) { return("error (matrix)"); } if (debugMode) { TextProc.WriteProcess("calculating"); } return(MatrixProcessor.ResolveExpression(separatedExpression)); }
private void ValidateMatrix() { _isUnitary = MatrixValidator.IsUnitary2x2(_matrix); OnPropertyChanged("ValidationMessage"); }
/// <summary> /// /// </summary> /// <returns></returns> protected override bool Execute() { Stopwatch sw = new Stopwatch(); sw.Start(); Build_BSO bBso = new Build_BSO(); if (!bBso.HasBuildPermission(Ado, SamAccountName, "update")) { Response.error = Label.Get("error.privilege"); return(false); } //do the physical structure validation //This is required for validation in the Matrix code, but is not used for px build Request.parameters.GrpCode = Utility.GetCustomConfig("APP_DEFAULT_GROUP"); Request.parameters.CprCode = Utility.GetCustomConfig("APP_DEFAULT_SOURCE"); //validate the px file //We get the PxDocument from the validator PxValidator pxValidator = new PxValidator(); PxDocument PxDoc = pxValidator.ParsePxFile(DTO.MtrInput); if (!pxValidator.ParseValidatorResult.IsValid) { Response.error = Error.GetValidationFailure(pxValidator.ParseValidatorResult.Errors); return(false); } Matrix theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? ""); UpdateMatrix(theMatrixData, DTO); if (theMatrixData.OtherLanguageSpec != null) { foreach (var spec in theMatrixData.OtherLanguageSpec) { if (spec.ValidationErrors != null) { Response.error = Label.Get("error.validation"); return(false); } } } Log.Instance.Debug("Object updated - " + theMatrixData.Cells.Count + " rows in " + sw.ElapsedMilliseconds + " milliseconds"); theMatrixData = bBso.UpdateMatrixFromBuild(theMatrixData, DTO, Ado); theMatrixData.MainSpec.SetEliminationsByCode(ref theMatrixData.MainSpec.Classification, DTO.Elimination); if (theMatrixData.OtherLanguageSpec != null) { foreach (Specification spec in theMatrixData.OtherLanguageSpec) { spec.SetEliminationsByCode(ref spec.Classification, DTO.Elimination); } } theMatrixData.ValidateMyMaps(); if (theMatrixData.MainSpec.ValidationErrors != null) { Response.error = Error.GetValidationFailure(theMatrixData.MainSpec.ValidationErrors); return(false); } //We should be able to validate the newly updated matrix now... MatrixValidator mValidator = new MatrixValidator(); if (!mValidator.Validate(theMatrixData)) { Response.error = Label.Get("error.validation"); return(false); } Log.Instance.Debug("Object updated - " + theMatrixData.Cells.Count + " rows in " + sw.ElapsedMilliseconds + " milliseconds"); //We need to check the matrix in case it incurred any validation problems at the time of creation //If there are, then we need to return the details of these errors to the caller and terminate this process if (theMatrixData.ValidationResult != null) { if (!theMatrixData.ValidationResult.IsValid) { Log.Instance.Debug(Error.GetValidationFailure(theMatrixData.ValidationResult.Errors)); Response.error = Label.Get("error.validation"); return(false); } } //SortId is for internal use only, so we remove it from the output foreach (var i in DTO.PxData.DataItems) { i.Remove("SortId"); } if (DTO.Format.FrmType == DatasetFormat.Px) { dynamic result = new ExpandoObject(); List <string> file = new List <string> { theMatrixData.GetPxObject(true) }; result.file = file; result.report = DTO.PxData.DataItems; Response.data = result; Log.Instance.Debug("Update complete in " + sw.ElapsedMilliseconds + " milliseconds"); return(true); } else if (DTO.Format.FrmType == DatasetFormat.JsonStat) { //Return the metadata and data, using one json-stat object for each specification List <JRaw> jsons = new List <JRaw>(); List <string> languages = new List <string>(); if (theMatrixData.Languages != null) { foreach (var lang in theMatrixData.Languages) { languages.Add(lang.ToPxValue()); } } else { languages.Add(theMatrixData.MainSpec.Language); } foreach (var lang in languages) { JsonStat json = theMatrixData.GetJsonStatObject(false, true, lang); jsons.Add(new JRaw(Serialize.ToJson(json))); } dynamic result = new ExpandoObject(); result.file = jsons; result.report = DTO.PxData.DataItems; Response.data = result; Log.Instance.Debug("Update complete in " + sw.ElapsedMilliseconds + " milliseconds"); return(true); } return(false); }
/// <summary> /// Execute /// </summary> /// <returns></returns> protected override bool Execute() { Build_BSO pBso = new Build_BSO(); if (!pBso.HasBuildPermission(Ado, SamAccountName, "create")) { Response.error = Label.Get("error.privilege"); return(false); } Matrix matrix = new Matrix(DTO) { MainSpec = new Matrix.Specification(DTO.matrixDto.LngIsoCode, DTO), TheLanguage = DTO.LngIsoCode, FormatType = DTO.Format.FrmType, FormatVersion = DTO.Format.FrmVersion }; //Get the Specifications if (DTO.DimensionList.Count > 1) { IEnumerable <string> otherLanguages = from lng in DTO.DimensionList where lng.LngIsoCode != DTO.matrixDto.LngIsoCode select lng.LngIsoCode; matrix.OtherLanguageSpec = new List <Matrix.Specification>(); List <string> otherLang = new List <string>(); foreach (var lang in otherLanguages) { matrix.OtherLanguageSpec.Add(new Matrix.Specification(lang, DTO)); otherLang.Add(lang); } matrix.OtherLanguages = otherLang; } //Create the blank csv with titles to enable the user to fill in their own data for the update matrix.Cells = GetBlankCells(matrix); //We should be able to validate the newly created matrix now... MatrixValidator mValidator = new MatrixValidator(); if (!mValidator.Validate(matrix)) { Response.error = Label.Get("error.validation"); return(false); } dynamic fileOutput = new ExpandoObject(); switch (DTO.Format.FrmType) { case Resources.Constants.C_SYSTEM_PX_NAME: List <dynamic> resultPx = new List <dynamic>(); resultPx.Add(matrix.GetPxObject(true).ToString()); Response.data = resultPx; break; case Resources.Constants.C_SYSTEM_JSON_STAT_NAME: dynamic result = new ExpandoObject(); List <JRaw> jsonData = new List <JRaw>(); jsonData.Add(new JRaw(Serialize.ToJson(matrix.GetJsonStatObject()))); if (matrix.OtherLanguageSpec != null) { foreach (Matrix.Specification s in matrix.OtherLanguageSpec) { matrix.MainSpec = s; jsonData.Add(new JRaw(Serialize.ToJson(matrix.GetJsonStatObject()))); } } Response.data = jsonData; break; default: Response.error = Label.Get("error.invalid"); return(false); } return(true); }