コード例 #1
0
        private static ImageSetParameters GetParameters(HttpRequest request, out string imageName, out string namespaceQualifiedTypeName)
        {
            ImageSetParameters retVal = new ImageSetParameters();

            imageName = string.Empty;
            namespaceQualifiedTypeName = string.Empty;

            foreach (string queryKey in request.QueryString.AllKeys)
            {
                //TODO: Enumify magic strings
                if (queryKey.Equals("in")) // Image Name
                {
                    imageName = request.QueryString[queryKey];
                }
                else if (queryKey.Equals("t"))
                {
                    namespaceQualifiedTypeName = request.QueryString[queryKey];
                }
                else
                {
                    retVal[queryKey] = HttpUtility.UrlDecode(request.QueryString[queryKey]);
                }
            }

            return(retVal);
        }
コード例 #2
0
        public static IImageSet GetImageSet(string namespaceQualifiedType, ImageSetParameters parameters)
        {
            Type type = Type.GetType(namespaceQualifiedType);

            if (type == null)
            {
                throw ExceptionHelper.CreateException <PixelServerException>("The type {0} was not found.", namespaceQualifiedType);
            }

            if (type.GetInterface("IImageSetProvider") == null)
            {
                throw ExceptionHelper.CreateException <PixelServerException>("The type {0} doesn't implement interface IImageSetProvider.", namespaceQualifiedType);
            }

            ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes);

            if (ctor == null)
            {
                throw ExceptionHelper.CreateException <PixelServerException>("The type {0} doesn't have a parameterless constructor defined.", namespaceQualifiedType);
            }

            object invokeTarget = ctor.Invoke(null);

            MethodInfo method = type.GetMethod("GetImageSet");

            IImageSet retVal = (IImageSet)method.Invoke(invokeTarget, new object[] { parameters });

            return(retVal);
        }
コード例 #3
0
        public IImageSet GetImageSet(ImageSetParameters parameters)
        {
            string classTypeString = parameters["classtype"];
            if (string.IsNullOrEmpty(classTypeString))
                throw ExceptionHelper.CreateException<PixelServerException>("No classtype was specified.");

            string methodName = "Get" + StringExtensions.CamelCase(classTypeString) + this.GetType().Name;
            MethodInfo method = this.GetType().GetMethod(methodName);
            return (IImageSet)method.Invoke(this, new object[] { parameters });
        }
コード例 #4
0
        public static bool ProcessPixelRequest(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            if (!IsPixelRequest(request))
            {
                return(false);
            }

            ImageSetParameters parameters = new ImageSetParameters();
            string             imageName  = string.Empty;
            string             nameSpaceQualifiedTypeName = string.Empty;

            parameters = GetParameters(request, out imageName, out nameSpaceQualifiedTypeName);
            if (string.IsNullOrEmpty(nameSpaceQualifiedTypeName))
            {
                return(ProcessResourceRequest(imageName, parameters));
            }

            try
            {
                //object retVal = method.Invoke(null, (object[])parameters);
                IImageSet retVal = GetImageSet(nameSpaceQualifiedTypeName, parameters);
                if (retVal == null)
                {
                    response.Clear();
                    response.StatusCode = 404;
                    response.Status     = "Image not found";
                    context.ApplicationInstance.CompleteRequest();
                    return(true);
                }

                IImageSet    imageSet = (IImageSet)retVal;
                MemoryStream ms       = new MemoryStream();

                // saving to a memory stream isn't necessary for jpeg but I'm leaving this in just in case I change the format to png later
                imageSet[imageName].Save(ms, ImageFormat.Png);

                response.Clear();
                //TODO: Parameterize the content type/ImageFormat
                response.ContentType = "image/Png"; // this must match the ImageFormat in the Save call above
                ms.WriteTo(response.OutputStream);
                imageSet.Dispose();
                context.ApplicationInstance.CompleteRequest();
            }
            catch (Exception ex)
            {
                LogManager.CurrentLog.AddEntry("An error occurred processing PixelServer request:\r\n Parameters: {0}", ex, new string[] { parameters.ToString() });
            }

            return(true);
        }
コード例 #5
0
        private static bool ProcessResourceRequest(string imageName, ImageSetParameters parameters)
        {
            HttpContext  context  = HttpContext.Current;
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            Resources.LoadResources(typeof(PixelServer).Assembly);

            //format valid values png, gif, jpg
            WebFormats  webFormat   = string.IsNullOrEmpty(parameters["f"]) ? WebFormats.gif : (WebFormats)Enum.Parse(typeof(WebFormats), parameters["f"]);
            ImageFormat imageFormat = ImageFormat.Gif;

            switch (webFormat)
            {
            case WebFormats.Invalid:
                break;

            case WebFormats.gif:
                break;

            case WebFormats.jpg:
                imageFormat = ImageFormat.Jpeg;
                break;

            case WebFormats.png:
                imageFormat = ImageFormat.Png;
                break;
            }

            if (Resources.Images.ContainsKey(EmbeddedPath + imageName))
            {
                Bitmap       image = Resources.Images[EmbeddedPath + imageName];
                MemoryStream ms    = new MemoryStream();
                image.Save(ms, imageFormat);
                response.Clear();

                response.ContentType = "image/" + webFormat.ToString();

                if (webFormat == WebFormats.jpg)
                {
                    image.Save(response.OutputStream, imageFormat);
                }
                else
                {
                    ms.WriteTo(response.OutputStream);
                }
                context.ApplicationInstance.CompleteRequest();

                return(true);
            }
            return(false);
        }
