/// <summary>
 ///     Runs the processor.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <exception cref="T:System.Exception"><c>Exception</c>.</exception>
 public void Process(UploadArgs args)
 {
     Assert.ArgumentNotNull(args, "args");
     for (var index = 0; index < args.Files.Count; ++index)
     {
         var file = args.Files[index];
         if (!string.IsNullOrEmpty(file.FileName))
         {
             try
             {
                 var flag = IsUnpack(args, file);
                 if (args.FileOnly)
                 {
                     if (flag)
                     {
                         UnpackToFile(args, file);
                     }
                     else
                     {
                         var filename = UploadToFile(args, file);
                         if (index == 0)
                         {
                             args.Properties["filename"] = FileHandle.GetFileHandle(filename);
                         }
                     }
                 }
                 else
                 {
                     var mediaUploader = new S3MediaUploader
                     {
                         File          = file,
                         Unpack        = flag,
                         Folder        = args.Folder,
                         Versioned     = args.Versioned,
                         Language      = args.Language,
                         AlternateText = args.GetFileParameter(file.FileName, "alt"),
                         Overwrite     = args.Overwrite,
                         FileBased     = args.Destination == UploadDestination.File
                     };
                     List <S3MediaUploadResult> list;
                     using (new SecurityDisabler())
                         list = mediaUploader.Upload();
                     Log.Audit(this, "Upload: {0}", file.FileName);
                     foreach (var S3MediaUploadResult in list)
                     {
                         ProcessItem(args, S3MediaUploadResult.Item, S3MediaUploadResult.Path);
                     }
                 }
             }
             catch (Exception ex)
             {
                 Log.Error("Could not save posted file: " + file.FileName, ex, this);
                 throw;
             }
         }
     }
 }
        protected override void ActivePageChanged(string page, string oldPage)
        {
            Assert.ArgumentNotNull(page, "page");
            Assert.ArgumentNotNull(oldPage, "oldPage");
            base.ActivePageChanged(page, oldPage);
            if (page == "Uploading")
            {
                this.NextButton.Disabled   = true;
                this.BackButton.Disabled   = true;
                this.CancelButton.Disabled = true;

                Context.ClientPage.ClientResponse.SetAttribute("Path", "value", FileHandle.GetFileHandle(this.Directory));
                Context.ClientPage.ClientResponse.SetAttribute("Overwrite", "value", this.OverwriteCheck.Checked ? "1" : "0");
                Context.ClientPage.ClientResponse.Timer("StartUploading", 10);
            }
            if (page != "LastPage")
            {
                return;
            }
            this.NextButton.Disabled   = true;
            this.BackButton.Disabled   = true;
            this.CancelButton.Disabled = true;
            this.CancelButton.Disabled = false;
        }
Beispiel #3
0
        public void Process(UploadArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");

            for (int index = 0; index < args.Files.Count; ++index)
            {
                HttpPostedFile file = args.Files[index];
                if (!string.IsNullOrEmpty(file.FileName))
                {
                    try
                    {
                        bool flag = UploadProcessor.IsUnpack(args, file);
                        if (args.FileOnly)
                        {
                            if (flag)
                            {
                                Save.UnpackToFile(args, file);
                            }
                            else
                            {
                                string uploadFile = this.UploadToFile(args, file);
                                if (index == 0)
                                {
                                    args.Properties["filename"] = (object)FileHandle.GetFileHandle(uploadFile);
                                }
                            }
                        }
                        else
                        {
                            byte[] fileData = null;
                            file.InputStream.Position = 0;
                            using (var binaryReader = new BinaryReader(file.InputStream))
                            {
                                fileData = binaryReader.ReadBytes(file.ContentLength);
                            }

                            if (fileData == null)
                            {
                                Log.Error($"Could not process the saved posted file {file.FileName}", null, (object)this);
                                return;
                            }

                            byte[] compressedBytes = _compressionManager.OptimizeImage(fileData);

                            //List<Sitecore.Resources.Media.MediaUploadResult> mediaUploadResultList;

                            using (new SecurityDisabler())
                                Upload(file, compressedBytes, flag, args, (args.Destination == UploadDestination.File));

                            Log.Audit((object)this, "Upload: {0}", new string[1]
                            {
                                file.FileName
                            });

                            //foreach (Sitecore.Resources.Media.MediaUploadResult mediaUploadResult in mediaUploadResultList)
                            //    this.ProcessItem(args, (MediaItem)mediaUploadResult.Item, mediaUploadResult.Path);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"Could not save posted file: {file.FileName}", ex, (object)this);
                        throw;
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Runs the processor.
 /// </summary>
 /// <param name="args">The arguments.</param>
 /// <exception cref="T:System.Exception"><c>Exception</c>.</exception>
 public void Process(UploadArgs args)
 {
     Assert.ArgumentNotNull(args, "args");
     for (int i = 0; i < args.Files.Count; i++)
     {
         HttpPostedFile httpPostedFile = args.Files[i];
         if (!string.IsNullOrEmpty(httpPostedFile.FileName))
         {
             try
             {
                 bool flag = UploadProcessor.IsUnpack(args, httpPostedFile);
                 if (args.FileOnly)
                 {
                     if (flag)
                     {
                         Save.UnpackToFile(args, httpPostedFile);
                     }
                     else
                     {
                         string filename = this.UploadToFile(args, httpPostedFile);
                         if (i == 0)
                         {
                             args.Properties["filename"] = FileHandle.GetFileHandle(filename);
                         }
                     }
                 }
                 else
                 {
                     MediaUploader mediaUploader = new MediaUploader
                     {
                         File          = httpPostedFile,
                         Unpack        = flag,
                         Folder        = args.Folder,
                         Versioned     = args.Versioned,
                         Language      = args.Language,
                         AlternateText = args.GetFileParameter(httpPostedFile.FileName, "alt"),
                         Overwrite     = args.Overwrite,
                         FileBased     = args.Destination == UploadDestination.File
                     };
                     System.Collections.Generic.List <MediaUploadResult> list;
                     using (new SecurityDisabler())
                     {
                         list = mediaUploader.Upload();
                     }
                     Log.Audit(this, "Upload: {0}", new string[]
                     {
                         httpPostedFile.FileName
                     });
                     foreach (MediaUploadResult current in list)
                     {
                         this.ProcessItem(args, current.Item, current.Path);
                     }
                 }
             }
             catch (System.Exception exception)
             {
                 Log.Error("Could not save posted file: " + httpPostedFile.FileName, exception, this);
                 throw;
             }
         }
     }
 }