コード例 #1
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;
                    var Repository = new Repository();
                    var Items      = await Repository.GetCats();

                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }

                //mostrar uma mensagem em caso de que se tenha gerado uma exceção.
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
コード例 #2
0
        //Atualiza os dados locais do Gato de maneira assincrona
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try {
                    IsBusy = true;
                    // cria instancia do repositório e inicia a tarefa assincrona
                    var Repository = new Repository();
                    var Items      = await Repository.GetCatsAzure();

                    //Limpa lista de e adiciona valores atualizados
                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                } catch (Exception ex) {
                    Error = ex;
                } finally {
                    IsBusy = false;
                }
                // se ocorreu um erro mostre para o usuário
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
コード例 #3
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception error = null;

                try
                {
                    IsBusy = true;
                    var Repositaro = new Repository();
                    var Items      = await Repositaro.GetCats();

                    Cats.Clear();
                    foreach (var Cat in Items)
                    {
                        Cats.Add(Cat);
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
                finally
                {
                    if (error != null)
                    {
                        await Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Error", error.Message, "Ok");
                    }
                    IsBusy = false;
                }
            }

            return;
        }
コード例 #4
0
        public async Task GetCats()
        {
            if (!IsBusy)
            {
                try
                {
                    IsBusy = true;
                    var items = await _repository.GetCats();

                    Cats.Clear();
                    foreach (var cat in items)
                    {
                        Cats.Add(cat);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;

                    if (Error != null)
                    {
                        await Application.Current.MainPage.DisplayAlert("Error!", Error.Message, "Ok");
                    }
                }
            }
        }
コード例 #5
0
        public async Task LoadAsync()
        {
            Int64 startTicks = Log.VIEWMODEL("(NavigationViewModel) Enter", Common.LOG_CATEGORY);

            var lookupCats = await _CatLookupDataService.GetCatLookupAsync();

            Cats.Clear();

            foreach (var item in lookupCats)
            {
                Cats.Add(
                    new NavigationItemViewModel(item.Id, item.DisplayMember,
                                                nameof(CatDetailViewModel),
                                                EventAggregator, DialogService));
            }

            var lookupDogs = await _DogLookupDataService.GetDogLookupAsync();

            Dogs.Clear();

            foreach (var item in lookupDogs)
            {
                Dogs.Add(
                    new NavigationItemViewModel(item.Id, item.DisplayMember,
                                                nameof(DogDetailViewModel),
                                                EventAggregator, DialogService));
            }

            //TODO(crhodes)
            // Load more TYPEs as needed here

            Log.VIEWMODEL("(NavigationViewModel) Exit", Common.LOG_CATEGORY, startTicks);
        }
コード例 #6
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;
                    var repository = new Repository();
                    var items      = await repository.GetCats();

                    Cats.Clear();
                    Cats.AddRange(items);
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    if (Error != null)
                    {
                        await messageService.ShowOkAsync("Error!", Error.Message);
                    }
                    IsBusy = false;
                }
            }
            return;
        }
コード例 #7
0
        async Task GetCats()
        {
            if (!IsBusy)
            {
                Exception Error = null;
                try
                {
                    IsBusy = true;
                    var repo  = new Repository();
                    var items = await repo.GetCats();

                    Cats.Clear();
                    foreach (var item in items)
                    {
                        Cats.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    Error = ex;
                }
                finally
                {
                    IsBusy = false;
                }
                if (Error != null)
                {
                    await Xamarin.Forms.Application.Current.MainPage.DisplayAlert(
                        "Error!", Error.Message, "OK");
                }
            }
            return;
        }
コード例 #8
0
 /// <summary>
 /// Loads collection from Json file and replaces current collection
 /// </summary>
 public void LoadFromJson()
 {
     Cats.Clear();
     using (StreamReader fs = File.OpenText("Cats.json"))
     {
         JsonSerializer serializer = new JsonSerializer();
         tempCats = (List <Cat>)serializer.Deserialize(fs, typeof(List <Cat>));
         foreach (var item in tempCats)
         {
             Cats.Add(item);
         }
     }
 }
コード例 #9
0
        /// <summary>
        /// Loads collection from Xml file and replaces current collection
        /// </summary>
        public void LoadFromXml()
        {
            XmlSerializer formatter = new XmlSerializer(typeof(List <Cat>));

            using (FileStream fs = new FileStream("Cats.xml", FileMode.OpenOrCreate))
            {
                tempCats = (List <Cat>)formatter.Deserialize(fs);
                Cats.Clear();
                fs.Close();
                foreach (var item in tempCats)
                {
                    Cats.Add(item);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Execute the LoadCats command.
        /// </summary>
        /// <returns>Asynchronous task.</returns>
        private async Task ExecuteLoadCatsCommand()
        {
            try
            {
                Cats.Clear();
                if (DataStore != null)
                {
                    var cats = await DataStore.GetAllAsync();

                    foreach (var cat in cats)
                    {
                        Cats.Add(cat);
                    }
                }
            }
            catch (Exception error)
            {
                Debug.WriteLine(error);
            }
            finally
            {
                IsBusy = false;
            }
        }