Пример #1
0
        public static string ToText <TRec>(TRec record, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null)
        {
            if (record is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoJSONWriter(xml, configuration))
                    w.Write(record as DataTable);
                return(xml.ToString());
            }
            else if (record is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoJSONWriter(xml, configuration))
                    w.Write(record as IDataReader);
                return(xml.ToString());
            }

            if (configuration == null)
            {
                configuration = new ChoJSONRecordConfiguration(typeof(TRec));
            }

            configuration.IgnoreRootName = true;
            configuration.RootName       = null;
            if (configuration.SingleElement == null)
            {
                configuration.SingleElement = true;
            }
            configuration.SupportMultipleContent = true;

            return(ToTextAll(ChoEnumerable.AsEnumerable <TRec>(record), configuration, traceSwitch, jsonPath));
        }
Пример #2
0
        public static string ToText <TRec>(TRec record, ChoYamlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string yamlPath = null)
        {
            if (record is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoYamlWriter(xml, configuration))
                    w.Write(record as DataTable);
                return(xml.ToString());
            }
            else if (record is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoYamlWriter(xml, configuration))
                    w.Write(record as IDataReader);
                return(xml.ToString());
            }

            if (configuration == null)
            {
                configuration = new ChoYamlRecordConfiguration();
            }

            if (configuration.SingleDocument == null)
            {
                configuration.SingleDocument = true;
            }
            return(ToTextAll(ChoEnumerable.AsEnumerable <TRec>(record), configuration, traceSwitch, yamlPath));
        }
Пример #3
0
 public static string ToText <TRec>(TRec record, ChoJSONRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string jsonPath = null)
     where TRec : class
 {
     configuration.IgnoreRootName = true;
     configuration.RootName       = null;
     configuration.SingleElement  = true;
     return(ToTextAll(ChoEnumerable.AsEnumerable <TRec>(record), configuration, traceSwitch, jsonPath));
 }
Пример #4
0
        public static string ToText <TRec>(TRec record, ChoXmlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string xpath = null)
            where TRec : class
        {
            XmlRootAttribute root  = ChoType.GetCustomAttribute <XmlRootAttribute>(typeof(TRec), false);
            string           xPath = null;

            if (record != null && !record.GetType().IsDynamicType())
            {
                xPath = root != null ? root.ElementName : typeof(TRec).Name;
            }
            return(ToTextAll(ChoEnumerable.AsEnumerable <TRec>(record), configuration, traceSwitch, xPath));
        }
Пример #5
0
 public static string ToText <TRec>(TRec record, ChoCSVRecordConfiguration configuration = null, TraceSwitch traceSwitch = null)
     where TRec : class
 {
     return(ToTextAll(ChoEnumerable.AsEnumerable(record), configuration, traceSwitch));
 }
Пример #6
0
        public static string ToText <TRec>(TRec record, ChoXmlRecordConfiguration configuration = null, TraceSwitch traceSwitch = null, string xpath = null)
            where TRec : class
        {
            if (record is DataTable)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as DataTable);
                return(xml.ToString());
            }
            else if (record is IDataReader)
            {
                StringBuilder xml = new StringBuilder();
                using (var w = new ChoXmlWriter(xml, configuration))
                    w.Write(record as IDataReader);
                return(xml.ToString());
            }

            if (configuration == null)
            {
                configuration = new ChoXmlRecordConfiguration(typeof(TRec));
                configuration.IgnoreRootName = true;
                configuration.RootName       = null;
            }

            configuration.IgnoreNodeName = true;

            if (record != null)
            {
                if (configuration.NodeName.IsNullOrWhiteSpace())
                {
                    ChoDynamicObject rec1 = record as ChoDynamicObject;
                    if (rec1 != null)
                    {
                        if (rec1.DynamicObjectName != ChoDynamicObject.DefaultName)
                        {
                            configuration.NodeName = rec1.DynamicObjectName;
                        }
                        else
                        {
                            //configuration.IgnoreNodeName = true;
                            //configuration.NodeName = null;
                        }
                    }
                    else
                    {
                        XmlRootAttribute root     = ChoType.GetCustomAttribute <XmlRootAttribute>(record.GetType(), false);
                        string           nodeName = "XElement";
                        if (root != null && !root.ElementName.IsNullOrWhiteSpace())
                        {
                            nodeName = root.ElementName.Trim();
                        }
                        else
                        {
                            nodeName = record.GetType().Name;
                        }

                        configuration.NodeName = nodeName;
                    }
                }
            }

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var parser = new ChoXmlWriter <TRec>(writer, configuration)
                        {
                            TraceSwitch = traceSwitch == null ? ChoETLFramework.TraceSwitch : traceSwitch
                        })
                        {
                            //parser.Configuration.XPath = xpath;

                            if (record != null)
                            {
                                parser.Write(ChoEnumerable.AsEnumerable <TRec>(record));
                            }

                            parser.Close();

                            writer.Flush();
                            stream.Position = 0;

                            return(reader.ReadToEnd());
                        }
        }
Пример #7
0
 public static string ToText(object record, TraceSwitch traceSwitch = null)
 {
     return(ToTextAll(ChoEnumerable.AsEnumerable <object>(record), traceSwitch));
 }
 public static string ToText <TRec>(TRec record, ChoFixedLengthRecordConfiguration configuration = null)
     where TRec : class
 {
     return(ToText(ChoEnumerable.AsEnumerable(record), configuration));
 }