示例#1
0
        void ServeImage(HttpClient client, HttpRequest request)
        {
            string itemname = request.GetParameter("name");

            // TODO: do that right ...
            itemname = itemname.Replace("+", " ");

            string resourcepath = GetType().Namespace + ".Images." + itemname.ToLower() + ".png";

            if (!ResourceAccessor.ContainsResource(GetType().Assembly, resourcepath))
            {
                client.WriteStatus(404, "Image not found");
                client.EndHeader();
                return;
            }

            byte[] imagedata = ResourceAccessor.GetResource <byte[]>(resourcepath);

            client.WriteStatus(200, "OK");
            client.WriteHeader("Content-Type", MimeTypes.GetMimeType(".png"));
            client.WriteHeader("Content-Length", imagedata.Length.ToString());
            client.EndHeader();
            using (System.IO.Stream stream = client.GetStream())
                stream.Write(imagedata, 0, imagedata.Length);
        }
示例#2
0
        /// <summary>
        /// get path under which image for item is server (or null when no image exists)
        /// </summary>
        /// <param name="itemname">name of item</param>
        /// <returns>path to image on server</returns>
        public string GetImagePath(string itemname)
        {
            string path;

            if (!imagecache.TryGetValue(itemname.ToLower(), out path))
            {
                string resourcepath = GetType().Namespace + ".Images." + itemname.ToLower() + ".png";
                if (ResourceAccessor.ContainsResource(GetType().Assembly, resourcepath))
                {
                    path = $"http://localhost/streamrc/image/item?name={HttpExtensions.URLEncode(itemname.ToLower())}";
                }

                imagecache[itemname.ToLower()] = path;
            }

            return(path);
        }
示例#3
0
        /// <summary>
        /// get path under which image for item is server (or null when no image exists)
        /// </summary>
        /// <returns>path to image on server</returns>
        public string GetKeeperImage()
        {
            string path;

            if (!imagecache.TryGetValue("shopkeeper_normal", out path))
            {
                string resourcepath = GetType().Namespace + ".Images." + "shopkeeper_normal" + ".png";
                if (ResourceAccessor.ContainsResource(GetType().Assembly, resourcepath))
                {
                    path = $"http://localhost/streamrc/image/shop/keeper";
                }

                imagecache["shopkeeper_normal"] = path;
            }

            return(path);
        }
示例#4
0
        void ServeImage(HttpClient client, HttpRequest request)
        {
            string resourcepath = GetType().Namespace + ".Images." + "shopkeeper_normal" + ".png";

            if (!ResourceAccessor.ContainsResource(GetType().Assembly, resourcepath))
            {
                client.WriteStatus(404, "Image not found");
                client.EndHeader();
                return;
            }

            byte[] imagedata = ResourceAccessor.GetResource <byte[]>(resourcepath);

            client.WriteStatus(200, "OK");
            client.WriteHeader("Content-Type", MimeTypes.GetMimeType(".png"));
            client.WriteHeader("Content-Length", imagedata.Length.ToString());
            client.EndHeader();
            using (System.IO.Stream stream = client.GetStream())
                stream.Write(imagedata, 0, imagedata.Length);
        }