コード例 #1
0
        private IContainer ExecuteEx()
        {
            YQLQuery query = new YQLQuery();

            query.
            Select("*").
            From("csv").
            Where("url", Register.Instance.Get("URL", "HISTORIC_API") + Arguments.First(a => (a.Id() == "symbol")).Get <String>()).And("columns", "Date,Open,High,Low,Close,Volume,AdjClose");

            DownloadRessourceHandler <String> dl = new DownloadRessourceHandler <String>();

            String url = Helper.FormatQuery(Register.Instance.Get("URL", "PUBLIC_API"), query.Yield(), Register.Instance.Get("URL", "TABLES"));

            String result = dl.Acquire(
                new Uri(Helper.FormatQuery(Register.Instance.Get("URL", "PUBLIC_API"), query.Yield(), Register.Instance.Get("URL", "TABLES"))), Helper.HandleStream);

            XDocument doc = XDocument.Parse(result);

            if (!OperationHelper.IsValidYQLResponse(doc))
            {
                return(OperationHelper.HandleErrors(doc));
            }

            Result.RegisterProperty <String>("symbol", Arguments.First(a => (a.Id() == "symbol")).Get <String>());

            foreach (XElement element in doc.XPathSelectElements("/*/results/*"))
            {
                IContainer container = (IContainer)Activator.CreateInstance(Result.GetType());

                Boolean header = true;

                foreach (XElement child in element.XPathSelectElements("child::*"))
                {
                    if (!header)
                    {
                        container.RegisterProperty <String>(child.Name.LocalName, child.Value);
                    }
                    header = false;
                }

                Result.RegisterProperty <IContainer>(element.Element("Date").Value, container);
            }

            Result.RegisterProperty <String>("script", result);

            return(Result);
        }
コード例 #2
0
        private IContainer ExecuteEx()
        {
            YQLQuery query = new YQLQuery();

            query.
            Select("title, link, description, pubDate").
            From("rss").
            Where("url", Register.Instance.Get("URL", "RSS_API") + Arguments.First(a => (a.Id() == "symbol")).Get <String>());

            DownloadRessourceHandler <String> dl = new DownloadRessourceHandler <String>();


            String result = dl.Acquire(
                new Uri(Helper.FormatQuery(Register.Instance.Get("URL", "PUBLIC_API"), query.Yield(), Register.Instance.Get("URL", "TABLES"))), Helper.HandleStream);


            XDocument doc = XDocument.Parse(result);

            if (!OperationHelper.IsValidYQLResponse(doc))
            {
                return(OperationHelper.HandleErrors(doc));
            }

            foreach (XElement element in doc.XPathSelectElements("/*/*/item"))
            {
                IContainer container = (IContainer)Activator.CreateInstance(Result.GetType());

                foreach (XElement property in element.XPathSelectElements("child::*"))
                {
                    container.RegisterProperty <String>(property.Name.LocalName, property.Value);
                }

                Result.RegisterProperty <IContainer>(element.Element("title").Value, container);
            }

            Result.RegisterProperty <String>("script", result);

            return(Result);
        }