Ejemplo n.º 1
0
 public RebelImage(ref RebelImageToTransfer tImg)
 {
     this.Id        = tImg.Id;
     this.Partition = tImg.Partition;
     this.Name      = tImg.Name;
     using (var ms = new MemoryStream(tImg.img))
     {
         this.Img = Image.FromStream(ms);
     }
 }
Ejemplo n.º 2
0
        public static RebelImage GetImage(int imageId)
        {
            if (ImgCache == null)
            {
                ImgCache = new Dictionary <int, RebelImage>();
            }

            //already loaded image
            if (ImgCache.ContainsKey(imageId))
            {
                return(ImgCache[imageId]);
            }

            //cache on the user's disk
            string path;

            //path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            path = @".\img";
            if (System.IO.Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, imageId.ToString() + ".idt");
            if (File.Exists(path))
            {
                string imgInner;
                imgInner = File.ReadAllText(path);
                RebelImageToTransfer tImg     = JsonConvert.DeserializeObject <RebelImageToTransfer>(imgInner);
                RebelImage           curImage = new RebelImage(ref tImg);
                ImgCache.Add(curImage.Id, curImage);
                return(curImage);
            }

            //get from server
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://*****:*****@"\\", @"\");
                    File.WriteAllText(path, resString);
                    ImgCache.Add(img.Id, img);

                    return(img);
                }
                else
                {
                    //Console.WriteLine(result.StatusCode);
                    return(null);
                }
            }
        }