Exemple #1
0
        /// <summary>
        /// Save as CSV.
        /// </summary>
        /// <param name="model">The model.</param>
        public override void ToCsv(UrlModel model)
        {
            var content = model.GetUrlData();
            var dataSet = Transform(content);

            TransformTime(dataSet);
            TransformData(dataSet, model);
        }
Exemple #2
0
        /// <summary>
        /// Transforms the data.
        /// </summary>
        /// <param name="ds">The ds.</param>
        /// <param name="model">The model.</param>
        private void TransformData(DataSet ds, UrlModel model)
        {
            List <DataTable> tables = ds.Tables.Cast <DataTable>().ToList();
            var results             = tables.GroupBy(g => GroupByUnique(g)).ToList();

            foreach (var result in results)
            {
                for (int i = 1; i < result.Count(); i++)
                {
                    result.First().Merge(result.Skip(i).Take(1).SingleOrDefault());
                }
                var file = string.Format("{0}_{1}.csv", model.GetRootFileName(""), result.Key);
                SaveFile(result.First(), model, file);
            }
        }
Exemple #3
0
        /// <summary>
        /// Saves the file.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="model">The model.</param>
        /// <param name="file">The file.</param>
        private void SaveFile(DataTable table, UrlModel model, string file)
        {
            var lines = new List <string>();

            var header = string.Join(",", table.ColumnNames());

            lines.Add(header);

            var values = table.AsEnumerable().Select(row => FormatRow(row));

            lines.AddRange(values);

            UrlModel.DeleteFile(file);
            File.WriteAllLines(file, lines);
        }
        /// <summary>
        /// Transforms the data.
        /// </summary>
        /// <param name="ds">The ds.</param>
        /// <param name="model">The model.</param>
        private void TransformData(DataSet ds, UrlModel model)
        {
            List <DataTable> tables = ds.Tables.Cast <DataTable>().ToList();
            var results             = tables.GroupBy(g => GroupByUnique(g)).ToList();

            foreach (var result in results)
            {
                for (int i = 1; i < result.Count(); i++)
                {
                    result.First().Merge(result.Skip(i).Take(1).SingleOrDefault());
                }

                //  result.First().
                OnDataTableCreated(this, new DataTableEventArgs(result.First(), result.Key));
            }
        }
Exemple #5
0
 /// <summary>
 /// To the CSV.
 /// </summary>
 /// <param name="model">The model.</param>
 public abstract void Transform(UrlModel model);
Exemple #6
0
 /// <summary>
 /// To the CSV.
 /// </summary>
 /// <param name="model">The model.</param>
 public abstract void ToCsv(UrlModel model);