Ejemplo n.º 1
0
        /// <summary>
        /// Parse the file to Row objects.
        /// </summary>
        /// <param name="stream">Stream which contains a file to parse.</param>
        /// <returns>List of parsed rows.</returns>
        public override IList <Entities.Row> Parse(System.IO.StreamReader stream)
        {
            List <Entities.Row> result = new List <Entities.Row>();
            Regex attributes           = new Regex(@"(@attribute )([\w\d._'-]+)([\s\{\}, \d\w]+)", RegexOptions.IgnoreCase);
            Regex data = new Regex("(@data)([\\d\\w, \r\n.'\"-]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);

            //get the entire file
            string file = stream.ReadToEnd();

            MatchCollection matchedAttributes = attributes.Matches(file);

            string[] attributesNames = new string[matchedAttributes.Count];
            int      index           = 0;

            foreach (Match m in matchedAttributes)
            {
                attributesNames[index++] = m.Groups[2].Value.Trim('\'');
            }

            index = 1;
            data.Match(file)
            .Groups[2]
            .Value
            .Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
            .ToList()
            .ForEach(x =>
            {
                //  x = x;
                Entities.Row row = new Entities.Row()
                {
                    Name = ("r" + index++)
                };

                int attrIndex = 0;

                x.Split(supportedDelimiters)
                .ToList()
                .ForEach(i =>
                {
                    row.Attributes.Add(new Entities.Attribute(attributesNames[attrIndex++], i.Trim('\'', '\"')));
                });

                result.Add(row);
            });

            Verify(result);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate rows for information system.
        /// </summary>
        /// <returns>List of rows.</returns>
        public IList <Entities.Row> Generate()
        {
            List <Entities.Row> result = new List <Entities.Row>(NumberOfObjects);

            for (int i = 0; i < NumberOfObjects; i++)
            {
                Entities.Row row = new Entities.Row();
                row.Name = "r" + (i + 1);

                for (int j = 0; j < NumberOfAttributes; j++)
                {
                    row.Attributes.Add(new Entities.Attribute("a" + (j + 1), RandomValue));
                }

                result.Add(row);
            }

            return(result);
        }