Ejemplo n.º 1
0
        /// <summary>
        /// Writes a delimited file using the given format.
        /// </summary>
        /// <param name="reporter"></param>
        /// <param name="data"></param>
        /// <param name="writer"></param>
        /// <param name="delimiter_type"></param>
        /// <param name="format"></param>
        public static void WriteDelimitedFile(
            IProgressReporter reporter,
            string[][] data,
            TextWriter writer,
            DelimiterType delimiter_type,
            IDelimitedFormat format)
        {
            // get the delimiter character
            char delimiter = GetDelimiterChar(delimiter_type);

            // initialize the progress status.
            ProgressStatus status = new ProgressStatus();
            if (reporter != null)
            {
                status.TotalNumber = data.Length;
                status.Status = ProgressStatus.ProgressStatusEnum.Busy;
                status.CurrentNumber = 0;
                status.Message = "Creating File...";

                // report the status.
                reporter.Report(status);
            }

            // export data
            if (reporter != null)
            {
                status.Message = "Exporting... {progress}!";
            }
            for (int idx = 0; idx < data.Length; idx++)
            {
                string[] line = data[idx];
                if (line != null &&
                    line.Length > 0)
                {
                    for (int col_idx = 0; col_idx < line.Length; col_idx++)
                    {
                        if (format.DoExport(idx))
                        {
                            object field_data = line[col_idx];
                            string field_data_string = format.ConvertValue(col_idx, field_data);
                            writer.Write(field_data_string);
                            // only delimiter at the end
                            if (col_idx < line.Length - 1)
                            {
                                writer.Write(delimiter);
                            }
                        }
                    }
                }
                if (reporter != null)
                {
                    status.CurrentNumber = idx + 1;
                    reporter.Report(status);
                }
                writer.WriteLine();
            }

            // report done
            if (reporter != null)
            {
                status.Message = "Exporting Done!";
                status.Status = ProgressStatus.ProgressStatusEnum.Succeeded;
                reporter.Report(status);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes a delimited file using the given format.
        /// </summary>
        /// <param name="reporter"></param>
        /// <param name="data"></param>
        /// <param name="writer"></param>
        /// <param name="delimiter_type"></param>
        /// <param name="format"></param>
        public static void WriteDelimitedFile(
            IProgressReporter reporter,
            string[][] data,
            TextWriter writer,
            DelimiterType delimiter_type,
            IDelimitedFormat format)
        {
            // get the delimiter character
            char delimiter = GetDelimiterChar(delimiter_type);

            // initialize the progress status.
            ProgressStatus status = new ProgressStatus();

            if (reporter != null)
            {
                status.TotalNumber   = data.Length;
                status.Status        = ProgressStatus.ProgressStatusEnum.Busy;
                status.CurrentNumber = 0;
                status.Message       = "Creating File...";

                // report the status.
                reporter.Report(status);
            }

            // export data
            if (reporter != null)
            {
                status.Message = "Exporting... {progress}!";
            }
            for (int idx = 0; idx < data.Length; idx++)
            {
                string[] line = data[idx];
                if (line != null &&
                    line.Length > 0)
                {
                    for (int col_idx = 0; col_idx < line.Length; col_idx++)
                    {
                        if (format.DoExport(idx))
                        {
                            object field_data        = line[col_idx];
                            string field_data_string = format.ConvertValue(col_idx, field_data);
                            writer.Write(field_data_string);
                            // only delimiter at the end
                            if (col_idx < line.Length - 1)
                            {
                                writer.Write(delimiter);
                            }
                        }
                    }
                }
                if (reporter != null)
                {
                    status.CurrentNumber = idx + 1;
                    reporter.Report(status);
                }
                writer.WriteLine();
            }

            // report done
            if (reporter != null)
            {
                status.Message = "Exporting Done!";
                status.Status  = ProgressStatus.ProgressStatusEnum.Succeeded;
                reporter.Report(status);
            }
        }