/// <summary>
 /// Creates a header with four (4) tabs
 /// </summary>
 public HeaderRenderControl(Font font, LogoDetails logo, TabDetails tab1, TabDetails tab2, TabDetails tab3, TabDetails tab4)
 {
     this._SetupHeaderControl(font, logo, new TabDetails[] { tab1, tab2, tab3, tab4 });
 }
        /// <summary>
        /// Renders and saves a tab to the tab storage directory
        /// </summary>
        private void _RenderTab(TabDetails tab, string path, int index, bool isLastTab)
        {
            //determine the correct path to this tab
            string templateTabPath = HttpContext.Current.Server.MapPath(
                string.Concat(
                    HeaderRenderControl.TEMPLATE_TAB_PATH_AND_PREFIX,
                    (index + 1),
                    (isLastTab ? HeaderRenderControl.TAB_LAST_POSTFIX : string.Empty),
                    HeaderRenderControl.TAB_FILE_TYPE
                ));

            //make sure the image is available
            if (!File.Exists(templateTabPath)) {
                throw new FileNotFoundException(
                    string.Format(
                        HeaderRenderControl.EXCEPTION_TEMPLATE_IMAGE_MISSING,
                        templateTabPath
                        ));
            }

            //load the image and the coordinates for this the text
            Image template = Image.FromFile(templateTabPath);
            Graphics render = Graphics.FromImage(template);

            //get the size and positions for this text
            SizeF size = render.MeasureString(tab.Text, this.TabFont);
            PointF center = HeaderRenderControl._TabPositions[index];

            //render the text at the appropriate position
            render.DrawString(
                tab.Text,
                this.TabFont,
                new SolidBrush(Color.Black),
                new PointF(
                    center.X - (size.Width / 2),
                    center.Y - (size.Height / 2)
                    ));

            //get the jpeg encoder
            ImageCodecInfo encoder = ImageCodecInfo.GetImageEncoders()
                .Where(o => o.FormatID == ImageFormat.Jpeg.Guid)
                .First();

            //set the image quality
            EncoderParameters parameters = new EncoderParameters(1);
            parameters.Param[0] = new EncoderParameter(
                Encoder.Quality,
                HeaderRenderControl.TAB_IMAGE_QUALITY
                );

            //save the final image for use
            template.Save(path, encoder, parameters);

            //clean up the rendering classes
            template.Dispose();
            render.Dispose();
        }
 /// <summary>
 /// Creates a header with one (1) tabs
 /// </summary>
 public HeaderRenderControl(Font font, LogoDetails logo, TabDetails tab1)
 {
     this._SetupHeaderControl(font, logo, new TabDetails[] { tab1 });
 }
        /// <summary>
        /// Creates the correct Url for an image and if needed, renders the tab
        /// </summary>
        /// <remarks>
        /// The URL is determined by generating a hashcode from the name provided
        /// this code is checked each time the page renders (incase the images 
        /// change).
        /// </remarks>
        public string GetTabUrl(TabDetails tab)
        {
            //make sure this tab doesn't exceed the maximum tabs
            int tabIndex = this.Tabs.ToList().IndexOf(tab);
            if (tabIndex == MAXIMUM_TABS) {
                throw new ArgumentOutOfRangeException(HeaderRenderControl.EXCEPTION_TOO_MANY_TAGS);
            }

            //make sure any tab was found to begin with
            if (tabIndex == -1) {
                throw new ArgumentException(HeaderRenderControl.EXCEPTION_TAG_NOT_IN_COLLECTION);
            }

            //create an identifier for this image using the index
            //of the tab and the text to display. This will determine
            //if this tab has already been rendered or not
            bool isLastTab = (tabIndex == Tabs.Length - 1);
            string identifier = string.Concat(
                tabIndex, //where the tab is
                tab.Text, //what the tag says
                isLastTab.ToString() //string true or false for it's end point
                )
                .GetHashCode()
                .ToString();

            //create the image name by appending the prefix and path
            //onto a hashcode of the file name.
            string imagePath = string.Concat(
                HeaderRenderControl.TAB_PATH_AND_PREFIX,
                identifier,
                HeaderRenderControl.TAB_FILE_TYPE
                );

            //check for this image - if it does not exist, remove it now
            string fullPath = HttpContext.Current.Server.MapPath(imagePath);
            if (!File.Exists(fullPath)) {

                //render the tab image
                this._RenderTab(tab, fullPath, tabIndex, isLastTab);
            }

            //return the path to this file
            return VirtualPathUtility.ToAbsolute(
                imagePath,
                HttpContext.Current.Request.ApplicationPath
                );
        }