Exemplo n.º 1
0
        internal static CsvFormatSettings CreateCsvFormatSettings(CdmTraitReference cdmTraitRef)
        {
            var result = new CsvFormatSettings();

            foreach (var argument in cdmTraitRef.Arguments)
            {
                switch (argument.Name)
                {
                case "columnHeaders":
                    result.ColumnHeaders = argument.Value == "true";
                    break;

                case "csvStyle":
                    result.CsvStyle = argument.Value;
                    break;

                case "delimiter":
                    result.Delimiter = argument.Value;
                    break;

                case "quoteStyle":
                    result.QuoteStyle = argument.Value;
                    break;

                case "encoding":
                    result.Encoding = argument.Value;
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public UnicodeCsvClipboardExporter()
 {
     IncludeColumnHeaders = true;
     FormatSettings       = new CsvFormatSettings();
     _indentationString   = "";
     _baseStream          = new ToStringMemoryStream();
 }
Exemplo n.º 3
0
        internal static CdmTraitReference CreateCsvTrait(CsvFormatSettings obj, CdmCorpusContext ctx)
        {
            var csvFormatTrait = ctx.Corpus.MakeRef <CdmTraitReference>(CdmObjectType.TraitRef, "is.partition.format.CSV", true);

            csvFormatTrait.SimpleNamedReference = false;

            if (obj.ColumnHeaders != null)
            {
                var columnHeadersArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "columnHeaders");
                columnHeadersArg.Value = obj.ColumnHeaders == true ? "true" : "false";
                csvFormatTrait.Arguments.Add(columnHeadersArg);
            }

            if (obj.CsvStyle != null)
            {
                var csvStyleArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "csvStyle");
                csvStyleArg.Value = obj.CsvStyle;
                csvFormatTrait.Arguments.Add(csvStyleArg);
            }

            if (obj.Delimiter != null)
            {
                var delimiterArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "delimiter");
                delimiterArg.Value = obj.Delimiter;
                csvFormatTrait.Arguments.Add(delimiterArg);
            }

            if (obj.QuoteStyle != null)
            {
                var quoteStyleArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "quoteStyle");
                quoteStyleArg.Value = obj.QuoteStyle;
                csvFormatTrait.Arguments.Add(quoteStyleArg);
            }

            if (obj.Encoding != null)
            {
                var encodingArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "encoding");
                encodingArg.Value = obj.Encoding;
                csvFormatTrait.Arguments.Add(encodingArg);
            }

            return(csvFormatTrait);
        }
Exemplo n.º 4
0
        internal static CdmTraitReference CreateCsvTrait(CsvFormatSettings obj, CdmCorpusContext ctx, CdmTraitReference host = null)
        {
            var csvFormatTrait = host ?? ctx.Corpus.MakeRef <CdmTraitReference>(CdmObjectType.TraitRef, "is.partition.format.CSV", false);
            var argumentNames  = new HashSet <string>(csvFormatTrait.Arguments.AllItems.Where(arg => arg.Name != null).Select(arg => arg.Name));

            if (obj.ColumnHeaders != null && !argumentNames.Contains("columnHeaders"))
            {
                var columnHeadersArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "columnHeaders");
                columnHeadersArg.Value = obj.ColumnHeaders == true ? "true" : "false";
                csvFormatTrait.Arguments.Add(columnHeadersArg);
            }

            if (obj.CsvStyle != null && !argumentNames.Contains("csvStyle"))
            {
                var csvStyleArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "csvStyle");
                csvStyleArg.Value = obj.CsvStyle;
                csvFormatTrait.Arguments.Add(csvStyleArg);
            }

            if (obj.Delimiter != null && !argumentNames.Contains("delimiter"))
            {
                var delimiterArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "delimiter");
                delimiterArg.Value = obj.Delimiter;
                csvFormatTrait.Arguments.Add(delimiterArg);
            }

            if (obj.QuoteStyle != null && !argumentNames.Contains("quoteStyle"))
            {
                var quoteStyleArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "quoteStyle");
                quoteStyleArg.Value = obj.QuoteStyle;
                csvFormatTrait.Arguments.Add(quoteStyleArg);
            }

            if (obj.Encoding != null && !argumentNames.Contains("encoding"))
            {
                var encodingArg = ctx.Corpus.MakeObject <CdmArgumentDefinition>(CdmObjectType.ArgumentDef, "encoding");
                encodingArg.Value = obj.Encoding;
                csvFormatTrait.Arguments.Add(encodingArg);
            }

            return(csvFormatTrait);
        }