Пример #1
0
        private async Task HandleFileDrop(DragEventArgs e)
        {
            if (romsListMain.SelectedIndex > -1 && e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] file_paths = (string[])(e.Data.GetData(DataFormats.FileDrop));

                var file = file_paths[0];

                if (ImageFileValidator.IsValid(file))
                {
                    var selected_rom = (Rom)romsListMain.SelectedObject;

                    Library.SetRomImage(selected_rom, file);

                    romsListMain.RefreshSelectedObjects();
                }
            }
            else if (romsListMain.SelectedIndex > -1 && e.Data.GetDataPresent(DataFormats.Html))
            {
                var selected_rom = (Rom)romsListMain.SelectedObject;

                string data = (string)e.Data.GetData(DataFormats.Html);

                string image_path = HtmlCodeImageUrlExtractor.Extract(data);

                Bitmap image = await ImageDownloader.Download(image_path);

                if (image != null)
                {
                    Library.SetRomImage(selected_rom, image);

                    romsListMain.RefreshSelectedObjects();
                }
            }
        }
Пример #2
0
        protected void ValidateProductModification(T command, List <Fault> faults)
        {
            ImageFileValidator.ValidateFileContent(faults, command.FileContent);
            ImageFileValidator.ValidateImageExtension(faults, command.FileTitle);
            ImageFileValidator.ValidateImageFileTitle(faults, command.FileTitle, command.FileContent);

            ProductValidator.ValidateProductName(faults, command.Name);
            ProductValidator.ValidateProductPrice(faults, command.Price);
        }
Пример #3
0
        /// <summary>
        /// Set image file validation
        /// </summary>
        /// <typeparam name="T">Data type</typeparam>
        /// <param name="fields">Fields</param>
        public static void ImageFile <T>(params ValidationField <T>[] fields)
        {
            string        validatorKey = typeof(ImageFileValidator).FullName;
            DataValidator validator;

            if (Validators.ContainsKey(validatorKey))
            {
                validator = Validators[validatorKey];
            }
            else
            {
                validator = new ImageFileValidator();
                Validators.Add(validatorKey, validator);
            }
            SetValidation(validator, fields);
        }