Example #1
0
        public static void UploadImage(IImageFile imageFile, MultipartFileData file = null)
        {
            try
            {
                if (GetContainers().ToList().Find(itm => itm == imageFile.GetContainer()) != null)
                {
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
                    CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer  container      = blobClient.GetContainerReference(imageFile.GetContainer());
                    CloudBlockBlob      imageBlob      = container.GetBlockBlobReference(imageFile.GetFileName());

                    if (file != null)
                    {
                        // Data is in local upload folder
                        imageBlob.UploadFromFile(file.LocalFileName, FileMode.Open);
                    }
                    else
                    {
                        // Data is in imageFile FileData
                        imageBlob.UploadFromByteArray(imageFile.GetFileData(), 0, imageFile.GetFileSize() - 1);
                    }
                }
                else
                {
                    throw new Exception("Container not found");
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public virtual IImageFileModel MapToModel(IImageFile entity, int currentDepth = 1)
        {
            currentDepth++;
            var model = NameableEntityMapper.MapToModel <IImageFile, ImageFileModel>(entity);

            // ImageFile Properties
            // <None>
            // Related Objects
            // <None>
            // Associated Objects
            model.Characters = entity.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToModelLite).ToList();
            model.Chats      = entity.Chats?.Where(i => i.Active).Select(ChatMapperExtensions.MapToModelLite).ToList();
            model.Concepts   = entity.Concepts?.Where(i => i.Active).Select(ConceptMapperExtensions.MapToModelLite).ToList();
            model.Episodes   = entity.Episodes?.Where(i => i.Active).Select(EpisodeMapperExtensions.MapToModelLite).ToList();
            model.Issues     = entity.Issues?.Where(i => i.Active).Select(IssueMapperExtensions.MapToModelLite).ToList();
            model.Locations  = entity.Locations?.Where(i => i.Active).Select(LocationMapperExtensions.MapToModelLite).ToList();
            model.Movies     = entity.Movies?.Where(i => i.Active).Select(MovieMapperExtensions.MapToModelLite).ToList();
            model.Objects    = entity.Objects?.Where(i => i.Active).Select(ObjectMapperExtensions.MapToModelLite).ToList();
            model.People     = entity.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToModelLite).ToList();
            model.Promos     = entity.Promos?.Where(i => i.Active).Select(PromoMapperExtensions.MapToModelLite).ToList();
            model.Publishers = entity.Publishers?.Where(i => i.Active).Select(PublisherMapperExtensions.MapToModelLite).ToList();
            model.StoryArcs  = entity.StoryArcs?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToModelLite).ToList();
            model.Teams      = entity.Teams?.Where(i => i.Active).Select(TeamMapperExtensions.MapToModelLite).ToList();
            model.Videos     = entity.Videos?.Where(i => i.Active).Select(VideoMapperExtensions.MapToModelLite).ToList();
            model.Volumes    = entity.Volumes?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToModelLite).ToList();
            // Return Entity
            return(model);
        }
 public virtual void MapToEntity(IImageFileModel model, ref IImageFile entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // ImageFile Properties
     // <None>
     // Related Objects
     // <None>
     // Associated Objects
     entity.Characters = model.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).ToList();
     entity.Chats = model.Chats?.Where(i => i.Active).Select(ChatMapperExtensions.MapToEntity).ToList();
     entity.Concepts = model.Concepts?.Where(i => i.Active).Select(ConceptMapperExtensions.MapToEntity).ToList();
     entity.Episodes = model.Episodes?.Where(i => i.Active).Select(EpisodeMapperExtensions.MapToEntity).ToList();
     entity.Issues = model.Issues?.Where(i => i.Active).Select(IssueMapperExtensions.MapToEntity).ToList();
     entity.Locations = model.Locations?.Where(i => i.Active).Select(LocationMapperExtensions.MapToEntity).ToList();
     entity.Movies = model.Movies?.Where(i => i.Active).Select(MovieMapperExtensions.MapToEntity).ToList();
     entity.Objects = model.Objects?.Where(i => i.Active).Select(ObjectMapperExtensions.MapToEntity).ToList();
     entity.People = model.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToEntity).ToList();
     entity.Promos = model.Promos?.Where(i => i.Active).Select(PromoMapperExtensions.MapToEntity).ToList();
     entity.Publishers = model.Publishers?.Where(i => i.Active).Select(PublisherMapperExtensions.MapToEntity).ToList();
     entity.StoryArcs = model.StoryArcs?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).ToList();
     entity.Teams = model.Teams?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).ToList();
     entity.Videos = model.Videos?.Where(i => i.Active).Select(VideoMapperExtensions.MapToEntity).ToList();
     entity.Volumes = model.Volumes?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).ToList();
 }
 public virtual void MapToEntity(IImageFileModel model, ref IImageFile entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // ImageFile Properties
     // <None>
     // Related Objects
     // <None>
     // Associated Objects
     entity.Characters = model.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).ToList();
     entity.Chats      = model.Chats?.Where(i => i.Active).Select(ChatMapperExtensions.MapToEntity).ToList();
     entity.Concepts   = model.Concepts?.Where(i => i.Active).Select(ConceptMapperExtensions.MapToEntity).ToList();
     entity.Episodes   = model.Episodes?.Where(i => i.Active).Select(EpisodeMapperExtensions.MapToEntity).ToList();
     entity.Issues     = model.Issues?.Where(i => i.Active).Select(IssueMapperExtensions.MapToEntity).ToList();
     entity.Locations  = model.Locations?.Where(i => i.Active).Select(LocationMapperExtensions.MapToEntity).ToList();
     entity.Movies     = model.Movies?.Where(i => i.Active).Select(MovieMapperExtensions.MapToEntity).ToList();
     entity.Objects    = model.Objects?.Where(i => i.Active).Select(ObjectMapperExtensions.MapToEntity).ToList();
     entity.People     = model.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToEntity).ToList();
     entity.Promos     = model.Promos?.Where(i => i.Active).Select(PromoMapperExtensions.MapToEntity).ToList();
     entity.Publishers = model.Publishers?.Where(i => i.Active).Select(PublisherMapperExtensions.MapToEntity).ToList();
     entity.StoryArcs  = model.StoryArcs?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).ToList();
     entity.Teams      = model.Teams?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).ToList();
     entity.Videos     = model.Videos?.Where(i => i.Active).Select(VideoMapperExtensions.MapToEntity).ToList();
     entity.Volumes    = model.Volumes?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).ToList();
 }
