Beispiel #1
0
        public static void PrintHeader(Type type, CsvWriterSettings settings)
        {
            string[] exclude = settings.ExcludeColumns;
            string   s       = string.Empty;

            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                if (exclude != null && exclude.Count(x => x.Contains(propertyInfo.Name)) > 0)
                {
                    continue;
                }

                if (s.Length > 0)
                {
                    s = String.Join(",", new string[] { s, propertyInfo.Name });
                }
                else
                {
                    s = propertyInfo.Name;
                }
            }

            settings.Writer.WriteLine(s);
            settings.Writer.Flush();
        }
Beispiel #2
0
        static void ExportToCSV(object obj, CsvWriterSettings settings)
        {
            string[] exclude = settings.ExcludeColumns;

            Type type = obj.GetType();

            PropertyInfo[] properties;
            if (!settings.Properties.TryGetValue(type, out properties))
            {
                properties = type.GetProperties();
                settings.Properties.Add(type, properties);
            }

            string s = string.Empty;

            for (int idx = 0; idx < properties.Length; idx++)
            {
                if (exclude != null && exclude.Count(x => x.Contains(properties[idx].Name)) > 0)
                {
                    continue;
                }

                var value          = properties[idx].GetValue(obj, null);
                var formattedValue = value == null ? String.Empty : value.ToString();

                if (value != null)
                {
                    if (value.GetType() == typeof(string))
                    {
                        formattedValue = "\"" + formattedValue + "\"";
                    }
                }

                if (s.Length > 0)
                {
                    s = String.Join(",", new string[] { s, formattedValue });
                }
                else
                {
                    s = formattedValue;
                }
            }

            settings.Writer.WriteLine(s);
            settings.Writer.Flush();
        }
Beispiel #3
0
        public static void PrintHeader(Type type, CsvWriterSettings settings)
        {
            string[] exclude = settings.ExcludeColumns;
            string s = string.Empty;
            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                if (exclude != null && exclude.Count(x => x.Contains(propertyInfo.Name)) > 0)
                    continue;

                if (s.Length > 0)
                    s = String.Join(",", new string[] { s, propertyInfo.Name });
                else
                    s = propertyInfo.Name;
            }

            settings.Writer.WriteLine(s);
            settings.Writer.Flush();
        }
Beispiel #4
0
        static void ExportToCSV(object obj, CsvWriterSettings settings)
        {
            string[] exclude = settings.ExcludeColumns;

            Type type = obj.GetType();
            PropertyInfo[] properties;
            if (!settings.Properties.TryGetValue(type, out properties))
            {
                properties = type.GetProperties();
                settings.Properties.Add(type, properties);
            }

            string s = string.Empty;
            for (int idx = 0; idx < properties.Length; idx++)
            {
                if (exclude != null && exclude.Count(x => x.Contains(properties[idx].Name)) > 0)
                    continue;

                var value = properties[idx].GetValue(obj, null);
                var formattedValue = value == null ? String.Empty : value.ToString();

                if (value != null)
                {
                    if (value.GetType() == typeof(string))
                        formattedValue = "\"" + formattedValue + "\"";
                }

                if (s.Length > 0)
                    s = String.Join(",", new string[] { s, formattedValue });
                else
                    s = formattedValue;

            }

            settings.Writer.WriteLine(s);
            settings.Writer.Flush();
        }
Beispiel #5
0
 public static void Dump(object obj, CsvWriterSettings settings)
 {
     ExportToCSV(obj, settings);
 }
Beispiel #6
0
        internal static void Compile(string[] fileNames,
                                     string linqFile,
                                     TextWriter outputStream,
                                     TextWriter errorStream,
                                     Type[] knownTypes  = null,
                                     DateTime?startTime = null,
                                     DateTime?endTime   = null)
        {
            StringWriter errorLogger = new StringWriter();
            string       query       = LinqpadHelpers.ExtractQuery(linqFile, errorLogger);

            Playback playback = new Playback();

            foreach (string file in fileNames)
            {
                string extension = Path.GetExtension(file);
                if (string.Equals(".etl", extension, StringComparison.InvariantCultureIgnoreCase))
                {
                    playback.AddEtlFiles(file);
                }
                //else if (string.Equals(".csv", extension, StringComparison.InvariantCultureIgnoreCase))
                //{
                //    playback.AddCsvFile(file);
                //}
            }

            Dictionary <string, object> playbackProperties = new Dictionary <string, object>();

            if (startTime.HasValue)
            {
                playbackProperties.Add("StartTime", startTime.Value);
            }

            if (endTime.HasValue)
            {
                playbackProperties.Add("EndTime", endTime.Value);
            }

            playback.KnownTypes = knownTypes;


            CsvWriterSettings csvsettings = new CsvWriterSettings
            {
                Writer = outputStream
            };

            Func <Type, object, Action <object> > onDumpStartCsv = (t, result) =>
            {
                CsvHelper.PrintHeader(t, csvsettings);

                Action <object> onNext = (o) =>
                {
                    CsvHelper.Dump(o, csvsettings);
                };

                return(onNext);
            };

            CompileAndRun(new QueryExecutionContext(playback, onDumpStartCsv),
                          query,
                          errorStream,
                          errorStream,
                          playbackProperties);
        }
Beispiel #7
0
        internal static void Compile(string[] fileNames,
            string linqFile,
            TextWriter outputStream,
            TextWriter errorStream,
            Type[] knownTypes = null,
            DateTime? startTime = null,
            DateTime? endTime = null)
        {
            StringWriter errorLogger = new StringWriter();
            string query = LinqpadHelpers.ExtractQuery(linqFile, errorLogger);

            Playback playback = new Playback();
            foreach (string file in fileNames)
            {
                string extension = Path.GetExtension(file);
                if (string.Equals(".etl", extension, StringComparison.InvariantCultureIgnoreCase))
                {
                    playback.AddEtlFiles(file);
                }
                //else if (string.Equals(".csv", extension, StringComparison.InvariantCultureIgnoreCase))
                //{
                //    playback.AddCsvFile(file);
                //}
            }

            Dictionary<string, object> playbackProperties = new Dictionary<string, object>();
            if (startTime.HasValue)
            {
                playbackProperties.Add("StartTime", startTime.Value);
            }

            if (endTime.HasValue)
            {
                playbackProperties.Add("EndTime", endTime.Value);
            }

            playback.KnownTypes = knownTypes;

            CsvWriterSettings csvsettings = new CsvWriterSettings
            {
                Writer = outputStream
            };

            Func<Type, object, Action<object>> onDumpStartCsv = (t, result) =>
            {
                CsvHelper.PrintHeader(t, csvsettings);

                Action<object> onNext = (o) =>
                {
                    CsvHelper.Dump(o, csvsettings);
                };

                return onNext;
            };

            CompileAndRun(new QueryExecutionContext(playback, onDumpStartCsv),
                query,
                errorStream,
                errorStream,
                playbackProperties);
        }
Beispiel #8
0
 public static void Dump(object obj, CsvWriterSettings settings)
 {
     ExportToCSV(obj, settings);
 }