Example #1
0
        /// <summary>
        /// Метод выводит МессаджБокс с описанием что за событие произошло по Респонс Коду
        /// </summary>
        /// <param name="result"></param>
        public static void ExplainResponse(ResponseCode result)
        {
            string message = "";

            switch (result)
            {
            case ResponseCode.Success:
                break;

            case ResponseCode.Fail:
                message = $"Неизвестная ошибка {result.ToString()}";
                break;

            case ResponseCode.Duplicate:
                message = "Дубликат!";
                break;

            case ResponseCode.NameExist:
                message = "Имя Уже существует!!!";
                break;

            case ResponseCode.KeyExist:
                message = "Ключ/Имя/Код уже существуют";
                break;

            case ResponseCode.IdNumberExist:
                message = "Персональный код Уже существует";
                break;

            case ResponseCode.PhoneExist:
                message = "Номер телефона уже существует";
                break;

            case ResponseCode.PassportExist:
                message = "Такой номер паспорта уже существует";
                break;

            case ResponseCode.DriverIdExist:
                message = "Такой номер прав уже существует";
                break;

            default:
                message = result.ToString();
                break;
            }

            MessageBox.Show(message, @"Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public void approved_response(string response, ResponseCode.Kind kind, string code)
        {
            var k = new ResponseCode(XE.Parse(response));

            Assert.Equal(kind, k.Value);
            Assert.Equal(code, k.ToString());
        }
        public void valid(string code, ResponseCode.Kind expected)
        {
            var kind = new ResponseCode(code);

            Assert.Equal(expected, kind.Value);
            Assert.Equal(code, kind.ToString());
        }
Example #4
0
        public static (ResponseType ResponseType, string Message) GetResource(this ResponseCode responseCode)
        {
            var codeAttribute = responseCode.GetAttribute <ResponseCodeAttribute>();
            var message       = GetResourceMessageValue(responseCode.ToString());

            return(codeAttribute.ResponseType, message);
        }
Example #5
0
 /// <summary>
 /// 设置返回400应答
 /// </summary>
 private void SetBadRequestResp(HttpActionContext actionContext, ResponseCode code)
 {
     SetBadRequestResp(actionContext, new ResponseData()
     {
         Code    = code,
         Message = code.ToString()
     });
 }
Example #6
0
 private void SetMultipushState(ResponseCode code, ConfigMultiportPushParam param)
 {
     _actionWrapper.InvokeAction(() =>
     {
         if (code != ResponseCode.kNIMResSuccess)
         {
             MessageBox.Show("MultiportPush 操作失败:" + code.ToString());
         }
     });
 }
Example #7
0
        public void CreateGroup(string login, string password)
        {
            ResponseCode code = client.CreateGroup(login, password);

            if (code == ResponseCode.GroupCreate_Success)
            {
                UpdateGroupsList();
            }
            else
            {
                MessageBox.Show(code.ToString());
            }
        }
Example #8
0
        public string ToString(ResponseCode code)
        {
            List <string> headers = new List <string>();

            foreach (var f in Fields)
            {
                headers.Add(f.Key + ": " + f.Value);
            }
            if (!string.IsNullOrWhiteSpace(ContentType))
            {
                headers.Add("Content-type: " + ContentType);
            }
            if (code != ResponseCode.None)
            {
                for (var i = 0; i < Cookies.Count; i++)
                {
                    headers.Add("Set-Cookie: " + Cookies[i]);
                }
            }
            else
            {
                for (var i = 0; i < Cookies.Count; i++)
                {
                    headers.Add("Cookie: " + Cookies[i]);
                }
            }
            headers.Sort();
            StringBuilder res = new StringBuilder();

            if (code == ResponseCode.None)
            {
                res.Append(Method.ToString()).Append(" ").Append(Path).Append(" ").Append(Version).Append("\n").Append("Host: ").Append(Host).Append("\n");
            }
            else
            {
                res.Append(Version).Append(" ").Append((int)code).Append(" ").Append(code.ToString()).Append("\n");
            }
            for (int i = 0; i < headers.Count; i++)
            {
                res.Append(headers[i]).Append("\n");
            }
            if (code != ResponseCode.None)
            {
                res.Append("Content-Length: " + Body.Length);
            }
            res.Append("\n\n");
            res.Append(Body);
            string ress = res.ToString();

            return(ress);
        }
Example #9
0
        public void JoinGroup(string login, string password)
        {
            //MessageBox.Show(client.JoinGroup(login, password).ToString());
            ResponseCode code = client.JoinGroup(login, password);

            if (code == ResponseCode.GroupJoin_Success)
            {
                UpdateGroupsList();
            }
            else
            {
                MessageBox.Show(code.ToString());
            }
        }
Example #10
0
 private void SyncMultipushState(ResponseCode code, ConfigMultiportPushParam param)
 {
     _actionWrapper.InvokeAction(() =>
     {
         if (code == ResponseCode.kNIMResSuccess)
         {
             multipushCheckbox.Checked = param.Enabled;
         }
         else
         {
             MessageBox.Show("MultiportPush 操作失败:" + code.ToString());
         }
     });
 }
        private bool IsValidRequest(ResponseCode code)
        {
            switch (code)
            {
            case ResponseCode.Valid:
                return(true);

            case ResponseCode.InvalidKey:
                Puts(Lang("ErrorInvalidKey"));
                return(false);

            case ResponseCode.Unavailable:
                Puts(Lang("ErrorServiceUnavailable"));
                return(false);

            default:
                Puts(string.Format(Lang("ErrorUnknown"), code.ToString()));
                return(false);
            }
        }
Example #12
0
        public StatusCode GetLocalizedStatusCode(ResponseCode responseCode)
        {
            string responseCodeValue = responseCode.ToString("D");
            char   statusTypeChar    = responseCodeValue[0];

            StatusType statusType = StatusType.Success;

            if (char.IsDigit(statusTypeChar))
            {
                int statusTypeCode = int.Parse(char.ToString(statusTypeChar), CultureInfo.InvariantCulture);

                if (Enum.IsDefined(typeof(StatusType), statusTypeCode))
                {
                    statusType = (StatusType)statusTypeCode;
                }
            }

            return(new StatusCode {
                Type = statusType, Code = responseCodeValue, Message = this._localizer[responseCodeValue]
            });
        }
Example #13
0
        public static string GetResponseCode(ResponseCode code)
        {
            var rs = string.Empty;

            switch (code.ToString())
            {
            case "SUCCESS":
                rs = "102";
                break;

            case "FAILED":
                rs = "103";
                break;

            case "NotFound":
                rs = "101";
                break;

            case "DataDupliacation":
                rs = "100";
                break;
            }
            return(rs);
        }
Example #14
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance. For easy printing / reading.
 /// </summary>
 /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
 public override string ToString()
 {
     foreach (KeyValuePair <string, List <Header> > keyValuePair in Headers.ToList())
     {
         if (keyValuePair.Value.Count <= 0)
         {
             Headers.Remove(keyValuePair.Key);
         }
     }
     try
     {
         string m = "";
         if (Method != null)
         {
             m = Method + " " + Uri + " " + Protocol + "\r\n";
         }
         else if (ResponseText.Length > 0)
         {
             m = Protocol + " " + ResponseCode.ToString() + " " + ResponseText + "\r\n";
         }
         string contentLength = "";
         foreach (List <Header> headers in Headers.Values.ToList())
         {
             try
             {
                 if (headers.First().Name == "Via")
                 {
                     m = m + HandleVia(headers);
                 }
                 else
                 {
                     if (headers.Count > 0)
                     {
                         string current = headers[0].Name + ": ";
                         foreach (Header h in headers)
                         {
                             current = current + h + ", ";
                         }
                         current = current.Remove(current.Length - 2);
                         current = current + "\r\n";
                         if (current.ToLower().Contains("content-length"))
                         {
                             contentLength = current;
                         }
                         else
                         {
                             m = m + current;
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 Debug.Assert(false, String.Format("Error converting message to string {0}", ex.Message));
             }
         }
         m = m + contentLength;
         m = m + "\r\n";
         if (Body.Length > 0)
         {
             m = m + Body;
         }
         return(m);
     }
     catch (Exception ex)
     {
         Debug.Assert(false, String.Format("Error converting message to string {0}", ex.Message));
     }
     return("Error converting Message");
 }
Example #15
0
        private byte[] BuildPacket()
        {
            byte[] buffer;
            if (DataBuffer == null)
            {
                DataBuffer = new Byte[0];
            }

            if (Version == "1.0")
            {
                if ((Method == "") && (ResponseCode == -1))
                {
                    return(DataBuffer);
                }
            }


            UTF8Encoding          UTF8 = new UTF8Encoding();
            String                sbuf;
            IDictionaryEnumerator en = TheHeaders.GetEnumerator();

            en.Reset();

            if (Method != "")
            {
                if (Version != "")
                {
                    sbuf = Method + " " + EscapeString(MethodData) + " HTTP/" + Version + "\r\n";
                }
                else
                {
                    sbuf = Method + " " + EscapeString(MethodData) + "\r\n";
                }
            }
            else
            {
                sbuf = "HTTP/" + Version + " " + ResponseCode.ToString() + " " + ResponseData + "\r\n";
            }
            while (en.MoveNext())
            {
                if (en.Value != null && ((String)en.Key != "CONTENT-LENGTH" || OverrideContentLength == true))
                {
                    if (en.Value.GetType() == typeof(string))
                    {
                        sbuf += (String)en.Key + ": " + (String)en.Value + "\r\n";
                    }
                    else
                    {
                        sbuf += (String)en.Key + ":";
                        foreach (string v in (ArrayList)en.Value)
                        {
                            sbuf += (" " + v + "\r\n");
                        }
                    }
                }
            }
            if (StatusCode == -1 && DontShowContentLength == false)
            {
                sbuf += "Content-Length: " + DataBuffer.Length.ToString() + "\r\n";
            }
            else if (Version != "1.0" && Version != "0.9" && Version != "" && DontShowContentLength == false)
            {
                if (OverrideContentLength == false)
                {
                    sbuf += "Content-Length: " + DataBuffer.Length.ToString() + "\r\n";
                }
            }

            sbuf += "\r\n";

            buffer = new byte[UTF8.GetByteCount(sbuf) + DataBuffer.Length];
            UTF8.GetBytes(sbuf, 0, sbuf.Length, buffer, 0);
            Array.Copy(DataBuffer, 0, buffer, buffer.Length - DataBuffer.Length, DataBuffer.Length);
            return(buffer);
        }
Example #16
0
 public string ToString(ResponseCode code)
 {
     List<string> headers = new List<string>();
     foreach (var f in Fields)
         headers.Add(f.Key + ": " + f.Value);
     if (!string.IsNullOrWhiteSpace(ContentType))
         headers.Add("Content-type: " + ContentType);
     if (code != ResponseCode.None)
         for (var i = 0; i < Cookies.Count; i++)
             headers.Add("Set-Cookie: " + Cookies[i]);
     else
         for (var i = 0; i < Cookies.Count; i++)
             headers.Add("Cookie: " + Cookies[i]);
     headers.Sort();
     StringBuilder res = new StringBuilder();
     if (code == ResponseCode.None)
         res.Append(Method.ToString()).Append(" ").Append(Path).Append(" ").Append(Version).Append("\n").Append("Host: ").Append(Host).Append("\n");
     else
         res.Append(Version).Append(" ").Append((int)code).Append(" ").Append(code.ToString()).Append("\n");
     for (int i = 0; i < headers.Count; i++)
         res.Append(headers[i]).Append("\n");
     if (code != ResponseCode.None)
         res.Append("Content-Length: " + Body.Length);
     res.Append("\n\n");
     res.Append(Body);
     string ress = res.ToString();
     return ress;
 }
Example #17
0
 protected AsiatekJsonResult <ResponseData> AsiatekJson(ResponseCode code, HttpStatusCode httpStatusCode = HttpStatusCode.OK)
 {
     return(this.AsiatekJson(code, code.ToString(), null, httpStatusCode));
 }
 private void OnRecallMessageCompleted(ResponseCode result, RecallNotification[] notify)
 {
     DemoTrace.WriteLine("撤回消息:" + result.ToString() + " " + notify.Dump());
 }
Example #19
0
 public static string ToString(ResponseCode value)
 {
     if (value == ResponseCode.Ok)
     {
         return("ok");
     }
     else if (value == ResponseCode.Error)
     {
         return("error");
     }
     else if (value == ResponseCode.Rejection)
     {
         return("rejection");
     }
     else if (value == ResponseCode.Rules)
     {
         return("rules");
     }
     else if (value == ResponseCode.Undeliverable)
     {
         return("undeliverable");
     }
     else
     {
         throw new ArgumentException("Unrecognized ResponseCode value: " + value.ToString());
     }
 }
Example #20
0
        public void SetCode(ResponseCode code, string msg = null)
        {
            _code = code;

            _msg = msg ?? code.ToString();
        }
Example #21
0
 public JsonResponse(ResponseCode code = ResponseCode.Ok)
 {
     Status = code.ToString();
 }
Example #22
0
 public static string GetDescribe(this ResponseCode code) => code.ToString();
Example #23
0
 public static string ToString(ResponseCode value)
 {
     if( value==ResponseCode.Ok )
         return "ok";
     else if( value==ResponseCode.Error )
         return "error";
     else if( value==ResponseCode.Rejection )
         return "rejection";
     else if( value==ResponseCode.Rules )
         return "rules";
     else if( value==ResponseCode.Undeliverable )
         return "undeliverable";
     else
         throw new ArgumentException("Unrecognized ResponseCode value: " + value.ToString());
 }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessengerException"/> class.
 /// </summary>
 /// <param name="code">
 /// The code.
 /// </param>
 /// <param name="innerException">
 /// The inner exception.
 /// </param>
 public MessengerException(ResponseCode code, Exception innerException = null)
     : base(code.ToString(), innerException)
 {
     this.Code = code;
 }
Example #25
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance. For easy printing / reading.
 /// </summary>
 /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
 public override string ToString()
 {
     try
     {
         foreach (KeyValuePair <string, List <Header> > keyValuePair in Headers.ToList())
         {
             if (keyValuePair.Value.Count <= 0)
             {
                 Headers.Remove(keyValuePair.Key);
             }
         }
         string m = "";
         if (Method != null)
         {
             m = Method + " " + Uri + " " + Protocol + "\r\n";
         }
         else if (ResponseText.Length > 0)
         {
             m = Protocol + " " + ResponseCode.ToString() + " " + ResponseText + "\r\n";
         }
         string contentLength = "";
         foreach (List <Header> headers in Headers.Values.ToList())
         {
             try
             {
                 if (headers.First().Name == "Via")
                 {
                     m = m + HandleVia(headers);
                 }
                 else
                 {
                     if (headers.Count > 0)
                     {
                         string current = headers[0].Name + ": ";
                         foreach (Header h in headers)
                         {
                             current = current + h + ", ";
                         }
                         current = current.Remove(current.Length - 2);
                         current = current + "\r\n";
                         if (current.ToLower().Contains("content-length"))
                         {
                             contentLength = current;
                         }
                         else
                         {
                             m = m + current;
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 // Get stack trace for the exception with source file information
                 var st = new StackTrace(ex, true);
                 // Get the top stack frame
                 var frame = st.GetFrame(0);
                 // Get the line number from the stack frame
                 var line = frame.GetFileLineNumber();
                 Debug.Assert(false, String.Format("1 Error converting message to string {0} \n {1} \n {2}", ex, line, Headers));
             }
         }
         m = m + contentLength;
         m = m + "\r\n";
         if (Body.Length > 0)
         {
             m = m + Body;
         }
         return(m);
     }
     catch (Exception ex)
     {
         Debug.Assert(false, String.Format("2 Error converting message to string {0} \n {1} \n {2}", ex, Headers.ToList(), Headers.Values.ToList()));
     }
     return("Error converting Message");
 }
Example #26
0
 public ProtocolException(ResponseCode errorCode, [NotNull] string errorMessage, [CanBeNull] Exception innerException)
     : this($"Encountered protocol exception {(short)errorCode} {errorCode.ToString()}: {errorMessage}",
            errorCode, errorMessage, innerException)
 {
 }