public override async Task InitializeAsync(object navigationData) { CurrentDate = DateTime.Now; IsBusy = true; try { var weather = _weatherService.GetWeatherInfoAsync(); var events = _eventsService.GetEvents(); var suggestions = _ridesService.GetSuggestions(); var tasks = new List <Task> { weather, events, suggestions }; while (tasks.Count > 0) { var finishedTask = await Task.WhenAny(tasks); tasks.Remove(finishedTask); if (finishedTask.Status == TaskStatus.RanToCompletion) { if (finishedTask == weather) { var weatherResults = await weather; if (weatherResults is WeatherInfo) { var weatherInfo = weatherResults as WeatherInfo; Location = weatherInfo.LocationName; Temp = Math.Round(weatherInfo.Temp).ToString(); } } else if (finishedTask == events) { var eventsResults = await events; Events = new ObservableCollection <Event>(eventsResults); } else if (finishedTask == suggestions) { var suggestionsResults = await suggestions; Suggestions = new ObservableCollection <Suggestion>(suggestionsResults); } } } } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { await DialogService.ShowAlertAsync("Communication error", "Error", "Ok"); } catch (Exception ex) { Debug.WriteLine($"Error loading data in: {ex}"); } IsBusy = false; }
public async Task Initialize(object navigationData) { CurrentDate = GlobalSettings.EventDate; IsBusy = true; try { var weather = _weatherService.GetDemoWeatherInfoAsync(); var events = _eventsService.GetEvents(); var suggestions = _ridesService.GetSuggestions(); var tasks = new List <Task> { weather, events, suggestions }; while (tasks.Count > 0) { var finishedTask = await Task.WhenAny(tasks); tasks.Remove(finishedTask); if (finishedTask.Status == TaskStatus.RanToCompletion) { if (finishedTask == weather) { var weatherResults = await weather; if (weatherResults is WeatherInfo) { var weatherInfo = weatherResults as WeatherInfo; Location = weatherInfo.LocationName; Temp = Math.Round(weatherInfo.Temp).ToString(); } } else if (finishedTask == events) { var eventsResults = await events; Events = new ObservableCollection <Event>(eventsResults); } else if (finishedTask == suggestions) { var suggestionsResults = await suggestions; Suggestions = new ObservableCollection <Suggestion>(suggestionsResults); } } } var traditions = new List <Tradition>(); var restaurants = new List <Restaurant>(); //销量 //traditions = await _censusService.GetTraditions(10, 0); //restaurants = await _censusService.GetRestaurants(10, 0); try { var traditionsModel = await _cacheManager.Get <List <Tradition> >(GlobalSettings.traditions_key); if (traditionsModel != null) { traditions = traditionsModel; } else { traditions = await _censusService.GetTraditions(10, 0); await _cacheManager.Set <List <Tradition> >(GlobalSettings.traditions_key, traditions); } // var restaurantsModel = await _cacheManager.Get <List <Restaurant> >(GlobalSettings.restaurants_key); if (restaurantsModel != null) { restaurants = restaurantsModel; } else { restaurants = await _censusService.GetRestaurants(10, 0); await _cacheManager.Set <List <Restaurant> >(GlobalSettings.restaurants_key, restaurants); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } var ridesResult = new List <Stats>(); foreach (var t in traditions) { if (t != null) { ridesResult.Add(new Stats { Title = t.BaseInfo.EndPointStorsName, Label1 = string.Format("{0}月销量", DateTime.Now.AddMonths(-1).Month), Label2 = string.Format("{0}月销量", DateTime.Now.Month), Value1 = "0", Value2 = "0" }); } } foreach (var t in restaurants) { if (t != null) { ridesResult.Add(new Stats { Title = t.BaseInfo.EndPointStorsName, Label1 = string.Format("{0}月", DateTime.Now.AddMonths(-1).Month), Label2 = string.Format("{0}月", DateTime.Now.Month), Value1 = "0", Value2 = "0" }); } } Statistics = new ObservableCollection <Stats>(ridesResult); //合计 TotalSum = 0; var statistics = await _censusService.GetStatistics(); statistics.ForEach(s => { TotalSum += s.EndPointSum; }); } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { //await _dialogService.ShowAlertAsync("Communication error", "Error", "Ok"); } catch (Exception ex) { Debug.WriteLine($"Error loading data in: {ex}"); } IsBusy = false; }
public override async Task InitializeAsync(object navigationData) { CurrentDate = DateTime.Now; IsBusy = true; try { var members = _memberService.GetMembers(); var weather = _weatherService.GetWeatherInfoAsync(); var events = _eventsService.GetEvents(); var suggestions = _ridesService.GetSuggestions(); var tasks = new List <Task> { weather, events, suggestions, members }; while (tasks.Count > 0) { var finishedTask = await Task.WhenAny(tasks); tasks.Remove(finishedTask); if (finishedTask.Status == TaskStatus.RanToCompletion) { if (finishedTask == weather) { var weatherResults = await weather; if (weatherResults is WeatherInfo) { var weatherInfo = weatherResults as WeatherInfo; Location = weatherInfo.LocationName; Temp = Math.Round(weatherInfo.Temp).ToString(); } } else if (finishedTask == events) { var eventsResults = await events; Events = new ObservableCollection <Event>(eventsResults); } else if (finishedTask == suggestions) { var suggestionsResults = await suggestions; Suggestions = new ObservableCollection <Suggestion>(suggestionsResults); } else if (finishedTask == members) { var memberResults = await members; //Invities Invitees[] invitiesObject = memberResults.Invitees; Invities = invitiesObject.Length.ToString(); //Attendees Attendees[] attendeesObject = memberResults.MeetingAttendees; Joined = attendeesObject.Length.ToString(); //New or Introduers HashSet <string> PersonIds = new HashSet <string>(invitiesObject.Select(s => s.PersonId)); var results = attendeesObject.Where(m => !PersonIds.Contains(m.PersonId)); Newjoin = results.Count().ToString(); //Not joined int attendees_invited = Math.Abs(attendeesObject.Length - results.Count()); NotJoined = Math.Abs(invitiesObject.Length - attendees_invited).ToString(); //Members var NewMember = new ObservableCollection <MeetingMembers>(); var newEvent = new ObservableCollection <Event>(); foreach (Attendees person in attendeesObject) { MeetingMembers meetingmembers = new MeetingMembers(); Event meetingevent = new Event(); if (person.EmpName.ToString().Trim() == "NaN") { meetingmembers.EmpName = "NEW"; meetingevent.Name = "NEW"; } else { meetingmembers.EmpName = person.EmpName; meetingevent.Name = person.EmpName; } meetingmembers.PersonId = person.PersonId; if (person.Department.ToString().Trim() == "NaN") { meetingmembers.Department = "NEW"; } else { meetingmembers.Department = person.Department; } meetingmembers.Gender = person.Gender; if (person.Smile == "Sad") { meetingmembers.Smiley = "Smiley1.png"; meetingevent.Emoction = "Smiley1.png"; } else if (person.Smile == "Smile") { meetingmembers.Smiley = "Smiley.png"; meetingevent.Emoction = "Smiley.png"; } else { meetingmembers.Smiley = "Smiley.png"; meetingevent.Emoction = "Smiley.png"; } meetingmembers.ImagePath = GlobalSettings.MemberEndpoint.ToString() + person.BlobName; meetingevent.ImagePath = meetingmembers.ImagePath; meetingmembers.Attendence = "Off.png"; meetingevent.Attendence = "Off.png"; meetingevent.Title = "Title"; meetingevent.Email = "*****@*****.**"; meetingevent.PhoneNumber = "123"; meetingevent.Venue = new Venue { Name = "Venue" }; newEvent.Add(meetingevent); NewMember.Add(meetingmembers); } HashSet <string> Id_Invitees = new HashSet <string>(invitiesObject.Select(s => s.PersonId)); var notPresent = attendeesObject.Where(m => !Id_Invitees.Contains(m.PersonId)); foreach (var person in notPresent) { if (person.EmpName.ToString().Trim() != "NaN") { MeetingMembers meetingmembers = new MeetingMembers(); Event meetingevent = new Event(); if (person.EmpName.ToString().Trim() == "NaN") { meetingmembers.EmpName = "NEW"; meetingevent.Name = "New"; } else { meetingmembers.EmpName = person.EmpName; meetingevent.Name = person.EmpName; } meetingmembers.PersonId = person.PersonId; if (person.Department.ToString().Trim() == "NaN") { meetingmembers.Department = "NEW"; } else { meetingmembers.Department = person.Department; } meetingmembers.Gender = person.Gender; if (person.Smile == "Sad") { meetingmembers.Smiley = "Smiley1.png"; meetingevent.Emoction = "Smiley1.png"; } else if (person.Smile == "Smile") { meetingmembers.Smiley = "Smiley.png"; meetingevent.Emoction = "Smiley.png"; } else { meetingmembers.Smiley = "Smiley.png"; meetingevent.Emoction = "Smiley.png"; } meetingmembers.ImagePath = GlobalSettings.MemberEndpoint.ToString() + person.BlobName; meetingevent.ImagePath = meetingmembers.ImagePath; meetingmembers.Attendence = "On.png"; meetingevent.Attendence = "On.png"; meetingevent.Title = "Title"; meetingevent.Email = "*****@*****.**"; meetingevent.PhoneNumber = "123"; meetingevent.Venue = new Venue { Name = "Venue" }; newEvent.Add(meetingevent); NewMember.Add(meetingmembers); } } Members = NewMember; Events = newEvent; } } } } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { await DialogService.ShowAlertAsync("Communication error", "Error", "Ok"); } catch (Exception ex) { Debug.WriteLine($"Error loading data in: {ex}"); } IsBusy = false; }