예제 #1
0
        //Overrides method for recording data during the initialization of the database
        protected override void Seed(ImageDataContext context)
        {
            context.ImageEntitys.RemoveRange(context.ImageEntitys);

            try
            {
                // Only get files that begin with the format .jpg
                string[] dirs = Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images/"), "*.jpg");

                foreach (string dir in dirs)
                {
                    context.ImageEntitys.Add(new ImageEntity
                    {
                        Description = String.Format("Image " + dir.Substring(dir.LastIndexOf('\\') + 1, dir.IndexOf('.') - dir.LastIndexOf('\\') - 1) + "."),
                        Photo       = ImageProvider.GetImage(dir)
                    });
                }
            }
            catch (Exception e)
            {
                //add error log
                //Console.WriteLine(e.Message);
            }

            context.SaveChanges();
            base.Seed(context);
        }
예제 #2
0
        public async Task <ActionResult> ClickerTest()
        {
            var dummy = new ClickerModel
            {
                Name         = "test",
                Data         = "DummyData" + new Random(10),
                Published_at = DateTime.Now
            };

            var payload = JsonConvert.SerializeObject(dummy);

            var result = await ImageProvider.GetImage(payload, "http://placeholder.no/api/clicker/inputdata");

            if (result != null && result is bool && (bool)result)
            {
                return new JsonResult()
                       {
                           Data = new { Result = "Success" },
                           JsonRequestBehavior = JsonRequestBehavior.AllowGet
                       }
            }
            ;
            else
            {
                return new JsonResult()
                       {
                           Data = new { Result = "Failure" },
                           JsonRequestBehavior = JsonRequestBehavior.AllowGet
                       }
            };
        }
예제 #3
0
 private void LoadImage()
 {
     Bitmap = ImageProvider.GetImage();
     if (Bitmap != null)
     {
         Loaded = true;
     }
 }
