public void CalcularHash() { var stringHash = $"{UserId}"; if (Albums != null && Albums.Any()) { foreach (var album in Albums.OrderBy(x => x.AlbumId)) { stringHash += $"{album.AlbumId}{album.AlbumTitle}"; if (album.Photos != null && album.Photos.Any()) { var fotosHash = album.Photos.OrderBy(x => x.PhotoId).Select(x => $"{x.PhotoId}{x.Title}{x.Url}{x.ThumbnailUrl}"); stringHash += string.Join(string.Empty, fotosHash); } } } var bytes = Encoding.UTF8.GetBytes(stringHash); using var crypto = new SHA256CryptoServiceProvider(); var hash = crypto.ComputeHash(bytes); var bytesString = hash.Select(x => x.ToString("x2")); Hash = string.Join(string.Empty, bytesString); }
private static List <Album> SetAlbum(string albums, ImageSource image) { Album album = new Album(albums, image); if (!Albums.Any(x => x.Title.Contains(albums))) { Albums.Add(album); } return(Albums); }
public override void ShowSpinner(bool show) { Log.Debug("ShowSpinner"); Application.Invoke(delegate { hboxButtons1.Sensitive = hboxButtons2.Sensitive = !show; hboxPublicPrivate.Visible = !show; hboxAlbums.Visible = Albums.Any() && !show; scrolledwindowPhotos.Visible = Albums.Any() && !show; _spinner.Visible = show; }); }
private void UpdateUI() { Log.Debug("UpdateUI"); Application.Invoke(delegate { labelPhotos1.Markup = labelPhotos2.Markup = string.Format("<small>{0} - {1} of {2} Albums</small>", FirstAlbum, LastAlbum, Total); labelPages1.Markup = labelPages2.Markup = string.Format("<small>{0} of {1} Pages</small>", Page, Pages); var pages = new ListStore(typeof(string)); comboboxPage1.Model = comboboxPage2.Model = pages; Enumerable.Range(1, int.Parse(Pages)).ToList().ForEach(p => pages.AppendValues(p.ToString())); comboboxPage1.Active = comboboxPage2.Active = int.Parse(Page) - 1; buttonPreviousPage1.Sensitive = buttonFirstPage1.Sensitive = buttonPreviousPage2.Sensitive = buttonFirstPage2.Sensitive = Page != "1"; buttonNextPage1.Sensitive = buttonLastPage1.Sensitive = buttonNextPage2.Sensitive = buttonLastPage2.Sensitive = Page != Pages; scrolledwindowPhotos.Vadjustment.Value = 0; hboxCenter.Sensitive = Albums.Any(); checkbuttonDownloadMultipleAlbums.Active = DownloadMultipleAlbums; hboxBottom1.Visible = !DownloadMultipleAlbums; hboxBottom2.Visible = DownloadMultipleAlbums; vbox1.Sensitive = vbox3.Sensitive = !DownloadMultipleAlbums; if ((SelectedPhotoset != null) && (SelectedPhotoset.Type == PhotosetType.Album)) { SelectedPhotoset = null; } UpdateSelectionUI(); }); albumsGrid.Items = Albums; }
public virtual bool IsOnAlbum(Album album) { ParamIs.NotNull(() => album); return(Albums.Any(a => a.Album.Equals(album))); }
public bool IsRecentAlbum() { return(Albums.Any(e => e.ReleaseDate >= DateTime.UtcNow.Date.AddDays(-14))); }
public async Task Sync(object context) { await Task.Run(async() => { // get account AccountEndpoint endpoint = new AccountEndpoint(await ImgurHelper.GetClient()); ImgurUser = await endpoint.GetAccountAsync(Name); bool me = (await ImgurHelper.GetToken()).AccountId == ImgurUser.Id.ToString(); // get local albums Album[] local = new DirectoryInfo(Root).GetDirectories().Where(it => it.Name[0] != '.').Select(it => Album.Get(it.FullName, "", null, true)).ToArray(); // get remote albums IAlbum[] remote = (await endpoint.GetAlbumsAsync(Name)).ToArray(); // (A) filter for albums with id only in local (not in remote) Album[] onlyLocal = local.Where(l => l.Id != null && !remote.Any(r => r.Id == l.Id)).ToArray(); // (B) filter for albums only in remote (not in local) IAlbum[] onlyRemote = remote.Where(r => !local.Any(l => l.Id == r.Id)).ToArray(); if (me) { // download albums (B) where not in json IAlbum[] download = onlyRemote.Where(r => !Albums.Any(a => a.Id == r.Id)).ToArray(); foreach (IAlbum album in download) { await Album.Get(Root, album.Title ?? album.Id, album.Id, true).Sync(context); } // delete albums (A) from local where in json if (Properties.Settings.Default.DeleteLocalFolder) { Album[] deleteLocal = onlyLocal.Where(l => Albums.Any(a => a.Id == l.Id && a.Synchronize)).ToArray(); foreach (Album album in deleteLocal) { bool ok = true; if (Properties.Settings.Default.AskDeleteLocalFolder) { MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete local album?", album.Root, MessageDialogStyle.AffirmativeAndNegative); ok = result == MessageDialogResult.Affirmative; } if (ok) { Directory.Delete(album.Root, true); } } } // delete albums (B) from remote where in json if (Properties.Settings.Default.DeleteRemoteFolder) { IAlbum[] deleteRemote = onlyRemote.Where(r => Albums.Any(a => a.Id == r.Id && a.Synchronize)).ToArray(); foreach (IAlbum album in deleteRemote) { bool ok = true; if (Properties.Settings.Default.AskDeleteRemoteFolder) { MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete Imgur album?", album.Title, MessageDialogStyle.AffirmativeAndNegative); ok = result == MessageDialogResult.Affirmative; } if (ok) { await endpoint.DeleteAlbumAsync(album.Id, Name); } } } // create albums without id Album[] upload = local.Where(l => l.Id == null && l.Synchronize).ToArray(); foreach (Album album in upload) { AlbumEndpoint ep = new AlbumEndpoint(await ImgurHelper.GetClient()); IAlbum rAlbum = await ep.CreateAlbumAsync(album.Title); album.ImgurAlbum = rAlbum; await album.Sync(context); } } else { // remove albums (A) if (Properties.Settings.Default.DeleteLocalFolder) { foreach (Album album in onlyLocal.Where(it => it.Synchronize)) { bool ok = true; if (Properties.Settings.Default.AskDeleteLocalFolder) { MessageDialogResult result = await DialogCoordinator.Instance.ShowMessageAsync(context, "Delete local album?", album.Root, MessageDialogStyle.AffirmativeAndNegative); ok = result == MessageDialogResult.Affirmative; } if (ok) { album.Remove(); } } } // download albums (B) foreach (IAlbum album in onlyRemote) { await Album.Get(Root, album.Title ?? album.Id, album.Id, true).Sync(context); } } // udpate json AlbumRoots = new DirectoryInfo(Root).GetDirectories().Where(it => it.Name[0] != '.').Select(it => it.FullName).ToList(); Album[] albums = AlbumRoots.Select(it => Album.Get(it, "")).ToArray(); App.Current.Dispatcher.Invoke((Action) delegate { Albums.Clear(); foreach (Album album in albums) { Albums.Add(album); } }); await Save(); // synchronize album images foreach (Album album in albums) { await album.Sync(context); } }); }