Exemplo n.º 1
0
        /// <summary>
        /// Creates a PXModel instance from a file.
        /// </summary>
        /// <param name="file">PX-file.</param>
        /// <param name="loadData">Whether to load data. False = only meta data.</param>
        /// <param name="except">Array of selections NOT to be included. Can be null.</param>
        /// <param name="explodeVariableCode">Variable code for variable to show one value at a time. Can be null.</param>
        /// <param name="explodeValueCode">Value code for the value to select for the variable explodeVariableCode. Can be null.</param>
        /// <returns></returns>
        public static PXModel CreatePxModel(FileInfo file, bool loadData, Selection[] except, string explodeVariableCode, string explodeValueCode)
        {
            PXFileBuilder builder = new PXFileBuilder();

            builder.SetPath(file.FullName);
            builder.BuildForSelection();

            if (loadData)
            {
                Selection[] selections = Selection.SelectAll(builder.Model.Meta);

                if (except != null)
                {
                    selections = selections.Except(except);
                }

                if (explodeVariableCode != null && explodeValueCode != null)
                {
                    selections = selections.Explode(explodeVariableCode, explodeValueCode);
                }

                builder.BuildForPresentation(selections);
            }

            if (builder.Model.Meta.GetPreferredLanguage() == null)
            {
                builder.Model.Meta.SetPreferredLanguage(builder.Model.Meta.Language);
            }

            return(builder.Model);
        }
        public void TestMethod1()
        {
            PCAxis.Paxiom.IPXModelBuilder builder = new PXFileBuilder();

            builder.SetPath("PR0101B3.px");
            builder.BuildForSelection();

            PXMeta meta = builder.Model.Meta;

            builder.BuildForPresentation(Selection.SelectAll(meta));

            PXModel myModel = builder.Model;



            var    dsf    = myModel.IsComplete;
            string actual = "";

            using (MemoryStream memStream = new MemoryStream(1000))
            {
                JsonStatSerializer jss = new JsonStatSerializer();
                jss.Serialize(myModel, memStream);

                actual = Encoding.UTF8.GetString(memStream.GetBuffer(), 0, (int)memStream.Length);
            }


            var expected = "{\"dataset\":{\"dimension\":{\"Product group\":{\"label\":\"Product group\",\"category\":{\"index\":{\"01\":0,\"01.1\":1,\"01.1.1\":2,\"01.1.2\":3,\"01.1.3\":4,\"01.1.4\":5,\"01.1.5\":6,\"01.1.6\":7},\"label\":{\"01\":\"01 Food and non-alcoholic beverages\",\"01.1\":\"01.1 Food\",\"01.1.1\":\"01.1.1 Bread and cereals\",\"01.1.2\":\"01.1.2 Meat\",\"01.1.3\":\"01.1.3 Fish\",\"01.1.4\":\"01.1.4 Milk, cheese and eggs\",\"01.1.5\":\"01.1.5 Oils and fats\",\"01.1.6\":\"01.1.6 Fruit\"}}},\"period\":{\"label\":\"period\",\"category\":{\"index\":{\"0\":0,\"1\":1,\"2\":2,\"3\":3,\"4\":4},\"label\":{\"0\":\"2006M01\",\"1\":\"2006M02\",\"2\":\"2006M03\",\"3\":\"2006M04\",\"4\":\"2006M05\"}}},\"id\":[\"Product group\",\"period\"],\"size\":[8,5],\"role\":{\"time\":[\"period\"]}},\"label\":\"Consumer Price Index (CPI) (by COICOP), 1980=100 PxcMetaTitleBy Product group PxcMetaTitleAnd period\",\"source\":\"Statistics Sweden\",\"updated\":\"2006-07-05T12:21:00Z\",\"value\":[237,238.6,238.7,238.3,242.1,246.1,247.9,248,247.6,251.9,245.3,243.6,245.3,244.7,245,229.3,232.2,232.2,232,232.9,316.3,314.9,321.9,315.3,332.8,266.9,267.4,267,266.3,267.8,208.8,211.2,211.8,211.5,211.7,232.2,227,231.8,232.8,238.2],\"extension\":{\"px\":{\"infofile\":\"PR0101\",\"decimals\":1}}}}";

            //Act

            //Assert
            //Check their equality.
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the metadata part of a px file.
        /// </summary>
        /// <param name="path">The path to the file</param>
        /// <returns>
        /// Return a PCAxis.Paxiom.PXMeta object containing the metadata 
        /// read from path
        /// </returns>
        public object Handle(string path, DatabaseLogger logger)
        {
            try
            {
                PCAxis.Paxiom.IPXModelBuilder builder = new PXFileBuilder();
                builder.SetPath(path);
                builder.BuildForSelection();
                if (builder.Errors.Count > 0)
                {
                    for (int i = 0; i < builder.Errors.Count; i++)
                    {
                        logger(new DatabaseMessage() { MessageType = DatabaseMessage.BuilderMessageType.Error, Message = "PX file is corrupted " + path + " "  + builder.Errors[i].Code });
                    }
                    return null;
                }
                if (builder.Warnings.Count > 0)
                {
                    for (int i = 0; i < builder.Warnings.Count; i++)
                    {
                        logger(new DatabaseMessage() { MessageType = DatabaseMessage.BuilderMessageType.Warning, Message = "PX file " + path + " " + builder.Warnings[i].Code });
                    }
                    return null;
                }
                return builder.Model.Meta;
            }
            catch (PCAxis.Paxiom.PXException ex)
            {
                logger(new DatabaseMessage() { MessageType = DatabaseMessage.BuilderMessageType.Error, Message = ex.ToString() });
            }

            return null;
        }
Exemplo n.º 4
0
        public static PXModel CreatePxModel(string filePath, string itterateVariableCode, string itterateValueCode)
        {
            PXFileBuilder builder = new PXFileBuilder();

            builder.SetPath(filePath);
            builder.BuildForSelection();

            List <Selection> selections = new List <Selection>();

            foreach (Variable variable in builder.Model.Meta.Variables)
            {
                if (variable.Code != itterateVariableCode)
                {
                    selections.Add(Selection.SelectAll(variable));
                }
                else
                {
                    selections.Add(new Selection(variable.Code).AddValueCode(itterateValueCode));
                }
            }

            builder.BuildForPresentation(selections.ToArray());

            return(builder.Model);
        }
Exemplo n.º 5
0
        public static PXModel CreatePxModel(FileInfo file, bool loadData)
        {
            PXFileBuilder builder = new PXFileBuilder();

            builder.SetPath(file.FullName);
            builder.BuildForSelection();

            if (!loadData)
            {
                return(builder.Model);
            }

            builder.BuildForPresentation(Selection.SelectAll(builder.Model.Meta));
            return(builder.Model);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reads the metadata part of a px file.
        /// </summary>
        /// <param name="path">The path to the file</param>
        /// <returns>
        /// Return a PCAxis.Paxiom.PXMeta object containing the metadata
        /// read from path
        /// </returns>
        public object Handle(string path, DatabaseLogger logger)
        {
            try
            {
                PCAxis.Paxiom.IPXModelBuilder builder = new PXFileBuilder();
                builder.SetPath(path);
                builder.BuildForSelection();
                if (builder.Errors.Count > 0)
                {
                    for (int i = 0; i < builder.Errors.Count; i++)
                    {
                        logger(new DatabaseMessage()
                        {
                            MessageType = DatabaseMessage.BuilderMessageType.Error, Message = "PX file is corrupted " + path + " " + PCAxis.Web.Core.Management.LocalizationManager.GetLocalizedString(builder.Errors[i].Code)
                        });
                    }
                    return(null);
                }
                if (builder.Warnings.Count > 0)
                {
                    for (int i = 0; i < builder.Warnings.Count; i++)
                    {
                        logger(new DatabaseMessage()
                        {
                            MessageType = DatabaseMessage.BuilderMessageType.Warning, Message = "PX file " + path + " " + PCAxis.Web.Core.Management.LocalizationManager.GetLocalizedString(builder.Warnings[i].Code)
                        });
                    }
                    return(null);
                }
                return(builder.Model.Meta);
            }
            catch (PCAxis.Paxiom.PXException ex)
            {
                logger(new DatabaseMessage()
                {
                    MessageType = DatabaseMessage.BuilderMessageType.Error, Message = ex.ToString()
                });
            }

            return(null);
        }