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


C# Train.CalculateMinutesToArrival方法代码示例

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


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

示例1: Main

            static void Main(string[] args)
            {
                int count;
                string trainKey;
                string station;
                string stationName;
                string route;
                string destination;
                string direction;
                string estArrivalTime;
                string runNumber;
                int isDelayed;
                int isArriving;
                List<Train> trains = new List<Train>();

                //Add your CTA API key here
                trainKey = null;

                //Add station here, CTA dev documentation has full list
                station = "30109";

                string type;

                if (station.Substring(0, 1) == "4")
                    type = "mapid";
                else
                    type = "stpid";

                //Imports XML data.
                XmlDocument APIDoc = null;
                XmlTextReader reader = new XmlTextReader("http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=" + trainKey + "&" + type + "=" + station);
                APIDoc = new XmlDocument();
                APIDoc.Load(reader);
                count = APIDoc.ChildNodes[1].SelectNodes("eta").Count;
                reader.Close();

                //Extracts data from XML and stroes in a Train object
                for (int i = 3; i < count + 2; i++)
                {
                    stationName = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[2].ChildNodes[0].Value;
                    route = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[5].ChildNodes[0].Value;
                    destination = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[3].ChildNodes[0].Value;
                    direction = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[8].ChildNodes[0].Value;
                    estArrivalTime = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[10].ChildNodes[0].Value;
                    runNumber = APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[4].ChildNodes[0].Value;
                    isDelayed = Convert.ToInt32(APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[13].ChildNodes[0].Value);
                    isArriving = Convert.ToInt32(APIDoc.ChildNodes[1].ChildNodes[i].ChildNodes[11].ChildNodes[0].Value);

                    Train train = new Train(stationName, route, destination, direction, runNumber);

                    train.Route = train.RouteNameConversion(route);
                    train.IsDelayed = train.IsTrainDelayed(isDelayed);
                    train.IsArriving = train.IsTrainArriving(isArriving);
                    train.ArrivalInMinutes = train.CalculateMinutesToArrival(estArrivalTime);
                    train.PrintString = train.PrintData();

                    trains.Add(train);
                }

                WriteListToConsole(trains);

                //WriteNextTrainToConsole(trains);

                Console.ReadLine();
            }
开发者ID:djgreen3,项目名称:CSharp-CTATrainTracker,代码行数:65,代码来源:Program.cs


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