コード例 #1
0
        /// <summary>
        /// Creates form instance.
        /// </summary>
        /// <param name="client">Zenfolio client to use for operations.</param>
        /// <param name="gallery">Destination gallery for uploading.</param>
        /// <param name="filePath">Path of the image to be uploaded.</param>
        /// <param name="mimeType">MIME type of the image.</param>
        public UploadDialog(
            ZenfolioClient client,
            PhotoSet gallery,
            string filePath,
            string mimeType
            )
        {
            _client      = client;
            _gallery     = gallery;
            _fileInfo    = new FileInfo(filePath);
            _totalChunks = (int)_fileInfo.Length / 1024;

            _mimeType = mimeType;
            InitializeComponent();
        }
コード例 #2
0
 public BrowseDialog(ZenfolioClient client)
 {
     _client = client;
     InitializeComponent();
 }
コード例 #3
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.AppSettings()
                         .CreateLogger();

            try
            {
                Log.Verbose("Main() Started");
                Log.Debug("args[{Args}]", JsonConvert.SerializeObject(args));

                Log.Information("----------- Application Started ----------- ");

                string mimeType = "image/jpeg";

                bool   loggedin    = false;
                long   galleryID   = 0;
                string galleryName = "";

                _client = new ZenfolioClient();


                while (!loggedin)
                {
                    Log.Debug("Attempting to log in as [{Login}]", Settings.Default.ZenfolioUserName);
                    loggedin = _client.Login(Settings.Default.ZenfolioUserName, Settings.Default.ZenfolioPassword);
                }

                //Load more detailed projection of selected gallery
                PhotoSet gallery = new PhotoSet();
                if (!string.IsNullOrEmpty(Settings.Default.ZenfolioGalleryID))
                {
                    gallery = _client.LoadPhotoSet(Convert.ToInt64(Settings.Default.ZenfolioGalleryID), InformatonLevel.Level1, true);

                    galleryID   = gallery.Id;
                    galleryName = gallery.Title;
                }
                else
                {
                    BrowseDialog dlgBrowse = new BrowseDialog(_client);
                    DialogResult dlgResult = dlgBrowse.ShowDialog();

                    galleryID   = dlgBrowse.SelectedGallery.Id;
                    galleryName = dlgBrowse.SelectedGallery.Title;

                    gallery = _client.LoadPhotoSet(galleryID, InformatonLevel.Level1, true);
                    Log.Information("Loaded Gallery [{Title}]", galleryName);
                }

                Log.Debug("Found images [{ImageCount}] in Zenfolio GalleryID[{GalleryID}]", gallery.PhotoCount, gallery.Id);

                var previousImageCount = 0;
                while (true)
                {
                    try
                    {
                        var imageFolderPath = Settings.Default.ImageFolderPath + $"//{galleryName}";

                        if (!Directory.Exists(imageFolderPath))
                        {
                            Directory.CreateDirectory(imageFolderPath);
                        }

                        var imagePaths = Directory.GetFiles(imageFolderPath);

                        if (imagePaths.Count() > previousImageCount)
                        {
                            Log.Debug("Found images [{ImagesCount}] in directory[{Directory}]", imagePaths.Length, imageFolderPath);

                            var newImageFileInfos = GetNewImageFileInfos(gallery, imagePaths);

                            if (newImageFileInfos.Count() > 0)
                            {
                                UploadImages(newImageFileInfos, gallery, mimeType);

                                newImageFileInfos = GetNewImageFileInfos(gallery, imagePaths);

                                previousImageCount = imagePaths.Count();
                            }
                        }

                        Thread.Sleep(Settings.Default.WaitTimeInSec * 1000);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, ex.Message);
                        Thread.Sleep(Settings.Default.WaitTimeInSec * 1000);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e, e.Message);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }