Example #1
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            dynamic result = new ExpandoObject();

            Stopwatch sw = new Stopwatch();

            sw.Start();

            //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);
            }
            Log.Instance.Debug("*Diagnostic* px valid: " + sw.ElapsedMilliseconds);

            Matrix matrixPxFile = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");



            Log.Instance.Debug("*Diagnostic* Matrix created: " + sw.ElapsedMilliseconds);

            //Sorting, in case the px file is not in SPC order
            Build_BSO pBso = new Build_BSO();
            //List<DataItem_DTO> existingItems = pBso.GetExistingDataItems(matrixPxFile, matrixPxFile.MainSpec, true, false);

            Specification theSpec = matrixPxFile.GetSpecFromLanguage(DTO.LngIsoCode);

            // pBso.SetMetadataSortIds(ref theSpec);

            List <DataItem_DTO> existingItems = pBso.GetMatrixDataItems(matrixPxFile, DTO.LngIsoCode, theSpec);

            // pBso.SetDataSortIds(ref existingItems, theSpec);

            //Log.Instance.Debug("*Diagnostic* GetExistingDataItems: " + sw.ElapsedMilliseconds);



            Log.Instance.Debug("*Diagnostic* Read Cells - count = " + matrixPxFile.Cells.Count + "  elapsed: " + sw.ElapsedMilliseconds);

            result.csv = matrixPxFile.GetCsvObject(existingItems, DTO.LngIsoCode, true);

            Log.Instance.Debug("*Diagnostic* GetCsvObject-   elapsed: " + sw.ElapsedMilliseconds);
            result.MtrCode = matrixPxFile.Code;
            Response.data  = result;

            Log.Instance.Debug("GetCsvObject: " + sw.ElapsedMilliseconds);

            return(true);
        }
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            //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;

            //Get this matrix from the px file
            theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");

            Build_BSO bBso = new Build_BSO();

            //We need to add the new periods to the matrix
            //And either add cells of default data or else the values from DTO.data

            var requestPeriods = DTO.Periods;//.OrderBy(x => x.Code).ToList();


            DTO.Periods = DTO.Periods.Except(theMatrixData.MainSpec.Frequency.Period).ToList();

            theMatrixData = bBso.UpdateMatrixFromBuild(theMatrixData, DTO, Ado);

            theMatrixData.MainSpec.MainValues = sortMainValuesSpc(theMatrixData.MainSpec);

            theMatrixData.MainSpec.Values = theMatrixData.MainSpec.MainValues;

            //bBso.Query needs to be in the same order as the periods in the matrix - why?
            theMatrixData = bBso.Query(theMatrixData, GetQueryMatrix(requestPeriods, theMatrixData));

            theMatrixData.ValidateMyMaps(true);

            var dataList = bBso.GetMatrixDataItems(theMatrixData, DTO.LngIsoCode, theMatrixData.MainSpec, false);

            dynamic result = new ExpandoObject();

            result.csv     = theMatrixData.GetCsvObject(dataList, DTO.LngIsoCode, true, null, DTO.Labels);
            result.MtrCode = theMatrixData.Code;
            Response.data  = result;


            return(true);
        }
Example #3
0
        /// <summary>
        /// Execute
        /// </summary>
        /// <returns></returns>
        protected override bool Execute()
        {
            //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);
            }

            //Get this matrix from the px file
            Matrix theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");

            Build_BSO bBso = new Build_BSO();


            //Get this matrix from the px file
            //theMatrixData = bBso.UpdateMatrixFromDto(theMatrixData, DTO, Ado, false, true);

            List <DataItem_DTO> itemList = bBso.GetDataForNewPeriods(theMatrixData, DTO, Ado);

            //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)
            //    {
            //        Response.error = Error.GetValidationFailure(theMatrixData.ValidationResult.Errors);
            //        return false;
            //    }
            //}

            dynamic result = new ExpandoObject();

            result.csv     = theMatrixData.GetCsvObject(itemList, DTO.LngIsoCode, true);
            result.MtrCode = theMatrixData.Code;
            Response.data  = result;


            return(true);
        }
Example #4
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()
        {
            //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);
            }

            //There might be a cache:
            Matrix theMatrixData;

            theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");

            Build_BSO bBso = new Build_BSO();

            List <DataItem_DTO> dataList;

            dataList = bBso.GetDataForAllPeriods(theMatrixData, DTO, Ado);


            dynamic result = new ExpandoObject();

            result.csv     = theMatrixData.GetCsvObject(dataList, DTO.LngIsoCode, true);
            result.MtrCode = theMatrixData.Code;
            Response.data  = result;


            return(true);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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);
            }

            //Get this matrix from the px file
            Matrix theMatrixData = new Matrix(PxDoc, DTO.FrqCodeTimeval ?? "", DTO.FrqValueTimeval ?? "");



            Log.Instance.Debug("Object updated - " + theMatrixData.Cells.Count + " rows in " + sw.ElapsedMilliseconds + " milliseconds");

            theMatrixData = bBso.UpdateMatrixFromBuild(theMatrixData, DTO, Ado);



            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 <dynamic> file   = new List <dynamic>();
                file.Add(theMatrixData.GetPxObject(true).ToString());
                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);
        }
