/// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            // Init
            List <string> FrqValues        = new List <string>();
            dynamic       validationResult = new ExpandoObject();

            validationResult.Signature         = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));// null;
            validationResult.FrqValueCandidate = FrqValues;

            if (!Validate(validationResult.Signature) && !RequiresResponse)
            {
                return(false);
            }

            if (RequiresResponse)
            {
                //cancel any validation errors and return an object to enable the user to choose which should be the time dimension
                Matrix.Specification langSpec = MatrixData.GetSpecFromLanguage(Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code"));
                if (langSpec == null)
                {
                    langSpec = MatrixData.MainSpec;
                }

                foreach (var v in langSpec.MainValues)
                {
                    FrqValues.Add(v.Key);
                }

                // Set Frequency candidates
                validationResult.FrqValueCandidate = FrqValues;
                validationResult.Signature         = null;
                Response.data = validationResult;
                return(true);
            }

            // Set the Signature
            Response.data = validationResult;
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            dynamic result = new ExpandoObject();


            //This is required for validation in the Matrix code, but is not used for px build
            Request.parameters.GrpCode = Utility.GetCustomConfig("APP_DEFAULT_GROUP");

            //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.source  = Utility.GetCustomConfig("APP_DEFAULT_SOURCE");

            //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);
            }



            //Get this matrix from the px file , but we also need to pass in the Timeval stuff
            //The "" bit is temporary until we make the parameters optional (Currently this interferes with existing overloads)
            Matrix theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");

            var signature = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));

            if (signature != DTO.Signature)
            {
                Response.error = Label.Get("error.validation");
                return(false);
            }



            Build_BSO pBso = new Build_BSO();

            result.FrqValue = "";
            result.template = pBso.GetCsvTemplate(theMatrixData, DTO.LngIsoCode, DTO.FrqCodeTimeval);
            result.MtrCode  = theMatrixData.Code;
            Response.data   = result;



            return(true);
        }
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            Build_BSO buildBso = new Build_BSO();

            if (!buildBso.HasBuildPermission(Ado, SamAccountName, "import"))
            {
                Response.error = Label.Get("error.privilege");
                return(false);
            }

            Stopwatch swMatrix = new Stopwatch();

            swMatrix.Start();

            var signature = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));

            if (signature != DTO.Signature)
            {
                Response.error = Label.Get("error.validation");
                return(false);
            }

            Matrix theMatrixData;



            PxDoc         = PxStatEngine.ParsePxInput(DTO.MtrInput);
            theMatrixData = new Matrix(PxDoc, DTO);


            Matrix_BSO mBso = new Matrix_BSO(Ado);


            int releaseId;



            // Check if a WIP Release already exists for the Matrix to Upload
            var latestRelease = mBso.GetLatestRelease(theMatrixData);

            if (latestRelease != null && !DTO.Overwrite && releaseAdo.IsWip(latestRelease.RlsCode)) //
            {
                Group_DTO_Create dtoGroup = this.GetGroup(DTO.GrpCode);
                if (latestRelease.GrpCode != DTO.GrpCode)
                {
                    Response.data = String.Format(Label.Get("px.duplicate-different-group"), theMatrixData.Code, latestRelease.GrpName + " (" + latestRelease.GrpCode + ")", dtoGroup.GrpName + " (" + DTO.GrpCode + ")");
                }
                else
                {
                    Response.data = String.Format(Label.Get("px.duplicate"), theMatrixData.Code);
                }
                return(true);
            }

            // Check if this Release already has a pending WorkflowRequest
            if (latestRelease != null && new WorkflowRequest_ADO().IsCurrent(Ado, latestRelease.RlsCode))
            {
                Response.error = String.Format(Label.Get("error.workflow"), theMatrixData.Code);
                return(false);
            }

            // Check if this Release has another pending live release
            if (latestRelease != null && new Release_ADO(Ado).IsLiveNext(latestRelease.RlsCode))
            {
                Response.error = String.Format(Label.Get("px.pendinglive"), theMatrixData.Code);
                return(false);
            }

            //Check if the matrix code is locked in the dataset table
            using (DatasetAdo dAdo = new DatasetAdo(new ADO("defaultConnection")))
            {
                ADO_readerOutput dResult = dAdo.ReadDatasetLocked(theMatrixData.Code);
                if (dResult.hasData)
                {
                    DateTime lockedTime = dResult.data[0].DttDatetimeLocked.Equals(DBNull.Value) ? default : (DateTime)dResult.data[0].DttDatetimeLocked;
                                          if (lockedTime.AddMinutes(Configuration_BSO.GetCustomConfig(ConfigType.server, "release.lockTimeMinutes")) > DateTime.Now)
                                          {
                                              Response.error = Label.Get("error.release.locked");
                                              return(false);
                                          }
                }

                dAdo.DatasetLockUpdate(theMatrixData.Code, DateTime.Now);
            }

            if (latestRelease != null)
            {
                if (latestRelease.RlsLiveFlag)
                {
                    releaseId = mBso.CloneRelease(latestRelease.RlsCode, DTO.GrpCode, SamAccountName);
                    mBso.CloneComment(latestRelease.RlsCode, releaseId, SamAccountName);
                }
                else
                {
                    if (latestRelease.GrpCode != DTO.GrpCode)
                    {
                        releaseId = releaseAdo.IncrementRevision(latestRelease.RlsCode, SamAccountName, DTO.GrpCode);
                    }
                    else
                    {
                        releaseId = releaseAdo.IncrementRevision(latestRelease.RlsCode, SamAccountName);
                    }

                    matrixAdo.Delete(latestRelease.RlsCode, SamAccountName);
                }



                // Clean up caching
                MemCacheD.CasRepositoryFlush(Resources.Constants.C_CAS_DATA_COMPARE_READ_ADDITION + latestRelease.RlsCode);
                MemCacheD.CasRepositoryFlush(Resources.Constants.C_CAS_DATA_COMPARE_READ_DELETION + latestRelease.RlsCode);
                MemCacheD.CasRepositoryFlush(Resources.Constants.C_CAS_DATA_COMPARE_READ_AMENDMENT + latestRelease.RlsCode);

                MemCacheD.CasRepositoryFlush(Resources.Constants.C_CAS_DATA_CUBE_READ_PRE_DATASET + latestRelease.RlsCode);
                MemCacheD.CasRepositoryFlush(Resources.Constants.C_CAS_DATA_CUBE_READ_PRE_METADATA + latestRelease.RlsCode);
            }
            else
            {
                releaseId = mBso.CreateRelease(theMatrixData, 0, 1, DTO.GrpCode, SamAccountName);
            }

            mBso.CreateMatrix(theMatrixData, releaseId, SamAccountName, DTO);


            swMatrix.Stop();
            Log.Instance.Info(string.Format("Matrix object created in {0} ms", Math.Round((double)swMatrix.ElapsedMilliseconds)));

            Stopwatch swLoad = new Stopwatch();

            swLoad.Start();

            //Do a Cartesian join to correctly label each data point with its dimensions
            //Create bulk tables from this and load them to the database

            var asyncTask = buildBso.CreateAndLoadDataTables(Ado, theMatrixData, true);

            //We must specifically retrieve any exceptions from the Task and then throw them. Otherwise they will be silent.
            if (asyncTask.Exception != null)
            {
                throw asyncTask.Exception;
            }

            matrixAdo.MarkMatrixAsContainingData(theMatrixData.MainSpec.MatrixId, true);

            Keyword_Release_BSO_CreateMandatory krBSO = new Keyword_Release_BSO_CreateMandatory();

            krBSO.Create(Ado, releaseId, SamAccountName, theMatrixData);

            swLoad.Stop();
            Log.Instance.Info(string.Format("Matrix loaded in DB in {0} ms", Math.Round((double)swLoad.ElapsedMilliseconds)));

            using (DatasetAdo dAdo = new DatasetAdo(new ADO("defaultConnection")))
            {
                dAdo.DatasetLockUpdate(theMatrixData.Code, default);
            }

            Response.data = JSONRPC.success;
            return(true);
        }
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            var           signature        = Utility.GetMD5(Utility.GetCustomConfig("APP_SALSA") + Utility.JsonSerialize_IgnoreLoopingReference(DTO.GetSignatureDTO()));
            dynamic       validationResult = new ExpandoObject();
            List <string> FrqValues        = new List <string>();

            PxStat.RequestLanguage.LngIsoCode = DTO.LngIsoCode;

            bool isValid = false;


            isValid = Validate();

            // }


            if (isValid)
            {
                validationResult.Signature         = signature;
                validationResult.FrqValueCandidate = FrqValues;
                Response.data = validationResult;



                return(true);
            }
            if (!isValid)
            {
                if (MatrixData != null)
                {
                    if (MatrixData.MainSpec.requiresResponse)
                    {
                        //cancel any validation errors and return an object to enable the user to choose which should be the time dimension
                        Matrix.Specification langSpec = MatrixData.GetSpecFromLanguage(DTO.LngIsoCode);
                        if (langSpec == null)
                        {
                            langSpec = MatrixData.MainSpec;
                        }

                        foreach (var v in langSpec.MainValues)
                        {
                            FrqValues.Add(v.Key);
                        }

                        validationResult.Signature         = null;
                        validationResult.FrqValueCandidate = FrqValues;
                        Response.data = validationResult;
                        return(true);
                    }
                }
                Response.data = validationResult;
                return(false);
            }


            //Response.error = Label.Get("error.validation");
            return(false);
        }