Пример #1
0
        public FFile UpdateSets(int fileID)
        {
            var file = fFileLogic.Get(fileID);

            if (file != null &&
                (file.Status == FFileStatus.Uploaded_NoSet ||
                 file.Status == FFileStatus.Uploaded_InSet)
                )
            {
                FlickrLogic.Log(file.Path, NoticeType.Upload, "Add to photo sets");

                SetLogic l     = new SetLogic();
                string   setID = l.AddPhoto(file);

                if (string.IsNullOrEmpty(setID))
                {
                }
                else
                {
                    file = fFileLogic.DoUpdate(fileID, file1 =>
                    {
                        file1.SetsID = setID;
                        file1.Status = FFileStatus.Uploaded_SyncSet;
                    });
                }
            }

            return(file);
        }
Пример #2
0
        public FFile Processing_HashCodeFound(int fileID)
        {
            var file = fFileLogic.UpdateHashCode(fileID);

            if (file != null && file.Status == FFileStatus.Existing)
            {
                FlickrLogic.Log(file.Path, NoticeType.Upload, "Checking HashCodeFound");

                file = fFileLogic.UpdateFlickrIds(fileID, GetPhoto_ByHashCode);
                fFileLogic.UpdateStatus(fileID);

                if (string.IsNullOrEmpty(file.PhotoID))
                {
                }
                else
                {
                    var context = flickr.PhotosGetAllContexts(file.PhotoID);
                    if (context == null)
                    {
                    }
                    else
                    {
                        if (context.Sets.Count > 0)
                        {
                            file = fFileLogic.DoUpdate(fileID, file1 =>
                            {
                                file1.Status = FFileStatus.Uploaded_InSet;
                            });
                        }
                        else
                        {
                            file = fFileLogic.DoUpdate(fileID, file1 =>
                            {
                                file1.Status = FFileStatus.Uploaded_NoSet;
                            });
                        }

                        UpdateSets(file.Id);
                    }
                }

                FlickrLogic.Log(file.Path, NoticeType.UploadDone, "Done " + file.Status.ToString());
            }

            return(file);
        }
        public bool CheckExistHashCode(Func <string, bool> flickrCheckF, int fFileID)
        {
            UpdateHashCode(fFileID);

            return(DoUpdate(fFileID, file =>
            {
                FlickrLogic.Log(file.Path, NoticeType.Upload, "Check existing");

                bool check = flickrCheckF(file.HashCode);

                if (check)
                {
                    FlickrLogic.Log(file.Path, NoticeType.UploadDone, "Existed");
                }

                return check;
            }, false));
        }
        async static Task UploadFolder()
        {
            if (string.IsNullOrEmpty(CurrentFolderPath))
            {

            }
            else
            {
                try
                {
                    var task = Task.Factory.StartNew(() =>
                    {
                        FFileLogic fFileLogic = new FFileLogic(CurrentFolderPath);
                        ParallelOptions opt = new ParallelOptions();
                        opt.MaxDegreeOfParallelism = MaxUpload;
                        opt.CancellationToken = CancellationToken;

                        try
                        {
                            var r = Parallel.ForEach(fFileLogic.TakeBuffer(), opt
                                , file =>
                            {
                                if (string.IsNullOrEmpty(CurrentFolderPath))
                                {
                                }
                                else
                                {
                                    FlickrLogic logic = new FlickrLogic(CurrentFolderPath);
                                    if (file == null)
                                    {

                                    }
                                    else if (file.Status == FFileStatus.New)
                                    {
                                        var t = logic.Upload(file.Id);

                                        try
                                        {
                                            Task.WaitAll(t);
                                        }
                                        catch (Exception ex1)
                                        {

                                        }

                                    }
                                    else if (file.Status == FFileStatus.Existing)
                                    {
                                        //logic.Processing_HashCodeFound(file.Id);

                                        try
                                        {
                                            logic.Processing_HashCodeFound(file.Id);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                        
                                    }
                                }
                            }

                            );
                        }
                        catch (Exception ex)
                        {

                        }


                    });
                    await task;
                }
                catch (Exception ex)
                {


                }
            }
        }
Пример #5
0
        async static Task DownloadSet()
        {
            if (string.IsNullOrEmpty(CurrentDownloadSetId))
            {
            }
            else
            {
                try
                {
                    var task = Task.Factory.StartNew(() =>
                    {
                        Flickr flickr = new Flickr();
                        var list      = flickr.PhotosetsGetPhotos(CurrentDownloadSetId);

                        SetLogic sL       = new SetLogic();
                        string saveFolder = sL.GetDownloadFolderPath(CurrentDownloadSetId);

                        if (list == null || list.Count == 0 || string.IsNullOrEmpty(saveFolder))
                        {
                        }
                        else
                        {
                            ParallelOptions opt        = new ParallelOptions();
                            opt.MaxDegreeOfParallelism = MaxUpload;

                            opt.CancellationToken = DownloadCancellationToken;

                            try
                            {
                                var r1 = Parallel.ForEach(list, opt
                                                          , photo =>
                                {
                                    var sizes = flickr.PhotosGetSizes(photo.PhotoId);
                                    if (sizes == null || sizes.Count == 0)
                                    {
                                    }
                                    else
                                    {
                                        var org = sizes.FirstOrDefault(r => r.Label == "Original" && r.MediaType == MediaType.Photos);
                                        if (org == null)
                                        {
                                        }
                                        else
                                        {
                                            Uri uri = new Uri(org.Source);

                                            string filename = Path.GetFileName(uri.LocalPath);

                                            WebClient webClient = new WebClient();
                                            string filePath     = Path.Combine(saveFolder, filename);

                                            if (File.Exists(filePath))
                                            {
                                            }
                                            else
                                            {
                                                webClient.DownloadFile(org.Source, filePath);
                                                FlickrLogic.Log(filePath, NoticeType.DownloadDone, "Downloaded");
                                            }
                                        }
                                    }
                                }
                                                          );
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    });
                    await task;
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #6
0
        async static Task UploadFolder()
        {
            if (string.IsNullOrEmpty(CurrentFolderPath))
            {
            }
            else
            {
                try
                {
                    var task = Task.Factory.StartNew(() =>
                    {
                        FFileLogic fFileLogic      = new FFileLogic(CurrentFolderPath);
                        ParallelOptions opt        = new ParallelOptions();
                        opt.MaxDegreeOfParallelism = MaxUpload;
                        opt.CancellationToken      = CancellationToken;

                        try
                        {
                            var r = Parallel.ForEach(fFileLogic.TakeBuffer(), opt
                                                     , file =>
                            {
                                if (string.IsNullOrEmpty(CurrentFolderPath))
                                {
                                }
                                else
                                {
                                    FlickrLogic logic = new FlickrLogic(CurrentFolderPath);
                                    if (file == null)
                                    {
                                    }
                                    else if (file.Status == FFileStatus.New)
                                    {
                                        var t = logic.Upload(file.Id);

                                        try
                                        {
                                            Task.WaitAll(t);
                                        }
                                        catch (Exception ex1)
                                        {
                                        }
                                    }
                                    else if (file.Status == FFileStatus.Existing)
                                    {
                                        //logic.Processing_HashCodeFound(file.Id);

                                        try
                                        {
                                            logic.Processing_HashCodeFound(file.Id);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                }
                            }

                                                     );
                        }
                        catch (Exception ex)
                        {
                        }
                    });
                    await task;
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #7
0
        async public Task <FFile> Upload(int fFileID)
        {
            while (IsNetworkOk == false)
            {
                await Task.Delay(TimeSpan.FromSeconds(3));
            }

            var file = fFileLogic.GetForSure(fFileID);

            if (file == null)
            {
                fFileLogic.DoUpdate(fFileID, f =>
                {
                    f.Status = FFileStatus.NonExisting;
                });
            }
            else
            {
                var isExisted = fFileLogic.CheckExistHashCode(ExistFile, fFileID);

                if (isExisted)
                {
                    file = fFileLogic.DoUpdate(fFileID, file1 =>
                    {
                        if (file1.Status == FFileStatus.New)
                        {
                            file1.Status           = FFileStatus.Existing;
                            file1.ProcessingStatus = null;
                        }
                    });
                }
                else
                {
                    var progress = new Progress <UploadProgressChangedEventArgs>();

                    progress.ToObservable()
                    .DistinctUntilChanged(r => (int)r.EventArgs.UploadPercentage() / 5)
                    .Subscribe(r =>
                    {
                        FlickrLogic.UploadEventList.Add(new Notice()
                        {
                            Type       = NoticeType.Upload,
                            JobDone    = r.EventArgs.BytesSent,
                            JobTotal   = r.EventArgs.TotalBytesToSend,
                            Percentage = r.EventArgs.UploadPercentage(),
                            FullPath   = file.Path,
                            Note       = "Uploading",
                        });
                    })
                    ;

                    var photoID = await flickr.UploadPicture(file.Path, tags : file.GetHashCodeTag(), progress : progress);

                    if (string.IsNullOrEmpty(photoID))
                    {
                    }
                    else
                    {
                        file = fFileLogic.DoUpdate(fFileID, file1 =>
                        {
                            file1.PhotoID = photoID;
                            file1.Status  = FFileStatus.Uploaded_NoSet;
                            file1.UserID  = Flickr.User.UserId;
                        });

                        UpdateSets(file.Id);

                        FlickrLogic.Log(file.Path, NoticeType.UploadDone, "Uploaded");
                    }
                }
            }

            return(file);
        }