当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.GetHashCode方法代码示例

本文整理汇总了C#中IDictionary.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GetHashCode方法的具体用法?C# IDictionary.GetHashCode怎么用?C# IDictionary.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.GetHashCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetResponse

        public string GetResponse(string host, IDictionary<string, object> arguments,
            bool useCookies = false)
        {
            const string contentType = "application/x-www-form-urlencoded";
            const string requestType = "POST";

            Logging.LogLine("POSTing to " + host + " " + arguments.GetHashCode(), "browser serv");

            var isFirst = true;

            if (useCookies)
            {
                if (!arguments.ContainsKey("csrf_token"))
                    arguments["csrf_token"] = GetCsrfToken();
            }

            var totalRequest = new StringBuilder();
            foreach (var arg in arguments.Where(arg => arg.Key != "type"))
            {
                if (!isFirst)
                    totalRequest.Append('&');
                else
                    isFirst = false;

                totalRequest.Append(arg.Key);
                totalRequest.Append('=');
                totalRequest.Append(HttpUtility.UrlEncode((string) arg.Value));
            }

            var toPost = Encoding.ASCII.GetBytes(totalRequest.ToString());

            var cachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
            var req = (HttpWebRequest) WebRequest.Create(host);
            req.CachePolicy = cachePolicy;
            req.Method = requestType;
            req.ContentType = contentType;
            req.ContentLength = toPost.Length;
            req.UserAgent = Constants.FriendlyName;

            if (useCookies)
                req.CookieContainer = loginCookies;

            using (var postStream = req.GetRequestStream())
                postStream.Write(toPost, 0, toPost.Length);

            using (var rep = (HttpWebResponse) req.GetResponse())
            using (var answerStream = rep.GetResponseStream())
            {
                if (answerStream == null)
                    return null;
                using (var answerReader = new StreamReader(answerStream))
                    return answerReader.ReadToEnd();
            }
        }
开发者ID:ZornTaov,项目名称:slimCat,代码行数:54,代码来源:BrowserService.cs