Example #8
0
        internal string GetSDMXdata(Matrix theMatrix, string LngIsoCode)
        {
            Specification theSpec = theMatrix.GetSpecFromLanguage(LngIsoCode);

            Build_BSO           bso       = new Build_BSO();
            List <DataItem_DTO> dataItems = bso.GetMatrixDataItems(theMatrix, LngIsoCode, theSpec, false, true);


            //sort the data in SCP order
            foreach (var item in dataItems)
            {
                item.sortWord = item.statistic.Code + '/';

                foreach (var cls in item.classifications)
                {
                    item.sortWord = item.sortWord + cls.Code + '/' + cls.Variable[0].Code;
                }
                item.sortWord = item.sortWord + item.period.Code;
            }

            var slist = dataItems.OrderBy(x => x.sortWord);

            int             counter  = 0;
            List <SdmxItem> sdmxList = new List <SdmxItem>();
            SdmxItem        sdmx     = new SdmxItem();

            foreach (var item in slist)
            {
                if (counter == 0 || counter % theSpec.Frequency.Period.Count == 0)
                {
                    if (sdmx.Period != null)
                    {
                        sdmxList.Add(sdmx);
                    }

                    sdmx = new SdmxItem()
                    {
                        Statistic = item.statistic, Classifications = item.classifications, Period = new List <PeriodRecordDTO_Create>(), Value = item.dataValue, PeriodValue = new Dictionary <string, dynamic>()
                    };
                    sdmx.Period.Add(item.period);
                    sdmx.PeriodValue.Add(item.period.Code, item.dataValue);
                }
                else
                {
                    sdmx.Period.Add(item.period);
                    sdmx.PeriodValue.Add(item.period.Code, item.dataValue);
                }
                counter++;
            }
            sdmxList.Add(sdmx);


            XNamespace messageNS = "http://www.sdmx.org/resources/sdmxml/schemas/v2_0/message";
            XNamespace c         = "http://www.sdmx.org/resources/sdmxml/schemas/v2_0/common";
            XNamespace xml       = "http://www.w3.org/XML/1998/namespace";
            XNamespace ss        = "http://www.sdmx.org/resources/sdmxml/schemas/v2_0/data/structurespecific";
            XNamespace xsi       = "http://www.sdmx.org/resources/sdmxml/schemas/v2_0/data/structurespecific";
            XNamespace g         = "http://www.sdmx.org/resources/sdmxml/schemas/v2_0/generic";


            XElement   id             = new XElement(g + "ID", theMatrix.Code);
            XElement   test           = new XElement(g + "Test", "false");
            XElement   prepared       = new XElement(g + "Prepared", theMatrix.CreationDateTime.ToString("yyyy-MM-ddTHH:mm"));
            XAttribute senderID       = new XAttribute("ID", "CSO");
            XAttribute senderNameAttr = new XAttribute(xml + "lang", LngIsoCode);
            XElement   senderName     = new XElement(g + "Name", theSpec.Source, senderNameAttr);
            XElement   sender         = new XElement(g + "Sender", senderName, senderID);

            XElement header = new XElement(g + "Header",
                                           id,
                                           test,
                                           prepared,
                                           sender
                                           );


            XElement keyfamilyref = new XElement(g + "KeyFamilyRef", "REF");
            XElement series       = new XElement(g + "Series");

            foreach (SdmxItem item in sdmxList)
            {
                XElement seriesKey = new XElement(g + "SeriesKey");
                seriesKey.Add(new XElement(g + "Value", new XAttribute("concept", theSpec.ContentVariable), new XAttribute("value", item.Statistic.Code)));

                seriesKey.Add(new XElement(g + "Value", new XAttribute("concept", theSpec.Frequency.Value), new XAttribute("value", theSpec.Frequency.Code)));

                foreach (var cls in item.Classifications)
                {
                    seriesKey.Add(new XElement(g + "Value", new XAttribute("concept", cls.Value), new XAttribute("value", cls.Variable[0].Code)));
                }
                series.Add(seriesKey);

                XElement attributes = new XElement(g + "Attributes");
                attributes.Add(new XElement(g + "Values", new XAttribute("concept", "UNIT_VALUE"), new XAttribute("value", item.Statistic.Unit)));
                series.Add(attributes);

                foreach (var per in item.Period)
                {
                    XElement Obs = new XElement(g + "Obs");
                    Obs.Add(new XElement(g + "Time", per.Code));
                    Obs.Add(new XElement(g + "ObsValue", new XAttribute("value", item.PeriodValue[per.Code])));
                    Obs.Add(new XElement(g + "Attributes", new XElement("Value", new XAttribute("concept", "OBS_STATUS"), new XAttribute("value", "A"))));
                    series.Add(Obs);
                }
            }

            XElement annotations = new XElement(c + "Annotations");

            if (theSpec.Notes != null)
            {
                foreach (string note in theSpec.Notes)
                {
                    annotations.Add(new XElement(c + "AnnotationText", new XAttribute(xml + "lang", LngIsoCode), note));
                }
            }


            XElement dataset = new XElement("DataSet", new XAttribute(XNamespace.Xmlns + "g", g), new XAttribute(XNamespace.Xmlns + "c", c), keyfamilyref, series, annotations);



            XElement root = new XElement(g + "GenericData", header, dataset);


            XmlDocument document = new XmlDocument();

            XmlDeclaration xmldecl;

            xmldecl            = document.CreateXmlDeclaration("1.0", null, null);
            xmldecl.Encoding   = "UTF-8";
            xmldecl.Standalone = "yes";



            document.Load(new StringReader(root.ToString()));

            XmlElement rt = document.DocumentElement;

            document.InsertBefore(xmldecl, rt);



            StringBuilder builder = new StringBuilder();

            using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder)))
            {
                writer.Formatting = Formatting.Indented;
                document.Save(writer);
            }

            return(builder.ToString());


            // return  root.ToString();
        }
Example #9
0
        /// <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);
        }