public override void Upload(MediaContent content, Stream source, string extension, bool uploadAndReplace)
        {
            if (content is Image)
            {
                ImageUploadingEvent eventArgs = new ImageUploadingEvent
                {
                    RawImageStream   = source,
                    ImageContentItem = content as Image
                };

                this.OnImageUploading(eventArgs);

                if (eventArgs.RawImageChanged)
                {
                    // Using a temp MemoryStream in order to prevent a closing/disposing
                    // the Stream or Image (image obj which has been created from that stream and in case of disposing the image it will also dispose the stream)
                    // earlier and causing a "A generic error occurred in GDI+" exception.
                    using (MemoryStream tempStream = new MemoryStream())
                    {
                        eventArgs.RawImageStream.CopyTo(tempStream);
                        base.Upload(content, tempStream, extension);
                    }

                    this.OnImageUploaded(new ImageUploadedEvent()
                    {
                        RawImageStream   = eventArgs.RawImageStream,
                        ImageContentItem = content as Image
                    });

                    return;
                }
            }

            base.Upload(content, source, extension, uploadAndReplace);
        }
        protected virtual void OnImageUploading(ImageUploadingEvent eventArgs)
        {
            if (eventArgs == null)
            {
                throw new ArgumentException("eventArgs");
            }

            EventHub.Raise(eventArgs);
        }
        private void HandleImageUploadingEvent(ImageUploadingEvent imageUploadingEvent)
        {
            if (imageUploadingEvent == null)
            {
                throw new ArgumentNullException("imageUploadingEvent");
            }

            var cognitiveImageProcessors = ObjectFactory.Container.ResolveAll <ICognitiveImageProcessor>();

            if (cognitiveImageProcessors != null && cognitiveImageProcessors.Any())
            {
                foreach (ICognitiveImageProcessor cognitiveImageProcessor in cognitiveImageProcessors)
                {
                    if (cognitiveImageProcessor.CanProcess())
                    {
                        cognitiveImageProcessor.Process(imageUploadingEvent.ImageContentItem, imageUploadingEvent.RawImageStream);
                    }
                }
            }
        }