示例2: RenderMacroAsString

        /// <summary>
        /// Renders the macro output as a string
        /// </summary>
        /// <param name="macroAlias"></param>
        /// <param name="macroParams"></param>
        /// <param name="currentControllerContext"></param>
        /// <param name="isForRichTextEditor">If the request is to render the contents in the back office rich text editor</param>
        /// <param name="resolveContent"></param>
        /// <returns></returns>
        public string RenderMacroAsString(
            string macroAlias,
            IDictionary<string, string> macroParams,
            ControllerContext currentControllerContext,
            bool isForRichTextEditor,
            Func<Content> resolveContent)
        {
            //method to get the string output of the ActionResult
            Func<ActionResult, string> getStringOutput = ar =>
                {
                    if (ar is ViewResultBase)
                    {
                        var viewResult = (ViewResultBase)ar;

                        return currentControllerContext.RenderViewResultAsString(viewResult);
                    }
                    if (ar is ContentResult)
                    {
                        var contentResult = (ContentResult)ar;
                        return contentResult.Content;
                    }
                    throw new NotSupportedException("Its not possible to retreive the output of a macro that doesn't return a ViewResultBase");
                };

            if (isForRichTextEditor)
            {
                return getStringOutput(RenderMacro(macroAlias, macroParams, currentControllerContext, true, resolveContent));
            }

            //if we not rendering for the rich text editor then check if we've cached this in the ScopedCache first, 
            //even though we are caching some macros in application cache, we're only caching the ActionResult and not the  text
            //output which still requires a tiny amount of processing, so we'll store all equal macro string output in ScopedCache too, 
            //as this will speed things regardless of whehter macros are cached or not if there's a few of the same ones per page

            return _applicationContext.FrameworkContext
                .ScopedCache.GetOrCreate("umb-macro-" + macroAlias + macroParams.GetHashCode(),
                                         () => getStringOutput(RenderMacro(macroAlias, macroParams, currentControllerContext, false, resolveContent)))
                                         .ToString();
        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:48,代码来源:MacroRenderer.cs

示例3: RequeueCommand

        private void RequeueCommand(IDictionary<string, object> command)
        {
            object value;
            if (!command.TryGetValue("retryAttempt", out value))
                value = 0;

            var retryAttempts = (int) value;
            Logging.LogLine(command.Get(Command)
                            + " " + command.GetHashCode()
                            + " fail #" + (retryAttempts + 1), "cmnd serv");

            if (retryAttempts >= 5) return;

            retryAttempts++;
            command["retryAttempt"] = retryAttempts;

            var delay = new Timer(2000 ^ retryAttempts);
            delay.Elapsed += (s, e) =>
            {
                EnqueueAction(command);
                delay.Stop();
                delay.Dispose();
            };
            delay.Start();
        }
开发者ID:WreckedAvent,项目名称:slimCat,代码行数:25,代码来源:ServerCommandService.cs

示例4: InterpretCommand

        private CommandHandlerDelegate InterpretCommand(IDictionary<string, object> command)
        {
            ChatModel.LastMessageReceived = DateTimeOffset.Now;

            if (command == null) return null;

            var commandType = command.Get(Command);

            Log(commandType + " " + command.GetHashCode(), noisyTypes.Contains(commandType));

            switch (commandType)
            {
                case SystemAuthenticate:
                    return LoginCommand;
                case SystemUptime:
                    return UptimeCommand;
                case AdminList:
                    return AdminsListCommand;
                case UserIgnore:
                    return IgnoreUserCommand;
                case UserList:
                    return InitialCharacterListCommand;
                case PublicChannelList:
                    return PublicChannelListCommand;
                case PrivateChannelList:
                    return PrivateChannelListCommand;
                case UserStatus:
                    return StatusChangedCommand;
                case ChannelAd:
                    return AdMessageCommand;
                case ChannelMessage:
                    return ChannelMessageCommand;
                case UserMessage:
                    return PrivateMessageCommand;
                case UserTyping:
                    return TypingStatusCommand;
                case ChannelJoin:
                    return JoinChannelCommand;
                case ChannelLeave:
                    return LeaveChannelCommand;
                case ChannelModerators:
                    return ChannelOperatorListCommand;
                case ChannelInitialize:
                    return ChannelInitializedCommand;
                case ChannelDescription:
                    return ChannelDescriptionCommand;
                case SystemMessage:
                case SystemError:
                    return ErrorCommand;
                case UserInvite:
                    return InviteCommand;
                case ChannelKick:
                case ChannelBan:
                    return KickCommand;
                case UserJoin:
                    return UserLoggedInCommand;
                case UserLeave:
                    return CharacterDisconnectCommand;
                case ChannelRoll:
                    return RollCommand;
                case AdminDemote:
                    return OperatorDemoteCommand;
                case AdminPromote:
                    return OperatorPromoteCommand;
                case ChannelDemote:
                    return OperatorDemoteCommand;
                case ChannelPromote:
                    return OperatorPromoteCommand;
                case Constants.ServerCommands.ChannelMode:
                    return RoomModeChangedCommand;
                case AdminBroadcast:
                    return BroadcastCommand;
                case SystemBridge:
                    return RealTimeBridgeCommand;
                case AdminReport:
                    return NewReportCommand;
                case SearchResult:
                    return SearchResultCommand;
                case ChannelSetOwner:
                    return SetNewOwnerCommand;
                default:
                    return null;
            }
        }
开发者ID:WreckedAvent,项目名称:slimCat,代码行数:84,代码来源:ServerCommandService.cs

示例5: RenderMacro

        /// <summary>
        /// Performs the action rendering
        /// </summary>
        /// <param name="macroAlias"></param>
        /// <param name="currentControllerContext"></param>
        /// <param name="isForRichTextEditor">If the request is to render the contents in the back office rich text editor</param>
        /// <param name="resolveContent">callback to get the 'Content' model</param>
        /// <param name="macroParams"></param>
        /// <returns></returns>
        /// <remarks>
        /// 
        /// We need to check if this is for the rich text editor, in which case, we need to bypass any caching
        /// so that it renders out the correct content,
        /// Then if its not for the RTE, we need to check our cache to see if its in there, if so then we'll just 
        /// return it, otherwise we will add the cached item with a dependency on our cache 'File' path.
        /// 
        /// </remarks>
        public ActionResult RenderMacro(
            string macroAlias,
            IDictionary<string, string> macroParams,
            ControllerContext currentControllerContext,
            bool isForRichTextEditor,
            Func<Content> resolveContent)
        {           

            ActionResult macroResult = null;

            if (!isForRichTextEditor)
            {
                //if its not for rich text....

                try
                {
                    var output = _applicationContext.FrameworkContext
                                .ApplicationCache.GetOrCreate("umb-macro-" + macroAlias + macroParams.GetHashCode(),
                                                              () =>
                                                              {
                                                                  var macroModel = GetMacroModel(macroAlias);

                                                                  //set the macroResult to the local variable
                                                                  macroResult = GetMacroResult(macroAlias, () => macroModel.Item1, resolveContent, macroParams, currentControllerContext);
                                                                  //if it is null, it means that there was no content item
                                                                  if (macroResult == null)
                                                                      return null;

                                                                  //check if the macro should be cached at all
                                                                  if (!macroModel.Item1.CacheByPage)
                                                                  {
                                                                      //By returning null, this will not be added to the cache and a null value returned
                                                                      return null;
                                                                  }
                                                                  //TODO: Check caching by member!

                                                                  //return our caching parameters
                                                                  //TODO: We might not want a 'normal' cache dependency at some point, need to determine a way to specify cache dependencies or create a custom one based on the 'File' object or something
                                                                  var cacheParams = new HttpRuntimeCacheParameters<ActionResult>(macroResult)
                                                                      {
                                                                          Dependencies = new CacheDependency(macroModel.Item2.RootedPath),
                                                                          SlidingExpiration = new TimeSpan(0, 0, 0, macroModel.Item1.CachePeriodSeconds)
                                                                      };
                                                                  return cacheParams;
                                                              });

                    //if this is null, it means:
                    // - there was no current node, or it didn't get cached because the macro definition said to not cache it.
                    //then we can check if our local 'macroResult' variable was set, if so it means:
                    // - there was a current node and it simply wasn't cached because of the macro definition.
                    if (output != null)
                        return (ActionResult)output;
                    if (macroResult != null)
                        return macroResult;
                    //return null because there must be no 'currentNode'
                    return null;

                }
                catch (ApplicationException ex)
                {
                    //if there's an exception, display a friendly message and log the error
                    var txt = "Macro.RenderingFailed.Message".Localize(this, new { Error = ex.Message, MacroName = macroAlias });
                    var title = "Macro.RenderingFailed.Title".Localize();
                    LogHelper.Error<MacroRenderer>(txt, ex);
                    return MacroError(txt, title);
                }

                
            }
            else
            {
                try
                {
                    //if it is for rich text...
                    var macroModel = GetMacroModel(macroAlias);

                    return !macroModel.Item1.RenderContentInEditor
                        ? NoRichTextRenderMode(macroAlias)
                        : GetMacroResult(macroAlias, () => macroModel.Item1, resolveContent, macroParams, currentControllerContext);
                }
                catch (ApplicationException ex)
                {
                    //if there's an exception, display a friendly message and log the error
//.........这里部分代码省略.........
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:101,代码来源:MacroRenderer.cs


注:本文中的IDictionary.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。