当前位置: 首页>>代码示例>>C#>>正文


C# Api.getApiData方法代码示例

本文整理汇总了C#中Api.getApiData方法的典型用法代码示例。如果您正苦于以下问题:C# Api.getApiData方法的具体用法?C# Api.getApiData怎么用?C# Api.getApiData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Api的用法示例。


在下文中一共展示了Api.getApiData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getDelays

    // Zijn er vertragingen voor deze gebruiker
    // op zijn opgeslagen route's?
    public string getDelays()
    {
        IList<BLLfavorites> routes = leesbareRoutes();

        // Zoek naar vertragingen
        Api api = new Api();

        foreach (var route in routes)
        {
            api.startStation = route.startStation;
            api.eindStation = route.eindStation;
        }

        XDocument doc = null;
        //Api irail = new Api();
        doc = api.getApiData("connections", "NL", "xml");

        Int16 test = 0;
        Boolean delayFound = false;
        IList<int> delays = null;

        int j = 0;

        foreach (var conn in doc.Elements("connections").Elements("connection"))
        {
            test = Convert.ToInt16(conn.Element("departure").Attribute("delay").Value);
            //delays.Add(Convert.ToInt16(conn.Element("departure").Attribute("delay").Value));
            //var test2 = conn.Element("departure").Attribute("delay").Value;
            if (test > 0)
            {
                delayFound = true;
            }
            j++;
        }

        if (delayFound == true)
        {
            return "Er zijn vertragingen gevonden";
        }
        else
        {
            return "Er zijn geen vertragingen gevonden";
        }
    }
开发者ID:Jan-Bart,项目名称:Not-a-school-project,代码行数:46,代码来源:BLLfavorites.cs

示例2: getStationName

    public string getStationName(string statID)
    {
        // Haal de stationslijst op
        XDocument doc = null;
        Api irail = new Api();
        doc = irail.getApiData("stations", "NL", "xml");

        // Zoek de naam van het station met het gegeven id
        List<Station> stations = (from stationss in doc.Elements("stations").Elements("station")
                                  where stationss.Attribute("id").Value == statID
                                  select new Station
                                  {
                                      stationNaam = stationss.Value,
                                      stationId =  stationss.Attribute("id").Value
                                  }).ToList();

        // Geef de naam van het station terug
        return stations[0].stationNaam;
    }
开发者ID:Jan-Bart,项目名称:Not-a-school-project,代码行数:19,代码来源:Station.cs

