/// <summary>
 /// 写入后就释放资源
 /// </summary>
 /// <param name="table"></param>
 /// <param name="path"></param>
 /// <param name="encoding"></param>
 public static void Write(ObjectTableStorage table, Stream path, Encoding encoding = null)
 {
     using (ObjectTableWriter writer = new ObjectTableWriter(path, encoding))
     {
         writer.Write(table);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 写入AllInOne文件
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="headerMarker"></param>
        /// <param name="spliter"></param>
        /// <param name="encoding"></param>
        public void WriteAsOneFile(Stream stream, string headerMarker = "#", string spliter = "\t", Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = Encoding.Default;
            }

            using (StreamWriter writer = new System.IO.StreamWriter(stream, encoding))
            {
                var length = GetMaxTableRowCount();
                for (int i = -1; i < length; i++)
                {
                    foreach (var table in this)
                    {
                        if (table.RowCount == 0)
                        {
                            continue;
                        }

                        if (table.RowCount > i)
                        {
                            if (i == -1)
                            {
                                writer.WriteLine(headerMarker + table.Name + spliter + table.ToSplitedTitleString(spliter));
                                continue;
                            }
                            var row = table.BufferedValues[i];

                            writer.WriteLine(table.Name + spliter + ObjectTableWriter.ToSplitedValueString(row, "", spliter, "G", table.ParamNames));
                        }
                    }
                }
                writer.Flush();
            }
        }
Esempio n. 3
0
        private static void ConvertToOneTable(string outDir, string inputPath)
        {
            var fileName   = Path.GetFileName(inputPath);
            var outputPath = Path.Combine(outDir, fileName + ".txt.xls");
            var ObsFile    = ObsFileUtil.ReadFile(inputPath);
            var table      = ObsFile.BuildObjectTable(true);

            ObjectTableWriter.Write(table, outputPath);
        }
Esempio n. 4
0
        public void Complete()
        {
            table.Name = "SiteInfo";
            var path = Path.Combine(this.OutputDirectory, "SiteInfo.txt.xls");

            Utils.FileUtil.CheckOrCreateDirectory(this.OutputDirectory);

            var span      = DateTime.Now - startTime;
            var m         = span.TotalMinutes;
            var seconds   = span.TotalSeconds;
            int FileCount = InputRawPathes.Length;

            ObjectTableWriter.Write(table, path);
            string info = "Completed, the total number is " + FileCount + ". The time consumption is " + m.ToString("0.000") + "m=" + seconds.ToString("0.00") + "s, with an average of " + (seconds / FileCount).ToString("0.000") + "s each file";

            log.Info(info);
        }
Esempio n. 5
0
        /// <summary>
        /// 写一个表
        /// </summary>
        /// <param name="storage"></param>
        /// <param name="directory"></param>
        /// <param name="isOverWrite">是否覆盖</param>
        public static void WriteTable(ObjectTableStorage storage, string directory, bool isOverWrite = true)
        {
            var OutputPath = Path.Combine(directory, storage.Name);

            if (!OutputPath.EndsWith(TableExtention, StringComparison.CurrentCultureIgnoreCase))
            {
                OutputPath += TableExtention;
            }

            if (!isOverWrite && File.Exists(OutputPath))
            {
                storage.log.Warn("忽略了已存在文件 " + OutputPath);
                return;
            }

            var writer = new ObjectTableWriter(OutputPath);

            writer.Write(storage);
            writer.CloseStream();
        }