예제 #1
0
        public static void Auth()
        {
            if (FlickrManager.OAuthToken == null)
            {
                var f            = FlickrManager.GetInstance();
                var requestToken = f.OAuthGetRequestToken("oob");

                string url = f.OAuthCalculateAuthorizationUrl(requestToken.Token, AuthLevel.Write);

                System.Diagnostics.Process.Start(url);

                Console.Write("Auth token: ");
                var token = Console.ReadLine().Trim();
                try {
                    var accessToken = f.OAuthGetAccessToken(requestToken, token);
                    FlickrManager.OAuthToken = accessToken;
                    Console.WriteLine("Successfully authenticated as " + accessToken.FullName);
                } catch (FlickrApiException ex) {
                    Console.WriteLine("Failed to get access token. Error message: " + ex.Message);
                }
                FlickrConfig.Save();
            }
            else
            {
                var accessToken = FlickrManager.OAuthToken;
                Console.WriteLine("Successfully authenticated as " + accessToken.FullName);
            }
        }
예제 #2
0
        public async Task Build()
        {
            PhotoSearchOptions o = new PhotoSearchOptions();

            o.Extras    = PhotoSearchExtras.AllUrls | PhotoSearchExtras.Description | PhotoSearchExtras.OriginalUrl | PhotoSearchExtras.ThumbnailUrl | PhotoSearchExtras.Tags | PhotoSearchExtras.Geo;
            o.SortOrder = PhotoSearchSortOrder.DatePostedDescending;             // DateTakenDescending
            //o.Tags = FlickrManager.MasterTag;
            //o.TagMode = TagMode.AllTags;
            o.UserId = FlickrManager.OAuthToken.UserId;
            //o.Text = "Path";
            o.PerPage = 500;
            o.Page    = 1;

            var f = FlickrManager.GetAuthInstance();


            int i       = 0;
            var results = f.PhotosSearch(o);

            do
            {
                Console.WriteLine("Result count (page " + results.Page + " of " + results.Pages + "): " + results.Count);
                foreach (var p in results)
                {
                    // Console.WriteLine (p.ToJson ());
                    var file = new RemoteFile(p);
                    LocalDatabase.RunLocked(() => LocalDatabase.Instance.RemoteFiles [file.Description] = file);

                    ByDesc [file.Description] = file;

                    Console.WriteLine("Remote file " + i + ": " + file);

                    i++;
                }

                LocalDatabase.RunLocked(() => LocalDatabase.Save());
                await Task.Delay(1000);

                o.Page++;
                results = f.PhotosSearch(o);
            } while (results != null && results.Count >= 0 && results.Page <= results.Pages);
        }
예제 #3
0
 public static void FixGeoLocation(LocalFile file, RemoteFile remote)
 {
     try {
         Console.Write("Fix geo location: " + remote.Description + " (" + file.GeoLocation + ")");
         var f = FlickrManager.GetAuthInstance();
         f.OnUploadProgress += F_OnUploadProgress;
         f.PhotosGeoSetLocation(remote.PhotoId, file.GeoLocation.Lat, file.GeoLocation.Lng);
         Console.WriteLine();
         remote.GeoLocation = file.GeoLocation;
         LocalDatabase.RunLocked(() => LocalDatabase.Instance.RemoteFiles [remote.Description] = remote);
     } catch (Exception ex) {
         CountFailures++;
         if (CountFailures > 10)
         {
             throw;
         }
         Console.WriteLine("Exception during fix geo location:");
         Console.WriteLine(ex);
         int sec = 2 * Math.Min(5, CountFailures);
         Console.WriteLine("Wait for " + sec + " seconds");
         System.Threading.Thread.Sleep(1000 * sec);
     }
 }
예제 #4
0
 public static void Upload(LocalFile file, int i, int n)
 {
     try {
         Console.Write("Upload local file " + i + " of " + n + ": " + file + " => ");
         var f = FlickrManager.GetAuthInstance();
         f.OnUploadProgress += F_OnUploadProgress;
         string photoId = f.UploadPicture(file.FullPath, file.Title, file.Description, string.Join(",", new [] {
             FlickrManager.MasterTag,
             file.PathTag
         }.Union(file.RelativePathNormalized.Split('/'))), false, false, false);
         Console.WriteLine("photoId: " + photoId);
     } catch (Exception ex) {
         CountFailures++;
         if (CountFailures > 10)
         {
             throw;
         }
         Console.WriteLine("Exception during upload:");
         Console.WriteLine(ex);
         int sec = 10 * Math.Min(5, CountFailures);
         Console.WriteLine("Wait for " + sec + " seconds");
         System.Threading.Thread.Sleep(1000 * sec);
     }
 }