예제 #4
0
        private void _textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try {
                if (!_tab.ItemsEventsDisabled)
                {
                    DisplayableProperty <TKey, TValue> .ApplyCommand(_tab, _attribute, _textBox.Text);
                }

                try {
                    byte[] data = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath1, _textBox.Text.ExpandString()) + _ext));

                    if (data != null)
                    {
                        WpfUtilities.TextBoxOk(_textBox);
                        _wrapper1.Image = ImageProvider.GetImage(data, _ext);
                        _wrapper1.Image.MakePinkTransparent();
                        _imageResource.Tag    = _textBox.Text;
                        _imageResource.Source = _wrapper1.Image.Cast <BitmapSource>();
                    }
                    else
                    {
                        WpfUtilities.TextBoxError(_textBox);
                        _wrapper1.Image       = null;
                        _imageResource.Source = null;
                    }
                }
                catch (ArgumentException) {
                    WpfUtilities.TextBoxError(_textBox);
                    _wrapper1.Image       = null;
                    _imageResource.Source = null;
                }

                try {
                    byte[] data2 = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath2, _textBox.Text.ExpandString()) + _ext));

                    if (data2 != null)
                    {
                        _wrapper2.Image = ImageProvider.GetImage(data2, _ext);
                        _wrapper2.Image.MakePinkTransparent();
                        _imagePreview.Tag    = _textBox.Text;
                        _imagePreview.Source = _wrapper2.Image.Cast <BitmapSource>();
                        //_imagePreview.Source.Freeze();
                    }
                    else
                    {
                        _wrapper2.Image      = null;
                        _imagePreview.Source = null;
                    }
                }
                catch (ArgumentException) {
                    _wrapper2.Image      = null;
                    _imagePreview.Source = null;
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
예제 #5
0
        public void resize_image_svg_returns_successfully()
        {
            var imageService = new ImageProvider(_server);
            var assembly     = typeof(ImageServiceTests).GetTypeInfo().Assembly;
            var bytes        = ReadFully(assembly.GetManifestResourceStream("Arragro.Providers.ImageServiceProvider.IntegrationTests.Resources.ArragroCMSLogo.svg"));
            var result       = imageService.GetImage(bytes, 300, 80, true).Result;

            Assert.False(result.IsImage);
            Assert.Equal(bytes.Length, result.Size);
        }
예제 #6
0
        /// <summary>
        ///   The create tab.
        /// </summary>
        /// <param name = "tabName">
        ///   The tab name.
        /// </param>
        /// <returns>
        /// </returns>
        private TabViewModel CreateTab(string tabName)
        {
            var tab = new TabViewModel(tabName, this);

            if (ImageProvider != null)
            {
                tab.Icon = ImageProvider.GetImage(SelectedObject.GetType(), Name);
            }

            return(tab);
        }
예제 #7
0
        private void InitiateCititor(UserModel selectedUser)
        {
            label8.Text  = String.Format("IdCititor : {0}", selectedUser.ID.ToString());
            label9.Text  = String.Format("Nume si Prenume : {0}", selectedUser.NumePenume);
            label10.Text = String.Format("Rezervari ramase : {0}", _rezervari.Where(x => x.StatusRezervare == 1).Count());
            label11.Text = String.Format("Imprumuturi ramase : {0}", _imprumutri.Where(x => x.DataRestituire == new DateTime()).Count());

            pictureBox3.Image = ImageProvider.GetImage(selectedUser.ID);

            InitiatiateImprumuturiGrid();
        }
예제 #8
0
        public void resize_image_jpg_quality_returns_successfully()
        {
            var imageService = new ImageProvider(_server);
            var assembly     = typeof(ImageServiceTests).GetTypeInfo().Assembly;
            var bytes        = ReadFully(assembly.GetManifestResourceStream("Arragro.Providers.ImageServiceProvider.IntegrationTests.Resources.bear-hands.jpg"));
            var result       = imageService.GetImage(bytes).Result;

            Assert.True(result.Size < bytes.Length);
            Assert.Equal("image/jpeg", result.MimeType);
            Assert.Equal(1201, result.Width);
            Assert.Equal(800, result.Height);
        }
예제 #9
0
        public async Task <ActionResult> RunTest()
        {
            var a    = "http://text2slides.westeurope.cloudapp.azure.com/text2slides";
            var b    = "Test of concept with a few words";
            var data = await ImageProvider.GetImage(b, "", "", a) as ImageList;

            return(new JsonResult()
            {
                Data = new { Result = data },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #10
0
        public void resize_image_gif_resize_returns_successfully()
        {
            var imageService = new ImageProvider(_server);
            var assembly     = typeof(ImageServiceTests).GetTypeInfo().Assembly;
            var bytes        = ReadFully(assembly.GetManifestResourceStream("Arragro.Providers.ImageServiceProvider.IntegrationTests.Resources.gold.gif"));
            var result       = imageService.GetImage(bytes, 300, 80, true).Result;

            Assert.True(result.Size < bytes.Length);
            Assert.Equal("image/gif", result.MimeType);
            Assert.Equal(300, result.Width);
            Assert.Equal(168, result.Height);
        }
예제 #11
0
        private void _textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try {
                byte[] data = _tab.Database.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath, _textBox.Text) + _ext));

                if (data != null)
                {
                    if (_ext == ".spr")
                    {
                        try {
                            Spr spr = new Spr(data, false);

                            if (spr.Images.Count > 0)
                            {
                                _wrapper.Image = spr.Images[0];
                                _wrapper.Image.MakePinkTransparent();
                                _wrapper.Image.MakeFirstPixelTransparent();
                                _image.Tag    = _textBox.Text;
                                _image.Source = _wrapper.Image.Cast <BitmapSource>();
                            }
                            else
                            {
                                _cancelImage();
                            }
                        }
                        catch {
                            _cancelImage();
                        }
                    }
                    else
                    {
                        _wrapper.Image = ImageProvider.GetImage(data, _ext);
                        _wrapper.Image.MakePinkTransparent();
                        _wrapper.Image.MakeFirstPixelTransparent();
                        _image.Tag    = _textBox.Text;
                        _image.Source = _wrapper.Image.Cast <BitmapSource>();
                    }
                }
                else
                {
                    _cancelImage();
                }
            }
            catch (Exception err) {
                _cancelImage();
                ErrorHandler.HandleException(err);
            }
        }
        public async Task <ActionResult> UploadSlideData([FromBody] SimpleImageModel model)
        {
            if (model == null || model.Id == 0)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var contentRepository    = ServiceLocator.Current.GetInstance <IContentRepository>();
            var contentLoaderWrapper = ServiceLocator.Current.GetInstance <ContentLoaderWrapper>();

            var reference    = new ContentReference(model.Id);
            var presentation = contentLoaderWrapper.GetPageFromReference <PresentationModel>(reference);


            var images   = contentRepository.GetChildren <ImageModel>(reference);
            var prevText = images.FirstOrDefault()?.Text ?? "";


            if (presentation != null)
            {
                var imageList = await ImageProvider.GetImage(model.Text, GetRandomWord(), prevText) as ImageList;

                if (imageList == null)
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }

                var imageModel = contentRepository.GetDefault <ImageModel>(presentation.ContentLink);
                imageModel.PageName = "New imagemodel number" + new Random().Next();
                imageModel.Text     = model.Text;
                imageModel.Url      = imageList?.Slides?.FirstOrDefault().Url;

                // Need AccessLevel.NoAccess to get permission to create and save this new page.
                contentRepository.Save(imageModel, SaveAction.Publish, AccessLevel.NoAccess);

                // Just changing the page name to contain its ContentLink ID, to make it more clear in the CMS
                imageModel.PageName = "Imagemodel nr. " + imageModel.ContentLink.ID;
                contentRepository.Save(imageModel, SaveAction.Publish, AccessLevel.NoAccess);

                throw new HttpResponseException(HttpStatusCode.Accepted);
            }

            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }
