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


C# IFrame.CreateError方法代码示例

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


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

示例1: Process

        public IFrame Process(IStompClient client, IFrame request)
        {
            var versions = request.Headers["accept-version"];
            if (versions == null)
            {
                var error = request.CreateError("Missing the 'accept-version' header.");
                error.Headers["version"] = "2.0";
                return error;
            }

            if (!versions.Contains("2.0"))
            {
                var error = request.CreateError("Only accepting stomp 2.0 clients.");
                error.Headers["version"] = "2.0";
                return error;
            }

            IFrame frame;
            if (!CheckCredentials(client, request, out frame)) 
                return frame;

            //TODO: Heartbeating.


            var response = new BasicFrame("CONNECTED");
            response.Headers["version"] = "2.0";
            response.Headers["server"] = _serverName;

            if (client.SessionKey != null)
                response.Headers["session"] = client.SessionKey;

            return response;
        }
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:33,代码来源:ConnectHandler.cs

示例2: CheckCredentials

        /// <summary>
        /// 
        /// </summary>
        /// <param name="client"></param>
        /// <param name="request"></param>
        /// <param name="errorFrame"></param>
        /// <returns><c>true</c> means that we should exist.</returns>
        private bool CheckCredentials(IStompClient client, IFrame request, out IFrame errorFrame)
        {
            if (_authenticationService.IsActivated)
            {
                var user = request.Headers["login"];
                var passcode = request.Headers["passcode"];
                if (user == null || passcode == null)
                {
                    var error =
                        request.CreateError(
                            "This broker have been configured to only allow authenticated clients. Send the 'login'/'password' headers in the 'STOMP' errorFrame.");
                    error.Headers["version"] = "2.0";
                    {
                        errorFrame = error;
                        return false;
                    }
                }

                var loginResult = _authenticationService.Login(user, passcode);
                if (!loginResult.IsSuccessful)
                {
                    var error = request.CreateError(loginResult.Reason);
                    error.Headers["version"] = "2.0";
                    {
                        errorFrame = error;
                        return false;
                    }
                }

                client.SetAsAuthenticated(loginResult.Token);
            }
            else
                client.SetAsAuthenticated(Guid.NewGuid().ToString());

            errorFrame = null;
            return true;
        }
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:44,代码来源:ConnectHandler.cs


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