public void Basic () 
		{
			WebColorConverter	conv;
			Color			c;

			conv = new WebColorConverter();

			Assert.AreEqual(true, conv.CanConvertFrom(null, typeof(string)), "B1");
			Assert.AreEqual(true, conv.CanConvertTo(null, typeof(string)), "B2");
			Assert.AreEqual(false, conv.CanConvertFrom(null, typeof(int)), "B3");
			Assert.AreEqual(false, conv.CanConvertTo(null, typeof(int)), "B4");

			c = Color.Fuchsia;
			Assert.AreEqual("Fuchsia", conv.ConvertTo(null, null, c, typeof(string)), "B5");

			c = Color.FromArgb(1, 2, 3);
			Assert.AreEqual("#010203", conv.ConvertTo(null, null, c, typeof(string)), "B6");

			c = Color.FromArgb(5, 1, 2, 3);
			Assert.AreEqual("#010203", conv.ConvertTo(null, null, c, typeof(string)), "B7");

			c = Color.FromArgb(254, 253, 252);
			Assert.AreEqual("#FEFDFC", conv.ConvertTo(null, null, c, typeof(string)), "B8");

			c = Color.FromKnownColor(KnownColor.BlanchedAlmond);
			Assert.AreEqual("BlanchedAlmond", conv.ConvertTo(null, null, c, typeof(string)), "B9");

			c = Color.FromName("OingoBoingo");
			Assert.AreEqual("#000000", conv.ConvertTo(null, null, c, typeof(string)), "B10");

			Assert.AreEqual(Color.FromArgb(0, 0, 79, 80), conv.ConvertFrom(null, null, "020304"), "B11");
			Assert.AreEqual(Color.FromArgb(0, 0, 79, 80), conv.ConvertFrom(null, null, "20304"), "B12");
			Assert.AreEqual(Color.FromArgb(127, 255, 255, 255), conv.ConvertFrom(null, null, "2147483647"), "B13");
			Assert.AreEqual(Color.FromArgb(128, 0, 0, 1), conv.ConvertFrom(null, null, "-2147483647"), "B14");
			Assert.AreEqual(Color.FromArgb(255, 2, 3, 4), conv.ConvertFrom(null, null, "#FF020304"), "B15");
			Assert.AreEqual(Color.FromArgb(2, 3, 4), conv.ConvertFrom(null, null, "#020304"), "B16");
			Assert.AreEqual(Color.FromArgb(0, 2, 3, 4), conv.ConvertFrom(null, null, "#20304"), "B17");
			Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "Fuchsia"), "B18");
			Assert.AreEqual(Color.FromArgb(0, 0, 2, 52), conv.ConvertFrom(null, null, "#234"), "B19");

			// Garbage/whitespace tests
			c = Color.FromName("\rGarbage\n");
			Assert.AreEqual("#000000", conv.ConvertTo(null, null, c, typeof(string)), "B20");
			Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "\rFuchsia\n"), "B21");
			Assert.AreEqual(Color.FromArgb(255, 1, 2, 3), conv.ConvertFrom(null, null, "#010203"), "B22");

			Assert.AreEqual(Color.Empty, conv.ConvertFrom(null, null, ""), "B23");

			Assert.AreEqual(Color.FromArgb(0, 0, 0, 1), conv.ConvertFrom(null, null, "#1"), "B24");
			Assert.AreEqual(Color.FromArgb(0, 0, 0, 0x12), conv.ConvertFrom(null, null, "#12"), "B25");
			Assert.AreEqual(Color.FromArgb(0, 0, 1, 0x23), conv.ConvertFrom(null, null, "#123"), "B26");
			Assert.AreEqual(Color.FromArgb(0, 0, 0x12, 0x34), conv.ConvertFrom(null, null, "#1234"), "B27");
			Assert.AreEqual(Color.FromArgb(0, 1, 0x23, 0x45), conv.ConvertFrom(null, null, "#12345"), "B28");
			Assert.AreEqual(Color.FromArgb(0xff, 0x12, 0x34, 0x56), conv.ConvertFrom(null, null, "#123456"), "B29");
			Assert.AreEqual(Color.FromArgb(0x1, 0x23, 0x45, 0x67), conv.ConvertFrom(null, null, "#1234567"), "B30");
			Assert.AreEqual(Color.FromArgb(0x12, 0x34, 0x56, 0x78), conv.ConvertFrom(null, null, "#12345678"), "B31");
		}
        public static string  CreateAuthCodeImg(int width,int height,out string authcode)
        {
            string db="1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
            string[] dbStr=db.Split(',');
            string codeStr=string.Empty;
            Random rand=new Random();
            for(int i=0;i<4;i++)
            {
               codeStr+=dbStr[rand.Next(dbStr.Length)];
            }
            Bitmap map=new Bitmap(width,height);
            Graphics g=Graphics.FromImage(map);
            WebColorConverter color=new WebColorConverter();
            g.Clear((Color)color.ConvertFromString("#FAE264"));
            //图片背景噪音线
            for(int i=0;i<12;i++)
            {
                int x1=rand.Next(map.Width);
                int x2=rand.Next(map.Width);
                int y1=rand.Next(map.Height);
                int y2=rand.Next(map.Height);
                g.DrawLine(new Pen(Color.LightGray),x1,y1,x2,y2);
            }
            Font font=new Font("Arial",15,FontStyle.Regular|FontStyle.Italic);
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
            new Rectangle(0,0,map.Width,map.Height),Color.Blue,Color.Gray,1.2f,true);
            g.DrawString(codeStr,font,brush,0,0);
            authcode = codeStr;
            //图片前景噪音点
            //for(int i=0;i<10;i++)
            //{
            //    int x=rand.Next(map.Width);
            //    int y=rand.Next(map.Height);
            //    map.SetPixel(x,y,Color.White);
            //}
            //画图片边框
            //g.DrawRectangle(new Pen(Color.Black),0,0,map.Width-1,map.Height-1);
            
            //MemoryStream stream=new MemoryStream();
            //map.Save(stream,System.Drawing.Imaging.ImageFormat.Gif);
            //HttpContext.Current.Response.ClearContent();
            //HttpContext.Current.Response.ContentType = "image/gif";
            //HttpContext.Current.Response.BinaryWrite(stream.ToArray());
            
            
            string fileName="ViewPage\\Images\\AuthCodeImg\\"+DateTime.Now.ToFileTime()+".gif";
            string path = HttpContext.Current.Server.MapPath("~");
            map.Save(path+fileName);

            g.Dispose();
            map.Dispose();

            return "~//"+fileName.Replace("\\","/"); 
        }
