// download one image from the url in the meta private void threadDownloadOneImage(ImageMetas metas) { try { using (WebClient webClient = new WebClient()) { var uri = new Uri(metas.Url.Replace("https://", "http://")); webClient.DownloadDataCompleted += ((o, e) => { if (e.Error == null) { var image = new CachedImg(); image.Metas = (ImageMetas)e.UserState; image.Bytes = e.Result; imagesQueue.Enqueue(image); } else { Debug.Log(e.Error); } }); webClient.DownloadDataAsync(uri, metas); } } catch (Exception e) { Debug.Log("error downloading " + metas.Url); Debug.Log(e); } }
// retrieve metas from the server private List <ImageMetas> threadDownloadMetas(int nbr) { try { using (WebClient metasWebClient = new WebClient()) { metasWebClient.Encoding = Encoding.UTF8; metasWebClient.Headers["Content-Type"] = "application/json"; string jsonString = metasWebClient.UploadString(WebCs.ImageSuggestionsUrl(nbr), User.CurrentUser.TagsVectorAsJson()); return(ImageMetas.FromJsonArray(jsonString)); } } catch (Exception e) { // TODO: handle error properly Debug.Log("error downloading metas " + e); Debug.Log(User.CurrentUser.TagsVectorAsJson()); return(new List <ImageMetas>()); } }
private void getAndDownload(string id) { using (WebClient webClient = new WebClient()) { webClient.Encoding = Encoding.UTF8; webClient.Headers["Content-Type"] = "application/json"; webClient.DownloadStringCompleted += (o, e) => { if (e.Error != null) { UnityEngine.Debug.Log("error downloading image " + id); } else { var metas = ImageMetas.FromJson(e.Result); var uri = new Uri(metas.Url.Replace("https://", "http://")); webClient.DownloadFileAsync(uri, Path.Combine(path, id + "." + metas.Format)); } }; webClient.DownloadStringAsync(new Uri(WebCs.ImageDetailsUrl(id))); } }
public static string Gallary(IEntityCommonInfo entity, bool withSlider = false, string folder = "Gallery", string filter = "") { var files = GetGallaryFiles(entity, folder); if (!files.Any()) { return(null); } var result = new List <string>(); if (!filter.IsEmpty()) { files = files.Where(x => x.Contains(filter)).ToList(); } var imageDescs = new ImageMetas().Descs(); foreach (var imageFile in files.Select(x => x.Replace('\\', '/')) .Where(x => !x.ToLowerInvariant().EndsWith("-s.jpg"))) { var imageUrl = Urls.SysToWeb(imageFile).ToLowerInvariant(); var smallImageUrl = GetSmallImageUrl(imageUrl); var name = Path.GetFileName(Path.GetDirectoryName(imageFile)) + "/" + Path.GetFileName(imageFile); var alt = imageDescs.GetValueOrDefault(name.ToLower()); var tagA = H.Anchor(imageUrl, H.Img(smallImageUrl).Alt(alt).ToString()) .Class("fancy-box").Rel("entity-fancy-box").Style("padding:5px"); result.Add(tagA.ToString()); } if (!withSlider || result.Count <= 3) { return(result.JoinWith("").Tag("div")); } return(CommonSiteHtmls.Carousel(result.CutInPartCount(3) .Select(x => H.span[x.JoinWith("")].Style("margin:0 20px").Class("fit-width-item")), true).ToString()); }
public void MarkAsDisliked(ImageMetas metas) { Assert.IsFalse(DislikedIds.Contains(metas.Id)); updateTagsVector(metas.Tags, false); DislikedIds.Add(metas.Id); }
public void MarkAsLiked(ImageMetas metas) { Assert.IsFalse(LikedIds.Contains(metas.Id)); updateTagsVector(metas.Tags, true); LikedIds.Add(metas.Id); }
public Image(ImageMetas metas, byte[] data) { Metas = metas; SetTexture(data); }
private void AddImageMeta(Transform transform) { var imageMeta = LegoImageMeta.Create(transform.GetComponent <YuLegoImage>()); ImageMetas.Add(imageMeta); }