Beispiel #1
0
        public static void Query(string was, string wo)
        {
            string dirName = System.IO.Path.GetDirectoryName(typeof(Program).Assembly.Location);
            string time    = System.DateTime.Now.ToString("yyyyMMdd_HHmmss_fff", System.Globalization.CultureInfo.InvariantCulture);

            string logFile    = System.IO.Path.Combine(dirName, time + "_Logfile.log.txt");
            string resultFile = System.IO.Path.Combine(dirName, time + "_Result.txt.xml");

            System.Console.WriteLine("Eröffne Logfile \"" + logFile + "\".");

            string url     = GetSearchUrl(was, wo);
            string xmlText = TelSearch.HttpRequest.HTTP_Get(logFile, url);

            if (xmlText != null)
            {
                cFeed telsearch = Tools.XML.Serialization.DeserializeXmlFromString <cFeed>(xmlText);

                Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, System.Console.Out);
                Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, resultFile);

                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine("XML-Resultate werdenn nach \"" + resultFile + "\" geschrieben.");
            }
            else
            {
                System.Console.WriteLine("Fehler beim Abruf von tel.search-XML.");
            }
        }
Beispiel #2
0
        // http://tel.search.ch/api/?was=john+meier&key=IhrSchluessel
        // cor:
        // http://tel.search.ch/api/help
        // http://admin.tel.search.ch/api/getkey#terms

        // http://blog.unto.net/add-opensearch-to-your-site-in-five-minutes.html
        static void Test()
        {
            string loc = System.Reflection.Assembly.GetExecutingAssembly().Location;

            loc = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(loc), @"..\..\".Replace('\\', System.IO.Path.DirectorySeparatorChar));
            loc = System.IO.Path.GetFullPath(loc);


            string fn = System.IO.Path.Combine(loc, "JohnMeier.xml");
            //fn = System.IO.Path.Combine(loc, "MeierError.xml");

            //Person pers = new Person();
            //Tools.XML.Serialization.SerializeToXml<Person>(pers, System.Console.Out);

            //cFeed telsearch = Tools.XML.Serialization.DeserializeXmlFromFile<cFeed>(fn);
            //string strText = System.IO.File.ReadAllText(fn, System.Text.Encoding.UTF8);

            string ApiKey = SecretManager.GetSecret <string>("tel.search.ch API Key");


            string name = "John Meier";

            string strURL = "http://tel.search.ch/api/?was=john+meier&key=API_KEX_HERE";

            strURL = string.Format("http://tel.search.ch/api/?was={0}&key={1}", System.Web.HttpUtility.UrlEncode(name), ApiKey);
            string strText = TelSearch.HttpRequest.HTTP_Get(@"D:\log_telsearch.log.txt", strURL);


            cFeed telsearch = Tools.XML.Serialization.DeserializeXmlFromString <cFeed>(strText);

            Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, System.Console.Out);
            Tools.XML.Serialization.SerializeToXml <cFeed>(telsearch, @"d:\lol.xml");


            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            System.Console.WriteLine(js.Serialize(telsearch));

            //System.Web.Script.Serialization.JavaScriptConverter jcon = new System.Web.Script.Serialization.JavaScriptConverter();

            // http://stackoverflow.com/questions/814001/json-net-convert-json-string-to-xml-or-xml-to-json-string
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.LoadXml(strText);


            string jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);

            // To convert JSON text contained in string json into an XML node
            System.Xml.XmlDocument doc2 = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(jsonText);
        } // End Sub Main