Example #3
0
        /// <summary>
        /// Retrieves a string representing the current menu array
        /// </summary>
        /// <returns>
        /// The current menu array
        /// </returns>
        public string ToMenuArray()
        {
            var wc = new WebColorConverter();

            var sb = new StringBuilder();

            sb.Append("=new Array(");
            sb.Append(CleanForJavascript(this.Text));
            sb.Append(", ");
            sb.Append(CleanForJavascript(this.Link));
            sb.Append(", ");
            sb.Append(CleanForJavascript(this.BackgroundImage));
            sb.Append(", ");
            sb.Append(this.Childs.Count);
            sb.Append(", ");
            if (this.Height.Value > 0)
            {
                sb.Append(this.Height.Value);
            }
            else
            {
                sb.Append(20);
            }

            sb.Append(", ");
            if (this.Width.Value > 0)
            {
                sb.Append(this.Width.Value);
            }
            else
            {
                sb.Append((this.Text.Length * 7) + 15);
            }

            sb.Append(", ");
            sb.Append(CleanForJavascript(wc.ConvertToString(this.ControlStyle.BackColor)));
            sb.Append(", ");
            sb.Append(CleanForJavascript(wc.ConvertToString(this.ControlHiStyle.BackColor)));
            sb.Append(", ");
            sb.Append(CleanForJavascript(wc.ConvertToString(this.ControlStyle.ForeColor)));
            sb.Append(", ");
            sb.Append(CleanForJavascript(wc.ConvertToString(this.ControlHiStyle.ForeColor)));
            sb.Append(", ");
            sb.Append(CleanForJavascript(wc.ConvertToString(this.ControlStyle.BorderColor)));
            sb.Append(");");
            sb.Append("\n");

            return sb.ToString();
        }
