コード例 #1
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// zaradi seznam Photo do Photosetu
        /// </summary>
        /// <param name="photosetCollection">seznam Photoset instanci z Flickru</param>
        /// <param name="photoSetTitle">title photosetu kam budu photo instance sazet - nemusi existovat</param>
        /// <param name="sortedPhotoIdSet">poradi Photos</param>
        private void AddFilesToPhotoset(FlickrExtender flickr, List <Photoset> photosetCollection, string photoSetTitle, List <string> sortedPhotoIdSet)
        {
            // existuje uz PhotoSet na flickru?
            var photoset = photosetCollection.FirstOrDefault(p => string.Equals(p.Title, photoSetTitle, StringComparison.OrdinalIgnoreCase));

            if (photoset == null)
            {
                // prvni photo - nutne pro zalozeni photosetu
                var firstPhotoId = sortedPhotoIdSet.FirstOrDefault();
                sortedPhotoIdSet.Remove(firstPhotoId);
                // zalozeni noveho photosetu + refreshnu seznam photosetu
                photoset = flickr.PhotosetsCreate(photoSetTitle, firstPhotoId);
                _logger.Write(string.Format("Created new photoset Id:{0} Primary photoId:{1}", photoset.PhotosetId, firstPhotoId));

                // refresh seznam photosetu - nebo teoreticky by melo stacit pridat novy photose do kolekce, ale mozna je lepsi si stahnout aktualni data? zatim necham ADD
                photosetCollection.Add(photoset);
            }

            // paralelni pridani fotek - veskere reporty pres report event - tj i finalni report s ETA atd
            flickr.ParallelAddPhotosToPhotoset(photoset, sortedPhotoIdSet, AddPhotosToPhotosetReportAction, 15).Wait();

            // nasledne nastavit poradi fotek v photosetu - ze je primary photo uz removed zrejme nevadi, poradi si uchova
            flickr.PhotosetsReorderPhotos(photoset.PhotosetId, sortedPhotoIdSet.ToArray());

            _logger.Write(string.Format("Reorder photoset:{0} files:({1})", photoset.PhotosetId, string.Join(",", sortedPhotoIdSet)));
        }
コード例 #2
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// Dodatecne zarazeni Photo instanci (j*z existujicich na Flickru) do Photosetu
        /// </summary>
        private void UpdateUnassignedPhotos(FlickrExtender flickr, List <PathWithFlickrFiles> filesWithoutSet, List <Photo> photosWithoutSet)
        {
            if (filesWithoutSet.Any())
            {
                var flickrPhotoSets = flickr.ParallelPhotosetsGetList(ParallelPhotosetsGetListProgressEvent).Result;

                var photosWithoutSetCrc
                    = photosWithoutSet
                      // TODO predelat na extension metodu Photo classu?
                      .SelectMany(photo => photo.Tags.Where(tag => !string.IsNullOrEmpty(tag) && tag.StartsWith(File4Flickr.FLUPCRC_TAG, StringComparison.InvariantCultureIgnoreCase))
                                  .Select(crcTag =>
                {
                    var crcFromTag = crcTag.Remove(0, File4Flickr.FLUPCRC_TAG.Length);
                    long crc;
                    long.TryParse(crcFromTag, out crc);
                    return(new { photo, crc });
                }))
                      .ToList();

                foreach (var pathWithFiles in filesWithoutSet)
                {
                    // zpetne dohledam pres CRC instanci Photo na serveru
                    var crcInPath = pathWithFiles.Photos.Select(p => p.Crc).ToList();
                    // seznam unassigned PhotoId pro tento adresar (photoset)
                    var photoIdsForPath = photosWithoutSetCrc.Where(p => crcInPath.Contains(p.crc)).Select(p => p.photo.PhotoId).ToList(); // TODO nasledne by se tu mel nejak resit orderby? nejspis by mel pribyt dalsi FLUP tag s poradim? zatim na to kaslu, pro potreby zalohovani to nema smysl

                    AddFilesToPhotoset(flickr, flickrPhotoSets, pathWithFiles.PhotosetName, photoIdsForPath);
                }
            }
        }
