Example #1
0
        /// <summary>
        /// 构建数节点
        /// </summary>
        /// <param name="htmlHelper">被扩展的htmlhelper实例</param>
        /// <param name="name"> 树选择器的名称</param>
        /// <param name="treeOptions">树的设置</param>
        /// <param name="treeNodes">树节点集合如果不填则通过ViewData传值</param>
        /// <exception cref="ArgumentNullException">ViewData为空时</exception>
        /// <returns></returns>
        public static MvcHtmlString Tree(this HtmlHelper htmlHelper, string name, TreeOptions treeOptions, IEnumerable<TreeNode> treeNodes = null)
        {
            if (treeNodes == null)
                if (htmlHelper.ViewData[name] != null)
                    treeNodes = htmlHelper.ViewData[name] as IEnumerable<TreeNode>;
            if (treeNodes == null)
                throw new ExceptionFacade("ViewData没有对name赋值");

            //定义属性字典
            Dictionary<string, object> result = new Dictionary<string, object>();
            //data属性字典
            Dictionary<string, object> data = new Dictionary<string, object>();
            //添加树节点数据
            data.TryAdd("TreeNodes", treeNodes.Select(n => n.ToUnobtrusiveHtmlAttributes()));
            //添加树属性数据
            data.TryAdd("Settings", treeOptions.ToUnobtrusiveHtmlAttributes());
            //将数据添加到集合中
            //建立标签元素
            TagBuilder builder = new TagBuilder("ul");

            //添加初始化数据树
            //添加用于脚本操作的标识
            result["plugin"] = "Tree";

            result.Add("data", Json.Encode(data));

            builder.MergeAttributes(result);
            builder.MergeAttribute("id", name);
            //样式
            builder.MergeAttribute("class", "ztree");
            htmlHelper.Script("~/Scripts/tunynet/zTree.js");
            return MvcHtmlString.Create(builder.ToString().Replace("&quot;|", "").Replace("|&quot;", ""));
        }
        public void TryAdd()
        {
            var dictionary = new Dictionary<int, string>();

            dictionary.TryAdd(0, "zero").ShouldBe(true);

            dictionary[0].ShouldBe("zero");

            dictionary.TryAdd(0, "0").ShouldBe(false);

            dictionary[0].ShouldBe("zero");
        }
Example #3
0
        public static IDictionary<string, TestDefinition> GetTestDefinitions(
            this IEnumerable<Type> monitoringTests)
        {
            var definitions =
                monitoringTests
                    .SelectMany(
                        t => t
                              .GetMethods(BindingFlags.Public |
                                          BindingFlags.Instance |
                                          BindingFlags.DeclaredOnly)
                              .Where(m => m.GetParameters().All(p => p.HasDefaultValue))
                              .Where(m => !m.IsSpecialName)
                              .Select(TestDefinition.Create));

            var dictionary = new Dictionary<string, TestDefinition>();
            var collisionCount = 0;

            foreach (var testDefinition in definitions)
            {
                if (!dictionary.TryAdd(testDefinition.TestName, testDefinition))
                {
                    var name = "TEST_NAME_COLLISION_" + ++collisionCount;
                    var definition = testDefinition;
                    dictionary.Add(name,
                                   new AnonymousTestDefinition(name,
                                                               _ =>
                                                               {
                                                                   throw new InvalidOperationException("Test could not be routed:\n" + definition.ToLogString());
                                                               }));
                }
            }

            return dictionary;
        }
