Esempio n. 1
0
        public void ExportData(IList <IData> instance, string path)
        {
            var strBuilder = new StringBuilder();
            var colSep     = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
            IEnumerable <string> variables = _factory.GetVariables(instance);

            foreach (var variable in variables)
            {
                strBuilder.Append(variable.Replace(colSep, string.Empty) + colSep);
            }
            strBuilder.Remove(strBuilder.Length - colSep.Length, colSep.Length);
            strBuilder.AppendLine();



            for (var i = 0; i < instance.Count; i++)
            {
                IList <IData> columnData = _factory.GetColumnData(instance[i]);
                for (var j = 0; j < columnData.Count; j++)
                {
                    if (j > 0)
                    {
                        strBuilder.Append(colSep);
                    }
                    strBuilder.Append(_factory.GetData(columnData[j]));
                }
                strBuilder.AppendLine();
            }
            using (var fileStream = new FileStream(path, FileMode.Create))
            {
                var encoding = Encoding.GetEncoding(Encoding.Default.CodePage,
                                                    new EncoderReplacementFallback("*"),
                                                    new DecoderReplacementFallback("*"));
                using (var writer = new StreamWriter(fileStream, encoding))
                {
                    writer.Write(strBuilder);
                }
            }
        }