示例#1
0
 public WindowsUniversalServices()
 {
     Compression  = new UniversalCompression();
     Cryptography = new UniversalCriptography();
     FileSystem   = new UniversalFileSystem();
     Http         = new UniversalHttpClient();
     Resources    = new UniversalResources();
     Location     = new UniversalLocation();
     Settings     = new UniversalPersistentSettings();
     MessageBox   = new MessageDialogService();
     Directions   = new UniversalDirections();
 }
        public static async Task Test(int count = 50)
        {
            var provider = new UniversalDirections();
            var sw       = Stopwatch.StartNew();
            var results  = await Task.WhenAll(Enumerable.Range(0, count).Select(async i =>
            {
                var swInner = Stopwatch.StartNew();
                var res     = await provider.WalkDistanceAsync(
                    47.473525, 19.052782,
                    47.478281 - 0.0033 * i, 19.043815
                    );
                sw.Stop();
                swInner.Stop();
                return(Tuple.Create(swInner.Elapsed, res));
            }));

            results = results.Where(r => r != null).ToArray();
            //var results = new List<Tuple<TimeSpan, RouteResult>>();
            //for (int i = 0; i < count; i++)
            //{
            //    var swInner = Stopwatch.StartNew();
            //    var res = await provider.QueryWalkDistance(
            //        new GeoCoordinate(47.473525, 19.052782),
            //        new GeoCoordinate(47.478281 - 0.0033 * i, 19.043815)
            //        );
            //    sw.Stop();
            //    swInner.Stop();
            //    results.Add(Tuple.Create(swInner.Elapsed, res));
            //}
            //results = results.Where(r => r != null).ToList();

            var average = TimeSpan.FromMilliseconds(results.Average(x => x.Item1.TotalMilliseconds));
            var total   = sw.Elapsed;

            await new MessageDialog(total + "\navg: " + average + "\ndist: " + results.First().Item2.DistanceInMeters + "\ntime: " + results.First().Item2.EstimatedDuration).ShowAsync();
        }