Example #4
0
        static void Main(string[] args)
        {
            //string a = "admin";
            //Console.WriteLine(a.To16bitMD5());
            //Console.WriteLine(a.To32bitMD5());
            //Console.WriteLine(a.ToSHA1());
            //Example1();
            //Example2();
            var a2 = "2010-12-12".To<DateTime>(DateTime.Now);

            Dictionary<string, string> dict = new Dictionary<string, string>();
            Dictionary<string, string> dict2 = new Dictionary<string, string>();
            dict2.Add("22222222", "");

            dict.TryAdd("12", "").TryAdd("34", "").AddOrReplace("34", "").AddRange(dict2, false);
            var asdf = "123".CompareTo("1");

            List<string> lst = new List<string>() { "wer", "dsfdsf", "sad" };
            lst.ForEach((item) => { Console.WriteLine(item); });

            List<User> lstUser = new List<User>
            {
                new User{Id=1, Name="柳永法",Age=28,IsMan=true},
                new User{Id=2, Name="柳永法1",Age=28,IsMan=true},
                new User{Id=3, Name="柳永法",Age=29,IsMan=true},
                new User{Id=4, Name="柳永法1",Age=29,IsMan=true},
            };

            var result1 = lstUser.Distinct(p => p.Age);
            var result2 = lstUser.Distinct((x, y) => x.Age == y.Age && x.IsMan == y.IsMan);
        }
        public void op_TryAdd_IDictionaryOfT_TKey_TValue_whenFalse()
        {
            var list = new Dictionary<string, int>
                           {
                               { "example", 123 }
                           };

            Assert.False(list.TryAdd("example", 456));
        }
        public void op_TryAdd_IDictionaryOfT_KeyValuePair_whenFalse()
        {
            var list = new Dictionary<string, int>
                           {
                               { "example", 123 }
                           };

            Assert.False(list.TryAdd(new KeyValuePair<string, int>("example", 456)));
        }
