Example #1
0
        public static void WriteOut <T>(Csv.Type.Common.CommonCsvList <T> sourceObject, List <string> headerList, out int count)
        {
            count = 0;
            //Create a Header string line - with quotes & delimiter
            if (headerList.Count == 0)
            {
                CsvMaker.GetDefaultFields <T>(ref headerList);
                sourceObject.HeaderString = CsvMaker.CsvLine(headerList);
            }
            else
            {
                sourceObject.HeaderString = CsvMaker.CsvLine(headerList);
            };

            using (StreamWriter sw = new StreamWriter(sourceObject.OutputPath, true))
            {
                //Write header string to file
                sw.WriteLine(sourceObject.HeaderString);

                foreach (var item in sourceObject.Items)
                {
                    //Create a csv line - with quotes and delimiter
                    sw.WriteLine(CsvMaker.CsvItem <T>(item));
                    sourceObject.Count++;
                }
                sw.WriteLine(EndofFileString());
            }
        }
Example #2
0
        public static void WriteOut <T>(Csv.Type.Common.CommonCsvList <T> sourceObject)
        {
            //Create a Header string line - with quotes & delimiter
            var header = "";

            if (sourceObject.HeaderList.Count == 0)
            {
                CsvMaker.GetDefaultFields <T>(ref sourceObject.HeaderList);
                header = CsvMaker.CsvLine(sourceObject.HeaderList);
            }
            else
            {
                CsvMaker.CsvLine(sourceObject.HeaderList);
            }

            using (StreamWriter sw = new StreamWriter(sourceObject.OutputPath, true))
            {
                //Write header string to file
                sw.WriteLine(header);

                foreach (var item in sourceObject.Items)
                {
                    sw.WriteLine(CsvMaker.CsvItem <T>(item));
                }
                sw.WriteLine(EndofFileString());
            }
        }
Example #3
0
        private static string EndofFileString()
        {
            List <string> eof = new List <string> {
                "EOF", $"{DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")}"
            };

            CsvMaker.CsvLine(eof, ',', '"');
            return(CsvMaker.CsvLine(eof, ',', '"'));
        }
Example #4
0
        static void HandleConnectionString(string connectionString)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                var           tablesInfo = TablesGetter.GetTablesInfo(connection);
                StringBuilder stringBuilder;

                foreach (var tableInfo in tablesInfo)
                {
                    var getAllRowsSql     = String.Format("SELECT * FROM [{0}]", tableInfo.Name);
                    var getAllRowsCommand = new SqlCommand(getAllRowsSql, connection);

                    using (SqlDataReader reader = getAllRowsCommand.ExecuteReader())
                    {
                        var columnsNames = ColumnsGetter.GetColumnsNames(reader);

                        stringBuilder = new StringBuilder();

                        foreach (var columnName in columnsNames)
                        {
                            var value = columnName;
                            stringBuilder.Append(value.Trim()).Append("\t");
                        }
                        stringBuilder.AppendLine();

                        while (reader.Read())
                        {
                            foreach (var columnName in columnsNames)
                            {
                                var value = reader[columnName].ToString();
                                stringBuilder.Append(value.Trim()).Append("\t");
                            }
                            stringBuilder.AppendLine();
                        }
                    }

                    CsvMaker.Make(tableInfo.TableCatalog, tableInfo.TableType, tableInfo.Name, stringBuilder);
                    Console.WriteLine(tableInfo.TableCatalog + " - " + tableInfo.TableType + " - " + tableInfo.Name);
                }

                if (tablesInfo.Count > 0)
                {
                    ZipMaker.Make(tablesInfo[0].TableCatalog);
                }
            }
        }
Example #5
0
        protected override void OnLogged(object sender, LoggedEventArgs e)
        {
            var log = e.Data;

            if (log == null)
            {
                return;
            }
            if (log.Level < MinimumLogLevel)
            {
                return;
            }
            if (writer_ == null)
            {
                throw new InvalidOperationException("writer_がnullです。");
            }
            string csvString = null;

            try{
                CsvMaker cm = new CsvMaker();
                cm.AddToken(log.Level);
                cm.AddToken(log.Tag);
                cm.AddToken(log.Time.ToString("yyyy/MM/dd HH:mm:ss.fff"));
                cm.AddToken(log.Message);
                cm.AddToken(log.Exception);

                // Exceptionがnullの時はコード情報出力しないようにしてる
                if (log.Exception != null || log.Level >= ECSLogLevel.Error)
                {
                    cm.AddToken(log.File);
                    cm.AddToken(log.Line);
                    cm.AddToken(log.Member);
                }
                csvString = cm.ToString();
            }
            catch (Exception ex) {
                throw new Exception("ログ情報からCSVへの変換に失敗しました。", ex);
            }
            writer_.WriteLine(csvString);
        }