Ejemplo n.º 1
0
        public static Source Get(Contexts.Sources.Source source)
        {
            var contextType = source.GetType();

            if (contextType == typeof(Contexts.Sources.Database))
            {
                return(new Database(source as Contexts.Sources.Database));
            }
            else if (contextType == typeof(Contexts.Sources.FlatFile))
            {
                return(new FlatFile(source as Contexts.Sources.FlatFile));
            }
            else
            {
                throw new ArgumentException();
            }
        }
Ejemplo n.º 2
0
        public override IEnumerable <Dictionary <string, object> > GetRows(Contexts.Sources.Source source)
        {
            var context = source as Contexts.Sources.FlatFile;

            using (var reader = new System.IO.StreamReader(context.Location))
            {
                string line = null;

                string[] columns = null;

                while ((line = reader.ReadLine()) != null)
                {
                    if (columns == null)
                    {
                        columns = ParseLine(line, context.Delimiters);
                    }
                    else
                    {
                        yield return(MakeRowObj(ParseLine(line, context.Delimiters), columns));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override IEnumerable <Dictionary <string, object> > GetRows(Contexts.Sources.Source source)
        {
            var context = source as Contexts.Sources.Database;

            using (var connection = new SqlConnection(context.ConnectionString))
            {
                connection.Open();

                using (var cmd = new SqlCommand(context.Command, connection))
                {
                    cmd.CommandTimeout = context.CommandTimeout;

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var rowObj = new Dictionary <string, object>();

                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                var data = reader[i];

                                if (context.SuppressNulls && data == DBNull.Value)
                                {
                                    continue;
                                }

                                ParseColumn(reader.GetName(i), data, rowObj);
                            }

                            yield return(rowObj);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public abstract IEnumerable <Dictionary <string, object> > GetRows(Contexts.Sources.Source source);