Example #7
0
        /// <summary>
        /// Uploadify的Helper方法用于非附件上传
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="name">名称</param>
        /// <param name="allowedFileExtensions">允许的文件类型
        ///  格式为(jpg,txt,doc)</param>
        ///  <param name="fileSizeLimit">允许上传文件大小(单位KB)</param>
        /// <param name="uploadFileOptions">指定上传配置类</param>
        /// <param name="buttonOptions">指定按钮属性的类</param>
        /// <returns></returns>
        public static MvcHtmlString Uploadify(this HtmlHelper htmlHelper, string name, string allowedFileExtensions, int fileSizeLimit, UploadFileOptions uploadFileOptions, ButtonOptions buttonOptions = null)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(allowedFileExtensions) || fileSizeLimit <= 0 || uploadFileOptions == null)
            {
                throw new ExceptionFacade("参数不能为空");
            }
            if (fileSizeLimit <= 0)
            {
                throw new ExceptionFacade("参数不能小于等于0");
            }

            htmlHelper.Script("~/Bundle/Scripts/Uploadify");

            //data属性字典
            Dictionary<string, object> data = new Dictionary<string, object>();
            //定义属性字典
            Dictionary<string, object> result = new Dictionary<string, object>();
            //参数
            Dictionary<string, object> formData = new Dictionary<string, object>();
            //文件流标识名
            string fileobjName = "Filedata";

            #region uploadify设置

            if (uploadFileOptions != null)
            {
                if (uploadFileOptions.AdditionalCallBacks != null)
                {
                    result = new Dictionary<string, object>(uploadFileOptions.AdditionalCallBacks);
                }

                //定义上传文件标示名称
                if (!string.IsNullOrEmpty(uploadFileOptions.FileObjName))
                {
                    result.TryAdd("fileObjName", uploadFileOptions.FileObjName);
                    fileobjName = uploadFileOptions.FileObjName;
                }
                //设置是否自动上传
                if (uploadFileOptions.IsAuto != null)
                {
                    result.TryAdd("auto", uploadFileOptions.IsAuto);
                }
                //设置可多选文件属性
                if (uploadFileOptions.IsMultiple != null)
                {
                    result.TryAdd("multi", uploadFileOptions.IsMultiple);
                }
                //设置都否缓存SWF文件
                if (uploadFileOptions.PreventCaching != null)
                {
                    result.TryAdd("preventCaching", uploadFileOptions.PreventCaching);
                }
                //设置显示进度的样式
                if (!string.IsNullOrEmpty(uploadFileOptions.ProgressData))
                {
                    result.TryAdd("progressData", uploadFileOptions.ProgressData);
                }
                //设置队列展示容器的ID
                if (!string.IsNullOrEmpty(uploadFileOptions.QueueId))
                {
                    result.TryAdd("queueID", uploadFileOptions.QueueId);
                }

                //设置队列可允许的个数
                result.TryAdd("queueSizeLimit", uploadFileOptions.QueueSizeLimit);

                //设置完成后是否移除属性
                if (uploadFileOptions.RemoveCompleted != null)
                {
                    result.TryAdd("removeCompleted", uploadFileOptions.RemoveCompleted);
                }
                //设置移除的延时属性
                if (uploadFileOptions.RemoveTimeout > 0)
                {
                    result.TryAdd("removeTimeout", uploadFileOptions.RemoveTimeout);
                }
                //设置于服务器端的成功上传的延时属性
                if (uploadFileOptions.SuccessTimeout > 0)
                {
                    result.TryAdd("successTimeout", uploadFileOptions.SuccessTimeout);
                }

                //设置可上传的文件数量限制
                result.TryAdd("uploadLimit", uploadFileOptions.UploadLimit);

                if (uploadFileOptions.AdditionalFormDatas != null)
                {
                    formData = new Dictionary<string, object>(uploadFileOptions.AdditionalFormDatas);
                }
                else
                {
                    formData.TryAdd("requestName", fileobjName);
                }

                result.TryAdd("formData", formData);

                //URL
                long userId = UserContext.CurrentUser != null ? UserContext.CurrentUser.UserId : 0;

                string uploadUrl = SiteUrls.Instance().UploadFile(userId);
                if (!string.IsNullOrEmpty(uploadFileOptions.UploaderUrl))
                {
                    uploadUrl = uploadFileOptions.UploaderUrl + ((uploadFileOptions.UploaderUrl.Contains("?") ? "&" : "?") + "CurrentUserIdToken=" + Utility.EncryptTokenForUploadfile(0.1, userId));
                }

                result.TryAdd("uploader", uploadUrl);
            }

            //设置可允许上传的类型 属性
            string fileTypeExts = FileTypeExts(allowedFileExtensions);
            if (string.IsNullOrEmpty(fileTypeExts))
                fileTypeExts = uploadFileOptions.FileTypeExts;
            if (string.IsNullOrEmpty(fileTypeExts))
                fileTypeExts = "*.*";
            result.TryAdd("fileTypeExts", fileTypeExts);

            //设置文件限制大小属性
            if (fileSizeLimit <= 0)
                fileSizeLimit = uploadFileOptions.FileSizeLimit;
            result.TryAdd("fileSizeLimit", fileSizeLimit);

            if (!string.IsNullOrEmpty(uploadFileOptions.FileTypeDescription))
                result.TryAdd("fileTypeDesc", uploadFileOptions.FileTypeDescription);

            //设置SWF路径
            string swfStr = SiteUrls.FullUrl("~/Scripts/jquery/uploadify/uploadify.swf");
            result.TryAdd("swf", swfStr);

            #endregion uploadify设置

            if (buttonOptions != null)
            {
                #region ButtonOptions设置

                //添加按钮的额外样式
                if (!string.IsNullOrEmpty(buttonOptions.CssClass))
                {
                    result.TryAdd("buttonClass", buttonOptions.CssClass);
                }
                //设置按钮的高度
                if (buttonOptions.Height != 0)
                {
                    result.TryAdd("height", buttonOptions.Height);
                }
                //设置按钮的宽度
                if (buttonOptions.Width != 0)
                {
                    result.TryAdd("width", buttonOptions.Width);
                }
                //设置按钮的显示背景图
                if (!string.IsNullOrEmpty(buttonOptions.ImageUrl))
                {
                    result.TryAdd("buttonImage", buttonOptions.ImageUrl);
                }
                //设置按钮的文本
                if (!string.IsNullOrEmpty(buttonOptions.Text))
                {
                    result.TryAdd("buttonText", buttonOptions.Text);
                }

                #endregion ButtonOptions设置
            }

            TagBuilder builder = new TagBuilder("div");
            //脚本操作标识
            data["plugin"] = "uploadify";
            data.TryAdd("data", Json.Encode(result));
            builder.MergeAttributes(data);
            builder.MergeAttribute("id", name);

            return MvcHtmlString.Create(builder.ToString().Replace("&quot;[", "").Replace("]&quot;", ""));
        }
        /// <summary>
        /// 删除按钮
        /// </summary>
        /// <param name="htmlHelper">被扩展的hemlHelper实例</param>
        /// <param name="ajaxdeletebutton">异步执行删除按钮</param>
        /// <returns>MvcForm</returns>
        public static MvcHtmlString AjaxDeleteButton(this HtmlHelper htmlHelper, AjaxDeleteButton ajaxdeletebutton)
        {
            //定义属性字典
            Dictionary<string, object> result = new Dictionary<string, object>();
            //建立标签元素
            TagBuilder builder = new TagBuilder("a");
            //判断html属性字典是否有数据
            //如果存在则导入到属性字典内
            if (ajaxdeletebutton.HtmlAttributes != null)

                result = new Dictionary<string, object>(ajaxdeletebutton.HtmlAttributes);
            //定义data属性字典
            Dictionary<string, object> data = new Dictionary<string, object>();

            //把错误提示信息添加到data字典里
            data.TryAdd("confirm", ajaxdeletebutton.Confirm);

            //将目标元素属性信息添加到data字典里
            data.TryAdd("deleteTarget", ajaxdeletebutton.DeleteTarget);

            //将成功回调函数名称添加data字典(如果存在)
            if (!string.IsNullOrEmpty(ajaxdeletebutton.Success))
            {
                data.TryAdd("SuccessFn", ajaxdeletebutton.Success);
            }
            //将失败回调函数名称添加data字典(如果存在)
            if (!string.IsNullOrEmpty(ajaxdeletebutton.Error))
            {
                data.TryAdd("ErrorFn", ajaxdeletebutton.Error);
            }

            //添加用于ajax操作的标识
            result["plugin"] = "AjaxDeleteButton";

            //添加data 属性
            result["data"] = Json.Encode(data);

            //将属性字典result导入到标签内属性内
            builder.MergeAttributes(result);

            //添加标签的href属性
            builder.MergeAttribute("href", ajaxdeletebutton.Url);

            //判断删除控件按钮文字是否有值
            if (!string.IsNullOrEmpty(ajaxdeletebutton.Text))
                builder.InnerHtml = ajaxdeletebutton.Text;
            else

                //判断删除控件按钮图标是否有值
                if (ajaxdeletebutton.Icon != null)

                    builder.InnerHtml = htmlHelper.Icon(ajaxdeletebutton.Icon.Value).ToString();
                else
                    return MvcHtmlString.Empty;

            //判断删除控件按钮提示信息是否有值
            if (!string.IsNullOrEmpty(ajaxdeletebutton.Tooltip))
            {
                builder.MergeAttribute("title", ajaxdeletebutton.Tooltip);
            }

            return MvcHtmlString.Create(builder.ToString());
        }
