public static bool IsImage(this HttpPostedFileBase file)
        {
            if (file.ContentType.Contains("image"))
            {
                return true;
            }

            var formats = new[]
            {
                ImageFormat.Jpeg,
                ImageFormat.Png,
                ImageFormat.Gif,
                ImageFormat.Jpeg,
                ImageFormat.Bmp,
                ImageFormat.Tiff
            };

            using (var img = Image.FromStream(file.InputStream))
            {
                return formats.Contains(img.RawFormat);
            }

            // Or can use:

            //string[] formats = new string[] { ".jpg", ".png", ".gif", ".jpeg", ".Bmp", ".Tiff" };

            //return formats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #2
0
        public void Translate()
        {
            if (TranslationService == null) return;
            var validTypes = new[]
            {
                typeof (Label),
                typeof (Button),
                typeof (SplitButton),
                typeof (CheckBox),
                typeof (RadioButton),
                typeof (GroupBox),
                typeof (TabControl),
                typeof (ToolStripMenuItem),
                typeof (ToolStripDropDownButton),
                typeof (ToolStripButton),
                typeof (LinkLabel),
                typeof (OLVColumn)
            };

            var fields = GetType()
                .GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
                .Select(fi => fi.GetValue(this))
                .Where(v => v != null && validTypes.Contains(v.GetType()))
                .ToList();

            foreach (var field in fields)
            {
                var text = (string) field.GetType().GetProperty("Text").GetValue(field, null);
                text = TranslationService.Translate(text);
                field.GetType().GetProperty("Text").SetValue(field, text, null);
            }
            Text = TranslationService.Translate(Text);

            Invalidate(true);
        }
        public void Fill_UpstairsAdded()
        {
            var populator = new DungeonPopulator();
            var dungeon = new FakeDungeon(5, 7);
            var points = new[] { new Point(2, 2), new Point(3, 3) };
            foreach (var p in points)
                dungeon[p].Type = XType.Empty;

            populator.Fill(dungeon);

            Assert.That(dungeon,
                Has.Exactly(1).Matches<Cell>(cell =>
                    cell.Type == XType.StairsUp
                    && points.Contains(cell.Location)));
        }