Exemplo n.º 1
0
        public static void DataTableTest()
        {
            Assert.Fail("Make database testable.");

            string connectionstring = @"Data Source=(localdb)\v11.0;Initial Catalog=TestDb;Integrated Security=True";

            using (var conn = new SqlConnection(connectionstring))
            {
                conn.Open();
                var            comm = new SqlCommand("SELECT * FROM Customers", conn);
                SqlDataAdapter adap = new SqlDataAdapter(comm);

                DataTable dt = new DataTable("Customer");
                adap.Fill(dt);

                using (var parser = new ChoXmlWriter("customers.xml").WithXPath("Customers/Customer").Configure(c => c.XmlRecordFieldConfigurations.Add(new ChoXmlRecordFieldConfiguration("CustId")
                {
                    IsXmlAttribute = true
                })))
                    parser.Write(dt);
            }
        }
Exemplo n.º 2
0
        public static void CustomStringArrayTest()
        {
            string expected = @"<Root>
  <Days>
    <Monday />
    <Tuesday />
    <Wed />
  </Days>
</Root>";
            string actual   = null;

            List <string> s = new List <string>();

            s.Add("Monday");
            s.Add("Tuesday");
            s.Add("Wed");

            StringBuilder sb = new StringBuilder();

            using (var w = new ChoXmlWriter(sb)
                           .Configure(c => c.IgnoreNodeName = true)
                           .WithField("Days", customSerializer: (v) =>
            {
                StringBuilder sb1 = new StringBuilder();
                sb1.AppendLine("<Days>");
                foreach (var r in (IList)v)
                {
                    sb1.AppendLine("<{0} />".FormatString(r).Indent(2, " "));
                }
                sb1.Append("</Days>");

                return(sb1.ToString());
            })
                   )
                w.Write(new { Days = s });
            actual = sb.ToString();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        static void Yaml2XmlTest()
        {
            string yaml = @"
emps:
    - id: 1
      name: Tom

    - id: 2
      name: Mark
";

            StringBuilder xml = new StringBuilder();

            using (var r = ChoYamlReader.LoadText(yaml).WithYamlPath("$.emps[*]"))
            {
                using (var w = new ChoXmlWriter(xml)
                               .WithRootName("Emps")
                               .WithNodeName("Emp")
                       )
                    w.Write(r);
            }
            Console.WriteLine(xml.ToString());
        }
Exemplo n.º 4
0
        static void ConfigFirstTest()
        {
            List <ExpandoObject> objs = new List <ExpandoObject>();
            dynamic rec1 = new ExpandoObject();

            rec1.Id       = 1;
            rec1.Name     = "Mark";
            rec1.IsActive = true;
            rec1.Message  = new ChoCDATA("Test");
            objs.Add(rec1);

            dynamic rec2 = new ExpandoObject();

            rec2.Id       = 2;
            rec2.Name     = null;
            rec2.IsActive = true;
            rec2.Message  = new ChoCDATA("Test");
            objs.Add(rec2);

            ChoXmlRecordConfiguration config = new ChoXmlRecordConfiguration();

            config.XmlRecordFieldConfigurations.Add(new ChoXmlRecordFieldConfiguration("Id"));
            config.XmlRecordFieldConfigurations.Add(new ChoXmlRecordFieldConfiguration("Name"));

            using (var stream = new MemoryStream())
                using (var reader = new StreamReader(stream))
                    using (var writer = new StreamWriter(stream))
                        using (var parser = new ChoXmlWriter(writer, config).WithXPath("Employees/Employee"))
                        {
                            parser.Write(objs);

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

                            Console.WriteLine(reader.ReadToEnd());
                        }
        }
Exemplo n.º 5
0
        public static void POCOCSVW2XmlNoFormattingTest()
        {
            string csv = @"Id, Name
1, Tom
2, Mark";

            StringBuilder xml = new StringBuilder();

            using (var r = ChoCSVReader <Emp> .LoadText(csv)
                           .WithFirstLineHeader())
            {
                using (var w = new ChoXmlWriter <Emp>(xml)
                               .ErrorMode(ChoErrorMode.ThrowAndStop)
                               //.IgnoreRootName()
                               //.IgnoreNodeName()
                               //.Configure(c => c.Formatting = System.Xml.Formatting.None)
                       )
                {
                    w.Write(r.First());
                }
            }

            Console.WriteLine(xml.ToString());
        }
Exemplo n.º 6
0
        public static void Json2Xml1()
        {
            string json = @"
[
    {
        ""firstName"": ""John"",
        ""lastName"": ""Smith"",
        ""age"": 25,
        ""address"": {
            ""streetAddress"": ""21 2nd Street"",
            ""city"": ""New York"",
            ""state"": ""NY"",
            ""postalCode"": ""10021""
        },
        ""phoneNumber"": [
            {
                ""type"": ""home"",
                ""number"": ""212 555-1234""
            },
            {
                ""type"": ""fax"",
                ""number"": ""646 555-4567""
            }
        ]
    },
    {
        ""firstName"": ""Tom"",
        ""lastName"": ""Mark"",
        ""age"": 50,
        ""address"": {
            ""streetAddress"": ""10 Main Street"",
            ""city"": ""Edison"",
            ""state"": ""NJ"",
            ""postalCode"": ""08837""
        },
        ""phoneNumber"": [
            {
                ""type"": ""home"",
                ""number"": ""732 555-1234""
            },
            {
                ""type"": ""fax"",
                ""number"": ""609 555-4567""
            }
        ]
    }
]
";

            using (var r = ChoJSONReader.LoadText(json))
            {
                using (var w = new ChoXmlWriter(Console.Out)
                               .UseXmlSerialization()
                               .Configure(c => c.OmitXsiNamespace = true)
                               .ErrorMode(ChoErrorMode.IgnoreAndContinue)
                       )
                {
                    w.Write(r);
                }
            }
        }
Exemplo n.º 7
0
        public static void QuickDynamicTest()
        {
            string expected = @"<Employees>
  <Employee>
    <Id>1</Id>
    <Name>Mark</Name>
    <IsActive>true</IsActive>
    <Message><![CDATA[Test]]></Message>
    <Array>
    <anyType xmlns:q1=""http://www.w3.org/2001/XMLSchema"" p3:type=""q1:int"" xmlns:p3=""http://www.w3.org/2001/XMLSchema-instance"">1</anyType>
    <anyType xmlns:q2=""http://www.w3.org/2001/XMLSchema"" p3:type=""q2:string"" xmlns:p3=""http://www.w3.org/2001/XMLSchema-instance"">abc</anyType>
  </Array>
    <Lint>
    <int>1</int>
    <int>2</int>
  </Lint>
    <Dict>
    <item>
      <key>
        <int>1</int>
      </key>
      <value>
        <string>abc</string>
      </value>
    </item>
  </Dict>
  </Employee>
  <Employee>
    <Id>2</Id>
    <Name>Jason</Name>
    <IsActive>true</IsActive>
    <Message><![CDATA[Test]]></Message>
  </Employee>
</Employees>";
            string actual   = null;

            ArrayList al = new ArrayList();

            al.Add(1);
            al.Add("abc");

            List <int> lint = new List <int>()
            {
                1, 2
            };

            Hashtable ht = new Hashtable();

            ht.Add(1, "abc");

            ChoSerializableDictionary <int, string> dict = new ChoSerializableDictionary <int, string>();

            dict.Add(1, "abc");

            List <ExpandoObject> objs = new List <ExpandoObject>();
            dynamic rec1 = new ExpandoObject();

            rec1.Id       = 1;
            rec1.Name     = "Mark";
            rec1.IsActive = true;
            rec1.Message  = new ChoCDATA("Test");
            rec1.Array    = al;
            rec1.Lint     = lint;
            //rec1.HT = ht;
            rec1.Dict = dict;
            objs.Add(rec1);

            dynamic rec2 = new ExpandoObject();

            rec2.Id       = 2;
            rec2.Name     = "Jason";
            rec2.IsActive = true;
            rec2.Message  = new ChoCDATA("Test");
            objs.Add(rec2);

            StringBuilder sb = new StringBuilder();

            using (var parser = new ChoXmlWriter(sb).WithXPath("Employees/Employee"))
            {
                parser.Write(objs);
            }
            actual = sb.ToString();

            Assert.AreEqual(expected, actual);

            //var a = ChoXmlReader.LoadText(sb.ToString()).ToArray();
            //var config = new ChoXmlRecordConfiguration();
            ////config.Configure(c => c.RootName = "Root");
            //Console.WriteLine(ChoXmlWriter.ToText(a.First(), config));
        }
Exemplo n.º 8
0
        public static void CustomMemberSerialization()
        {
            string expected = @"<Choices>
  <Choice>
    <Emp>
    <Id>0</Id>
    <Name>Raj</Name>
  </Emp>
    <Ids>
    <int>1</int>
    <int>2</int>
    <int>3</int>
  </Ids>
    <EmpArrs>
      <Emp>
    <Id>1</Id>
    <Name>Tom</Name>
  </Emp>
  <Emp>
    <Id>2</Id>
    <Name>Mark</Name>
  </Emp>
  </EmpArrs>
    <Options>op 1,op 2</Options>
  </Choice>
  <Choice>
    <Emp>
    <Id>0</Id>
    <Name>Raj</Name>
  </Emp>
    <Ids>
    <int>1</int>
    <int>2</int>
    <int>3</int>
  </Ids>
    <EmpArrs>
      <Emp>
    <Id>1</Id>
    <Name>Tom</Name>
  </Emp>
  <Emp>
    <Id>2</Id>
    <Name>Mark</Name>
  </Emp>
  </EmpArrs>
    <Options>op 1,op 2</Options>
  </Choice>
</Choices>";
            string actual   = null;

            var sb = new StringBuilder();

            using (var p = new ChoXmlWriter <Choice>(sb)
                           .WithField("Options", valueConverter: o => String.Join(",", o as string[]))
                           //.Configure(c => c.Formatting = System.Xml.Formatting.None)
                   )
            {
                List <Choice> l = new List <Choice>
                {
                    new Choice
                    {
                        Options = new[] { "op 1", "op 2" },
                        EmpArr  = new Emp[] { new Emp {
                                                  Id = 1, Name = "Tom"
                                              }, new Emp {
                                                  Id = 2, Name = "Mark"
                                              }, null },
                        Emp = new Emp {
                            Id = 0, Name = "Raj"
                        },
                        //EmpDict = new Dictionary<int, Emp> { { 1, new Emp { Id = 11, Name = "Tom1" } } },
                        Ids = new List <int> {
                            1, 2, 3
                        }
                    },
                    new Choice
                    {
                        Options = new[] { "op 1", "op 2" },
                        EmpArr  = new Emp[] { new Emp {
                                                  Id = 1, Name = "Tom"
                                              }, new Emp {
                                                  Id = 2, Name = "Mark"
                                              }, null },
                        Emp = new Emp {
                            Id = 0, Name = "Raj"
                        },
                        //EmpDict = new Dictionary<int, Emp> { { 1, new Emp { Id = 11, Name = "Tom1" } } },
                        Ids = new List <int> {
                            1, 2, 3
                        }
                    }
                };
                p.Write(l);
            }
            actual = sb.ToString();

            Console.WriteLine(actual);
            //Assert.AreEqual(expected, actual);
            //Console.WriteLine(ChoXmlWriter.ToText<Choice>(new Choice { Options = new[] { "op 1", "op 2" } }));
        }
Exemplo n.º 9
0
        public static void CustomNodeNameTest()
        {
            string xml1 = @"<Root>
  <Node1>
    <Id>1</Id>
    <FirstName>Tom</FirstName>
  </Node1>
  <Node2>
    <Id>2</Id>
    <FirstName>Mark</FirstName>
  </Node2>
</Root>";

            using (var r = ChoXmlReader.LoadText(xml1))
            {
                foreach (var rec in r)
                {
                    Console.WriteLine(rec.Dump());
                }
            }

            return;

            string csv = @"Id, First Name
1, Tom
2, Mark";

            StringBuilder xml = new StringBuilder();

            using (var r = ChoCSVReader.LoadText(csv)
                           .WithFirstLineHeader())
            {
                using (var w = new ChoXmlWriter(xml)
                               .ErrorMode(ChoErrorMode.ThrowAndStop)
                               .Setup(s => s.CustomeNodeNameOverride += (o, e) =>
                {
                    e.NodeName = $"Node{e.Index}";
                })
                       )
                {
                    w.Write(r);
                }
            }

            Console.WriteLine(xml.ToString());

            //using (var reader = new ChoCSVReader("C:\\Server Media\\test3.csv")
            //    .WithFirstLineHeader()
            //    .Configure(c => c.FileHeaderConfiguration.IgnoreColumnsWithEmptyHeader = true)
            //    )
            //{
            //    using (var writer = new ChoXmlWriter(sb)
            //        .Configure(c => c.RootName = "Records")
            //        .Configure(c => c.NodeName = "Record")
            //        .Configure(c => c.EmptyXmlNodeValueHandling = ChoEmptyXmlNodeValueHandling.Empty)
            //        .Configure(c => c.ErrorMode = ChoErrorMode.ThrowAndStop)
            //        )
            //    {
            //        writer.Write(reader.Select(r =>
            //        {
            //            r.RenameKey("Company Name", "CompanyName");
            //            return r;
            //        }));
            //    }
            //}
        }
Exemplo n.º 10
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (InputFileTextBox.Text == "")
            {
                return;
            }
            string InputText = System.IO.File.ReadAllText(InputFileTextBox.Text);

            //Console.WriteLine(InputText);
            InputText = Regex.Replace(InputText, ":", "_");
            InputText = Regex.Replace(InputText, "\"", "");


            //double JulianDate = StartMJD + 2400000.5;

            List <ProcessedPositions> processedPositions = new List <ProcessedPositions>();
//            processedPositions.Add(new ProcessedPositions() { ID = 0, PanelName = "test" });
            double Alt;
            double Az;
            int    count = 0;

            foreach (var rec in ChoCSVReader <Position> .LoadText(InputText).WithFirstLineHeader())
            {
                Console.WriteLine($"panelname: " + rec.panelname.ToString());
                Console.WriteLine($"RA_decimal: {rec.RA_decimal}");
                Console.WriteLine($"Dec_decimal: {rec.Dec_decimal}");
                (Alt, Az) = ConvertAltAz(rec.RA_decimal, rec.Dec_decimal, StartJulian);

                processedPositions.Add(new ProcessedPositions()
                {
                    ID = count, PanelName = rec.panelname.ToString(), Dec_decimal = rec.Dec_decimal, RA_decimal = rec.RA_decimal, Alt = Alt, Az = Az, TimeShot = utility.DateJulianToLocal(StartJulian)
                });

                StartJulian = StartJulian + (Convert.ToDouble(MinutesPerShotTextBox.Text) / 1440);
                count++;
            }
            OutputDataGrid.ItemsSource = processedPositions;
            UpdateAutoTimeZone();

            StringBuilder sb = new StringBuilder();

            using (var p = ChoCSVReader.LoadText(InputText).WithFirstLineHeader())
            {
                //    Console.WriteLine(p.ToString());
                using (var w = new ChoXmlWriter(sb)
                               .Configure(c => c.RootName = "Mosaic")
                               .Configure(c => c.NodeName = "Position")
                       )
                    w.Write(p);
            }
            //Console.WriteLine(sb.ToString());

            //InputXML =

            /*
             * try
             * {
             *
             *  StringReader SR_InputXML = new StringReader(sb.ToString());
             *  XmlReader xr = XmlReader.Create(SR_InputXML);
             *
             *  XslCompiledTransform myXSLT;
             *  myXSLT = new XslCompiledTransform();
             *  //                myXSLT.Load(System.IO.Directory.GetCurrentDirectory() + "\\" + TemplateComboBox.SelectedItem.ToString());
             *  myXSLT.Load(files[TemplateComboBox.SelectedIndex]);
             *
             *  //myXSLT.Load('C:\Users\3ricj\source\repos\PositionTransmogrifier\bin\Debug\QuickShot.xslt');
             *  XmlTextWriter myWriter = new XmlTextWriter(OutputXMLFile, null);
             *  myXSLT.Transform(xr, null, myWriter);
             * }
             * catch { MessageBox.Show("Error performing conversion"); }
             *
             * MessageBox.Show("Converted file: " + OutputXMLFile);
             *
             * //System.Windows.Application.Current.Shutdown();
             */
        }