public BrowserWindow(User user, Preferences preferences)
        {
            InitializeComponent();
            Title += VersionHelper.GetVersionString();
            Preferences = preferences;
            User = user;
            AllSelectedPhotos = new Dictionary<string, Dictionary<string, Photo>>();

            PagePhotoList.SelectionChanged += (sender, args) =>
            {
                if (_doNotSyncSelectedItems) return;
                AllSelectedPhotos[Page] = PagePhotoList.SelectedItems.Cast<Photo>().
                    ToDictionary(p => p.Id, p => p);
                PropertyChanged.Notify(() => SelectedPhotosExist);
                PropertyChanged.Notify(() => SelectedPhotosCountText);
                PropertyChanged.Notify(() => AreAnyPagePhotosSelected);
                PropertyChanged.Notify(() => AreAllPagePhotosSelected);
            };

            SpinnerInner.SpinnerCanceled += (sender, args) => _presenter.CancelDownload();

            FileCache.AppCacheDirectory = Preferences.CacheLocation;

            _presenter = Bootstrapper.GetPresenter<IBrowserView, IBrowserPresenter>(this);
            _presenter.InitializePhotoset();
        }
        public async Task<PhotosResponse> GetPhotosAsync(string methodName, User user, Preferences preferences, int page,
            IProgress<ProgressUpdate> progress)
        {
            var progressUpdate = new ProgressUpdate
            {
                OperationText = "Getting list of photos...",
                ShowPercent = false
            };
            progress.Report(progressUpdate);

            var extraParams = new Dictionary<string, string>
            {
                {ParameterNames.UserId, user.UserNsId},
                {ParameterNames.SafeSearch, SafeSearch.GetValue(preferences.SafetyLevel)},
                {
                    ParameterNames.PerPage,
                    preferences.PhotosPerPage.ToString(CultureInfo.InvariantCulture)
                },
                {ParameterNames.Page, page.ToString(CultureInfo.InvariantCulture)}
            };

            var photosResponse = (Dictionary<string, object>)
                await _oAuthManager.MakeAuthenticatedRequestAsync(methodName, extraParams);

            return photosResponse.GetPhotosResponseFromDictionary();
        }
 public void Logout()
 {
     _preferences = null;
     _logic.Logout();
     _view.ShowSpinner(false);
     _view.ShowLoggedOutControl();
 }
        public async Task Download(IEnumerable<Photo> photos, CancellationToken cancellationToken,
            IProgress<ProgressUpdate> progress, Preferences preferences)
        {
            IList<Photo> photosList = photos as IList<Photo> ?? photos.ToList();
            if (!photosList.Any()) return;

            await _downloadLogic.Download(photosList, cancellationToken, progress, preferences);
        }
 public async void InitializeScreen()
 {
     _view.ShowSpinner(true);
     _view.ShowLoggedOutControl();
     _preferences = _preferencesLogic.GetPreferences();
     if (!await _logic.IsUserLoggedInAsync(ApplyUser))
     {
         Logout();
     }
 }
 public void ShowLoggedInControl(Preferences preferences)
 {
     Preferences = preferences;
     FileCache.AppCacheDirectory = Preferences != null
         ? Preferences.CacheLocation
         : Preferences.GetDefault().CacheLocation;
     PreferencesButton.Dispatch(
         p => p.Visibility = (Preferences != null ? Visibility.Visible : Visibility.Collapsed));
     LoggedInCanvas.Dispatch(c => c.Visibility = Visibility.Visible);
     LoggedOutCanvas.Dispatch(c => c.Visibility = Visibility.Collapsed);
 }
        public PreferencesWindow(User user, Preferences preferences)
        {
            InitializeComponent();
            Title += VersionHelper.GetVersionString();
            Preferences = preferences;
            User = user;

            _presenter = Bootstrapper.GetPresenter<IPreferencesView, IPreferencesPresenter>(this);

            SetCacheSize();
        }
 public void OpenPreferencesWindow(Preferences preferences)
 {
     var preferencesWindow = new PreferencesWindow(User, preferences);
     preferencesWindow.Show();
     Close();
 }
        private async Task DownloadPhotos(IEnumerable<Photo> photos, CancellationToken cancellationToken,
            IProgress<ProgressUpdate> progress, Preferences preferences)
        {
            try
            {
                var progressUpdate = new ProgressUpdate
                {
                    Cancellable = true,
                    OperationText = "Downloading photos...",
                    PercentDone = 0,
                    ShowPercent = true
                };
                progress.Report(progressUpdate);

                int doneCount = 0;
                IList<Photo> photosList = photos as IList<Photo> ?? photos.ToList();
                int totalCount = photosList.Count();

                DirectoryInfo imageDirectory = CreateDownloadFolder(preferences.DownloadLocation);

                foreach (Photo photo in photosList)
                {
                    string photoUrl = photo.OriginalUrl;
                    string photoExtension = "jpg";
                    switch (preferences.DownloadSize)
                    {
                        case PhotoDownloadSize.Medium:
                            photoUrl = photo.Medium800Url;
                            break;
                        case PhotoDownloadSize.Large:
                            photoUrl = photo.Large1024Url;
                            break;
                        case PhotoDownloadSize.Original:
                            photoUrl = photo.OriginalUrl;
                            photoExtension = photo.DownloadFormat;
                            break;
                    }

                    Photo photoWithPreferredTags = photo;

                    if (preferences.NeedOriginalTags)
                    {
                        photoWithPreferredTags = await _originalTagsLogic.GetOriginalTagsTask(photo);
                    }

                    string photoName = preferences.TitleAsFilename ? GetSafeFilename(photo.Title) : photo.Id;
                    string targetFileName = Path.Combine(imageDirectory.FullName,
                        string.Format("{0}.{1}", photoName, photoExtension));
                    WriteMetaDataFile(photoWithPreferredTags, targetFileName, preferences);

                    WebRequest request = WebRequest.Create(photoUrl);

                    var buffer = new byte[4096];

                    await DownloadAndSavePhoto(targetFileName, request, buffer);

                    doneCount++;
                    progressUpdate.PercentDone = doneCount*100/totalCount;
                    progressUpdate.DownloadedPath = imageDirectory.FullName;
                    progress.Report(progressUpdate);
                    if (progressUpdate.PercentDone != 100) cancellationToken.ThrowIfCancellationRequested();
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
 public async Task Download(IEnumerable<Photo> photos, CancellationToken cancellationToken,
     IProgress<ProgressUpdate> progress, Preferences preferences)
 {
     await DownloadPhotos(photos, cancellationToken, progress, preferences);
 }
 private static void WriteMetaDataFile(Photo photo, string targetFileName, Preferences preferences)
 {
     Dictionary<string, string> metadata = preferences.Metadata.ToDictionary(metadatum => metadatum,
         metadatum =>
             photo.GetType()
                 .GetProperty(metadatum)
                 .GetValue(photo, null)
                 .ToString());
     if (metadata.Count > 0)
         File.WriteAllText(string.Format("{0}.json", targetFileName), metadata.ToJson(), Encoding.Unicode);
 }
 public void SavePreferences(Preferences preferences)
 {
     _repository.Save(preferences);
 }
 public void Save(Preferences preferences)
 {
     _logic.SavePreferences(preferences);
 }
Пример #14
0
 public Session(User user, Preferences preferences, Photoset photoset = null) {
     User = user;
     Preferences = preferences;
     SelectedPhotoset = photoset;
 }