Beispiel #1
0
        public async Task Test_Add_WithDetectedObjects()
        {
            var mapperConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new Mappings.AutoMapperPictureProfile());
            });

            var request = new PictureRequest
            {
                Id              = "dsadas",
                Name            = "name",
                AppPath         = "app\\path",
                OriginalPath    = "orig\\path",
                FolderName      = "folderName",
                FolderAppPath   = "folderAppPath",
                FolderSortOrder = 365,
                Size            = 39943,
                Tags            = new List <string> {
                    "tag1, tag2"
                },
                CreateTimestamp = DateTime.Now,
                DetectedObjects = new List <string> {
                    "object1", "object2", "object3"
                }
            };

            var service  = new PictureService(new PictureRepositoryMock(), new TagRepositoryMock(), mapperConfig.CreateMapper(), new MetadataServiceMock());
            var response = await service.Add(request);

            Assert.AreEqual(3, response.DetectedObjects.Count());
        }
Beispiel #2
0
        public async Task GetPictureInfoService()
        {
            //Arange
            var db             = GetDatabase();
            var pictureService = new PictureService(db);

            var album = new Album()
            {
                Id    = 1,
                Title = "Album"
            };

            db.Add(album);
            db.SaveChanges();

            var picture1 = new Picture()
            {
                Id          = 1,
                Description = "Picture",
                AlbumId     = album.Id
            };

            db.Add(picture1);
            db.SaveChanges();

            //Act
            var pic = pictureService.GetPictureInfo(1);

            //Assert
            pic.Description.Should()
            .Match(picture1.Description);

            pic.AlbumName.Should()
            .Match(album.Title);
        }
Beispiel #3
0
        public PictureInfoDTO UploadImage(PictureDTO pictureDto)
        {
            var            securityInfo   = SecurityManager.EnsureAuthentication(pictureDto);
            PictureService pictureService = new PictureService(Session, securityInfo, Configuration);

            return(pictureService.UploadImage(pictureDto));
        }
Beispiel #4
0
        public async Task Test_Add_AllPropertiesHaveValues()
        {
            var mapperConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new Mappings.AutoMapperPictureProfile());
            });

            var request = new PictureRequest
            {
                Id              = "dsadas",
                Name            = "name",
                AppPath         = "app\\path",
                OriginalPath    = "orig\\path",
                FolderName      = "folderName",
                FolderAppPath   = "folderAppPath",
                FolderSortOrder = 365,
                Size            = 39943,
                Tags            = new List <string> {
                    "tag1, tag2"
                },
                CreateTimestamp = DateTime.Now
            };

            var service  = new PictureService(new PictureRepositoryMock(), new TagRepositoryMock(), mapperConfig.CreateMapper(), new MetadataServiceMock());
            var response = await service.Add(request);

            AssertAllPropertiesHaveValues(response);
        }