コード例 #3
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// provede nahrani novych souboru z lokalu na Flickr
        /// </summary>
        private void SynchronizePhotos(FlickrExtender flickr, List <PathWithFlickrFiles> newDirs)
        {
            if (newDirs.Any())
            {
                var flickrPhotoSets = flickr.ParallelPhotosetsGetList(ParallelPhotosetsGetListProgressEvent).Result;

                var totalCount     = newDirs.SelectMany(p => p.Photos).Count();
                var totalLength    = newDirs.SelectMany(p => p.Photos).Sum(p => p.Length);
                var uploadedLength = 0L;
                var uploadedCount  = 0;
                var totalStart     = DateTime.Now;

                // pripadne prazdne adresare vyhodim - nemeli by tu vsak uz byt ;-)
                newDirs = newDirs.Where(p => p.Photos.Any()).ToList();

                foreach (var dir in newDirs)
                {
                    _logger.Write(string.Format("Processing folder:'{0}'-'{1}' files:{2}", dir.DirectoryInfo.FullName, dir.PhotosetName, dir.Photos.Count));

                    // pridat soubory
                    var uploadFileResults = flickr.ParallelUploadFiles(dir.Photos, p => ParallelUploadFilesReportAction(p)).Result;

                    // ty pak zaradit do photosetu
                    AddFilesToPhotoset(flickr, flickrPhotoSets, dir.PhotosetName, uploadFileResults);

                    // jen hlaseni o prubehu
                    ReportTotalProgress(totalCount, totalLength, ref uploadedLength, ref uploadedCount, totalStart, uploadFileResults);
                }
            }
        }
コード例 #4
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// vytvoreni instance VtFlickr
        /// </summary>
        private FlickrExtender CreateAuthenticatedFlickrInstance()
        {
            _logger.Write("Trying to connect Flickr...");

            var flickr = new FlickrExtender(FlupApiKey, FlupSharedSecret, _logger, _ini.UseDefaultProxy).VtCheckAuth();

            return(flickr);
        }
コード例 #5
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
 /// <summary>
 /// zarazeni set of Photo do Photosetu
 /// </summary>
 private void AddFilesToPhotoset(FlickrExtender flickr, List <Photoset> photosetCollection, string photoSetTitle, List <UploadFileResult> uploadedPhotos)
 {
     if (uploadedPhotos.Any())
     {
         // vychozi trideni dle filename
         var sortedFiles = uploadedPhotos.OrderBy(p => p.File4Flickr.FullName).Select(p => p.PhotoId).ToList();
         AddFilesToPhotoset(flickr, photosetCollection, photoSetTitle, sortedFiles);
     }
 }
コード例 #6
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// Resi problem s Photo soubory, ktere byly uspesne preneseny na Flickr, ale j*z nedoslo k zarazeni do Photosetu (preruseni prenosu atd),
        /// tj ted visi na serveru nezarazene. Bohuzel Flickr API nenabizi zadnou fci na dohledani techto souboru, je tedy jedina moznost vzit vsechny
        /// Flup fotky + Photosety a po stav porovnat :-/
        /// </summary>
        /// <param name="flupFlickrPhotos">seznam vsech Photo instanci na flickru</param>
        /// <returns>seznam Photo instanci na flickeru, ktere nejsou zarazeny v Photosetu</returns>
        private List <Photo> CheckPhotosWithoutPhotoset(FlickrExtender flickr, List <Photo> flupFlickrPhotos)
        {
            //1. seznam photosetu
            var photosets = flickr.ParallelPhotosetsGetList(ParallelPhotosetsGetListProgressEvent).Result;

            //2. seznam Photo od vsech Photoset - API nic takoveho neumoznuje, takze je nutne projit Photosety rucne
            var photosetsGetPhotosAllResultSet = flickr.ParallelGetPhotosFromPhotosets(photosets, ParallelGetPhotosFromPhotosetsProgressEvent, 10).Result;

            //3. vybrat z flupFlickrPhotos fotky bez photosetu
            var allPhotoIdWithPhotosetSet = photosetsGetPhotosAllResultSet.SelectMany(x => x.PhotoIdSet).ToList();
            var photosWithoutPhotoset     = flupFlickrPhotos.Where(p => !allPhotoIdWithPhotosetSet.Contains(p.PhotoId)).ToList();

            return(photosWithoutPhotoset);
        }
コード例 #7
0
ファイル: Flup.cs プロジェクト: vittichy/Flup
        /// <summary>
        /// dohledani souboru z Flickru, kter maji tag FLUP
        /// - zde by bylo idealni pouzit vyhledavaci VtPhotosSearchByTag, ktera pouziva fce flickeru PhotosSearch, bohuzel vyhledavani chvili funguje
        /// a chvili zas ne :-/ takze vezmu vse a rucne vyhodim neflupove soubory :-/
        /// </summary>
        private async Task <List <Photo> > GetFlupFlickrPhotos(FlickrExtender flickr)
        {
            _logger.Write("Looking for Flickr files...");

            var allFlickrFilesFromUser = await flickr.ParallelGetPhotos(PhotosSearchReportProgress);

            return(allFlickrFilesFromUser);

            // obcas funguje, obcas ne :-/ - vubec prace s Flickr tagama je dost podivna, nektere si upravi, nektere neupravi a search API je nedohleda :-/
            //
            // var flickrPhotoCollection = flickr.VtPhotosSearchByTag(File4Flickr.FLUP_TAG);
            // _logger.Write(string.Format("Found {0} photos with {1} tag.", flickrPhotoCollection.Count, File4Flickr.FLUP_TAG));
            // return flickrPhotoCollection;
        }