Inheritance: System.Exception
示例#1
0
        public async Task <NormalResult> ConnectAsync(string url,
                                                      string userName,
                                                      string password,
                                                      string parameters)
        {
            lock (_syncRoot)
            {
                CloseConnection();

                Connection = new HubConnection(url);

                // 一直到真正连接前才触发登录事件
                //if (this.Container != null)
                //    this.Container.TriggerLogin(this);

                //if (this.Container != null && this.Container.TraceWriter != null)
                //    Connection.TraceWriter = this.Container.TraceWriter;

                // Connection.Credentials = new NetworkCredential("testusername", "testpassword");
                Connection.Headers.Add("username", userName);
                Connection.Headers.Add("password", password);
                Connection.Headers.Add("parameters", parameters);

                HubProxy = Connection.CreateHubProxy("MyHub");

                {
                    var handler = HubProxy.On <string, IList <MessageRecord> >("addMessage",
                                                                               (name, messages) =>
                                                                               OnAddMessageRecieved(name, messages)
                                                                               );
                    _handlers.Add(handler);
                }

                /*
                 * // *** setInfo
                 * {
                 *  var handler = HubProxy.On<SetInfoRequest>("setInfo",
                 *  (param) => OnSetInfoRecieved(param)
                 *  );
                 *  _handlers.Add(handler);
                 * }
                 */

                /*
                 * // *** search
                 * {
                 *  var handler = HubProxy.On<SearchRequest>("search",
                 *  (param) => OnSearchRecieved(param)
                 *  );
                 *  _handlers.Add(handler);
                 * }
                 */

                /*
                 * // *** webCall
                 * {
                 *  var handler = HubProxy.On<WebCallRequest>("webCall",
                 *  (param) => OnWebCallRecieved(param)
                 *  );
                 *  _handlers.Add(handler);
                 * }
                 *
                 * // *** close
                 * {
                 *  var handler = HubProxy.On<CloseRequest>("close",
                 *  (param) => OnCloseRecieved(param)
                 *  );
                 *  _handlers.Add(handler);
                 * }
                 */
            }

            try
            {
                await Connection.Start().ConfigureAwait(false);

                _userName = userName;

                {
                    /*
                     * _exiting = false;
                     * AddInfoLine("成功连接到 " + this.ServerUrl);
                     * TriggerConnectionStateChange("Connected");
                     */
                    return(new NormalResult());
                }
            }
            catch (HttpRequestException ex)
            {
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = ex.Message,
                    ErrorCode = "HttpRequestException"
                });
            }
            catch (Microsoft.AspNet.SignalR.Client.HttpClientException ex)
            {
                Microsoft.AspNet.SignalR.Client.HttpClientException ex0 = ex as Microsoft.AspNet.SignalR.Client.HttpClientException;
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = ex.Message,
                    ErrorCode = ex0.Response.StatusCode.ToString()
                });
            }
            catch (AggregateException ex)
            {
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = GetExceptionText(ex)
                });
            }
            catch (Exception ex)
            {
                return(new NormalResult
                {
                    Value = -1,
                    ErrorInfo = ExceptionUtil.GetExceptionText(ex)
                });
            }
        }
示例#2
0
 public void LogWebError(Exception e, HttpClientException f)
 {
     errorLogHubProxy.Invoke("LogWebError", e);
 }