Ejemplo n.º 1
0
        public void ArivaSomePrices()
        {
            DatumLocator locator = new DatumLocator("StockPrices",
                                                    new Site("Ariva",
                                                             new Navigation(DocumentType.Html,
                                                                            OS.CombinePaths(TestDataRoot, "Recognition", "ariva.prices.${stock.isin}.html")),
                                                             new PathTableFormat("Ariava.Prices",
                                                                                 "/BODY[0]/DIV[5]/DIV[0]/DIV[3]/DIV[0]/TABLE[${TableIndex}]",
                                                                                 new FormatColumn("date", typeof(DateTime), "dd.MM.yy"),
                                                                                 new FormatColumn("open", typeof(double), "000000,0000"),
                                                                                 new FormatColumn("close", typeof(double), "000000,0000"),
                                                                                 new FormatColumn("volume", typeof(int), "000000,0000"))
            {
                SkipRows    = new int[] { 0, 1 },
                SkipColumns = new int[] { 0, 3, 4 }
            },
                                                             new DataContent("Euro")));

            LookupPolicy fetchPolicy = new LookupPolicy();

            fetchPolicy.Lut["${stock.isin}"] = "DE0005003404";
            fetchPolicy.Lut["${TableIndex}"] = "0";

            var webScrapSC = new ServiceProvider().Browser();
            var provider   = new GenericDatumProvider(webScrapSC, locator, fetchPolicy, null);

            var result = provider.Fetch();

            Assert.AreEqual("/BODY[0]/DIV[5]/DIV[0]/DIV[3]/DIV[0]/TABLE[${TableIndex}]", ((PathTableFormat)locator.Sites[0].Format).Path);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ResultTable);

            var table = result.ResultTable;

            Assert.AreEqual(21, table.Rows.Count);

            Assert.AreEqual(4, table.Columns.Count);
            Assert.AreEqual("date", table.Columns[0].ColumnName);
            Assert.AreEqual("open", table.Columns[1].ColumnName);
            Assert.AreEqual("close", table.Columns[2].ColumnName);
            Assert.AreEqual("volume", table.Columns[3].ColumnName);

            Assert.AreEqual(GetDate("2008-07-07"), (DateTime)table.Rows[0]["date"]);
            Assert.AreEqual(38.37d, (double)table.Rows[0]["open"], 0.000001d);
            Assert.AreEqual(38.93d, (double)table.Rows[0]["close"], 0.000001d);
            Assert.AreEqual(1155400, (int)table.Rows[0]["volume"]);

            Assert.AreEqual(GetDate("2008-06-09"), (DateTime)table.Rows[20]["date"]);
            Assert.AreEqual(45.21d, (double)table.Rows[20]["open"], 0.000001d);
            Assert.AreEqual(44.50d, (double)table.Rows[20]["close"], 0.000001d);
            Assert.AreEqual(1113865, (int)table.Rows[20]["volume"]);
        }
Ejemplo n.º 2
0
        public void TupleProperty()
        {
            var site = new Site("Ariva",
                                new Navigation(DocumentType.Html, string.Empty),
                                new SeparatorSeriesFormat("Ariava.Prices")
            {
                Anchor = Anchor.ForRow(new StringContainsLocator(0, ">>${TableIndex}<<"))
            },
                                new DataContent("Euro"));

            var fetchPolicy = new LookupPolicy();

            fetchPolicy.Lut["${TableIndex}"] = "0";

            var format = (SeparatorSeriesFormat)fetchPolicy.GetFormat(site);

            Assert.That(((StringContainsLocator)format.Anchor.Row).Pattern, Is.EqualTo(">>0<<"));
        }
Ejemplo n.º 3
0
        public void ArivaEps_DE0005140008()
        {
            var locator = new DatumLocator("Eps",
                                           new Site("Ariva",
                                                    new Navigation(DocumentType.Html,
                                                                   OS.CombinePaths(TestDataRoot, "Recognition", "ariva.fund.${stock.isin}.html")),
                                                    new PathSeriesFormat("Ariava.Eps")
            {
                Path               = "/BODY[0]/DIV[5]/DIV[0]/DIV[3]/TABLE[7]/TBODY[0]/TR[5]/TD[1]",
                TimeAxisPosition   = 1,
                Expand             = CellDimension.Row,
                SeriesNamePosition = 0,
                ValueFormat        = new FormatColumn("value", typeof(double), "000000,0000"),
                TimeAxisFormat     = new FormatColumn("year", typeof(int), "0000")
            },
                                                    new DataContent("Euro")));

            var fetchPolicy = new LookupPolicy();

            fetchPolicy.Lut["${stock.isin}"] = "DE0005140008";

            var webScrapSC = new ServiceProvider().Browser();
            var provider   = new GenericDatumProvider(webScrapSC, locator, fetchPolicy, null);

            var result = provider.Fetch();

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ResultTable);

            var table = result.ResultTable;

            Assert.AreEqual(6, table.Rows.Count);

            Assert.AreEqual(2002, (int)table.Rows[0][1]);
            Assert.AreEqual(0.64d, (double)table.Rows[0][0], 0.00001d);
            Assert.AreEqual(2007, (int)table.Rows[5][1]);
            Assert.AreEqual(13.65d, (double)table.Rows[5][0], 0.00001d);
        }
Ejemplo n.º 4
0
        public List <LookupPolicy> restPolicy(IUimDataContext datacontext, string lookupIDquery, string policyNoSearch)
        {
            List <LookupPolicy> list = new List <LookupPolicy>();
            string URL = selectCustomValue(datacontext.CustomValue, "RestURL=");

            //string URL = "https://api.fwd.co.th/dev-mock/dataentryFacadeService/fetchFundMasterData";
            // string urlParameters = "?api_key=123";
            try
            {
                LookupPolicy lookup = new LookupPolicy()
                {
                    lookupID = lookupIDquery, policyNo = policyNoSearch
                };
                string json = JsonConvert.SerializeObject(lookup);

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(URL);

                // Add an Accept header for JSON format.

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // List data response.
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, URL);
                request.Content = new StringContent(json);
                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage response = client.PostAsync(string.Empty, request.Content).Result;

                //System.Windows.MessageBox.Show("REST API");
                if (response.IsSuccessStatusCode)
                {
                    //System.Windows.MessageBox.Show(response.IsSuccessStatusCode.ToString());

                    // Parse the response body.
                    IEnumerable <LookupPolicy> lookupPolicy = response.Content.ReadAsAsync <IEnumerable <LookupPolicy> >().Result;  //Make sure to add a reference to System.Net.Http.Formatting.dll

                    // System.Windows.MessageBox.Show("START LOOP");
                    foreach (var d in lookupPolicy)
                    {
                        list.Add(new LookupPolicy {
                            TitleName = d.TitleName, firstName = d.firstName, lastName = d.lastName, idCardNo = d.idCardNo, policyNo = d.policyNo, birthDate = d.birthDate
                        });
                    }
                }
                else
                {
                    System.Windows.MessageBox.Show("API Lookup Policy FAIL");
                }



                client.Dispose();
                return(list);
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.ToString());
            }
            return(list);
        }