Example #5
0
        bool CreateThumbnail(SafeUri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
        {
            var    pixels = size == ThumbnailSize.Normal ? 128 : 256;
            Pixbuf pixbuf;

            try {
                pixbuf = imageFile.Load();
            } catch (Exception e) {
                Log.DebugFormat("Failed loading image for thumbnailing: {0}", imageFile.Uri);
                Log.DebugException(e);
                return(false);
            }

            double scale_x = (double)pixbuf.Width / pixels;
            double scale_y = (double)pixbuf.Height / pixels;
            double scale   = Math.Max(1.0, Math.Max(scale_x, scale_y));
            // Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
            // Seems to only happen in rare(?) cases
            int target_x = Math.Max((int)(pixbuf.Width / scale), 1);
            int target_y = Math.Max((int)(pixbuf.Height / scale), 1);

            var thumb_pixbuf = pixbuf.ScaleSimple(target_x, target_y, InterpType.Bilinear);
            var mtime        = fileSystem.File.GetMTime(imageFile.Uri).ToString();

            thumb_pixbuf.Savev(thumbnailUri.LocalPath, "png",
                               new string [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
                               new string [] { imageFile.Uri, mtime });

            pixbuf.Dispose();
            thumb_pixbuf.Dispose();

            return(true);
        }
Example #6
0
		bool CreateThumbnail (SafeUri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
		{
			var pixels = size == ThumbnailSize.Normal ? 128 : 256;
			Pixbuf pixbuf;
			try {
				pixbuf = imageFile.Load ();
			} catch (Exception e) {
				Log.DebugFormat ("Failed loading image for thumbnailing: {0}", imageFile.Uri);
				Log.DebugException (e);
				return false;
			}

			double scale_x = (double)pixbuf.Width / pixels;
			double scale_y = (double)pixbuf.Height / pixels;
			double scale = Math.Max (1.0, Math.Max (scale_x, scale_y));
			// Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
			// Seems to only happen in rare(?) cases
			int target_x = Math.Max ((int)(pixbuf.Width / scale), 1);
			int target_y = Math.Max ((int)(pixbuf.Height / scale), 1);

			var thumb_pixbuf = pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear);
			var mtime = fileSystem.File.GetMTime (imageFile.Uri).ToString ();
			thumb_pixbuf.Savev (thumbnailUri.LocalPath, "png",
				new string [] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
				new string [] { imageFile.Uri, mtime });

			pixbuf.Dispose ();
			thumb_pixbuf.Dispose ();

			return true;
		}
Example #7
0
        public void ImageFileDisposeFlushes()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = Encoding.ASCII.GetBytes("This is some sample data!");
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Dispose();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[100];
            Assert.AreEqual(25, file1.Read(data1, 100));
            byte[] trucatedData = new byte[25];
            Array.Copy(data1, trucatedData, 25);
            Assert.AreEqual("This is some sample data!", Encoding.ASCII.GetString(trucatedData));
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
Example #8
0
        protected virtual void ProcessRequest(RequestItem request)
        {
            IImage originalImage;

            try {
                using (IImageFile img = imageFileFactory.Create(request.Uri)) {
                    if (request.Width > 0)
                    {
                        originalImage = img.Load(request.Width, request.Height);
                    }
                    else
                    {
                        originalImage = img.Load();
                    }
                }
            } catch (Exception e) {
                Log.Exception(e);
                return;
            }

            if (originalImage == null)
            {
                return;
            }

            request.Result = originalImage;
        }
        public ThumbnailInfo(IVisualActionDispatcher dispatcher, IImageFile imageFile)
        {
            _dispatcher = dispatcher;
            ImageFile   = imageFile ?? throw new ArgumentNullException(nameof(imageFile));

            ThumbnailImage = GlobalData.LoadingImageThumbnail;
        }
Example #10
0
 /// <summary>
 /// Fits the specified image to the supplied max width / height.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="maxWidthHeight">max width / height.</param>
 /// <param name="fitMode">The fit mode.</param>
 /// <param name="scaleMode">The scale mode.</param>
 /// <param name="alignMode">The align mode.</param>
 /// <param name="format">The format.</param>
 /// <param name="quality">The quality.</param>
 /// <param name="colors">The colors.</param>
 /// <param name="bgColor">Color of the background.</param>
 /// <returns></returns>
 public static IFilteredImage Fit(this IImageFile image, int maxWidthHeight,
                                  FitMode fitMode     = FitMode.Pad, ScaleMode scaleMode = ScaleMode.Down,
                                  AlignMode alignMode = AlignMode.MiddleCenter, ImageFormat format = ImageFormat.Auto,
                                  int quality         = 90, int colors = 256, string bgColor = "")
 {
     return(image.Fit(maxWidthHeight, maxWidthHeight, fitMode, scaleMode, alignMode,
                      format, quality, colors, bgColor));
 }
 protected bool Deactivate(IImageFile entity)
 {
     // Deactivate it
     ImageFilesRepository.Deactivate(entity);
     // Try to Save Changes
     ImageFilesRepository.SaveChanges();
     // Finished!
     return(true);
 }
 public virtual bool AreEqual(IImageFileModel model, IImageFile entity)
 {
     return(NameableEntityMapper.AreEqual(model, entity)
            // ImageFile Properties
            // <None>
            // Related Objects
            // <None>
            );
 }
 public virtual bool AreEqual(IImageFileModel model, IImageFile entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // ImageFile Properties
         // <None>
         // Related Objects
         // <None>
         ;
 }
Example #14
0
 /// <summary>
 /// Creates a new object.
 /// </summary>
 public ImageServer()
 {
     _ImageFile                = Factory.ResolveSingleton <IImageFile>();
     _BrushFactory             = Factory.ResolveSingleton <IBrushFactory>();
     _ImageServerConfiguration = Factory.ResolveSingleton <IImageServerConfiguration>();
     _SharedConfiguration      = Factory.ResolveSingleton <ISharedConfiguration>();
     _Graphics = Factory.ResolveSingleton <IWebSiteGraphics>();
     _AircraftPictureManager       = Factory.ResolveSingleton <IAircraftPictureManager>();
     _AutoConfigPictureFolderCache = Factory.ResolveSingleton <IAutoConfigPictureFolderCache>();
 }
Example #15
0
 public UserService(IUserProfileRepository userProfileRepository,
                    IUserExtendRepository userExtendRepository,
                    IWebpagesMembershipRepository webpagesMembershipRepository,
                    ICacheWraper cacheWraper, IImageFile imageFile)
 {
     this._userExtendRepository = userExtendRepository;
     this._userProfileRepository = userProfileRepository;
     this._webpagesMembershipRepository = webpagesMembershipRepository;
     this._cacheWraper = cacheWraper;
     this._imageFile = imageFile;
 }
Example #16
0
 public UserService(IUserProfileRepository userProfileRepository,
                    IUserExtendRepository userExtendRepository,
                    IWebpagesMembershipRepository webpagesMembershipRepository,
                    ICacheWraper cacheWraper, IImageFile imageFile)
 {
     this._userExtendRepository         = userExtendRepository;
     this._userProfileRepository        = userProfileRepository;
     this._webpagesMembershipRepository = webpagesMembershipRepository;
     this._cacheWraper = cacheWraper;
     this._imageFile   = imageFile;
 }
        public virtual IImageFileModel MapToModelListing(IImageFile entity, int currentDepth = 1)
        {
            currentDepth++;
            var model = NameableEntityMapper.MapToModelListing <IImageFile, ImageFileModel>(entity);

            // ImageFile Properties
            // <None>
            // Related Objects
            // <None>
            // Return Entity
            return(model);
        }
        public MsSqlVolume(IConnectorConfig config, IImageEditorService imageEditorService,

             ICryptoService cryptoService,
            IUploadFile uploadFile, IKey key, IImageFile imageFile)
        {
            _config = config;
            _imageEditorService = imageEditorService;
            _cryptoService = cryptoService;
            _uploadFile = uploadFile;
            _key = key;
            _imageFile = imageFile;
        }
 protected bool Remove(IImageFile entity)
 {
     if (entity == null)
     {
         return(true);
     }                                    // No entity found to remove, consider it passed
     // Remove it
     ImageFilesRepository.Remove(entity);
     // Try to Save Changes
     ImageFilesRepository.SaveChanges();
     // Finished!
     return(true);
 }
Example #20
0
        public BlogPostBuilder WithImage(IImageFile file)
        {
            if (file == null)
            {
                return(this);
            }

            _image = async() =>
            {
                using (var stream = file.OpenStream())
                    return(await _imageService.Save(stream, file.FileName, file.ContentType));
            };

            return(this);
        }
Example #21
0
        public void OpenANonExistFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");

            IImageFile file = disk.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNull(file);

            System.IO.File.Delete(filename);
        }
Example #22
0
        public void SetImage(IImageFile imageFile)
        {
            _imageFile = imageFile ?? throw new ArgumentNullException(nameof(imageFile));

            Title = _imageFile.FileName;

            if (_imageViewState == ImageViewState.FullScreen)
            {
                GoFullScreen();
            }
            else if (_imageViewState == ImageViewState.Detailed)
            {
                GoDetailed();
            }
        }
Example #23
0
        public async Task <IImageFile> ProcessIImageFile(byte[] imageAsBytes, IImageFile image)
        {
            List <Task> tasks = new List <Task>();

            try
            {
                // Convert bytes to image
                using (var ms = new MemoryStream(imageAsBytes))
                {
                    // Create an image file
                    var sysImage = ms.ToImage();
                    //create the thumbnail image
                    var    sysImageThumb  = sysImage.Scale(128, 128);
                    var    sysImageScaled = sysImage.Scale(1000, 1000);
                    string guid           = Guid.NewGuid().ToString();
                    image.FileType      = "jpg";
                    image.FileName      = $"{guid}.{image.FileType}";
                    image.FileNameThumb = $"{guid}_thumb.{image.FileType}";
                    // Upload main image
                    using (Eyon.Utilities.API.AmazonWebService service = new Utilities.API.AmazonWebService(_config.GetValue <string>("AWS:AccessKey")
                                                                                                            , _config.GetValue <string>("AWS:SecretKey")))
                    {
                        using (var newMs = new MemoryStream(ms.Capacity))
                        {
                            newMs.ToStream(sysImageScaled);  // Call ToStream to converts the file to jpeg
                            tasks.Add(service.PutAsync(newMs, _config.GetValue <string>("AWS:Bucket"), image.FileName));
                            using (var newMsThumb = new MemoryStream(ms.Capacity))
                            {
                                newMsThumb.ToStream(sysImageThumb);
                                tasks.Add(service.PutAsync(newMsThumb, _config.GetValue <string>("AWS:Bucket"), image.FileNameThumb));
                                await Task.WhenAll(tasks.ToArray());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await TryDeleteAsync(image.FileName);
                await TryDeleteAsync(image.FileNameThumb);

                throw new SafeException(Models.Enums.ErrorType.AnErrorOccurred, ex);
            }
            return(image);
        }
Example #24
0
        public void CreateWriteLoadReadMultiTrackFile()
        {
            string filename = System.IO.Path.GetTempFileName();

            DiskImage disk = new DiskImage();

            Assert.AreEqual(true, disk.CreateImage(filename));
            disk.Format("Name", "1");
            IImageFile file = disk.Open("TEST", C64FileType.PRG, "wb");

            Assert.IsNotNull(file);

            byte[] data = new byte[2000];
            for (int i = 0; i < 2000; ++i)
            {
                data[i] = (byte)(i % 256);
            }
            Assert.AreEqual(data.Length, file.Write(data, data.Length));
            file.Close();
            disk.Dispose();

            DiskImage disk1 = new DiskImage();

            Assert.AreEqual(true, disk1.LoadImage(filename));
            IImageFile file1 = disk1.Open("TEST", C64FileType.PRG, "rb");

            Assert.IsNotNull(file1);
            byte[] data1 = new byte[3000];
            Assert.AreEqual(2000, file1.Read(data1, 3000));
            byte[] trucatedData = new byte[2000];
            Array.Copy(data1, trucatedData, 2000);
            for (int i = 0; i < 2000; ++i)
            {
                Assert.AreEqual(i % 256, trucatedData[i]);
            }
            file1.Close();
            disk1.Dispose();

            System.IO.File.Delete(filename);
        }
Example #25
0
        bool CreateThumbnail(Uri thumbnailUri, ThumbnailSize size, IImageFile imageFile)
        {
            var    pixels = size == ThumbnailSize.Normal ? 128 : 256;
            IImage image;

            try {
                image = imageFile.Load();
            } catch (Exception e) {
                Log.DebugFormat("Failed loading image for thumbnailing: {0}", imageFile.Uri);
                Log.DebugException(e);
                return(false);
            }

            double scale_x = (double)image.Width / pixels;
            double scale_y = (double)image.Height / pixels;
            double scale   = Math.Max(1.0, Math.Max(scale_x, scale_y));
            // Ensures that the minimum value is 1 so that pixbuf.ScaleSimple doesn't return null
            // Seems to only happen in rare(?) cases
            int target_x = Math.Max((int)(image.Width / scale), 1);
            int target_y = Math.Max((int)(image.Height / scale), 1);

            var thumbImage = image as Image <Rgba32>;

            thumbImage.Mutate(x => x.Resize(target_x, target_y));              // pixbuf.ScaleSimple (target_x, target_y, InterpType.Bilinear);
            var mtime = fileSystem.File.GetLastWriteTime(imageFile.Uri).ToString();

            using (var stream = new FileStream(thumbnailUri.LocalPath, FileMode.Create)) {
                thumbImage.SaveAsPng(stream, new PngEncoder());
            }
            // FIXME
            //thumbImage.SaveAsPng (. .Savev (thumbnailUri.LocalPath, "png",
            //	new string[] { ThumbnailService.ThumbUriOpt, ThumbnailService.ThumbMTimeOpt, null },
            //	new string[] { imageFile.Uri.AbsoluteUri, mtime });

            image.Dispose();
            thumbImage.Dispose();

            return(true);
        }
Example #26
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        public WebSiteGraphics()
        {
            _ImageFile    = Factory.ResolveSingleton <IImageFile>();
            _PenFactory   = Factory.ResolveSingleton <IPenFactory>();
            _BrushFactory = Factory.ResolveSingleton <IBrushFactory>();
            _FontFactory  = Factory.ResolveSingleton <IFontFactory>();

            _SplashFillBrush  = _BrushFactory.CreateBrush(255, 255, 255, 255, useCache: true);
            _SplashFontFamily = _FontFactory.GetFontFamilyOrFallback(
                _SplashFontStyle,
                "Tahoma",
                "Microsoft Sans Serif",
                "MS Reference Sans Serif",
                "Roboto",
                "Droid Sans",
                "MS Sans Serif",
                "Verdana",
                "Helvetica",
                "Sans Serif",
                "Sans"
                );
        }
Example #27
0
        public static async Task <IImageFile> CreateImageFromRequest(string container, string fileName, HttpRequestMessage request)
        {
            var provider = new MultipartMemoryStreamProvider();
            await request.Content.ReadAsMultipartAsync(provider);

            IImageFile imageFile = CreateImageModel(container);

            foreach (var item in provider.Contents)
            {
                switch (item.Headers.ContentDisposition.Name.Replace("\"", ""))
                {
                case "AvatarFile":
                    var fileData = await item.ReadAsByteArrayAsync();

                    var contentType = item.Headers.ContentType.ToString();
                    var fileSize    = fileData.Length;
                    imageFile.SetMetadata(container, fileName, contentType, fileData);
                    break;
                }
            }

            return(imageFile);
        }
 public virtual IImageFileModel MapToModelLite(IImageFile entity, int currentDepth = 1)
 {
     currentDepth++;
     var model = NameableEntityMapper.MapToModelLite<IImageFile, ImageFileModel>(entity);
     // ImageFile Properties
     // <None>
     // Related Objects
     // <None>
     // Return Entity
     return model;
 }
 public void Update(IImageFile entity)
 {
     Context.SetModified(entity);
 }
            public IImage GetNextImage()
            {
                while( true ) {
                    if( imageFile == null ) {
                        if( fileNames.Count > 0 ) {
                            imageFile = imageTools.OpenImageFile( (string)fileNames.Dequeue() );
                            nextPageIndex = 0;
                        } else {
                            return null;
                        }
                    }
                    assert( imageFile != null );
                    if( nextPageIndex < imageFile.PagesCount ) {
                        IImage nextPage = imageFile.OpenImagePage( nextPageIndex++ );

                        // Here you can apply any required preprocessing to the image in memory
                        // using built-in IImageProcessingTools (see description), your own algorithms or
                        // third-party components
                        // ...

                        return nextPage;
                    } else {
                        imageFile = null;
                        continue;
                    }
                }
            }
 public DiscImageViewItem(DiscViewItem discItem, DiscImageType imageType, IImageFile imageFile)
 {
     DiscSourcePath = discItem?.SourcePath ?? throw new ArgumentNullException(nameof(discItem));
     ImageType      = imageType;
     this.imageFile = imageFile;
 }
 public void Remove(IImageFile entity)
 {
     Context.ImageFiles.Remove((ImageFile)entity);
 }
		private void ShowImage(IImageFile imageFile)
		{
			_View.DataContext = imageFile;
		}
 public virtual IImageFileModel MapToModel(IImageFile entity, int currentDepth = 1)
 {
     currentDepth++;
     var model = NameableEntityMapper.MapToModel<IImageFile, ImageFileModel>(entity);
     // ImageFile Properties
     // <None>
     // Related Objects
     // <None>
     // Associated Objects
     model.Characters = entity.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToModelLite).ToList();
     model.Chats = entity.Chats?.Where(i => i.Active).Select(ChatMapperExtensions.MapToModelLite).ToList();
     model.Concepts = entity.Concepts?.Where(i => i.Active).Select(ConceptMapperExtensions.MapToModelLite).ToList();
     model.Episodes = entity.Episodes?.Where(i => i.Active).Select(EpisodeMapperExtensions.MapToModelLite).ToList();
     model.Issues = entity.Issues?.Where(i => i.Active).Select(IssueMapperExtensions.MapToModelLite).ToList();
     model.Locations = entity.Locations?.Where(i => i.Active).Select(LocationMapperExtensions.MapToModelLite).ToList();
     model.Movies = entity.Movies?.Where(i => i.Active).Select(MovieMapperExtensions.MapToModelLite).ToList();
     model.Objects = entity.Objects?.Where(i => i.Active).Select(ObjectMapperExtensions.MapToModelLite).ToList();
     model.People = entity.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToModelLite).ToList();
     model.Promos = entity.Promos?.Where(i => i.Active).Select(PromoMapperExtensions.MapToModelLite).ToList();
     model.Publishers = entity.Publishers?.Where(i => i.Active).Select(PublisherMapperExtensions.MapToModelLite).ToList();
     model.StoryArcs = entity.StoryArcs?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToModelLite).ToList();
     model.Teams = entity.Teams?.Where(i => i.Active).Select(TeamMapperExtensions.MapToModelLite).ToList();
     model.Videos = entity.Videos?.Where(i => i.Active).Select(VideoMapperExtensions.MapToModelLite).ToList();
     model.Volumes = entity.Volumes?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToModelLite).ToList();
     // Return Entity
     return model;
 }
Example #35
0
        public void Save(IDiskImage di)
        {
            if (RawData == null)
            {
                throw new InvalidOperationException("Cannot save a file without loading one first.");
            }

            RawData[SexOffset]            = (byte)Sex;
            RawData[ClassOffset]          = (byte)Class;
            RawData[RaceOffset]           = (byte)Race;
            RawData[HitPointsOffset]      = (byte)(HitPoints & 0x00ff);
            RawData[HitPointsOffset + 1]  = (byte)(HitPoints >> 8);
            RawData[ExperienceOffset]     = (byte)(Experience & 0x00ff);
            RawData[ExperienceOffset + 1] = (byte)(Experience >> 8);

            RawData[StrengthOffset]     = (byte)Strength;
            RawData[AgilityOffset]      = (byte)Agility;
            RawData[StaminaOffset]      = (byte)Stamina;
            RawData[CharismaOffset]     = (byte)Charisma;
            RawData[WisdomOffset]       = (byte)Wisdom;
            RawData[IntelligenceOffset] = (byte)Intelligence;

            for (int i = 0; i < 10; ++i)
            {
                RawData[SpellsOffset + i] = (byte)Spells[i];
            }

            for (int i = 0; i < 5; ++i)
            {
                RawData[ArmorOffset + i] = (byte)Armor[i];
            }

            for (int i = 0; i < 15; ++i)
            {
                RawData[WeaponsOffset + i] = (byte)Weapons[i];
            }

            RawData[FoodOffset]     = (byte)(Food & 0x00ff);
            RawData[FoodOffset + 1] = (byte)(Food >> 8);

            RawData[CoinsOffset]     = (byte)(Coins & 0x00ff);
            RawData[CoinsOffset + 1] = (byte)(Coins >> 8);

            for (int i = 0; i < 4; ++i)
            {
                RawData[GemsOffset + i] = (byte)Gems[i];
            }

            RawData[EnemyShipsOffset] = (byte)EnemyShips;

            RawData[LocationOffset]     = (byte)Location.X;
            RawData[LocationOffset + 1] = (byte)Location.Y;


            IImageFile image = di.Open("P" + RosterId, C64FileType.PRG, "wb");

            if (image == null)
            {
                throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for write.");
            }

            int len = image.Write(RawData, RawData.Length);

            if (len != RawData.Length)
            {
                throw new System.IO.IOException("There was an error writing file 'P" + RosterId + ".PRG'.");
            }

            image.Close();
        }
Example #36
0
        public void Load(IDiskImage di, int rosterNumber)
        {
            byte[] buffer = new byte[200000]; // they seem to be 460 bytes, but screw it better safe than sorry.

            IImageFile image = di.Open("P" + rosterNumber, C64FileType.PRG, "rb");

            if (image == null)
            {
                throw new System.IO.FileLoadException("Cannot open save file 'P" + RosterId + ".PRG' for read.");
            }
            int len = image.Read(buffer, buffer.Length);

            RawData = new byte[len];
            Buffer.BlockCopy(buffer, 0, RawData, 0, len);
            image.Close();


            RosterId   = rosterNumber;
            m_name     = ProcessName();
            Sex        = (U1Sex)RawData[SexOffset];
            Class      = (U1Class)RawData[ClassOffset];
            Race       = (U1Race)RawData[RaceOffset];
            HitPoints  = RawData[HitPointsOffset] | (RawData[HitPointsOffset + 1] << 8);
            Experience = RawData[ExperienceOffset] | (RawData[ExperienceOffset + 1] << 8);

            Strength     = RawData[StrengthOffset];
            Agility      = RawData[AgilityOffset];
            Stamina      = RawData[StaminaOffset];
            Charisma     = RawData[CharismaOffset];
            Wisdom       = RawData[WisdomOffset];
            Intelligence = RawData[IntelligenceOffset];

            for (int i = 0; i < 10; ++i)
            {
                Spells[i] = RawData[SpellsOffset + i];
            }

            for (int i = 0; i < 5; ++i)
            {
                Armor[i] = RawData[ArmorOffset + i];
            }

            for (int i = 0; i < 15; ++i)
            {
                Weapons[i] = RawData[WeaponsOffset + i];
            }

            Food  = RawData[FoodOffset] | (RawData[FoodOffset + 1] << 8);
            Coins = RawData[CoinsOffset] | (RawData[CoinsOffset + 1] << 8);

            for (int i = 0; i < 4; ++i)
            {
                Gems[i] = RawData[GemsOffset + i];
            }

            for (int i = 0; i < 6; ++i)
            {
                m_transportation[i] = RawData[TransportationOffset + i];
            }
            m_transportation[6] = RawData[TimeMachineOffset];

            EnemyShips = RawData[EnemyShipsOffset];

            Location.X = RawData[LocationOffset];
            Location.Y = RawData[LocationOffset + 1];
        }
Example #37
0
 /// <summary>
 /// Fits the specified image to the supplied max width.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="maxWidth">Width of the max.</param>
 /// <returns></returns>
 public static IFilteredImage FitWidth(this IImageFile image, int maxWidth)
 {
     return(new FilteredImage(image).FitWidth(maxWidth));
 }
Example #38
0
 public FilteredImage(IImageFile image)
 {
     Image   = image;
     Filters = new Dictionary <string, object>();
 }
Example #39
0
 /// <summary>
 /// Fits the specified image to the supplied max height.
 /// </summary>
 /// <param name="image">The image.</param>
 /// <param name="maxHeight">Max height.</param>
 /// <returns></returns>
 public static IFilteredImage FitHeight(this IImageFile image, int maxHeight)
 {
     return(new FilteredImage(image).FitHeight(maxHeight));
 }
 protected bool Remove(IImageFile entity)
 {
     if (entity == null) { return true; } // No entity found to remove, consider it passed
     // Remove it
     ImageFilesRepository.Remove(entity);
     // Try to Save Changes
     ImageFilesRepository.SaveChanges();
     // Finished!
     return true;
 }
 protected bool Deactivate(IImageFile entity)
 {
     // Deactivate it
     ImageFilesRepository.Deactivate(entity);
     // Try to Save Changes
     ImageFilesRepository.SaveChanges();
     // Finished!
     return true;
 }
 public static bool AreEqual(this IImageFileModel model, IImageFile entity)
 {
     return Mapper.AreEqual(model, entity);
 }
Example #43
0
        public new Bitmap Extract(String sPath)
        {
            SimpleObjectFactory sof = new SimpleObjectFactory();

            IImageFile cimg    = sof.getImageFile();
            Bitmap     cbmp    = cimg.getBitMap(sPath);
            int        cwidth  = cimg.getWidth(sPath);
            int        cheight = cimg.getHeight(sPath);

            int    cx = 0, cy = 0;
            string swidth = null, sheight = null;

            for (int i = 0; i < 5; i++)
            {
                Color lp = cbmp.GetPixel(cx, cy);
                int   ca = lp.A;
                int   cr = lp.R;
                int   cg = lp.G;
                int   cb = lp.B;
                swidth += (cr % 2).ToString();
                swidth += (cg % 2).ToString();
                swidth += (cb % 2).ToString();
                cx++;
            }


            for (int i = 0; i < 5; i++)
            {
                Color lp = cbmp.GetPixel(cx, cy);
                int   ca = lp.A;
                int   cr = lp.R;
                int   cg = lp.G;
                int   cb = lp.B;
                sheight += (cr % 2).ToString();
                sheight += (cg % 2).ToString();
                sheight += (cb % 2).ToString();
                cx++;
            }


            int sw = Convert.ToInt32(swidth, 2);
            int sh = Convert.ToInt32(sheight, 2);

            Bitmap s = new Bitmap(sw, sh);

            for (int i = 0; i < sh; i++)
            {
                for (int j = 0; j < sw; j++)
                {
                    string all = null;
                    for (int k = 0; k < 11; k++)
                    {
                        Color lp = cbmp.GetPixel(cx, cy);
                        int   ca = lp.A;
                        int   cr = lp.R;
                        int   cg = lp.G;
                        int   cb = lp.B;

                        all += (cr % 2).ToString();
                        all += (cg % 2).ToString();
                        all += (cb % 2).ToString();

                        cx++;
                        if (cx == cwidth)
                        {
                            cx = 0; cy++;
                        }
                    }
                    string alpha = all.Substring(0, 8);
                    int    sa    = Convert.ToInt32(alpha, 2);
                    string red   = all.Substring(8, 8);
                    int    sr    = Convert.ToInt32(red, 2);
                    string green = all.Substring(16, 8);
                    int    sg    = Convert.ToInt32(green, 2);
                    string blue  = all.Substring(24, 8);
                    int    sb    = Convert.ToInt32(blue, 2);

                    s.SetPixel(j, i, Color.FromArgb(sa, sr, sg, sb));
                }
            }

            return(s);
        }
 public static void MapToEntity(this IImageFileModel model, ref IImageFile entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
Example #45
0
 public AvatarController(IImageFile imagefile, IUserService userService)
 {
     this._imagefile = imagefile;
     this._userService = userService;
 }
        public FileServerImageEditorService(Dev.Framework.FileServer.IImageFile imageFile)
        {
            _imageFile = imageFile;

        }
Example #47
0
 public FilteredImage(IImageFile image)
 {
     Image = image;
     Filters = new Dictionary<string, object>();
 }
 public void Add(IImageFile entity)
 {
     Context.ImageFiles.Add((ImageFile)entity);
 }
Example #49
0
 /// <summary>
 /// Returns a media url.
 /// </summary>
 /// <param name="image">The image file.</param>
 /// <param name="resizingOptions">The resizing options.</param>
 /// <returns></returns>
 public IHtmlString MediaUrl(IImageFile image, ResizingOptions resizingOptions)
 {
     return(MediaUrl(image.KeyPath, resizingOptions));
 }
Example #50
0
 /// <summary>
 /// Returns a media url.
 /// </summary>
 /// <param name="image">The image file.</param>
 /// <param name="resizingOptions">The resizing options.</param>
 /// <returns></returns>
 public IHtmlString MediaUrl(IImageFile image, ResizingOptions resizingOptions)
 {
     return MediaUrl(image.KeyPath, resizingOptions);
 }
 public void Deactivate(IImageFile entity)
 {
     entity.Active = false;
     Update(entity);
 }