public MainWindowViewModel(FlickrManager mgr) { _mgr = mgr; _updateSetsTimer = new Timer(OnUpdateSets, null, 5000, 30000); Task.Run(() => ReloadTree()).ConfigureAwait(false); Task.Run(() => FillPhotosFromPath(@"C:\Users\Tilli\odrive\OneDrive\Bilder\Familie\2001")).ConfigureAwait(false); }
protected FlickrManager LoadToken() { var mgr = new FlickrManager(); AccessToken token; try { using (var stream = KeyFile.OpenRead()) { token = stream.Load <AccessToken>(); } } catch (Exception ex) { throw new InvalidOperationException($"Error loading token '{KeyFile.FullName}'. {ex.Message}"); } try { mgr.ApplyToken(token); } catch (Exception ex) { throw new InvalidOperationException($"Supplied token is invalid. {ex.Message}"); } return(mgr); }
public override void Execute() { if (!ModeChosen) { throw new InvalidOperationException("Invalid mode"); } var mgr = new FlickrManager(); mgr.InteractiveAuthorize(); Console.WriteLine("Please enter the code displayed on the website:"); var code = Console.ReadLine(); mgr.InteractiveAuthorizeComplete(code); var token = mgr.GetToken(); using (var stream = KeyFile.OpenWrite()) { token.ToXml(stream, Encoding.UTF8, null); } Console.WriteLine($"Token successfully exported to\r\n{KeyFile.FullName}"); }
private void SetFromCommandline(FlickrManager mgr, HashSet <PhotoModel> list) { var f = mgr.Surrogate; var sets = f.PhotosetsGetList(mgr.AccountDetails.UserId); var knownSets = new List <PhotosetModel>(50); foreach (var s in sets.Select(s => new PhotosetModel(s.PhotosetId, s.Title, s.Description))) { knownSets.Add(s); } foreach (var item in list) { item.Tags = Expand(Tags, item)?.Split(','); item.Title = Expand(Title, item); item.ContentType = ContentType; item.Description = Expand(Description, item); item.SafetyLevel = SafetyLevel; item.SearchState = SearchState; item.IsFamily = IsFamily; item.IsFriend = IsFriend; item.IsPublic = IsPublic; foreach (var s in item.Sets) { if (!knownSets.Contains(s)) { knownSets.Add(s); } } foreach (var setNameExpression in AddToSets) { var setName = Expand(setNameExpression, item); var key = setName.ToLowerInvariant(); var keyIsId = key.StartsWith("id:"); if (keyIsId) { key = key.Substring(3); } PhotosetModel set; var candidates = knownSets.Where( s => (keyIsId && s.Id.ToLowerInvariant() == key) || (!keyIsId && s.Title.ToLowerInvariant() == key)).ToArray(); if (candidates.Length > 1) { var albums = string.Join(", ", sets.Select(s => $"'{s.Title}' (ID:{s.PhotosetId})")); throw new InvalidOperationException( $"Multiple albums with '{setName}' were found on the server. Please use the ID instead (ID:<id> syntax). Possible albums are: {albums}"); } if (!candidates.Any()) { if (keyIsId) { var albums = string.Join(", ", sets.Select(s => $"'{s.Title}' (ID:{s.PhotosetId})")); throw new InvalidOperationException( $"The Album with ID '{key}' was not found on the server. Possible albums are: {albums}"); } if (AutoCreateSets) { set = new PhotosetModel(null, setName, null); knownSets.Add(set); } else { var albums = string.Join(", ", sets.Select(s => $"'{s.Title}' (ID:{s.PhotosetId})")); throw new InvalidOperationException( $"The Album with ID or named '{setName}' was not found on the server. Possible albums are: {albums}"); } } else { set = candidates.Single(); } if (!item.Sets.Contains(set)) { item.Sets.Add(set); } } } }
public UploadManager(CancellationToken cancellationToken, FlickrManager mgr) { _cancellationToken = cancellationToken; _mgr = mgr; }