예제 #13
0
        private void _items_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try {
                if (_items.SelectedItem != null)
                {
                    object selectedItem = _items.SelectedItem;

                    string displayFileName = ((FileEntry)selectedItem).DisplayRelativePath;
                    SelectedPath         = _metaGrf.FindTkPath(Path.Combine(_explorerPath, displayFileName));
                    _wrapper.Image       = ImageProvider.GetImage(_metaGrf.GetData(Path.Combine(_explorerPath, displayFileName)), Path.GetExtension(displayFileName));
                    _imagePreview.Tag    = displayFileName;
                    _imagePreview.Source = _wrapper.Image.Cast <BitmapSource>();
                }
            }
            catch {
                _wrapper.Image       = null;
                _imagePreview.Source = null;
            }
        }
예제 #14
0
 /// <summary>
 /// Fetches an image of the requested size.
 /// </summary>
 /// <param name="key">Key used to identify an image.</param>
 /// <param name="size">Size of image to obtain.</param>
 /// <returns>If supported, returns requested image. A value of null
 /// indicates that the requested size is not supported.</returns>
 public virtual Image GetImage(object key, ImageSize size)
 {
     return(ImageProvider.GetImage(key, size));
 }
예제 #15
0
        private void InitiateUserInfo()
        {
            label3.Text = user.NumePenume;

            pictureBox2.Image = ImageProvider.GetImage(user.ID);
        }
예제 #16
0
        protected override void OnLoad(EventArgs e)
        {
            pictureBox1.Image = ImageProvider.GetImage(Utilizator.ID);

            label2.Text = Utilizator.NumePenume;
        }
 /// <summary>
 /// Fetches an image of the requested size.
 /// </summary>
 /// <param name="key">Key used to identify an image.</param>
 /// <param name="size">Size of image to obtain.</param>
 /// <returns>If supported, returns requested image. A value of null
 /// indicates that the requested size is not supported.</returns>
 public virtual Image GetImage(object key, ShengToolStripImageSize size)
 {
     return ImageProvider.GetImage(key, size);
 }