Example #9
0
        /// <summary>
        /// 自定义皮肤设置
        /// </summary>
        /// <param name="presentAreaKey"></param>
        /// <param name="ownerId"></param>
        /// <param name="isUseCustomStyle"></param>
        /// <returns></returns>
        public ActionResult _CustomSettings(string presentAreaKey = PresentAreaKeysOfBuiltIn.UserSpace, long ownerId = 0, bool isUseCustomStyle = false)
        {
            if (!ThemeService.Validate(presentAreaKey, ownerId))
                return Content("没有设置皮肤的权限");

            var customStyleEntity = new CustomStyleService().Get(presentAreaKey, ownerId);
            CustomStyle customStyle = null;
            if (customStyleEntity != null)
            {
                customStyle = customStyleEntity.CustomStyle;
            }
            //配色方案相关操作
            IEnumerable<CustomStyle> colorSchemes = new CustomStyleService().GetColorSchemes(presentAreaKey);
            ViewData["colorSchemes"] = colorSchemes;

            if (customStyle == null)
            {
                customStyle = CustomStyle.New();
                BackgroundImageStyle backgroundImageStyle = new BackgroundImageStyle();
                customStyle.BackgroundImageStyle = backgroundImageStyle;
                Dictionary<string, string> definedColours = null;
                if (colorSchemes.Count() > 0)
                    definedColours = colorSchemes.First().DefinedColours;
                else
                {
                    definedColours = new Dictionary<string, string>();
                    definedColours[ColorLabel.PageBackground.ToString()] = "#f2e3bf";
                    definedColours[ColorLabel.ContentBackground.ToString()] = "#f8f0e6";
                    definedColours[ColorLabel.BorderBackground.ToString()] = "#ebe6d9";
                    definedColours[ColorLabel.MainTextColor.ToString()] = "#666";
                    definedColours[ColorLabel.SubTextColor.ToString()] = "#ccc";
                    definedColours[ColorLabel.MainLinkColor.ToString()] = "#cc6673";
                    definedColours[ColorLabel.SubLinkColor.ToString()] = "#efc0ca";
                }
                customStyle.DefinedColours = definedColours;
            }

            Dictionary<string, object> customStyleCssBlock = new Dictionary<string, object>();
            if (customStyle.IsUseBackgroundImage)
            {
                customStyleCssBlock.TryAdd("background-image", "url('" + customStyle.BackgroundImageStyle.Url + "')");
                customStyleCssBlock.TryAdd("background-repeat", customStyle.BackgroundImageStyle.IsRepeat ? "repeat" : "no-repeat");
                customStyleCssBlock.TryAdd("background-attachment", customStyle.BackgroundImageStyle.IsFix ? "fixed" : "scroll");
                string position = "center";
                switch (customStyle.BackgroundImageStyle.BackgroundPosition)
                {
                    case BackgroundPosition.Left:
                        position = "left";
                        break;
                    case BackgroundPosition.Center:
                        position = "center";
                        break;
                    case BackgroundPosition.Right:
                        position = "right";
                        break;
                    default:
                        position = "center";
                        break;
                }
                customStyleCssBlock.TryAdd("background-position", position + " top");
            }

            ViewData["customStyleCssBlock"] = System.Web.Helpers.Json.Encode(customStyleCssBlock);
            List<SelectListItem> selectHeaderHeight = new List<SelectListItem> { new SelectListItem { Text = "20", Value = "20" }, new SelectListItem { Text = "60", Value = "60" }, new SelectListItem { Text = "100", Value = "100" } };
            ViewData["HeaderHeight"] = new SelectList(selectHeaderHeight, "Value", "Text", customStyle.HeaderHeight);

            return View(customStyle);
        }
