示例#1
0
 public Task Run()
 {
     return(Task.Run(() =>
     {
         ProgressCount = _images.Count;
         Progress = 0;
         _cancel = false;
         NotifyPropertyChanged("CanCancel");
         IsRunning = true;
         var count = _images.Count;
         AddStatus("Converting " + count + " images started");
         foreach (var image in _images.ToList())
         {
             if (_cancel)
             {
                 AddStatus("Converting canceled");
                 break;
             }
             try
             {
                 AddStatus("Loading image: " + image.FileName);
                 var bytes = File.ReadAllBytes(image.FilePath);
                 using (var ms = new MemoryStream(bytes))
                 {
                     var bitmap = new Bitmap(ms);
                     AddStatus("Image loaded");
                     if (_sizeConverter != null)
                     {
                         AddStatus("Resizing image");
                         bitmap = _sizeConverter.Convert(bitmap);
                     }
                     AddStatus("Saving image");
                     _storage.Save(image, bitmap);
                     AddStatus("Image Saved");
                 }
                 Progress++;
             }
             catch (Exception ex)
             {
                 AddErrorStatus(ex);
                 _hasErrors = true;
             }
             AddStatus(string.Empty);
         }
         AddStatus("Converting images ended");
         AddStatus(Progress + " images succesfully converted");
         AddStatus(count - Progress + " images failed");
         if (_hasErrors)
         {
             AddStatus("Some errors occured! Please check log for more info");
         }
         IsRunning = false;
         _cancel = true;
         _hasErrors = false;
         NotifyPropertyChanged("CanCancel");
         _log.Save();
     }));
 }
示例#2
0
        public void Synchronize(IImage image)
        {
            var request = new ImageSaveRequest
            {
                Entity = new ImageEntity
                {
                    imageId   = image.Reference.Code,
                    createdBy = image.CreatedBy.Code,
                    createdOn = image.CreatedOn,
                    extension = image.Extention,
                    status    = (int)image.Status
                },
                ImageStream = image.ImageStream
            };

            _imageStorage.Save(request);
        }