Наследование: ViewModelBase
Пример #1
0
 public void TrackNavigateToParkingLotEvent(MetaDataCityRow city, ParkingLot parkingLot)
 {
     var properties = new Dictionary<string, string>
     {
         { "city", city.Id },
         { "parkingLot", parkingLot.Id }
     };
     _client.TrackEvent("Navigate to parking lot", properties);
     _tracker.SendEvent("ui_action", "navigate_to_parking_lot", city.Id + " > " + parkingLot.Id, 0);
 }
Пример #2
0
 public static void UpdateParkingLots(this VoiceCommandPhrases phrase, MetaDataCityRow city, IEnumerable<ParkingLot> lots)
 {
     var item = phrase.Cities.FirstOrDefault(x => x.Id == city.Id);
     if (item != null)
     {
         item.ParkingLots = lots.Select(x => new VoiceCommandCityPhrase
         {
             Id = x.Id,
             Name = x.Name
         }).ToList();
     }
 }
Пример #3
0
 public static void UpdateCity(this VoiceCommandPhrases phrase, MetaDataCityRow city)
 {
     var item = phrase.Cities.FirstOrDefault(x => x.Id == city.Id);
     if (item == null)
     {
         item = new VoiceCommandMetaDataPhrase
         {
             Id = city.Id
         };
         phrase.Cities.Add(item);
     }
     item.Name = city.Name;
 }
Пример #4
0
        public void HandleApiExceptionForForecastData(ApiException e, MetaDataCityRow city, ParkingLot lot)
        {
            _tracking.TrackException(e, new Dictionary<string, string>()
            {
                { "handled", "true"},
                { "type", "forecast"},
                { "city", city?.Id },
                { "lot", lot?.Id }
            });
            var mailStr = string.Format(EmailFormat,
                ContactEmail,
                Uri.EscapeDataString(string.Format(_res.ExceptionMailForecastSubject, lot?.Name, city?.Name)),
                Uri.EscapeDataString(string.Format(_res.ExceptionMailForecastBody, lot?.Name, city?.Name, e.Message))
                );
            var content = new ToastContent
            {
                Launch = "handledForecastApiException",
                Visual = new ToastVisual
                {
                    TitleText = new ToastText
                    {
                        Text = _res.ExceptionToastTitle
                    },

                    BodyTextLine1 = new ToastText
                    {
                        Text = string.Format(_res.ExceptionToastForecastContent, lot?.Name, city?.Name)
                    }
                },
                Actions = new ToastActionsCustom
                {
                    Buttons =
                    {
                        new ToastButton(_res.ExceptionToastShowInBrowserButton, city?.Url.ToString())
                        {
                            ActivationType = ToastActivationType.Protocol,
                        },
                        new ToastButton(_res.ExceptionToastContactDevButton, mailStr)
                        {
                            ActivationType = ToastActivationType.Protocol,
                        }
                    }
                }
            };
            ShowToast(content);
        }
Пример #5
0
 public void TrackReloadCityEvent(MetaDataCityRow city)
 {
     var properties = new Dictionary<string, string>
     {
         { "city", city.Id },
     };
     _client.TrackEvent("Reload city", properties);
     _tracker.SendEvent("ui_action", "reload_city", city.Id, 0);
 }
Пример #6
0
 public void TrackSelectParkingLotEvent(MetaDataCityRow city, ParkingLot parkingLot)
 {
     var properties = new Dictionary<string, string>
     {
         { "city", city?.Id },
         { "parkingLot", parkingLot?.Id }
     };
     _client.TrackEvent("Select parking lot", properties);
     _tracker.SendEvent("ui_action", "select_parking_lot", city?.Id + " > " + parkingLot?.Id, 0);
 }
Пример #7
0
 public void TrackSelectCityEvent(MetaDataCityRow city)
 {
     var properties = new Dictionary<string, string>
     {
         { "city", city?.Id },
     };
     _client.TrackEvent("Select city", properties);
     _tracker.SendEvent("ui_action", "select_city", city?.Id, 0);
 }
Пример #8
0
 private async Task<City> GetCity(string cityId, bool forceServerRefresh = false, MetaDataCityRow cityMetaData = null)
 {
     if (_cityLoading.ContainsKey(cityId) && _cityLoading[cityId] != null && !_cityLoading[cityId].IsFaulted && !_cityLoading[cityId].IsCompleted && !_cityLoading[cityId].IsCanceled)
     {
         if (!forceServerRefresh || _initialized)
         {
             return await _cityLoading[cityId];
         }
     }
     _cityLoading[cityId] = Task.Run(async () =>
     {
         Debug.WriteLine("[MainVm] GetCity for {0} (forcerefresh={1})", cityId, forceServerRefresh);
         if (!forceServerRefresh)
         {
             var offlineCity = await GetOfflineCityData(cityId);
             if (offlineCity != null)
             {
                 Debug.WriteLine("[MainVm] GetCity for {0} (forcerefresh={1}): found offline data", cityId,
                     forceServerRefresh);
                 return offlineCity;
             }
         }
         if (!InternetAvailable)
         {
             Debug.WriteLine(
                 "[MainVm] GetCity for {0} (forcerefresh={1}): internet not available, returning null", cityId,
                 forceServerRefresh);
             return null;
         }
         Debug.WriteLine("[MainVm] GetCity for {0} (forcerefresh={1}): perform request", cityId,
             forceServerRefresh);
         City city;
         try
         {
             city = await _client.GetCityAsync(cityId);
         }
         catch (ApiException e)
         {
             _exceptionService.HandleApiExceptionForCityData(e, MetaData.Cities.Get(cityId));
             return null;
         }
         Debug.WriteLine("[MainVm] GetCity for {0} (forcerefresh={1}): got response", cityId, forceServerRefresh);
         _cityHasOnlineData[cityId] = true;
         await Task.Run(() =>
         {
             Task.Factory.StartNew(async () =>
             {
                 await Task.Delay(4000);
                 _storage.SaveCityData(cityId, city);
             });
             Task.Factory.StartNew(async () =>
             {
                 await Task.Delay(2000);
                 _voiceCommands.UpdateParkingLotList(cityMetaData ?? SelectedCity, city);
             });
         });
         return city;
     });
     return await _cityLoading[cityId];
 }
Пример #9
0
        public MainViewModel(IParkenDdClient client,
            VoiceCommandService voiceCommandService,
            JumpListService jumpList,
            ParkingLotListFilterService filterService,
            SettingsService settings,
            StorageService storage,
            GeolocationService geo,
            TrackingService tracking,
            ExceptionService exceptionService)
        {
            _client = client;
            _voiceCommands = voiceCommandService;
            _jumpList = jumpList;
            _filterService = filterService;
            _settings = settings;
            _storage = storage;
            _geo = geo;
            _tracking = tracking;
            _exceptionService = exceptionService;

            Messenger.Default.Register(this, (SettingChangedMessage msg) =>
            {
                if (msg.IsSetting(nameof(_settings.ShowExperimentalCities)))
                {
                    var temp = SelectedCity;
                    _selectedCity = null;
                    RaisePropertyChanged(() => SelectedCity);
                    RaisePropertyChanged(() => MetaDataCities);
                    _selectedCity = temp;
                    RaisePropertyChanged(() => SelectedCity);
                }
            });

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(MetaDataCities))
                {
                    UpdateServiceData();
                }
            };

            NetworkInformation.NetworkStatusChanged += sender =>
            {
                UpdateInternetAvailability();
            };
            UpdateInternetAvailability();
        }
Пример #10
0
 private void CityChosen(MetaDataCityRow city)
 {
     SelectedCity = city;
 }