コード例 #1
0
 public RebelImageToTransfer(ref RebelImage rImage)
 {
     this.Id        = rImage.Id;
     this.Partition = rImage.Partition;
     this.Name      = rImage.Name;
     using (var ms = new MemoryStream())
     {
         rImage.Img.Save(ms, rImage.Img.RawFormat);
         this.img = ms.ToArray();
     }
 }
コード例 #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);
                }
            }
        }