Exemplo n.º 1
0
        private void LoadAlbums()
        {
            try
            {
                String url    = string.Format("/{0}/albums", SelectedPage.Split(new [] { "||" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                string token  = SelectedPage.Split(new[] { "||" }, StringSplitOptions.RemoveEmptyEntries)[1];
                var    client = new FacebookClient
                {
                    AccessToken = AccessToken,
                    AppId       = ClientId,
                    AppSecret   = ClientSecret
                };
                Albums = new AsyncObservableCollection <ValuePair>();
                do
                {
                    dynamic albums = client.Get(url, new { limit = 25, offset = 0 });

                    foreach (dynamic data in albums.data)
                    {
                        Albums.Add(new ValuePair()
                        {
                            Value = data.id + "||" + token, Name = data.name
                        });
                    }

                    if (albums.paging != null && !String.IsNullOrEmpty(albums.paging.next))
                    {
                        url = albums.paging.next;
                    }
                    else
                    {
                        url = String.Empty;
                    }
                } while (!String.IsNullOrEmpty(url));
                if (string.IsNullOrEmpty(SelectedAlbum) && Albums.Any())
                {
                    SelectedAlbum = Albums[0].Value;
                }
            }
            catch (Exception)
            {
            }
        }
        private void LoadAlbums()
        {
            try
            {
                String url = string.Format("/{0}/albums", SelectedPage.Split(new []{"||"},StringSplitOptions.RemoveEmptyEntries)[0]);
                string token = SelectedPage.Split(new[] {"||"}, StringSplitOptions.RemoveEmptyEntries)[1];
                var client = new FacebookClient
                {
                    AccessToken = AccessToken,
                    AppId = ClientId,
                    AppSecret = ClientSecret
                };
                Albums = new AsyncObservableCollection<ValuePair>();
                do
                {
                    dynamic albums = client.Get(url, new { limit = 25, offset = 0 });

                    foreach (dynamic data in albums.data)
                    {
                        Albums.Add(new ValuePair() { Value = data.id+"||"+token, Name = data.name });
                    }

                    if (albums.paging != null && !String.IsNullOrEmpty(albums.paging.next))
                        url = albums.paging.next;
                    else
                        url = String.Empty;
                } while (!String.IsNullOrEmpty(url));
                if (string.IsNullOrEmpty(SelectedAlbum) && Albums.Any())
                {
                    SelectedAlbum = Albums[0].Value;
                }
            }
            catch (Exception)
            {

            }
        }
        public CreatePackagedSolutionViewModel(IDialogCoordinator dialogCoordinator)
        {
            #region Initialize collections

            Appliances = new AsyncObservableCollection <Appliance>();
            SetupFilterableView(Appliances);

            AppliancesInPackagedSolution     = new AsyncObservableCollection <ApplianceInstance>();
            AppliancesInPackagedSolutionView = CollectionViewSource.GetDefaultView(AppliancesInPackagedSolution);

            #endregion

            #region Initialize properties

            _dialogCoordinator = dialogCoordinator;
            PackagedSolution   = new PackagedSolution();

            #endregion

            #region Bind event listeners

            AppliancesInPackagedSolution.CollectionChanged += PackageSolutionAppliances_CollectionChanged;

            #endregion

            #region Command declarations

            NavigateBackCmd = new RelayCommand(async x =>
            {
                if (!IsDataSaved)
                {
                    var result = await NavigationService.ConfirmDiscardChanges(_dialogCoordinator);
                    if (result == false)
                    {
                        return;
                    }
                }
                NavigationService.GoBack();
            });

            AddApplianceToPackagedSolutionCmd = new RelayCommand(
                x =>
            {
                HandleAddApplianceToPackagedSolution(SelectedAppliance);
            },
                x => SelectedAppliance != null);

            RemoveApplianceFromPackagedSolutionCmd = new RelayCommand(x =>
            {
                AppliancesInPackagedSolution.Remove(SelectedApplianceInstance);
            }, x => SelectedApplianceInstance != null);

            EditApplianceCmd = new RelayCommand(x =>
            {
                RunEditApplianceDialog();
            }, x => SelectedAppliance != null);

            RemoveApplianceCmd = new RelayCommand(x =>
            {
                DropAppliance(SelectedAppliance);
            }, x => SelectedAppliance != null);

            NewPackagedSolutionCmd = new RelayCommand(x =>
            {
                CreateNewPackagedSolution();
            }, x => AppliancesInPackagedSolution.Any());

            SavePackagedSolutionCmd = new RelayCommand(x =>
            {
                if (string.IsNullOrEmpty(PackagedSolution.Name))
                {
                    RunSaveDialog();
                }
                else
                {
                    SaveCurrentPackagedSolution();
                }
            }, x => AppliancesInPackagedSolution.Any());

            CreateNewApplianceCmd = new RelayCommand(x =>
            {
                RunCreateApplianceDialog();
            });

            PrintEnergyLabelCmd = new RelayCommand(x =>
            {
                //PackagedSolution.Appliances = AppliancesInPackagedSolution.ToList();
                new SaveEnergyLabelDialog(PackagedSolution).RunDialog();
            }, x => AppliancesInPackagedSolution.Any() && IsDataSaved);
            #endregion
        }