コード例 #6
0
        public IImageSet GetImageSet(ImageSetParameters parameters)
        {
            string classTypeString = parameters["classtype"];

            if (string.IsNullOrEmpty(classTypeString))
            {
                throw ExceptionHelper.CreateException <PixelServerException>("No classtype was specified.");
            }

            string     methodName = "Get" + StringExtensions.CamelCase(classTypeString) + this.GetType().Name;
            MethodInfo method     = this.GetType().GetMethod(methodName);

            return((IImageSet)method.Invoke(this, new object[] { parameters }));
        }
コード例 #7
0
ファイル: Tab.cs プロジェクト: BryanApellanes/Naizari
        //string lineWidth, string radius, string horizontalMargin, string verticalMargin, string htmlLineColor, string htmlBackgroundColor, string htmlFillColor)
        public static IImageSet GetTopTab(ImageSetParameters parameters)
        {
            int intLineWidth;
            int intRadius;
            int intHorizontalMargin;
            int intVerticalMargin;
            int intTabHeight;

            string lineWidth = parameters["linewidth"];
            string lineColor = parameters["linecolor"];
            string radius = parameters["radius"];
            string horizontalMargin = parameters["hmargin"];
            string verticalMargin = parameters["vmargin"];
            string htmlBackgroundColor = parameters["backgroundcolor"];
            string htmlFillColor = parameters["fillcolor"];
            string tabHeight = parameters["tabh"];

            if (int.TryParse(lineWidth, out intLineWidth))
            {
                if (int.TryParse(radius, out intRadius))
                {
                    if (int.TryParse(horizontalMargin, out intHorizontalMargin))
                    {
                        if (int.TryParse(verticalMargin, out intVerticalMargin))
                        {
                            if (int.TryParse(tabHeight, out intTabHeight))
                            {
                                Tab tabs = new Tab(new QuarterCircles(intLineWidth, intRadius,
                                    new SolidBrush(ColorTranslator.FromHtml(htmlBackgroundColor)),
                                    new SolidBrush(ColorTranslator.FromHtml(htmlFillColor)),
                                    intHorizontalMargin,
                                    intVerticalMargin), intTabHeight, lineColor);

                                return (IImageSet)tabs.GetTop();
                            }
                        }
                    }
                }
            }

            return null;
        }
コード例 #8
0
        //string lineWidth, string radius, string horizontalMargin, string verticalMargin, string htmlLineColor, string htmlBackgroundColor, string htmlFillColor)
        public static IImageSet GetTopTab(ImageSetParameters parameters)
        {
            int intLineWidth;
            int intRadius;
            int intHorizontalMargin;
            int intVerticalMargin;
            int intTabHeight;

            string lineWidth           = parameters["linewidth"];
            string lineColor           = parameters["linecolor"];
            string radius              = parameters["radius"];
            string horizontalMargin    = parameters["hmargin"];
            string verticalMargin      = parameters["vmargin"];
            string htmlBackgroundColor = parameters["backgroundcolor"];
            string htmlFillColor       = parameters["fillcolor"];
            string tabHeight           = parameters["tabh"];

            if (int.TryParse(lineWidth, out intLineWidth))
            {
                if (int.TryParse(radius, out intRadius))
                {
                    if (int.TryParse(horizontalMargin, out intHorizontalMargin))
                    {
                        if (int.TryParse(verticalMargin, out intVerticalMargin))
                        {
                            if (int.TryParse(tabHeight, out intTabHeight))
                            {
                                Tab tabs = new Tab(new QuarterCircles(intLineWidth, intRadius,
                                                                      new SolidBrush(ColorTranslator.FromHtml(htmlBackgroundColor)),
                                                                      new SolidBrush(ColorTranslator.FromHtml(htmlFillColor)),
                                                                      intHorizontalMargin,
                                                                      intVerticalMargin), intTabHeight, lineColor);

                                return((IImageSet)tabs.GetTop());
                            }
                        }
                    }
                }
            }

            return(null);
        }
