Beispiel #1
0
        protected override async Task InitializeOnceAsync(INavigationParameters parameters)
        {
            await base.InitializeOnceAsync(parameters);

            ValidationSessionId = (int)parameters["id"];
            Title = (string)parameters["name"];

            ValidationSession validationSession = await AppDataService.GetValidationSessionByIdAsync(ValidationSessionId);

            Mapper.Map(validationSession, SamplePointsViewModel);

            if (Connectivity.NetworkAccess == NetworkAccess.Internet)
            {
                // TODO: Localization
                NotificationService.Notify("Synchronizing points...");

                await ApiClient.GetValidationSessionSampleItemsByIdAsync(ValidationSessionId)
                .ContinueWith(async(result) =>
                {
                    Mapper.Map(result.Result, SamplePointsViewModel,
                               opt => opt.Items[nameof(ValidationSession.Id)] = ValidationSessionId);

                    Extent extent = SamplePointsViewModel.Points.GroupBy(x => true)
                                    .Select(x => new
                    {
                        top    = x.Max(y => y.Latitude),
                        right  = x.Max(y => y.Longitude),
                        bottom = x.Min(y => y.Latitude),
                        left   = x.Min(y => y.Longitude),
                    })
                                    .Select(x => new Extent(x.top, x.left, x.right, x.bottom))
                                    .Single();

                    EventAggregator.GetEvent <ZoomToExtentEvent>().Publish(extent);

                    AppDataService.DisableDetectChanges();

                    Mapper.Map(SamplePointsViewModel, validationSession, opt =>
                    {
                        opt.Items[nameof(ValidationSession)] = validationSession;
                        opt.Items[nameof(LegendItem)]        = validationSession.LegendItems.ToDictionary(x => x.Id, x => x);
                    });

                    AppDataService.EnableDetectChanges();
                    await AppDataService.SaveChangesAsync();

                    // TODO: Localization
                    NotificationService.Notify("Points successfully synchronized!");
                });
            }
            else
            {
                Extent extent = SamplePointsViewModel.Points.GroupBy(x => true)
                                .Select(x => new
                {
                    top    = x.Max(y => y.Latitude),
                    right  = x.Max(y => y.Longitude),
                    bottom = x.Min(y => y.Latitude),
                    left   = x.Min(y => y.Longitude),
                })
                                .Select(x => new Extent(x.top, x.left, x.right, x.bottom))
                                .Single();

                EventAggregator.GetEvent <ZoomToExtentEvent>().Publish(extent);
            }

            MapClickCommand = new DelegateCommand(MapClickAsync);
        }