Example #10
0
        /// <summary>
        /// Tree属性集合
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, object> ToUnobtrusiveHtmlAttributes()
        {
            var result = new Dictionary<string, object>();
            //先获取额外的Tree设置
            if (AdditionalSetOptions != null)
                result = new Dictionary<string, object>(AdditionalSetOptions);
            //数据设置
            Dictionary<string, object> data = new Dictionary<string, object>();
            Dictionary<string, object> simpleData = new Dictionary<string, object>();
            //设置默认支持事件
            Dictionary<string, object> callBack = new Dictionary<string, object>();

            #region 设置编辑属性

            //判断是否开启可编辑状态

            bool isRename = false, isRemove = false, enable = false, isCopy = false, isMove = false;
            Dictionary<string, object> edit = new Dictionary<string, object>();
            Dictionary<string, object> drag = new Dictionary<string, object>();
            //首先判断是否开启  拖拽功能
            if (this.IsDrag)
            {
                //编辑设置开启 然后设置关闭 删除 改名  (默认)功能
                enable = true;
                isCopy = true;
                isMove = true;
            }
            //添加drag设置
            drag.TryAdd("isCopy", isCopy);
            drag.TryAdd("isMove", isMove);
            //判断是否开启可改名
            if (this.IsRename)
            {
                //先判断是否已经设定
                if (!enable)
                    enable = true;
                isRename = true;
            }
            //判断是否开启删除
            if (this.IsRemove)
            {
                if (!enable)
                    enable = true;
                isRemove = true;
            }
            //判断是否被开启编辑功能
            if (enable)
            {
                edit.TryAdd("enable", enable);
                //判断是否开启拖拽
                edit.TryAdd("drag", drag);
                edit.TryAdd("showRemoveBtn", isRemove);
                edit.TryAdd("showRenameBtn", isRename);
                result.TryAdd("edit", edit);
            }

            #endregion 设置编辑属性

            #region 设置数据属性

            //设置启用简单数据
            simpleData.TryAdd("enable", true);
            //修正根节点表示值根节点表示
            simpleData.TryAdd("rootPId", RootId);
            //设置简单数据
            data.TryAdd("simpleData", simpleData);
            //合并数据
            result.TryAdd("data", data);

            #endregion 设置数据属性

            #region 设置勾选框

            //判断是否开启勾选框
            if (this.SelectBoxType != null)
            {
                Dictionary<string, object> check = new Dictionary<string, object>();
                //设置勾选框开启
                check.TryAdd("enable", true);
                if (this.SelectBoxType == SelectBoxTypes.Checkbox)
                {
                    //设置勾选框类型
                    check.TryAdd("chkStyle", this.SelectBoxType.ToString().ToLower());
                }
                else
                {
                    //设置勾选类型
                    check.TryAdd("chkStyle", this.SelectBoxType.ToString().ToLower());
                    if (this.RadioBoxType != null)
                    {
                        //设置单选按钮范围
                        check.TryAdd("radioType", this.RadioBoxType.ToString().ToLower());
                    }
                    else
                    {
                        //设置单选默认按钮范围 Level
                        check.TryAdd("radioType", RadioBoxTypes.Level.ToString().ToLower());
                    }
                }

                //合并勾选框
                result.TryAdd("check", check);
            }

            #endregion 设置勾选框

            #region 设置回调函数

            //默认的回调事件添加
            //展开前的回调函数
            //判断是否开启单一路径功能
            if (this.AdditionalCallBacks != null)
            {
                callBack = this.AdditionalCallBacks;
                if (callBack.ContainsKey("onExpand"))
                {
                    callBack["addOnExpand"] = callBack["onExpand"];
                }
                if (callBack.ContainsKey("beforeExpand"))
                {
                    callBack["addBeforeExpand"] = callBack["beforeExpand"];
                }
            }
            if (IsSinglePath)
            {
                callBack["beforeExpand"] = "|" + "beforeExpand" + "|";
                //被展开时的回调函数
                callBack["onExpand"] = "|" + "onExpand" + "|";
            }
            //合并默认回调函数
            if (callBack != null)
                result.TryAdd("callback", callBack);

            #endregion 设置回调函数

            #region 设置异步加载

            //判断是否启用异步加载
            if (!string.IsNullOrEmpty(this.AsyncUrl))
            {
                //异步加载设置
                Dictionary<string, object> async = new Dictionary<string, object>();
                //设置异步开启
                async.TryAdd("enable", true);
                //设置异步提交参数数据类型
                async.TryAdd("contentType", "application/json");
                //设置自动提交父节点属性的参数 参数为parentId
                string[] autoParam = new string[] { "id=parentId" };
                async.TryAdd("autoParam", autoParam);
                //设置获取数据的Url地址
                async.TryAdd("url", this.AsyncUrl);
                //合并异步加载
                result.TryAdd("async", async);
            }

            #endregion 设置异步加载

            //整合设置

            return result;
        }
