public async Task ImgurImageAsync(EventContext e) { if (string.IsNullOrEmpty(e.Arguments.ToString())) { e.Channel.QueueMessageAsync(e.GetResource(LocaleTags.ImageNotFound)); return; } var client = new MashapeClient(ImgurClientId, ImgurKey); var endpoint = new GalleryEndpoint(client); var images = await endpoint.SearchGalleryAsync($"title:{e.Arguments.ToString()}"); List <IGalleryImage> actualImages = new List <IGalleryImage>(); foreach (IGalleryItem item in images) { if (item as IGalleryImage != null) { actualImages.Add(item as IGalleryImage); } } if (actualImages.Count > 0) { IGalleryImage i = actualImages[MikiRandom.Next(0, actualImages.Count)]; e.Channel.QueueMessageAsync(i.Link); } else { e.Channel.QueueMessageAsync(e.GetResource(LocaleTags.ImageNotFound)); } }
private void AddGalleryView(IEnumerable <IGalleryItem> gallery) { foreach (var item in gallery) { if (item is Imgur.API.Models.IGalleryImage) { IGalleryImage image = (IGalleryImage)item; ImageInfo _info = new ImageInfo { Name = image.Name, Image = new BitmapImage(new Uri(image.Link)), Item = image, id = image.Id }; _images.Add(_info); } else { IGalleryAlbum album = (IGalleryAlbum)item; if (album.Images != null && album.Images.Count() > 0) { IImage firstImage = album.Images.First(); ImageInfo info = new ImageInfo { Name = album.Title, Image = new BitmapImage(new Uri(firstImage.Link)), Item = item, id = firstImage.Id }; _images.Add(info); } } } Images.ItemsSource = null; Images.ItemsSource = _images; }
public async Task ImgurImageAsync(EventContext e) { if (string.IsNullOrEmpty(e.arguments)) { return; } var client = new MashapeClient(Global.config.ImgurClientId, Global.config.ImgurKey); var endpoint = new GalleryEndpoint(client); var images = await endpoint.SearchGalleryAsync($"title:{e.arguments}"); List <IGalleryImage> actualImages = new List <IGalleryImage>(); foreach (IGalleryItem item in images) { if (item as IGalleryImage != null) { actualImages.Add(item as IGalleryImage); } } if (actualImages.Count > 0) { IGalleryImage i = actualImages[MikiRandom.Next(0, actualImages.Count)]; await e.Channel.SendMessage(i.Link); } else { await e.Channel.SendMessage(Locale.GetEntity(e.Channel.Id.ToDbLong()).GetString(Locale.ImageNotFound)); } }
public GalleryImageModel(IGalleryImage data) { this.Id = data.GalleryImageId; this.Uid = data.GalleryImageUid; this.Image = data.Image; this.Thumbnail = data.Thumbnail; }
public async Task ImgurImageAsync(ICommandContext e) { string title = e.Arguments.Pack.TakeAll(); if (string.IsNullOrEmpty(title)) { e.Channel.QueueMessage(e.Locale.GetString("miki_module_fun_image_error_no_image_found")); return; } var client = new MashapeClient(ImgurClientId, ImgurKey); var endpoint = new GalleryEndpoint(client); var images = await endpoint.SearchGalleryAsync($"title:{title}"); List <IGalleryImage> actualImages = new List <IGalleryImage>(); foreach (IGalleryItem item in images) { if (item as IGalleryImage != null) { actualImages.Add(item as IGalleryImage); } } if (actualImages.Count > 0) { IGalleryImage i = actualImages[MikiRandom.Next(0, actualImages.Count)]; e.Channel.QueueMessage(i.Link); } else { e.Channel.QueueMessage(e.Locale.GetString("miki_module_fun_image_error_no_image_found")); } }
private static void PutInList(T elem, string query, List <LvEntity> list) { if (typeof(IImage).IsAssignableFrom(elem.GetType())) { IImage result = (IImage)elem; if (query == null || (result.Title ?? result.Name).Contains(query)) { list.Add(new LvEntity(result.Title ?? result.Name, result.Link, result.Description, result.Id, result.Favorite.Value, LvEntity.ImgType.IMAGE)); } } else if (typeof(IGalleryImage).IsAssignableFrom(elem.GetType())) { IGalleryImage result = (IGalleryImage)elem; if (query == null || (result.Title ?? result.Name).Contains(query)) { list.Add(new LvEntity(result.Title ?? result.Name, result.Link, result.Description, result.Id, result.Favorite.Value, LvEntity.ImgType.IMAGE)); } } else if (typeof(IGalleryAlbum).IsAssignableFrom(elem.GetType())) { IGalleryAlbum result = (IGalleryAlbum)elem; if (query == null || result.Title.Contains(query)) { list.Add(new LvEntity(result.Title, result.Link, result.Description, result.Id, result.Favorite.Value, LvEntity.ImgType.ALBUM)); } } }
private Picture fillPicture(IGalleryImage image) { Picture pic = new Picture(); pic.Link = image.Link; pic.Name = ((image.Topic != null) ? (image.Topic) : ("")); pic.Title = ((image.Title != null) ? (image.Title) : ("")); return(pic); }
public static GalleryImage CreateGalleryImage(IGalleryImage data) { return(new GalleryImage { GalleryImageId = data.GalleryImageId, GalleryImageUid = data.GalleryImageUid, GalleryId = data.GalleryId, Image = data.Image, Thumbnail = data.Thumbnail }); }
public IGalleryImage InsertGalleryImage(IGalleryImage data) { var db = new TooksCmsDAL(); var g = GalleryImage.CreateGalleryImage(data); db.GalleryImages.Add(g); db.SaveChanges(); return(g); }
public async Task ImgurImageAsync(IContext e) { string title = e.GetArgumentPack().Pack.TakeAll(); var locale = e.GetLocale(); if (string.IsNullOrEmpty(title)) { await e.ErrorEmbedResource("miki_module_fun_image_error_no_image_found") .ToEmbed() .QueueAsync(e, e.GetChannel()); return; } var endpoint = new GalleryEndpoint(imgurClient); IEnumerable <IGalleryItem> images; try { images = await endpoint.SearchGalleryAsync($"title:{title}") .ConfigureAwait(false); } catch (ImgurException) { throw new InternalServerErrorException("imgur.com"); } List <IGalleryImage> actualImages = new List <IGalleryImage>(); foreach (IGalleryItem item in images) { if (item is IGalleryImage image) { actualImages.Add(image); } } if (actualImages.Count > 0) { IGalleryImage i = MikiRandom.Of(actualImages); e.GetChannel().QueueMessage(e, null, i.Link); } else { await e.ErrorEmbedResource("miki_module_fun_image_error_no_image_found") .ToEmbed() .QueueAsync(e, e.GetChannel()); } }
public IGalleryImage UpdateGalleryImage(IGalleryImage data) { var db = new TooksCmsDAL(); if (!CheckGalleryImageExists(db, data.GalleryImageId)) { throw new DataNotFoundException("Database does not contain GalleryImage with id:" + data.GalleryId.ToString()); } var g = db.GalleryImages.Single(g_ => g_.GalleryImageId == data.GalleryImageId); g.Update(data); db.SaveChanges(); return(g); }
public void CanCreateUpdateGetDeleteGalleryImage() { using (var context = FluentMockContext.Start(GetType().FullName)) { Region region = Region.USWestCentral; string rgName = TestUtilities.GenerateName("vmexttest"); string galleryName = TestUtilities.GenerateName("jsim"); string galleryImageName = "JavaImages"; var azure = TestHelper.CreateRollupClient(); try { // Create a gallery // IGallery javaGallery = azure.Galleries.Define(galleryName) .WithRegion(region) .WithNewResourceGroup(rgName) .WithDescription("java's image gallery") .Create(); // // Create an image in the gallery // IGalleryImage galleryImage = azure.GalleryImages.Define(galleryImageName) .WithExistingGallery(javaGallery) .WithLocation(region) .WithIdentifier("JavaSDKTeam", "JDK", "Jdk-9") .WithGeneralizedWindows() // Optionals - Start .WithUnsupportedDiskType(DiskSkuTypes.StandardLRS) .WithUnsupportedDiskType(DiskSkuTypes.PremiumLRS) .WithRecommendedMaximumCPUsCountForVirtualMachine(25) .WithRecommendedMaximumMemoryForVirtualMachine(3200) // Options - End .Create(); Assert.NotNull(galleryImage); Assert.NotNull(galleryImage.Inner); Assert.Equal(galleryImage.Location, region.ToString(), ignoreCase: true); Assert.True(galleryImage.OSType.Equals(OperatingSystemTypes.Windows)); Assert.True(galleryImage.OSState.Equals(OperatingSystemStateTypes.Generalized)); Assert.Equal(2, galleryImage.UnsupportedDiskTypes.Count); Assert.NotNull(galleryImage.Identifier); Assert.Equal("JavaSDKTeam", galleryImage.Identifier.Publisher); Assert.Equal("JDK", galleryImage.Identifier.Offer); Assert.Equal("Jdk-9", galleryImage.Identifier.Sku); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.VCPUs); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Max); Assert.Equal(25, galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Max); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.Memory); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.Memory.Max); Assert.Equal(3200, galleryImage.RecommendedVirtualMachineConfiguration.Memory.Max); // // Update an image in the gallery // galleryImage.Update() .WithoutUnsupportedDiskType(DiskSkuTypes.PremiumLRS) .WithRecommendedMinimumCPUsCountForVirtualMachine(15) .WithRecommendedMemoryForVirtualMachine(2200, 3200) .Apply(); Assert.Equal(1, galleryImage.UnsupportedDiskTypes.Count); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.VCPUs); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Max); Assert.Equal(25, galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Max); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Min); Assert.Equal(15, galleryImage.RecommendedVirtualMachineConfiguration.VCPUs.Min); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.Memory); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.Memory.Max); Assert.Equal(3200, galleryImage.RecommendedVirtualMachineConfiguration.Memory.Max); Assert.NotNull(galleryImage.RecommendedVirtualMachineConfiguration.Memory.Min); Assert.Equal(2200, galleryImage.RecommendedVirtualMachineConfiguration.Memory.Min); // // List images in the gallery // IEnumerable <IGalleryImage> images = azure.GalleryImages.ListByGallery(rgName, galleryName); Assert.Single(images); // // Get image from gallery // galleryImage = azure.GalleryImages.GetByGallery(rgName, galleryName, galleryImageName); Assert.NotNull(galleryImage); Assert.NotNull(galleryImage.Inner); // // Delete an image from gallery // azure.GalleryImages.DeleteByGallery(rgName, galleryName, galleryImageName); } finally { try { azure.ResourceGroups.DeleteByName(rgName); } catch { } } } }
public void CanCreateUpdateGetDeleteGalleryImageVersion() { using (var context = FluentMockContext.Start(GetType().FullName)) { Region region = Region.USWestCentral; string rgName = TestUtilities.GenerateName("vmexttest"); string galleryName = TestUtilities.GenerateName("jsim"); string galleryImageName = "SampleImages"; var azure = TestHelper.CreateRollupClient(); try { IGallery gallery = azure.Galleries.Define(galleryName) .WithRegion(region) .WithNewResourceGroup(rgName) .WithDescription("java's image gallery") .Create(); // // Create an image in the gallery (a container to hold custom linux image) // IGalleryImage galleryImage = azure.GalleryImages.Define(galleryImageName) .WithExistingGallery(gallery) .WithLocation(region) .WithIdentifier("JavaSDKTeam", "JDK", "Jdk-9") .WithGeneralizedLinux() .Create(); // // Create a custom image to base the version on // IVirtualMachineCustomImage customImage = PrepareCustomImage(rgName, region, azure); // String customImageId = "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/javacsmrg91482/providers/Microsoft.Compute/images/img96429090dee3"; // // Create a image version based on the custom image // string versionName = "0.0.4"; IGalleryImageVersion imageVersion = azure.GalleryImageVersions.Define(versionName) .WithExistingImage(rgName, gallery.Name, galleryImage.Name) .WithLocation(region.ToString()) .WithSourceCustomImage(customImage) // Options - Start .WithRegionAvailability(Region.USEast2, 1) // Options - End .Create(); Assert.NotNull(imageVersion); Assert.NotNull(imageVersion.Inner); Assert.NotNull(imageVersion.PublishingProfile.TargetRegions); Assert.Equal(2, imageVersion.PublishingProfile.TargetRegions.Count); Assert.False(imageVersion.IsExcludedFromLatest); imageVersion = azure.GalleryImageVersions.GetByGalleryImage(rgName, gallery.Name, galleryImage.Name, imageVersion.Name); Assert.NotNull(imageVersion); Assert.Null(imageVersion.ReplicationStatus); imageVersion = azure.GalleryImageVersions.GetByGalleryImageWithReplicationStatus(rgName, gallery.Name, galleryImage.Name, imageVersion.Name); Assert.NotNull(imageVersion); Assert.NotNull(imageVersion.ReplicationStatus); Assert.NotNull(imageVersion.ReplicationStatus.AggregatedState); // // Update image version // imageVersion.Update() .WithoutRegionAvailability(Region.USEast2) .Apply(); Assert.NotNull(imageVersion.PublishingProfile.TargetRegions); Assert.Equal(1, imageVersion.PublishingProfile.TargetRegions.Count); Assert.False(imageVersion.IsExcludedFromLatest); // // List image versions // IEnumerable <IGalleryImageVersion> versions = galleryImage.ListVersions(); Assert.NotNull(versions); Assert.True(versions.Count() > 0); // // Delete the image version // azure.GalleryImageVersions.DeleteByGalleryImage(rgName, galleryName, galleryImageName, versionName); } finally { try { azure.ResourceGroups.DeleteByName(rgName); } catch { } } } }
public void Update(IGalleryImage data) { GalleryId = data.GalleryId; Image = data.Image; Thumbnail = data.Thumbnail; }
public DownloadService(IGalleryImage api, IPackArchiveToCbz packer) { _api = api; _packer = packer; }
public GalleryImage(IGalleryImage data) : base(data, typeof(IGalleryImage)) { }