示例#1
0
        /// <summary>
        /// Prepare the output file, write headers if needed.
        /// </summary>
        ///
        /// <param name="outputFile">The output file.</param>
        ///<returns>The file to write to.</returns>
        private new StreamWriter PrepareOutputFile(FileInfo outputFile)
        {
            try
            {
                outputFile.Delete();
                var tw = new StreamWriter(outputFile.OpenWrite());

                // write headers, if needed
                if (ProduceOutputHeaders)
                {
                    var line = new StringBuilder();


                    // handle provided fields, not all may be used, but all should
                    // be displayed
                    foreach (String heading  in  InputHeadings)
                    {
                        AppendSeparator(line, Format);
                        line.Append("\"");
                        line.Append(heading);
                        line.Append("\"");
                    }


                    // now add the output fields that will be generated
                    foreach (AnalystField field  in  _analyst.Script.Normalize.NormalizedFields)
                    {
                        if (field.Output && !field.Ignored)
                        {
                            AppendSeparator(line, Format);
                            line.Append("\"Output:");
                            line.Append(CSVHeaders.TagColumn(field.Name, 0,
                                                             field.TimeSlice, false));
                            line.Append("\"");
                        }
                    }

                    tw.WriteLine(line.ToString());
                }

                return(tw);
            }
            catch (IOException e)
            {
                throw new QuantError(e);
            }
        }
示例#2
0
        /// <summary>
        /// Write the headers.
        /// </summary>
        ///
        /// <param name="tw">The output stream.</param>
        private void WriteHeaders(StreamWriter tw)
        {
            var line = new StringBuilder();

            foreach (AnalystField stat  in  _analyst.Script.Normalize.NormalizedFields)
            {
                int needed = stat.ColumnsNeeded;

                for (int i = 0; i < needed; i++)
                {
                    AppendSeparator(line, InputFormat);
                    line.Append('\"');
                    line.Append(CSVHeaders.TagColumn(stat.Name, i,
                                                     stat.TimeSlice, needed > 1));
                    line.Append('\"');
                }
            }
            tw.WriteLine(line.ToString());
        }
示例#3
0
        /// <summary>
        /// Add headings for a raw file.
        /// </summary>
        ///
        /// <param name="line">The line to write the raw headings to.</param>
        /// <param name="prefix">The prefix to place.</param>
        /// <param name="format">The format to use.</param>
        public void AddRawHeadings(StringBuilder line,
                                   String prefix, CSVFormat format)
        {
            int subFields = ColumnsNeeded;

            for (int i = 0; i < subFields; i++)
            {
                String str = CSVHeaders.TagColumn(_name, i,
                                                  _timeSlice, subFields > 1);
                BasicFile.AppendSeparator(line, format);
                line.Append('\"');
                if (prefix != null)
                {
                    line.Append(prefix);
                }
                line.Append(str);
                line.Append('\"');
            }
        }