Beispiel #5
0
        public async Task <IActionResult> CreateManufacturer(
            [ModelBinder(typeof(JsonModelBinder <ManufacturerDto>))]
            Delta <ManufacturerDto> manufacturerDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            //If the validation has passed the manufacturerDelta object won't be null for sure so we don't need to check for this.

            Picture insertedPicture = null;

            // We need to insert the picture before the manufacturer so we can obtain the picture id and map it to the manufacturer.
            if (manufacturerDelta.Dto.Image?.Binary != null)
            {
                insertedPicture = await PictureService.InsertPictureAsync(manufacturerDelta.Dto.Image.Binary, manufacturerDelta.Dto.Image.MimeType, string.Empty);
            }

            // Inserting the new manufacturer
            var manufacturer = await _factory.InitializeAsync();

            manufacturerDelta.Merge(manufacturer);

            if (insertedPicture != null)
            {
                manufacturer.PictureId = insertedPicture.Id;
            }

            await _manufacturerService.InsertManufacturerAsync(manufacturer);


            await UpdateAclRolesAsync(manufacturer, manufacturerDelta.Dto.RoleIds);

            await UpdateDiscountsAsync(manufacturer, manufacturerDelta.Dto.DiscountIds);

            await UpdateStoreMappingsAsync(manufacturer, manufacturerDelta.Dto.StoreIds);

            //search engine name
            if (manufacturerDelta.Dto.SeName != null)
            {
                var seName = await _urlRecordService.ValidateSeNameAsync(manufacturer, manufacturerDelta.Dto.SeName, manufacturer.Name, true);

                await _urlRecordService.SaveSlugAsync(manufacturer, seName, 0);
            }

            await CustomerActivityService.InsertActivityAsync("AddNewManufacturer", await LocalizationService.GetResourceAsync("ActivityLog.AddNewManufacturer"), manufacturer);

            // Preparing the result dto of the new manufacturer
            var newManufacturerDto = await _dtoHelper.PrepareManufacturerDtoAsync(manufacturer);

            var manufacturersRootObject = new ManufacturersRootObject();

            manufacturersRootObject.Manufacturers.Add(newManufacturerDto);

            var json = JsonFieldsSerializer.Serialize(manufacturersRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Beispiel #6
0
        public HttpResponseMessage PostAddCommentToPicture(CommentModel comment, int pictureId, string sessionKey)
        {
            try
            {
                var userService = new UserService();
                var user        = userService.GetUserBySessionKey(sessionKey);

                Validator.ValidateUser(user, USER_ACCESS_DENIED);

                var pictureService = new PictureService();
                var picture        = pictureService.GetPictureById(pictureId);

                Validator.ValidatePicture(picture, PICTURE_NOT_FOUND);

                var newComment = pictureService.AddPictureComment(comment, picture, user);

                var commentToReturn = new CommentModel()
                {
                    CreatedAt = newComment.CreatedAt,
                    Id        = newComment.Id,
                    Text      = newComment.Text,
                    UserName  = user.UserName
                };

                return(this.Request.CreateResponse(HttpStatusCode.Created, commentToReturn));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #7
0
        public async Task DaveAsync()
        {
            var stream = await PictureService.GetLocalImage("dave");

            stream.Seek(0, SeekOrigin.Begin);
            await Context.Channel.SendFileAsync(stream, "dave.png");
        }
 public void Test_GetSizeOfValidPictures()
 {
     ISerieService serieService = ObjectFactory.GetInstance<ISerieService>();
     var serie = serieService.GetById(5);
     PictureService pictureService = new PictureService(serie.Id, EType.Serie);
     Assert.AreEqual(1, pictureService.GetSize());
 }
Beispiel #9
0
        public static string ValidateImage(this string imagePath)
        {
            string src = string.Empty, url = string.Empty;
            var    query = "";

            try
            {
                if (!string.IsNullOrEmpty(imagePath))
                {
                    src = HttpContext.Current.Server.MapPath(String.Concat("~/", imagePath));

                    url = File.Exists(src) ? PictureService.BuildUrlCore(imagePath, query, null) : PictureService.BuildUrlCore(Constant.ImageNoExsits, query, null);
                }
                else
                {
                    url = PictureService.BuildUrlCore(Constant.ImageNoExsits, query, null);
                }
            }
            catch (Exception ex)
            {
                string exx = ex.Message;
            }

            return(url);
        }
Beispiel #10
0
        public async Task CatAsync()
        {
            var stream = await PictureService.GetCatPictureAsync();

            stream.Seek(0, SeekOrigin.Begin);
            await Context.Channel.SendFileAsync(stream, "cat.png");
        }
Beispiel #11
0
        public async Task Lovenstein()
        {
            HtmlDocument myDoc;

            while (true)
            {
                Random r    = new Random();
                int    rint = r.Next(1, MAX_LOVENSTEIN);
                Stream html = await HttpService.GetHttpAsync("http://www.mrlovenstein.com/comic/" + rint);

                myDoc = new HtmlDocument();
                myDoc.Load(html);
                if (myDoc.GetElementbyId("section_404") == null)
                {
                    break;
                }
            }

            HtmlNode comic      = myDoc.GetElementbyId("comic_main_image");
            string   pictureURI = comic.Attributes["src"].Value;

            pictureURI = "http://www.mrlovenstein.com" + pictureURI;
            var image = await PictureService.GetPictureAsync(pictureURI);

            image.Seek(0, SeekOrigin.Begin);
            await Context.Channel.SendFileAsync(image, "randomcomic.jpg");
        }
Beispiel #12
0
        public async Task DeleteImageAsyncShould_DeleteTheImageFromCloudAnd_ImageInfoFromDB()
        {
            //Arrange
            var cloudService = new Mock <ICloudImageService>();

            cloudService.Setup(cs => cs.UploadFormFileAsync(It.IsAny <IFormFile>()))
            .Returns(It.IsAny <Task <ImageUploadResult> >());

            var picInfoWriter = new Mock <IPictureInfoWriterService>();

            var service = new PictureService(this.Db, cloudService.Object, picInfoWriter.Object);

            var user = UserCreator.Create();

            await this.Db.AddAsync(user);

            var image = ImageInfoCreator.CreateWithFullData(user.Id);

            await this.Db.AddAsync(image);

            await this.Db.SaveChangesAsync();

            //Act
            await service.DeleteImageAsync(image.Id);

            //Assert
            cloudService.Verify(c => c.DeleteImages(It.IsAny <string>()), Times.Once);

            this.Db.CloudinaryImages
            .FirstOrDefault(i => i.Id == DefaultImageId).Should().BeNull();
        }
Beispiel #13
0
 public async Task Nuke([Remainder] string url = null)
 {
     // Glory to the USSR
     Context.Channel.SendMessageAsync("This is going to take quite some time. Hang tight and I'll ping you when I'm done.");
     PictureService.DeepfryImage(Context, url, 10);
     Context.Channel.SendMessageAsync(Context.Message.Author.Mention);
 }
 public void Test_GetPictures_FoundSome()
 {
     IFigurService figurService = ObjectFactory.GetInstance<IFigurService>();
     var figur = figurService.GetById(5);
     PictureService pictureService = new PictureService(figur.Id, EType.Figur);
     Assert.AreEqual(2, pictureService.GetPictures().Count);
 }
Beispiel #15
0
        public async Task KaQingusAsync()
        {
            var stream = await PictureService.GetLocalImage("kaqingus");

            stream.Seek(0, SeekOrigin.Begin);
            await Context.Channel.SendFileAsync(stream, "kaqingus.png");
        }
 public void Test_GetPictures_NoMatches()
 {
     ISerieService serieService = ObjectFactory.GetInstance<ISerieService>();
     var serie = serieService.GetById(4);
     PictureService pictureService = new PictureService(serie.Id, EType.Serie);
     Assert.AreEqual(0, pictureService.GetPictures().Count);
 }
        public async Task EditPicuresShoudBeSuccessful()
        {
            // Arrange
            var db = this.Context;

            this.PopulateData(db);

            var picturesService = new PictureService(db);
            var pictureId       = 1;
            var newUrlPath      = "htp://somepathsuccess.jpg";

            // Act
            await picturesService.Edit(pictureId, newUrlPath);

            // Assert
            db
            .Pictures
            .Where(p => p.Id == pictureId)
            .Select(p => p.Id)
            .FirstOrDefault()
            .Should()
            .Be(pictureId);

            db
            .Pictures
            .Where(p => p.Id == pictureId)
            .Select(p => p.UrlPath)
            .FirstOrDefault()
            .Should()
            .Be(newUrlPath);
        }
Beispiel #18
0
        public async Task sonicsays([Remainder] string text)
        {
            var readSettings = new MagickReadSettings
            {
                TextEncoding    = Encoding.Unicode,
                FontFamily      = PictureService.GetBestFont(text),
                FontStyle       = FontStyleType.Bold,
                FillColor       = MagickColors.White,
                BackgroundColor = MagickColors.Black,
                Width           = 980,
                Height          = 624
            };

            PictureService.AnnotateImage(Context, "sonicsaystemplate", text, readSettings, MagickColors.Black, 41, 93, 539, 93, 41, 406, 539, 406);
            //System.Drawing.Image backing = System.Drawing.Image.FromFile(Environment.CurrentDirectory + "\\Content\\sonicsaystemplate.png");
            //Graphics canvas = Graphics.FromImage(backing);
            //Rectangle r = new Rectangle(new Point(44, 112), new Size(514, 291));
            //StringFormat s = new StringFormat();
            //s.Alignment = StringAlignment.Near;
            //s.LineAlignment = StringAlignment.Center;
            //canvas.DrawString(text, new Font(FontFamily.GenericSansSerif, 50), Brushes.White, r, s);
            //MemoryStream outgoing = new MemoryStream();
            //canvas.Save();
            //backing.Save(outgoing, System.Drawing.Imaging.ImageFormat.Png);
            //outgoing.Seek(0, SeekOrigin.Begin);
            //return Context.Channel.SendFileAsync(outgoing, "sonicsays.png");
        }
        public void ReturnAllPicturesOfCountriesInPassedContinent()
        {
            // Arrange
            var    mockedUnitOfWork = new Mock <IUnitOfWork>();
            var    mockedRepository = new Mock <IEfGenericRepository <Picture> >();
            string continent        = "random";

            var mockedContinent = new Mock <Continent>();
            var country         = new Country()
            {
                Continent = mockedContinent.Object
            };

            IEnumerable <Picture> pictures = new List <Picture>()
            {
                new Picture()
                {
                    Country = country
                }
            };

            mockedRepository.Setup(x => x.GetAll(It.IsAny <Expression <Func <Picture, bool> > >())).Returns(pictures);

            var service = new PictureService(mockedRepository.Object, mockedUnitOfWork.Object);

            // Act
            var actualPictures = service.GetPicturesByContinent(continent);

            // Assert
            CollectionAssert.AreEquivalent(pictures, actualPictures);
        }
Beispiel #20
0
        public HttpResponseMessage GetAllPictures(int pictureCount = 20)
        {
            try
            {
                var pictureService = new PictureService();
                var allPictures    = pictureService.GetAllPictures(pictureCount).ToList();
                var pictures       = from picture in allPictures
                                     select new PictureModel()
                {
                    Comments = from comment in picture.Comments
                               select new CommentModel()
                    {
                        Text      = comment.Text,
                        UserName  = comment.User.UserName,
                        CreatedAt = comment.CreatedAt
                    },
                    CreateDate    = picture.CreateDate,
                    Id            = picture.Id,
                    Url           = picture.Url,
                    Title         = picture.Title,
                    PositiveVotes = picture.Votes.Count(v => v.isPositive == true),
                    NegativeVotes = picture.Votes.Count(v => v.isPositive == false)
                };

                return(this.Request.CreateResponse(HttpStatusCode.OK, pictures));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #21
0
        public void addPics()
        {
            try
            {
                this.pics.Add(new Pic各种(FabricService.GetMianLiaoFile(this.model.Dto定制下单.SYTLE_FABRIC_ID), this.mianliaoname.Text, "面料"));
            }
            catch
            {
                this.pics.Add(new Pic各种(Image.FromFile(@"pic\SSHIRT.jpg"), this.mianliaoname.Text, "面料"));
            }
            UC设计点选择 c = new UC设计点选择();

            foreach (Control card in this.panel3.Controls)
            {
                if (card is UC设计点选择)
                {
                    c = (UC设计点选择)card;
                    try
                    {
                        this.pics.Add(new Pic各种(PictureService.GetImage(c.itemValue), c.itemName, c.PitemName));
                    }
                    catch
                    {
                        this.pics.Add(new Pic各种(Image.FromFile(@"pic\SSHIRT.jpg"), c.itemName, c.PitemName));
                    }
                }
            }
        }
Beispiel #22
0
        public async Task DeleteAlbumShouldReturnTrueIfAlbumExists()
        {
            // Arrange
            var db    = MockManager.GetMockDatabase();
            var album = new Album
            {
                Id       = 1,
                Pictures = new List <Picture>()
            };

            await db.Albums.AddAsync(album);

            await db.SaveChangesAsync();

            var pictureService = new PictureService(db);

            // Act
            var result = await pictureService.DeleteAlbumByIdAsync(1);

            // Assert
            result
            .Should()
            .Be(true);

            var albumExists = await db.Albums.FirstOrDefaultAsync();

            albumExists
            .Should()
            .BeNull();
        }
Beispiel #23
0
        public async Task CreateAlbumShouldReturnTrueIfUserExists()
        {
            // Arrange
            var userId = Guid.NewGuid().ToString();
            var db     = MockManager.GetMockDatabase();
            var user   = new User
            {
                Id = userId
            };

            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            var pictureService = new PictureService(db);

            // Act
            var result = await pictureService.CreateAlbumAsync("New album", "New description", user.Id);

            // Assert
            result
            .Should()
            .Be(true);

            var userAlbum = await db.Albums.FirstOrDefaultAsync();

            userAlbum
            .Should()
            .NotBeNull();
        }
Beispiel #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="houseList"></param>
        /// <returns></returns>
        private List <HousePicture> newHousePicture(List <House> houseList)
        {
            List <HousePicture> hps = new List <HousePicture>();


            foreach (House h in houseList)
            {
                HousePicture hp = new HousePicture
                {
                    hid         = h.hid,
                    area        = h.area,
                    price       = h.price,
                    pay         = h.pay,
                    unitType    = h.unitType,
                    floor       = h.floor,
                    community   = h.community,
                    pubPerson   = h.pubPerson,
                    time        = h.time,
                    type        = h.type,
                    isRecommend = h.isRecommend,
                    houseDesc   = h.houseDesc,
                    region      = h.region
                };
                hp.pics = PictureService.LoadEntities(p => p.hid == h.hid).ToList();
                hps.Add(hp);
            }
            return(hps);
        }
Beispiel #25
0
        public async Task AlbumOwnerIdShouldReturnTheIdOfUserIfAlbumExists()
        {
            // Arrange
            var userId = Guid.NewGuid().ToString();
            var db     = MockManager.GetMockDatabase();
            var user   = new User
            {
                Id = userId
            };
            var album = new Album
            {
                Id   = 1,
                Name = "My album",
                User = user
            };

            await db.Albums.AddAsync(album);

            await db.SaveChangesAsync();

            var pictureService = new PictureService(db);

            // Act
            var result = await pictureService.AlbumOwnerId(1);

            // Assert
            result
            .Should()
            .NotBeNull()
            .And
            .Be(userId);
        }
Beispiel #26
0
        public void ReturnAllPicturesOfUserWithPassedUsername()
        {
            // Arrange
            var    mockedUnitOfWork = new Mock <IUnitOfWork>();
            var    mockedRepository = new Mock <IEfGenericRepository <Picture> >();
            string username         = "******";
            var    mockedUser       = new Mock <User>();

            IEnumerable <Picture> pictures = new List <Picture>()
            {
                new Picture()
                {
                    Creator = mockedUser.Object
                }
            };

            mockedRepository.Setup(x => x.GetAll(It.IsAny <Expression <Func <Picture, bool> > >())).Returns(pictures);

            var service = new PictureService(mockedRepository.Object, mockedUnitOfWork.Object);

            // Act
            var actualPictures = service.GetPicturesByUsername(username);

            // Assert
            CollectionAssert.AreEquivalent(pictures, actualPictures);
        }
Beispiel #27
0
        public void ReturnPictures_WhenPassedStringMatchesPartOfPicturesDescriptionButDifferentCasing()
        {
            // Arrange
            var    mockedUnitOfWork = new Mock <IUnitOfWork>();
            var    mockedRepository = new Mock <IEfGenericRepository <Picture> >();
            string description      = "random";

            IEnumerable <Picture> pictures = new List <Picture>()
            {
                new Picture()
                {
                    Description = description + " more text"
                }
            };

            mockedRepository.Setup(x => x.GetAll(It.IsAny <Expression <Func <Picture, bool> > >())).Returns(pictures);

            var service = new PictureService(mockedRepository.Object, mockedUnitOfWork.Object);

            // Act
            var actualPictures = service.GetPictureByDescription(description.ToUpper());

            // Assert
            CollectionAssert.AreEquivalent(pictures, actualPictures);
        }
Beispiel #28
0
        public IActionResult CreateCategory(
            [ModelBinder(typeof(JsonModelBinder <CategoryDto>))]
            Delta <CategoryDto> categoryDelta)
        {
            // Here we display the errors if the validation has failed at some point.
            if (!ModelState.IsValid)
            {
                return(Error());
            }

            //If the validation has passed the categoryDelta object won't be null for sure so we don't need to check for this.

            Picture insertedPicture = null;

            // We need to insert the picture before the category so we can obtain the picture id and map it to the category.
            if (categoryDelta.Dto.Image?.Binary != null)
            {
                insertedPicture = PictureService.InsertPicture(categoryDelta.Dto.Image.Binary, categoryDelta.Dto.Image.MimeType, string.Empty);
            }

            // Inserting the new category
            var category = _factory.Initialize();

            categoryDelta.Merge(category);

            if (insertedPicture != null)
            {
                category.PictureId = insertedPicture.Id;
            }

            _categoryService.InsertCategory(category);


            UpdateAclRoles(category, categoryDelta.Dto.RoleIds);

            UpdateDiscounts(category, categoryDelta.Dto.DiscountIds);

            UpdateStoreMappings(category, categoryDelta.Dto.StoreIds);

            //search engine name
            if (categoryDelta.Dto.SeName != null)
            {
                var seName = _urlRecordService.ValidateSeName(category, categoryDelta.Dto.SeName, category.Name, true);
                _urlRecordService.SaveSlug(category, seName, 0);
            }

            CustomerActivityService.InsertActivity("AddNewCategory",
                                                   LocalizationService.GetResource("ActivityLog.AddNewCategory"), category);

            // Preparing the result dto of the new category
            var newCategoryDto = _dtoHelper.PrepareCategoryDTO(category);

            var categoriesRootObject = new CategoriesRootObject();

            categoriesRootObject.Categories.Add(newCategoryDto);

            var json = JsonFieldsSerializer.Serialize(categoriesRootObject, string.Empty);

            return(new RawJsonActionResult(json));
        }
Beispiel #29
0
 public UserLeftEvent(DiscordSocketClient discord, ILogger logger, PictureService pictureService)
 {
     _discord        = discord;
     _manager        = new Manager(Assets.MONGO_DB_CONNECTION_QUERY);
     _logger         = logger;
     _pictureService = pictureService;
 }
Beispiel #30
0
        public async Task MimiAsync(IUser user = null, int?position = null)
        {
            try
            {
                // Get a stream containing an image of a cat
                var stream = await PictureService.GetMimiPictureAsync(position);

                // Streams must be seeked to their beginning before being uploaded!
                stream.Seek(0, SeekOrigin.Begin);

                string mention = string.Empty;
                if (user != null)
                {
                    mention = user.Mention;
                }

                await Context.Channel.SendFileAsync(stream, "mimi.png", $"STOP CREEPING MIMI {mention}!");

                CommandsService.AddCommandHistory(Context.User, "mimi", true);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, ex.Message);
                CommandsService.AddCommandHistory(Context.User, "mimi", false);
            }
        }
 public ActionResult Create([Bind(Include = "Id,Caption,Description,ImageUrl")] Project project, HttpPostedFileBase projectPic)
 {
     try
     {
         if (ModelState.IsValid && (projectPic != null && projectPic.ContentLength > 0) && PictureService.DaliEslikaFormat(projectPic))
         {
             if (String.IsNullOrEmpty(project.Caption))
             {
                 project.Caption = "Solar Project";
             }
             if (String.IsNullOrEmpty(project.Description))
             {
                 project.Description = "Solar Project";
             }
             string slikaIme = "";
             PictureService.ZacuvajSlikaPlusMala(projectPic, Server.MapPath("~/Pictures/Projects"), "Chicago_Solar_Tesla", ref slikaIme);
             project.ImageUrl = @"~/Pictures/Projects/" + slikaIme;
             db.Projects.Add(project);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("ChoosePicture", "Plese choose picture for the project!");
         }
     }
     catch (Exception ex)
     {
         return(Content("Greska:" + ex.Message)); //privremeno
     }
     return(View(project));
 }
Beispiel #32
0
        public async Task LemonEmbAsync(int?position = null)
        {
            try
            {
                if (Context.User.Id != 173079361136623616)
                {
                    return;
                }
                var eb = new EmbedBuilder();
                eb.AddField("Lemon philosophical quotes", "Learn with the best")
                .WithCurrentTimestamp()
                .WithAuthor(Context.Client.CurrentUser)
                .AddField("Called", CommandsService.GetTimesCommandWasCalled("lemonEmb"))
                .WithImageUrl(await PictureService.GetLemonStringAsync(position));

                // Get a stream containing an image of a cat
                var stream = await PictureService.GetLemonPictureAsync(position);

                // Streams must be seeked to their beginning before being uploaded!
                stream.Seek(0, SeekOrigin.Begin);

                await Context.Channel.SendMessageAsync("", false, eb.Build());

                CommandsService.AddCommandHistory(Context.User, "lemonEmb", true);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, ex.Message);
                CommandsService.AddCommandHistory(Context.User, "lemonEmb", false);
            }
        }
Beispiel #33
0
        public async Task CreepAsync(IUser user = null)
        {
            try
            {
                if (user == null)
                {
                    await Context.Channel.SendMessageAsync("Who is the creep?");
                }

                // Get a stream containing an image of a cat
                var stream = await PictureService.GetCreepPictureAsync(null);

                // Streams must be seeked to their beginning before being uploaded!
                stream.Seek(0, SeekOrigin.Begin);

                await Context.Channel.SendFileAsync(stream, "creep.png", $"{user.Mention} don't be a creep mate");

                CommandsService.AddCommandHistory(Context.User, "creep", true);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, ex.Message);
                CommandsService.AddCommandHistory(Context.User, "creep", false);
            }
        }
        public void Test_SavePicturesToGlobalFolder()
        {
            PictureService pictureService = new PictureService(2, EType.Instructions);
            List<Picture> pictures = pictureService.GetPictures();

            Assert.AreEqual(1, pictureService.GetSize());

            PictureHandler pictureHandler = new PictureHandler(pictures);
            pictureHandler.SavePictures();
        }
        public void Test_LoadPictures_NotACorrectPath()
        {
            PictureService pictureService = new PictureService(2, EType.Instructions);
            List<Picture> pictures = pictureService.GetPictures();

            Assert.AreEqual(1, pictureService.GetSize());

            PictureHandler pictureHandler = new PictureHandler(pictures);
            pictureHandler.LoadPictures();
        }
        public void Test_LoadPictures_NoPictureChosen()
        {
            PictureService pictureService = new PictureService(10, EType.Instructions);
            List<Picture> pictures = pictureService.GetPictures();

            Assert.AreEqual(0, pictureService.GetSize());

            PictureHandler pictureHandler = new PictureHandler(pictures);
            pictureHandler.LoadPictures();
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     int aid = 0;
     if (int.TryParse(Context.Request["aid"], out aid))
     {
         if (!IsPostBack)
         {
             Image1_SlideShowExtender.ContextKey = Context.Request["aid"];
             PictureService p = new PictureService();
             List<Picture> pics = p.GetPictures(aid);
             if (pics.Count > 0)
             {
                 Image1.ImageUrl = "sqlimage.axd?name=pic&picId=" + pics[0].Id.ToString();
             }
             PicturesListView.DataSource = pics;
             PicturesListView.DataBind();
         }
     }
 }