コード例 #9
0
ファイル: PixelServer.cs プロジェクト: BryanApellanes/Naizari
        private static bool ProcessResourceRequest(string imageName, ImageSetParameters parameters)
        {
            HttpContext context = HttpContext.Current;
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;

            Resources.LoadResources(typeof(PixelServer).Assembly);

            //format valid values png, gif, jpg
            WebFormats webFormat = string.IsNullOrEmpty(parameters["f"]) ? WebFormats.gif : (WebFormats)Enum.Parse(typeof(WebFormats), parameters["f"]);
            ImageFormat imageFormat = ImageFormat.Gif;
            switch (webFormat)
            {
                case WebFormats.Invalid:
                    break;
                case WebFormats.gif:
                    break;
                case WebFormats.jpg:
                    imageFormat = ImageFormat.Jpeg;
                    break;
                case WebFormats.png:
                    imageFormat = ImageFormat.Png;
                    break;
            }

            if (Resources.Images.ContainsKey(EmbeddedPath + imageName))
            {
                Bitmap image = Resources.Images[EmbeddedPath + imageName];
                MemoryStream ms = new MemoryStream();
                image.Save(ms, imageFormat);
                response.Clear();

                response.ContentType = "image/" + webFormat.ToString();

                if (webFormat == WebFormats.jpg)
                    image.Save(response.OutputStream, imageFormat);
                else
                    ms.WriteTo(response.OutputStream);
                context.ApplicationInstance.CompleteRequest();

                return true;
            }
            return false;
        }
コード例 #10
0
ファイル: PixelServer.cs プロジェクト: BryanApellanes/Naizari
        private static ImageSetParameters GetParameters(HttpRequest request, out string imageName, out string namespaceQualifiedTypeName)
        {
            ImageSetParameters retVal = new ImageSetParameters();
            imageName = string.Empty;
            namespaceQualifiedTypeName = string.Empty;

            foreach (string queryKey in request.QueryString.AllKeys)
            {
                //TODO: Enumify magic strings
                if (queryKey.Equals("in")) // Image Name
                    imageName = request.QueryString[queryKey];
                else if (queryKey.Equals("t"))
                    namespaceQualifiedTypeName = request.QueryString[queryKey];
                else
                    retVal[queryKey] = HttpUtility.UrlDecode(request.QueryString[queryKey]);
            }

            return retVal;
        }
コード例 #11
0
ファイル: PixelServer.cs プロジェクト: BryanApellanes/Naizari
        public static bool ProcessPixelRequest(HttpContext context)
        {
            HttpRequest request = context.Request;
            HttpResponse response = context.Response;

            if (!IsPixelRequest(request))
                return false;

            ImageSetParameters parameters = new ImageSetParameters();
            string imageName = string.Empty;
            string nameSpaceQualifiedTypeName = string.Empty;
            parameters = GetParameters(request, out imageName, out nameSpaceQualifiedTypeName);
            if (string.IsNullOrEmpty(nameSpaceQualifiedTypeName))
                return ProcessResourceRequest(imageName, parameters);

            try
            {

                //object retVal = method.Invoke(null, (object[])parameters);
                IImageSet retVal = GetImageSet(nameSpaceQualifiedTypeName, parameters);
                if (retVal == null)
                {
                    response.Clear();
                    response.StatusCode = 404;
                    response.Status = "Image not found";
                    context.ApplicationInstance.CompleteRequest();
                    return true;
                }

                IImageSet imageSet = (IImageSet)retVal;
                MemoryStream ms = new MemoryStream();

                // saving to a memory stream isn't necessary for jpeg but I'm leaving this in just in case I change the format to png later
                imageSet[imageName].Save(ms, ImageFormat.Png);

                response.Clear();
                //TODO: Parameterize the content type/ImageFormat
                response.ContentType = "image/Png"; // this must match the ImageFormat in the Save call above
                ms.WriteTo(response.OutputStream);
                imageSet.Dispose();
                context.ApplicationInstance.CompleteRequest();
            }
            catch(Exception ex)
            {
                LogManager.CurrentLog.AddEntry("An error occurred processing PixelServer request:\r\n Parameters: {0}", ex, new string[] { parameters.ToString() });
            }

            return true;
        }
コード例 #12
0
ファイル: PixelServer.cs プロジェクト: BryanApellanes/Naizari
        public static IImageSet GetImageSet(string namespaceQualifiedType, ImageSetParameters parameters)
        {
            Type type = Type.GetType(namespaceQualifiedType);
            if (type == null)
                throw ExceptionHelper.CreateException<PixelServerException>("The type {0} was not found.", namespaceQualifiedType);

            if (type.GetInterface("IImageSetProvider") == null)
                throw ExceptionHelper.CreateException<PixelServerException>("The type {0} doesn't implement interface IImageSetProvider.", namespaceQualifiedType);

            ConstructorInfo ctor = type.GetConstructor(Type.EmptyTypes);
            if (ctor == null)
                throw ExceptionHelper.CreateException<PixelServerException>("The type {0} doesn't have a parameterless constructor defined.", namespaceQualifiedType);

            object invokeTarget = ctor.Invoke(null);

            MethodInfo method = type.GetMethod("GetImageSet");

            IImageSet retVal = (IImageSet)method.Invoke(invokeTarget, new object[]{ parameters });

            return retVal;
        }