Beispiel #1
0
        public void GetTypedDataSet()
        {
            var cfg     = new FileReader().Read(@"Files\PersonAndPet.xml", null, new Cfg.Net.Loggers.NullLogger());
            var sh      = new ShorthandRoot(@"Files\Shorthand.xml", new FileReader());
            var process = new Process(cfg, new JintValidator("js"), new ShorthandModifier(sh, "sh"));

            var personContext = new PipelineContext(new DebugLogger(), process, process.Entities.Last());
            var entityInput   = new InputContext(personContext, new Incrementer(personContext));
            var rowFactory    = new RowFactory(entityInput.RowCapacity, entityInput.Entity.IsMaster, false);
            var rows          = new InternalReader(entityInput, rowFactory).Read().ToArray();

            Assert.IsInstanceOf <IEnumerable <IRow> >(rows);
            Assert.AreEqual(3, rows.Length);

            var dale    = rows[0];
            var micheal = rows[1];

            Assert.IsInstanceOf <int>(dale[FieldAt(4)]);
            Assert.AreEqual(1, dale[FieldAt(4)]);
            Assert.AreEqual("Dale", dale[FieldAt(5)]);
            Assert.AreEqual("Michael", micheal[FieldAt(5)]);

            foreach (var row in rows)
            {
                Console.WriteLine(row);
            }
        }
        public override object GetValue(int i)
        {
            var result = InternalReader.GetValue(i);

            if (result is Guid)
            {
                result = CorrectGuid((Guid)result);
            }
            return(result);
        }
        public TestSerializer(Stream stream)
        {
            var internalReader = new InternalReader();
            _reader = new Bms1Reader(internalReader, internalReader);
            _reader.Stream = new System.IO.BinaryReader(stream);
            internalReader.Stream = _reader.Stream;

            var internalWriter = new InternalWriter();
            _writer = new Bms1Writer(internalWriter, internalWriter);
            _writer.Stream = new System.IO.BinaryWriter(stream);
            internalWriter.Stream = _writer.Stream;
        }
Beispiel #4
0
        public override void Dispose()
        {
            if (!InternalReader.IsClosed)
            {
                Tools.Exceptions.ExecuteIgnoringException(InternalReader.Close);
                InternalReader.Dispose();
            }

            if (InternalCommand != null)
            {
                Tools.Exceptions.ExecuteIgnoringException(InternalCommand.Dispose);
            }
        }
        public void TestMethod1()
        {
            var cfg     = @"<cfg name='process' read-only='true'>
   <entities>
      <add name='entity'>
         <rows>
            <add FirstName='Dale' LastName='Newman' />
         </rows>
         <fields>
            <add name='FirstName' />
            <add name='LastName' />
         </fields>
         <calculated-fields>
            <add name='FullName'>
               <transforms>
                  <add method='razor' template='@{var fullName = Model.FirstName + "" "" + Model.LastName;}@fullName' >
                     <parameters>
                        <add field='FirstName' />
                        <add field='LastName' />
                     </parameters>
                  </add>
               </transforms>
            </add>
         </calculated-fields>
      </add>
   </entities>
</cfg>";
            var process = new Process(cfg);

            Assert.AreEqual(0, process.Errors().Length);

            // manually build out test without autofac to make it more of a unit test
            var logger    = new ConsoleLogger();
            var entity    = process.Entities.First();
            var field     = entity.CalculatedFields.First();
            var operation = field.Transforms.First();
            var context   = new PipelineContext(logger, process, entity, field, operation);
            var transform = new RazorTransform(context);
            var input     = new InputContext(context);
            var reader    = new InternalReader(input, new RowFactory(input.RowCapacity, entity.IsMaster, false));

            var rows = transform.Operate(reader.Read()).ToArray();

            Assert.AreEqual("Dale Newman", rows[0][field]);
        }
 public override Guid GetGuid(int i)
 {
     return(CorrectGuid(InternalReader.GetGuid(i)));
 }
Beispiel #7
0
        /// <summary>
        /// Read a BackOffice row from the EasyForex XML file and
        /// parse the row into currentRow.
        /// </summary>
        /// <returns>current row, null value mean end of file.</returns>
        protected override OrganicRankingsRow GetRow()
        {
            Token[] tokens = new Token[]
            {
                new Token("Url", "<h2 class=r><a href=\"", "\""),
                new Token("Title", new string[] { "class=l", ",'')\">" }, "</a>"),
                new Token("Description", "class=std>", "<br>")
            };

            string buffer = String.Empty;

            char[]             nextChar      = new char[1];
            bool               copying       = false;
            int                tokenIndex    = 0;
            int                subTokenIndex = 0;
            OrganicRankingsRow row           = new OrganicRankingsRow();

            // Keep reading until a complete row is scanned
            while (InternalReader.Read(nextChar, 0, 1) > 0)
            {
                Token token = tokens[tokenIndex];

                // Add the next character to the buffer
                buffer += nextChar[0];

                if (!copying)
                {
                    string subToken = token.Start[subTokenIndex];

                    // LOOKING FOR THE NEXT VALUE
                    if (buffer == subToken)
                    {
                        if (subTokenIndex == token.Start.Length - 1)
                        {
                            // Found all the start tokens, start copying
                            subTokenIndex = 0;
                            copying       = true;
                        }
                        else
                        {
                            // Need to look for the next token, advance to the next
                            subTokenIndex++;
                        }
                        buffer = String.Empty;
                    }
                    else if (buffer != subToken.Substring(0, buffer.Length))
                    {
                        // What we have so far does not match the token, try just the current character
                        if (nextChar[0] == subToken[0])
                        {
                            // The last read character matches the beginning of a token, so continue with it
                            buffer = nextChar[0].ToString();
                        }
                        else
                        {
                            // The current character is worthless as well, so just reset the buffer
                            buffer = String.Empty;
                        }
                    }
                }
                else
                {
                    // COPYING A VALUE WHILE LOOKING FOR ITS END TOKEN
                    if (buffer.Length >= token.End.Length && buffer.Substring(buffer.Length - token.End.Length, token.End.Length) == token.End)
                    {
                        copying = false;

                        // Apply value (without end token)
                        row.ApplyValue(token.Name, Cleanup(buffer.Substring(0, buffer.Length - token.End.Length)));

                        if (tokenIndex == tokens.Length - 1)
                        {
                            // Found all tokens
                            return(row);
                        }
                        else
                        {
                            // Move to next token
                            tokenIndex++;
                            buffer = String.Empty;
                        }
                    }
                }
            }

            // Arrived to end of file.
            return(null);
        }