Example #4
0
        public override void Initialize()
        {
            _editor.ToolsFile = ToolsFile;
            _editor.EnableViewState = false;
            _editor.ExternalDialogsPath = moduleFolderPath + "Dialogs/";

            _editor.OnClientCommandExecuting = "OnClientCommandExecuting";


            if (! string.IsNullOrEmpty(ConfigFile))
            {
                XmlDocument xmlDoc = GetValidConfigFile();
                var colorConverter = new WebColorConverter();
                var items = new ArrayList();

                if (xmlDoc != null)
                {
                    foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                    {
                        if (node.Attributes == null || node.Attributes["name"] == null || node.InnerText.Length == 0)
                        {
                            continue;
                        }

                        string propertyName = node.Attributes["name"].Value;
                        string propValue = node.InnerText;
                        //use reflection to set all string and bool properties
                        SetEditorProperty(propertyName, propValue);
                        //the following collections are handled by the tools file now:
                        //CssFiles, Colors, Symbols, Links, FontNames, FontSizes, Paragraphs, RealFontSizes
                        //CssClasses, Snippets, Languages
                        switch (propertyName)
                        {
                            case "AutoResizeHeight":
                                {
                                    _editor.AutoResizeHeight = bool.Parse(node.InnerText);
                                    break;
                                }
                            case "BorderWidth":
                                {
                                    _editor.BorderWidth = Unit.Parse(node.InnerText);
                                    break;
                                }
                            case "EnableResize":
                                {
                                    _editor.EnableResize = bool.Parse(node.InnerText);
                                    break;
                                }
                            case "NewLineBr":
                                {
                                    //use NewLineMode as NewLineBR has been obsoleted
                                    if (bool.Parse(node.InnerText)==true)
                                    {
                                        _editor.NewLineMode = EditorNewLineModes.Br;
                                        }
                                    else
                                    {
                                        _editor.NewLineMode = EditorNewLineModes.P; 
                                    }
                                    break;
                                }
                            case "Height":
                                {
                                    _editor.Height = Unit.Parse(node.InnerText);
                                    break;
                                }
                            case "Width":
                                {
                                    _editor.Width = Unit.Parse(node.InnerText);
                                    break;
                                }
                            case "ScriptToLoad":
                                {
                                    string path = Context.Request.MapPath(PortalSettings.ActiveTab.SkinPath) + node.InnerText;
                                    if (File.Exists(path))
                                    {
                                        _scripttoload = PortalSettings.ActiveTab.SkinPath + node.InnerText;
                                    }
                                    break;
                                }
                            case "ContentFilters":
                                {
                                    _editor.ContentFilters = (EditorFilters) (Enum.Parse(typeof (EditorFilters), node.InnerText));
                                    break;
                                }
                            case "ToolbarMode":
                                {
                                    _editor.ToolbarMode = (EditorToolbarMode) (Enum.Parse(typeof (EditorToolbarMode), node.InnerText, true));
                                    break;
                                }
                            case "EditModes":
                                {
                                    _editor.EditModes = (EditModes) (Enum.Parse(typeof (EditModes), node.InnerText, true));
                                    break;
                                }
                            case "StripFormattingOptions":
                                {
                                    _editor.StripFormattingOptions = (EditorStripFormattingOptions) (Enum.Parse(typeof (EditorStripFormattingOptions), node.InnerText, true));
                                    break;
                                }
                            case "MaxImageSize":
                                {
                                    _editor.ImageManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "MaxFlashSize":
                                {
                                    _editor.FlashManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "MaxMediaSize":
                                {
                                    _editor.MediaManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "MaxDocumentSize":
                                {
                                    _editor.DocumentManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "MaxTemplateSize":
                                {
                                    _editor.TemplateManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "MaxSilverlightSize":
                                {
                                    _editor.SilverlightManager.MaxUploadFileSize = int.Parse(node.InnerText);
                                    break;
                                }
                            case "FileBrowserContentProviderTypeName":
                                {
                                    _editor.ImageManager.ContentProviderTypeName = node.InnerText;
                                    _editor.FlashManager.ContentProviderTypeName = node.InnerText;
                                    _editor.MediaManager.ContentProviderTypeName = node.InnerText;
                                    _editor.DocumentManager.ContentProviderTypeName = node.InnerText;
                                    _editor.TemplateManager.ContentProviderTypeName = node.InnerText;
                                    _editor.SilverlightManager.ContentProviderTypeName = node.InnerText;
                                    break;
                                }
                            case "SpellAllowAddCustom":
                                {
                                    // RadSpell properties
                                    _editor.SpellCheckSettings.AllowAddCustom = bool.Parse(node.InnerText);
                                    break;
                                }
                            case "SpellCustomDictionarySourceTypeName":
                                {
                                    _editor.SpellCheckSettings.CustomDictionarySourceTypeName = node.InnerText;
                                    break;
                                }
                            case "SpellCustomDictionarySuffix":
                                {
                                    _editor.SpellCheckSettings.CustomDictionarySuffix = node.InnerText;
                                    break;
                                }
                            case "SpellDictionaryPath":
                                {
                                    _editor.SpellCheckSettings.DictionaryPath = node.InnerText;
                                    break;
                                }
                            case "SpellDictionaryLanguage":
                                {
                                    _editor.SpellCheckSettings.DictionaryLanguage = node.InnerText;
                                    break;
                                }
                            case "SpellEditDistance":
                                {
                                    _editor.SpellCheckSettings.EditDistance = int.Parse(node.InnerText);
                                    break;
                                }
                            case "SpellFragmentIgnoreOptions":
                                {
                                    //SpellCheckSettings.FragmentIgnoreOptions = (FragmentIgnoreOptions)Enum.Parse(typeof(FragmentIgnoreOptions), node.InnerText, true);
                                    break;
                                }
                            case "SpellCheckProvider":
                                {
                                    _editor.SpellCheckSettings.SpellCheckProvider = (SpellCheckProvider) (Enum.Parse(typeof (SpellCheckProvider), node.InnerText, true));
                                    break;
                                }
                            case "SpellWordIgnoreOptions":
                                {
                                    _editor.SpellCheckSettings.WordIgnoreOptions = (WordIgnoreOptions) (Enum.Parse(typeof (WordIgnoreOptions), node.InnerText, true));
                                    break;
                                }
                            case "ImagesPath":
                                {
                                    PopulateFolder(node.InnerText, "ImageManager");
                                    break;
                                }
                            case "FlashPath":
                                {
                                    PopulateFolder(node.InnerText, "FlashManager");
                                    break;
                                }
                            case "MediaPath":
                                {
                                    PopulateFolder(node.InnerText, "MediaManager");
                                    break;
                                }
                            case "DocumentsPath":
                                {
                                    PopulateFolder(node.InnerText, "DocumentManager");
                                    break;
                                }
                            case "TemplatePath":
                                {
                                    PopulateFolder(node.InnerText, "TemplateManager");
                                    break;
                                }
                            case "SilverlightPath":
                                {
                                    PopulateFolder(node.InnerText, "SilverlightManager");
                                    break;
                                }
                            case "ContentAreaMode":
                                {
                                    _editor.ContentAreaMode = (EditorContentAreaMode)Enum.Parse(typeof(EditorContentAreaMode), node.InnerText);
                                    break;
                                }
                            case "LinksUseTabNames":
                                {
                                    try
                                    {
                                        _linksUseTabNames = bool.Parse(node.InnerText);
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                }
                            case "LinksUseRelativeUrls":
                                {
                                    try
                                    {
                                        _linksUseRelativeUrls = bool.Parse(node.InnerText);
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                }
                            case "ShowPortalLinks":
                                {
                                    try
                                    {
                                        _ShowPortalLinks = bool.Parse(node.InnerText);
                                    }
                                    catch
                                    {
                                    }
                                    break;
                                }
                            case "CssFile":
                                {
                                    string path = Context.Request.MapPath(PortalSettings.ActiveTab.SkinPath) + node.InnerText;
                                    if (File.Exists(path))
                                    {
                                        _editor.CssFiles.Clear();
                                        _editor.CssFiles.Add(PortalSettings.ActiveTab.SkinPath + node.InnerText);
                                    }
                                    else
                                    {
                                        path = Context.Request.MapPath(PortalSettings.HomeDirectory) + node.InnerText;
                                        if (File.Exists(path))
                                        {
                                            _editor.CssFiles.Clear();
                                            _editor.CssFiles.Add(PortalSettings.HomeDirectory + node.InnerText);
                                        }
                                    }

                                    break;
                                }
                            default:
                                {
                                    // end of RadSpell properties
                                    if (propertyName.EndsWith("Filters"))
                                    {
                                        items.Clear();

                                        if (node.HasChildNodes)
                                        {
                                            if (node.ChildNodes.Count == 1)
                                            {
                                                if (node.ChildNodes[0].NodeType == XmlNodeType.Text)
                                                {
                                                    items.Add(node.InnerText);
                                                }
                                                else if (node.ChildNodes[0].NodeType == XmlNodeType.Element)
                                                {
                                                    items.Add(node.ChildNodes[0].InnerText);
                                                }
                                            }
                                            else
                                            {
                                                foreach (XmlNode itemnode in node.ChildNodes)
                                                {
                                                    items.Add(itemnode.InnerText);
                                                }
                                            }
                                        }

                                        var itemsArray = (string[]) (items.ToArray(typeof (string)));
                                        switch (propertyName)
                                        {
                                            case "ImagesFilters":
                                                _editor.ImageManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;

                                            case "FlashFilters":
                                                _editor.FlashManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;

                                            case "MediaFilters":
                                                _editor.MediaManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;

                                            case "DocumentsFilters":
                                                _editor.DocumentManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;

                                            case "TemplateFilters":
                                                _editor.TemplateManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;

                                            case "SilverlightFilters":
                                                _editor.SilverlightManager.SearchPatterns = ApplySearchPatternFilter(itemsArray);
                                                break;
                                        }
                                    }

                                    break;
                                }
                        }
                    }
                }
                else
                {
                    //could not load config
                }
            }
            else
            {
                //could not load config (config file property empty?)
            }
        }
Example #5
0
        /// <summary>
        /// Retrieves a string representing the current menu array
        /// </summary>
        /// <param name="prefix">
        /// The prefix.
        /// </param>
        /// <returns>
        /// The current menu array
        /// </returns>
        protected string ToMenuArray(string prefix)
        {
            var wc = new WebColorConverter();

            var sb = new StringBuilder();

            sb.Append("<script type = 'text/javascript'>\n");
            sb.Append("  function Go(){return}\n");
            sb.Append("</script>\n");

            sb.Append("<script type = 'text/javascript'>\n");

            sb.Append("var NoOffFirstLineMenus = ");
            sb.Append(this.Childs.Count);
            sb.Append(";\n");

            // MH:
            sb.Append("var CssItemClassName = ");
            sb.Append("\"");
            sb.Append(this.ControlItemStyle.CssClass);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var CssHiClassName = ");
            sb.Append("\"");
            sb.Append(this.ControlHiStyle.CssClass);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var CssSubClassName = ");
            sb.Append("\"");
            sb.Append(this.ControlSubStyle.CssClass);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var CssHiSubClassName = ");
            sb.Append("\"");
            sb.Append(this.ControlHiSubStyle.CssClass);
            sb.Append("\"");
            sb.Append(";\n");

            // MH:
            sb.Append("var LowBgColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.BackColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var LowSubBgColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlSubStyle.BackColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var HighBgColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlHiStyle.BackColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var HighSubBgColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlHiSubStyle.BackColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var FontLowColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ForeColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var FontSubLowColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlSubStyle.ForeColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var FontHighColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlHiStyle.ForeColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var FontSubHighColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlHiSubStyle.ForeColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var BorderColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.BorderColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var BorderSubColor = ");
            sb.Append("\"");
            sb.Append(wc.ConvertToString(this.ControlSubStyle.BorderColor));
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var BorderWidth = ");
            sb.Append(this.BorderWidth.Value);
            sb.Append(";\n");

            sb.Append("var BorderBtwnElmnts = ");
            sb.Append(this.BorderBtwnElmnts ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var FontFamily = ");
            sb.Append("\"");
            sb.Append(this.Font.Name);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var FontSize = ");
            sb.Append(this.Font.Size.Unit.Value);
            sb.Append(";\n");

            sb.Append("var FontBold = ");
            sb.Append(this.Font.Bold ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var FontItalic = ");
            sb.Append(this.Font.Italic ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var MenuTextCentered = ");
            sb.Append("\"");
            sb.Append(this.MenuTextCentered.ToString().ToLower());
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var MenuCentered = ");
            sb.Append("\"");
            sb.Append(this.MenuCentered.ToString().ToLower());
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var MenuVerticalCentered = ");
            sb.Append("\"");
            sb.Append(this.MenuVerticalCentered.ToString().ToLower());
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var ChildOverlap = ");
            sb.Append(this.ChildOverlap.ToString(new CultureInfo("en-US").NumberFormat));
            sb.Append(";\n");

            sb.Append("var ChildVerticalOverlap = ");
            sb.Append(this.ChildVerticalOverlap.ToString(new CultureInfo("en-US").NumberFormat));
            sb.Append(";\n");

            sb.Append("var LeftPaddng = ");
            sb.Append(this.LeftPaddng);
            sb.Append(";\n");

            sb.Append("var TopPaddng = ");
            sb.Append(this.TopPaddng);
            sb.Append(";\n");

            sb.Append("var StartTop = ");
            sb.Append(this.StartTop);
            sb.Append(";\n");

            sb.Append("var StartLeft = ");
            sb.Append(this.StartLeft);
            sb.Append(";\n");

            sb.Append("var VerCorrect = ");
            sb.Append(this.VerCorrect);
            sb.Append(";\n");

            sb.Append("var HorCorrect = ");
            sb.Append(this.HorCorrect);
            sb.Append(";\n");

            sb.Append("var FirstLineHorizontal = ");
            sb.Append(this.Horizontal ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var MenuFramesVertical = ");
            sb.Append(this.MenuFramesVertical ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var DissapearDelay = ");
            sb.Append(this.DissapearDelay);
            sb.Append(";\n");

            sb.Append("var TakeOverBgColor = ");
            sb.Append(this.TakeOverBgColor ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var FirstLineFrame = ");
            sb.Append("\"");
            sb.Append(this.FirstLineFrame);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var SecLineFrame = ");
            sb.Append("\"");
            sb.Append(this.SecLineFrame);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var DocTargetFrame = ");
            sb.Append("\"");
            sb.Append(this.DocTargetFrame);
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var HideTop = ");
            sb.Append(this.HideTop ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var TargetLoc = ");
            sb.Append("\"");

            // sb.Append(TargetLoc);
            // sb.Append(this.Controls[0].ClientID);
            sb.Append("MenuPos"); // NS4 bug fix
            sb.Append("\"");
            sb.Append(";\n");

            sb.Append("var MenuWrap = ");
            sb.Append(this.MenuWrap ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var RightToLeft = ");
            sb.Append(this.RightToLeft ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var UnfoldsOnClick = ");
            sb.Append(this.UnfoldsOnClick ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var WebMasterCheck = ");
            sb.Append(this.WebMasterCheck ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var ShowArrow = ");
            sb.Append(this.ShowArrow ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var KeepHilite = ");
            sb.Append(this.KeepHilite ? 1 : 0);
            sb.Append(";\n");

            sb.Append("var Arrws = ");
            sb.Append("[");
            for (var i = 0; i <= this.arrws.GetUpperBound(0); i++)
            {
                sb.Append("\"");
                sb.Append(this.ImagesPath + this.arrws[i].ImageUrl);
                sb.Append("\", ");
                sb.Append(this.arrws[i].Width.Value);
                sb.Append(", ");
                sb.Append(this.arrws[i].Height.Value);
                if (i != this.arrws.GetUpperBound(0))
                {
                    sb.Append(", ");
                }
            }

            sb.Append("]");
            sb.Append(";\n");

            sb.Append("function BeforeStart(){;}\n");
            sb.Append("function AfterBuild(){;}\n");
            sb.Append("function BeforeFirstOpen(){;}\n");
            sb.Append("function AfterCloseAll(){;}\n");

            sb.Append(this.Childs.ToMenuArray(prefix));

            sb.Append("</script>\n");
            sb.AppendFormat("<script type = 'text/javascript' src = '{0}menu_com.js'></script>\n", this.ClientScriptPath);
            sb.Append("<noscript>Your browser does not support script</noscript>\n");

            return sb.ToString();
        }
Example #6
0
        void UpdateOnClientClick()
        {
            String url = Url;
            if (!url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) url = Control.ResolveUrl(url);
            string jsFuncName = Control.ClientID + "ShowDialog";

            if (!Control.Page.ClientScript.IsClientScriptBlockRegistered(GetType(), jsFuncName))
            {
                StringBuilder showJs = new StringBuilder(), moreJs = new StringBuilder();
                if (Width != Unit.Empty) showJs.AppendFormat("Width:{0},", (Int32)Width.Value);
                if (Height != Unit.Empty) showJs.AppendFormat("Height:{0},", (Int32)Height.Value);
                if (ClickedRowBackColor != Color.Empty)
                {
                    string color = new WebColorConverter().ConvertToString(ClickedRowBackColor);
                    showJs.AppendFormat(@"
BeforeShow:function(){{GridViewExtender.HighlightRow(ele,'{0}',true);}},
AfterClose:function(){{GridViewExtender.HighlightRow(ele,'{0}',false);}},
", color);
                    // 使用到GridViewExtender的地方引入相关的js
                    Control.Page.ClientScript.RegisterClientScriptResource(typeof(GridViewExtender), "XControl.View.GridViewExtender.js");
                }
                if (this.Control is GridView)
                {
                    moreJs.AppendFormat("stopEventPropagation(event);");
                    if (!Control.Page.ClientScript.IsClientScriptBlockRegistered(typeof(object), "stopEventPropagation"))
                    {
                        Control.Page.ClientScript.RegisterClientScriptBlock(typeof(object), "stopEventPropagation", Helper.JsMinSimple(@"
;function stopEventPropagation(e){
    try{
        if(typeof e != 'undefined'){
            if(typeof e.stopPropagation != 'undefined'){
                e.stopPropagation();
            }else if(typeof e.cancelBubble != 'undefined'){
                e.cancelBubble = true;
            }
        }
    }catch(ex){}
}
"), true);
                    }
                }

                Control.Page.ClientScript.RegisterClientScriptBlock(GetType(), jsFuncName, Helper.JsMinSimple(@"
;function {0}(ele, event, title, url, msgRow, msgTitle, msg, btnRow){{
    try{{
        ShowDialog({{
            ID:'win'+Math.random(),
            Title:title,
            URL:url,
            ShowMessageRow:msgRow,
            MessageTitle:msgTitle,
            Message:msg,
            {1}
            ShowButtonRow:btnRow
        }});
        {2}
    }}catch(ex){{{3}}};
    return false;
}}
", jsFuncName, showJs, moreJs, XTrace.Debug ? "alert(ex);" : ""), true);
            }

            OnClientClick = Helper.HTMLPropertyEscape(@"return {0}(this,event,'{1}','{2}',{3},'{4}','{5}',{6});",
                jsFuncName,
                Helper.JsStringEscape(Title), Helper.JsStringEscape(url),
                ShowMessageRow.ToString().ToLower(),
                Helper.JsStringEscape(MessageTitle), Helper.JsStringEscape(Message),
                ShowButtonRow.ToString().ToLower()
            );

        }
		public void NamedColorsCSS2 ()
		{
			WebColorConverter wcc = new WebColorConverter ();
			Color c;

			c = (Color)wcc.ConvertFrom (null, null, "ActiveBorder");
			Assert.IsTrue (c.IsKnownColor, "#A1");
			Assert.AreEqual ("ActiveBorder", c.Name, "#A1-1");

			c = (Color)wcc.ConvertFrom (null, null, "ActiveCaption");
			Assert.IsTrue (c.IsKnownColor, "#A2");
			Assert.AreEqual ("ActiveCaption", c.Name, "#A2-1");

			c = (Color)wcc.ConvertFrom (null, null, "AppWorkspace");
			Assert.IsTrue (c.IsKnownColor, "#A3");
			Assert.AreEqual ("AppWorkspace", c.Name, "#A3-1");

			c = (Color)wcc.ConvertFrom (null, null, "Background");
			Assert.IsTrue (c.IsKnownColor, "#A4");
			Assert.AreEqual ("Desktop", c.Name, "#A1-4");

			c = (Color)wcc.ConvertFrom (null, null, "ButtonFace");
			Assert.IsTrue (c.IsKnownColor, "#A5");
			Assert.AreEqual ("Control", c.Name, "#A5-1");

			c = (Color)wcc.ConvertFrom (null, null, "ButtonHighlight");
			Assert.IsTrue (c.IsKnownColor, "#A6");
			Assert.AreEqual ("ControlLightLight", c.Name, "#A6-1");

			c = (Color)wcc.ConvertFrom (null, null, "ButtonShadow");
			Assert.IsTrue (c.IsKnownColor, "#A7");
			Assert.AreEqual ("ControlDark", c.Name, "#A7-1");
			
			c = (Color)wcc.ConvertFrom (null, null, "ButtonText");
			Assert.IsTrue (c.IsKnownColor, "#A8");
			Assert.AreEqual ("ControlText", c.Name, "#A8-1");

			c = (Color)wcc.ConvertFrom (null, null, "CaptionText");
			Assert.IsTrue (c.IsKnownColor, "#A9");
			Assert.AreEqual ("ActiveCaptionText", c.Name, "#A9-1");

			c = (Color)wcc.ConvertFrom (null, null, "GrayText");
			Assert.IsTrue (c.IsKnownColor, "#A10");
			Assert.AreEqual ("GrayText", c.Name, "#A10-1");

			c = (Color)wcc.ConvertFrom (null, null, "Highlight");
			Assert.IsTrue (c.IsKnownColor, "#A11");
			Assert.AreEqual ("Highlight", c.Name, "#A11-1");

			c = (Color)wcc.ConvertFrom (null, null, "HighlightText");
			Assert.IsTrue (c.IsKnownColor, "#A12");
			Assert.AreEqual ("HighlightText", c.Name, "#A12-1");

			c = (Color)wcc.ConvertFrom (null, null, "InactiveBorder");
			Assert.IsTrue (c.IsKnownColor, "#A13");
			Assert.AreEqual ("InactiveBorder", c.Name, "#A13-1");

			c = (Color)wcc.ConvertFrom (null, null, "InactiveCaption");
			Assert.IsTrue (c.IsKnownColor, "#A14");
			Assert.AreEqual ("InactiveCaption", c.Name, "#A14-1");

			c = (Color)wcc.ConvertFrom (null, null, "InactiveCaptionText");
			Assert.IsTrue (c.IsKnownColor, "#A15");
			Assert.AreEqual ("InactiveCaptionText", c.Name, "#A15-1");

			c = (Color)wcc.ConvertFrom (null, null, "InfoBackground");
			Assert.IsTrue (c.IsKnownColor, "#A16");
			Assert.AreEqual ("Info", c.Name, "#A16-1");

			c = (Color)wcc.ConvertFrom (null, null, "InfoText");
			Assert.IsTrue (c.IsKnownColor, "#A17");
			Assert.AreEqual ("InfoText", c.Name, "#A17-1");

			c = (Color)wcc.ConvertFrom (null, null, "Menu");
			Assert.IsTrue (c.IsKnownColor, "#A18");
			Assert.AreEqual ("Menu", c.Name, "#A18-1");

			c = (Color)wcc.ConvertFrom (null, null, "MenuText");
			Assert.IsTrue (c.IsKnownColor, "#A19");
			Assert.AreEqual ("MenuText", c.Name, "#A19-1");

			c = (Color)wcc.ConvertFrom (null, null, "ScrollBar");
			Assert.IsTrue (c.IsKnownColor, "#A20");
			Assert.AreEqual ("ScrollBar", c.Name, "#A20-1");

			c = (Color)wcc.ConvertFrom (null, null, "ThreeDDarkShadow");
			Assert.IsTrue (c.IsKnownColor, "#A21");
			Assert.AreEqual ("ControlDarkDark", c.Name, "#A21-1");

			c = (Color)wcc.ConvertFrom (null, null, "ThreeDFace");
			Assert.IsTrue (c.IsKnownColor, "#A22");
			Assert.AreEqual ("Control", c.Name, "#A22-1");

			c = (Color)wcc.ConvertFrom (null, null, "ThreeDHighlight");
			Assert.IsTrue (c.IsKnownColor, "#A23");
			Assert.AreEqual ("ControlLight", c.Name, "#A23-1");

			c = (Color)wcc.ConvertFrom (null, null, "ThreeDLightShadow");
			Assert.IsTrue (c.IsKnownColor, "#A24");
			Assert.AreEqual ("ControlLightLight", c.Name, "#A24-1");

			Exception ex = null;
			try {
				c = (Color)wcc.ConvertFrom (null, null, "ThreeDShadow");
			} catch (Exception e) {
				ex = e;
			}			
			Assert.IsNotNull (ex, "#A25");

			c = (Color)wcc.ConvertFrom (null, null, "Window");
			Assert.IsTrue (c.IsKnownColor, "#A26");
			Assert.AreEqual ("Window", c.Name, "#A26-1");

			c = (Color)wcc.ConvertFrom (null, null, "WindowFrame");
			Assert.IsTrue (c.IsKnownColor, "#A27");
			Assert.AreEqual ("WindowFrame", c.Name, "#A27-1");

			c = (Color)wcc.ConvertFrom (null, null, "WindowText");
			Assert.IsTrue (c.IsKnownColor, "#A28");
			Assert.AreEqual ("WindowText", c.Name, "#A28-1");
		}
		public void MalformatTest7 () 
		{
			WebColorConverter	conv;

			conv = new WebColorConverter();
			Assert.AreEqual(Color.FromArgb(255, 254, 254, 254), conv.ConvertFrom(null, null, "garbage"), "M7");
		}
		public void MalformatTest6 () 
		{
			WebColorConverter	conv;

			conv = new WebColorConverter();
			Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "#Fuchsia"), "M6");
		}
		public void MalformatTest5 () 
		{
			WebColorConverter	conv;

			conv = new WebColorConverter();
			// Overflow
			Assert.AreEqual(Color.FromArgb(255, 254, 254, 254), conv.ConvertFrom(null, null, "4294901502"), "M5");
		}
		public void MalformatTest4 () 
		{
			WebColorConverter	conv;

			conv = new WebColorConverter();
			Assert.AreEqual(Color.FromArgb(255, 1, 2, 3), conv.ConvertFrom(null, null, "#010203 Garbage"), "M4");
		}
		public void MalformatTest1 () 
		{
			WebColorConverter	conv;

			conv = new WebColorConverter();
			Assert.AreEqual(Color.Fuchsia, conv.ConvertFrom(null, null, "\rFuchsi\na\n"), "M1");
		}
Example #13
0
		public void RoundTrip ()
		{
			WebColorConverter wcc = new WebColorConverter ();
			
			Color c = (Color) wcc.ConvertFrom(null, null, " captiontext ");
			Assert.AreEqual ("ActiveCaptionText", wcc.ConvertTo (null, null, c, typeof (string)), "#1");
		}		
Example #14
0
        /*产生验证图片*/
        public void CreateImages(string code)
        {
            Bitmap image = new Bitmap(60, 20);
            Graphics g = Graphics.FromImage(image);
            WebColorConverter ww = new WebColorConverter();
            g.Clear((Color)ww.ConvertFromString("#ffffff"));

            Random random = new Random();
            //画图片的背景噪音线
            for (int i = 0; i < 10; i++)
            {
                int x1 = random.Next(100);
                int x2 = random.Next(100);
                int y1 = random.Next(40);
                int y2 = random.Next(40);

                g.DrawLine(new Pen(Color.LightGray), x1, y1, x2, y2);
            }
            Font font = new Font("Arial", 12, FontStyle.Bold | FontStyle.Italic);
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
            new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.Gray, 1.2f, true);

            //画验证码字符串
            for (int i = 0; i < code.Length; i++)
            {
                g.DrawString(code[i].ToString(), font, brush, i * 14 + 2, 2);
            }

            //画图片的前景噪音点
            //for (int i = 0; i < 300; i++)
            //{
            //    int x = random.Next(image.Width);
            //    int y = random.Next(image.Height);
            //    image.SetPixel(x, y, Color.LightGray);
            //}

            //画图片的边框线
            g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);

            Response.Buffer = true;
            Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
            Response.Expires = 0;
            Response.CacheControl = "no-cache";
            Response.AppendHeader("Pragma", "No-Cache");
            //将验证码图片写入内存流,并将其以 "image/Png" 格式输出
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            try
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                Response.ClearContent();
                Response.ContentType = "image/Png";
                Response.BinaryWrite(ms.ToArray());
            }
            finally
            {
                //显式释放资源
                g.Dispose();
                image.Dispose();

            }
        }
Example #15
0
 /// <summary>
 /// #ff00ff, #f0f  => color
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 private Color ConvertStringToColor(string text)
 {
     if (!string.IsNullOrEmpty(text))
     {
         Color r = Color.White;
         WebColorConverter wcc = new WebColorConverter();
         text.Trim();
         text = text.Replace("#", "");
         if (text.Length == 6)
         {
             r = (Color)wcc.ConvertFromString("#" + text);
         }
         if (text.Length == 3)
         {
             text = string.Format("{0}{0}{1}{1}{2}{2}",
                 text[0], text[1], text[2]);
             r = (Color)wcc.ConvertFromString("#" + text);
         }
         return r;
     }
     return Color.White;
 }