Example #11
0
        /// <summary>
        /// 转为Html属性集合
        /// </summary>
        public IDictionary<string, object> ToHtmlAttributes()
        {
            var result = new Dictionary<string, object>();
            result["plugin"] = "ajaxForm";
            var data = new Dictionary<string, object>();
            data.TryAdd("target", this.Target);
            data.TryAdd("replaceTarget", this.ReplaceTarget);
            if (this.Method.HasValue)
                data.TryAdd("type", this.Method.Value == FormMethod.Post ? "POST" : "GET");
            if (this.DataType.HasValue)
            {
                string dataType = "html";

                switch (this.DataType)
                {
                    case AjaxDataType.Html:
                        break;
                    case AjaxDataType.Xml:
                        dataType = "xml";
                        break;
                    case AjaxDataType.Json:
                        dataType = "json";
                        break;
                    case AjaxDataType.Script:
                        dataType = "script";
                        break;
                    default:
                        break;
                }
                data.TryAdd("dataType", dataType);
            }
            data.TryAdd("beforeSubmitFn", this.BeforeSubmitCallBack);
            data.TryAdd("successFn", this.OnSuccessCallBack);
            data.TryAdd("errorFn", this.OnErrorCallBack);
            data.TryAdd("resetForm", this.ResetForm);
            data.TryAdd("clearForm", this.ClearForm);
            data.TryAdd("closeDialog", this.CloseDialog);
            data.TryAdd("data", this.ExtraData);
            data.TryAdd("url", this.Url);
            result.Add("data", Json.Encode(data));
            return result;
        }
        public void op_TryAdd_IDictionaryOfT_TKey_TValue_whenTrue()
        {
            var list = new Dictionary<string, string>();

            Assert.True(list.TryAdd("example", string.Empty));
        }
        public void op_TryAdd_IDictionaryOfT_KeyValuePair_whenTrue()
        {
            var list = new Dictionary<string, string>();

            Assert.True(list.TryAdd(new KeyValuePair<string, string>("example", string.Empty)));
        }
        private static ClientMessageHeader ParseClientMessage(Stream clientStream)
        {
            var streamReader = new StreamReader(clientStream);
            {
                clientStream.Position = 0;

                var httpCmd = String.Empty;

                for (var i = 0; i < 10; i++)
                {
                    httpCmd = streamReader.ReadLine();

                    if (String.IsNullOrEmpty(httpCmd))
                    {
                        continue;
                    }
                    if (httpCmd.Count(c => c.Equals(' ')) >= 2)
                    {
                        break;
                    }
                }

                if (String.IsNullOrEmpty(httpCmd))
                {
                    return null;
                }

                var splitBuffer = httpCmd.Split(new[] { ' ' }, 3);

                var method = splitBuffer[0];
                var remoteUri = splitBuffer[1];
                if (method.Equals("CONNECT", StringComparison.InvariantCultureIgnoreCase))
                {
                    remoteUri = "https://" + remoteUri;
                }
                var protocollVersion = splitBuffer[2];

                splitBuffer = protocollVersion.Split(new[] { '/' }, 2);
                var protocol = splitBuffer[0];
                var version = splitBuffer[1];

                var headers = new Dictionary<string, string>();
                while (true)
                {
                    var headerline = streamReader.ReadLine();
                    if (String.IsNullOrEmpty(headerline))
                    {
                        break;
                    }

                    var lineBuffer = headerline.Split(new[] { ':' }, 2);
                    var key = lineBuffer[0].Trim();
                    var value = lineBuffer[1].Trim();
                    headers.TryAdd(key, value);
                }

                if (remoteUri.StartsWith("/"))
                {
                    remoteUri = string.Format("https://{0}{1}", headers["Host"], remoteUri);
                }

                var message = new ClientMessageHeader
                {
                    Method = method,
                    RemoteUri = new Uri(remoteUri),
                    Protocol = protocol,
                    ProtocolVersion = Version.Parse(version),
                    Headers = headers
                };

                clientStream.Position = 0;

                return message;
            }
        }
        //SELECT METHODS
        public static MenuItems GetTreeMenu()
        {
            MenuItems mu = new MenuItems();
            List<MenuItem> dbmi = new List<MenuItem>();
            Queue<Tuple<string,CustTreeItems>> toAddParent = new Queue<Tuple<string,CustTreeItems>>();
            
            dbmi.AddRange(DAL.DAL.ExecuteDataReader("S_AllControls_ControlName_PermissionName", FillMenuItem));
            
            List<CustTreeItems> menulist = new List<CustTreeItems>();
            Dictionary<string, CustTreeItems> itemsDictionary = new Dictionary<string, CustTreeItems>();
            Dictionary<string, CustTreeItems> addPermissions = new Dictionary<string, CustTreeItems>();

            foreach(var t in dbmi)
            {
                CustTreeItems c;
                if (!itemsDictionary.ContainsKey(t.Name))
                {
                    c = new CustTreeItems();
                    c.Name = t.Name;
                    c.HasAccess = false;
                }
                else
                {
                    c = itemsDictionary[t.Name];
                }
                if (!string.IsNullOrEmpty(t.PermissionName))
                {
                    c.HasPermissions = true;
                    c.Options.Add(new Permission(c, t.PermissionName, t.PermissionDescription, false));
                }
                if (!string.IsNullOrEmpty(t.ParentName))
                {
                    c.HasParent = true;
                    if (itemsDictionary.ContainsKey(t.ParentName))
                    {
                        CustTreeItems parent = itemsDictionary[t.ParentName];
                        c.Parent = parent;
                        int count = parent.Items.Where(x => x.Name == c.Name).Count();
                        if(count == 0)
                        parent.Items.Add(c);

                        itemsDictionary.TryAdd(t.Name, c);
                    }
                    else
                    {
                        toAddParent.Enqueue(Tuple.Create(t.ParentName,c));
                    }
                }
                else
                {
                    itemsDictionary.TryAdd(t.Name, c);
                }
                itemsDictionary.TryAdd(t.Name, c);
            }

            //niet zo efficient maar mijn vermoedelijke efficientere manier liet het afweten
            //als parent in itemsdictionary -> bind 
            //als parent niet in itemsdicionary -> enqueue en voer op het einde uit
            //in het beste scenario staat alles op volgorde, in het slechtste staat mijn parent steeds op het einde
            while(toAddParent.Count > 0)
            {
                Tuple<string, CustTreeItems> it = toAddParent.Dequeue();
                CustTreeItems child = it.Item2;
                if (itemsDictionary.ContainsKey(it.Item1))
                {
                    CustTreeItems parent = itemsDictionary[it.Item1];
                    child.Parent = parent;
                    int count = parent.Items.Where(x => x.Name == child.Name).Count();
                    if (count == 0)
                        parent.Items.Add(child);
                    itemsDictionary.TryAdd(it.Item1, child);
                }
                else
                {
                    toAddParent.Enqueue(it);
                }

            }


            //foreach(MenuItem menuitem in dbmi)
            //{
            //    CustTreeItems cti;
            //    if (itemsDictionary.ContainsKey(menuitem.Name))
            //    {
            //        cti = itemsDictionary[menuitem.Name] ?? new CustTreeItems(menuitem.Name);
            //    }
            //    else
            //    {
            //        cti = new CustTreeItems(menuitem.Name);
            //    }
            //    cti.HasAccess = false;
            //    if (!string.IsNullOrEmpty(menuitem.PermissionName))
            //    {
            //        cti.HasPermissions = true;
            //        cti.Options.Add(new Permission(cti, menuitem.PermissionName, menuitem.PermissionDescription, false));
            //    }
            //    if (cti.HasParent = !string.IsNullOrEmpty(menuitem.ParentName))
            //    {
            //        CustTreeItems parent;
            //        if (itemsDictionary.TryGetValue(menuitem.ParentName, out parent))
            //        {
            //            parent.Items.Add(cti);
            //            cti.Parent = parent;
            //        }
            //        else
            //        {
            //            toAddParent.Add( Tuple.Create(menuitem.ParentName, cti) );
            //        }
            //    }
            //    foreach(var tuple in toAddParent)
            //    {
            //        if(tuple.Item1 == menuitem.Name)
            //        {
            //            CustTreeItems child = tuple.Item2;
            //            child.Parent = cti;
            //            cti.Items.Add(child);
            //            break;
            //        }
            //    }
            //    itemsDictionary.TryAdd(menuitem.Name, cti);
            //}

            ////itemsDictionary.Values.Where(treeitem => !treeitem.HasParent).ToList().ForEach(x => mu.Items.Add(x));
            foreach (var v in itemsDictionary)
            {
                if (!v.Value.HasParent)
                {
                    mu.Items.Add(v.Value);
                }
            }
            return mu;
        }