示例3: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["longitude"] == null || Session["latitude"] == null)
        {
            if (Request.Form["txtLng"] == null || Request.Form["txtLat"] == null)
            {
                Response.Redirect("~/requestLocation.aspx");
            }
            else
            {
                Session["longitude"] = Request.Form["txtLng"];
                Session["latitude"] = Request.Form["txtLat"];
            }
        }

        double myX = 0;
        double myY = 0;

        try
        {
            myX = Double.Parse(Session["longitude"].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            myY = Double.Parse(Session["latitude"].ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-us"));
        }
        catch (Exception)
        {
            Response.Redirect("~/overview.aspx");
        }

        GLatLng p1 = new GLatLng();

        p1.lat = myY;
        p1.lng = myX;

        GMap1.setCenter(p1, 15);

        GMap1.addGMapUI(new GMapUI());

        GMap1.Height = 400;
        GMap1.Width = 800;

        GMapUIOptions options = new GMapUIOptions();
        options.maptypes_hybrid = true;
        options.keyboard = true;
        options.maptypes_physical = true;
        options.zoom_scrollwheel = true;

        GIcon icoon = new GIcon();
        icoon.image = "img/userLocation.png";
        icoon.iconSize = new GSize(32, 32);
        icoon.shadowSize = new GSize(60, 32);

        GMarker marker1 = new GMarker(p1, icoon);
        GMap1.addGMarker(marker1);

        GInfoWindow userWindow = new GInfoWindow();
        userWindow.gMarker = marker1;
        userWindow.html = "<h3>U bevindt zich hier</h3>";
        GMap1.addInfoWindow(userWindow);

        Api api = new Api();
        XDocument doc = api.getApiData("stations/", "NL", "xml");

        foreach (XElement d in doc.Descendants("stations").Descendants("station"))
        {
            string lat = d.Attribute("locationY").Value;
            string lng = d.Attribute("locationX").Value;

            double y = Double.Parse(lat, System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            double x = Double.Parse(lng, System.Globalization.CultureInfo.GetCultureInfo("en-us"));

            double distance = GetDistanceBetweenPoints(myX, myY, x, y);

            Station s = new Station(d.Value.ToString(), y, x, distance);
            stations.Add(s);
        }

        var stationsQueryAble = stations.AsQueryable();
        stationsQueryAble = stationsQueryAble.OrderBy(stat => stat.afstandTotHuidigeLocatie);

        stations = stationsQueryAble.ToList();

        for (int i = 0; i < 5; i++)
        {
            GLatLng p2 = new GLatLng();
            p2.lat = stations[i].locY;
            p2.lng = stations[i].locX;
            GMarker marker = new GMarker(p2);
            GMap1.addGMarker(marker);

            GInfoWindow win1 = new GInfoWindow();

            win1.gMarker = marker;
            win1.html = "<h3><a href='overview.aspx?station=" + stations[i].stationNaam + "'>" + stations[i].stationNaam + " station</a></h3><p>afstand: " + Math.Round(stations[i].afstandTotHuidigeLocatie, 2) + "km</p>";
            GMap1.addInfoWindow(win1);
        }
    }
开发者ID:Jan-Bart,项目名称:Not-a-school-project,代码行数:96,代码来源:Default.aspx.cs

示例4: getList

    protected void getList(string station)
    {
        try
        {
            string startStation = station;

            // XML ophalen
            XDocument doc = null;
            Api irail = new Api();
            doc = irail.getApiData("liveboard/?station=" + startStation + "&fast=true", "NL", "xml");

            // List leegmaken (eventuele data van vorige request zit er nog in)
            departures.Clear();

            foreach (XElement d in doc.Descendants("departure"))
            {
                // Vertraging parsen naar datetimes
                string strDelay = d.Attribute("delay").Value;

                if (strDelay == "cancel")
                {
                    strDelay = "0";
                }

                double dblDelay = Convert.ToDouble(strDelay);
                DateTime dtDelay = new DateTime();

                // Jaar op 1900 zetten, anders klaagt sql bij insert (jaar mag niet 0 zijn)
                dtDelay = dtDelay.AddYears(1900);
                dtDelay = dtDelay.AddSeconds(dblDelay);

                // Tijd parsen naar datetime
                XElement timeNode = d.Element("time");
                string strTime = timeNode.Attribute("formatted").Value;

                DateTime time = DateTime.Parse(strTime);
                // ToUniversalTime (anders wordt er 1u bijgeteld, zomer-winteruur?)
                time = time.ToUniversalTime();

                // Andere data opvangen
                string destinationStation = d.Element("station").Value;
                string platform = d.Element("platform").Value;
                string vehicle = d.Element("vehicle").Value;

                // Nieuw object maken met data
                Departure departure = new Departure(startStation, destinationStation, platform, vehicle, time, dtDelay);

                // Toevoegen aan list
                departures.Add(departure);
            }

            // Data tegen repeater smijten
            rptDepartures.DataSource = departures;
            rptDepartures.DataBind();
            overviewPanel.Visible = true;
        }
        catch (Exception ex)
        {
            feedback.Attributes["class"] = "alert-message block-message";
            lblFeedback.Text = "Er is een fout opgetreden bij het laden van het overzicht.";
        }
    }
开发者ID:Jan-Bart,项目名称:Not-a-school-project,代码行数:62,代码来源:overview.aspx.cs


注:本文中的Api.getApiData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。