예제 #18
0
        private void _threadStart(object sender, TextChangedEventArgs e)
        {
            try {
                var    text  = _textBox.Text;
                var    tuple = e == null ? sender as ReadableTuple <int> : _tab._listView.SelectedItem as ReadableTuple <int>;
                byte[] data  = _tab.ProjectDatabase.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath, text) + _ext));

                if (tuple != null)
                {
                    if (e != null)
                    {
                        _redirect = tuple.GetIntNoThrow(ServerMobAttributes.Sprite);
                    }

                    if (_redirect > 0)
                    {
                        var db = _tab.GetMetaTable <int>(ServerDbs.Mobs);
                        tuple     = db.TryGetTuple(_redirect);
                        _redirect = 0;

                        if (tuple != null)
                        {
                            var val = tuple.GetValue <string>(ServerMobAttributes.ClientSprite);
                            data = _tab.ProjectDatabase.MetaGrf.GetData(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath, val) + _ext));
                        }
                    }
                }

                if (data != null)
                {
                    if (_ext == ".spr")
                    {
                        try {
                            var image = Spr.GetFirstImage(data);

                            if (image != null)
                            {
                                _wrapper.Image = image;
                                _wrapper.Image.MakePinkTransparent();
                                _wrapper.Image.MakeFirstPixelTransparent();

                                _image.BeginDispatch(delegate {
                                    var bitmap    = _wrapper.Image.Cast <BitmapSource>();
                                    _image.Tag    = text;
                                    _image.Source = bitmap;
                                });
                            }
                            else
                            {
                                _cancelImage();
                            }
                        }
                        catch {
                            _cancelImage();
                        }
                    }
                    else
                    {
                        _wrapper.Image = ImageProvider.GetImage(data, _ext);
                        _wrapper.Image.MakePinkTransparent();
                        _wrapper.Image.MakeFirstPixelTransparent();

                        _image.BeginDispatch(delegate {
                            var bitmap    = _wrapper.Image.Cast <BitmapSource>();
                            _image.Tag    = text;
                            _image.Source = bitmap;
                        });
                    }
                }
                else
                {
                    _cancelImage();
                }
            }
            catch (Exception err) {
                _cancelImage();
                ErrorHandler.HandleException(err);
            }
        }
예제 #19
0
        private void _textBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            try {
                if (!_tab.ItemsEventsDisabled)
                {
                    DisplayableProperty <TKey, TValue> .ApplyCommand(_tab, _attribute, _textBox.Text);
                }

                try {
                    byte[] data = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath1, _textBox.Text.ExpandString()) + _ext));

                    if (data != null)
                    {
                        _textBox.Dispatch(p => p.Background = Application.Current.Resources["GSearchEngineOk"] as Brush);

                        _wrapper1.Image = ImageProvider.GetImage(data, _ext);
                        _wrapper1.Image.MakePinkTransparent();

                        if (_wrapper1.Image.GrfImageType == GrfImageType.Bgr24)
                        {
                            _wrapper1.Image.Convert(GrfImageType.Bgra32);
                        }

                        _imageResource.Tag    = _textBox.Text;
                        _imageResource.Source = _wrapper1.Image.Cast <BitmapSource>();
                    }
                    else
                    {
                        _textBox.Dispatch(p => p.Background = Application.Current.Resources["GSearchEngineError"] as Brush);
                        _wrapper1.Image       = null;
                        _imageResource.Source = null;
                    }
                }
                catch (ArgumentException) {
                    _textBox.Dispatch(p => p.Background = Application.Current.Resources["GSearchEngineError"] as Brush);
                    _wrapper1.Image       = null;
                    _imageResource.Source = null;
                }

                try {
                    byte[] data2 = _tab.ProjectDatabase.MetaGrf.GetDataBuffered(EncodingService.FromAnyToDisplayEncoding(GrfPath.Combine(_grfPath2, _textBox.Text.ExpandString()) + _ext));

                    if (data2 != null)
                    {
                        _wrapper2.Image = ImageProvider.GetImage(data2, _ext);
                        _wrapper2.Image.MakePinkTransparent();
                        _imagePreview.Tag    = _textBox.Text;
                        _imagePreview.Source = _wrapper2.Image.Cast <BitmapSource>();
                        //_imagePreview.Source.Freeze();
                    }
                    else
                    {
                        _wrapper2.Image      = null;
                        _imagePreview.Source = null;
                    }
                }
                catch (ArgumentException) {
                    _wrapper2.Image      = null;
                    _imagePreview.Source = null;
                }
            }
            catch {
                //ErrorHandler.HandleException(err);
            }
        }