/// <summary> /// If the last transaction hasn't yet a given response given, a response is /// generated, otherwise a REPORT request with the namespace 000 (equivalent /// to a response) is generated /// </summary> /// <param name="reason">one of <tt>MessageAbortEvent</tt> response codes except CONTINUATIONFLAG</param> /// <param name="reasonExtraInfo">corresponds to the comment as defined on RFC 4975 formal syntax. If null, it isn't sent any comment.</param> override public void Abort(ResponseCodes reason, string reasonExtraInfo) { // Sanity checks if (LastSendTransaction == null) { throw new InternalError("abort was called on an incoming message without an assigned Transaction!"); } if (!ResponseCode.IsAbortCode(reason)) { throw new IllegalUseException("The reason must be one of the response codes on MessageAbortedEvent excluding the continuation flag reason"); } // Check to see if we already responded to the transaction being // received/last transaction known if (!LastSendTransaction.HasResponse) { LastSendTransaction.TransactionManager.GenerateResponse(LastSendTransaction, reason, reasonExtraInfo); } else // let's generate the REPORT { FailureReport failureReport = new FailureReport(this, Session, LastSendTransaction, "000", reason, reasonExtraInfo); // send it Session.TransactionManager.AddPriorityTransaction(failureReport); } // mark this message as aborted _aborted = true; }
public async void TestMethod_RegisterUser1() { string UserName = ""; string EMail = ""; string Password = ""; var sc = new ScorocodeApi(); ScorocodeSdkStateHolder stateHolder = new ScorocodeSdkStateHolder( /* applicationId */ "", /* clientKey */ "", /* masterKey */ "", /* fileKey */ "", /* messageKey */ "", /* scriptKey */ "", /* webSocket */ "" ); RequestRegisterUser requestRegisterUsers; Dictionary <string, object> doc = new Dictionary <string, object>() { { "key1", "value1" }, { "key2", "value2" } }; DocumentInfo docInfo = new DocumentInfo(doc); requestRegisterUsers = new RequestRegisterUser(stateHolder, UserName, EMail, Password, docInfo); ResponseCodes responsCodes = await sc.RegisterAsync(requestRegisterUsers); }
public virtual string GetTextResponseForStatus(ResponseCodes code, params string[] args) { var template = CommandsTemplates[code]; template = string.Format(template, args); return(template); }
public static async Task Write(Stream stream, HttpResponse response) { await stream.WriteLineAsync($"HTTP/1.1 {response.ResponseCode} {ResponseCodes.Get(response.ResponseCode)}"); response.Header ??= new(); response.Header["Connection"] = "close"; if (response.ResponseStream != null) { if (!response.Header.ContainsKey("Content-Length")) { response.Header["Transfer-Encoding"] = "chunked"; await SendHeader(stream, response.Header); await SendContent(stream, response.ResponseStream); } else { await SendHeader(stream, response.Header); await SendContent(stream, response.ResponseStream, Convert.ToInt64(response.Header["Content-Length"])); } } else if (response.ResponseAsyncEnumerable != null) { response.Header["Transfer-Encoding"] = "chunked"; response.Header["Trailer"] = "X-Status"; await SendHeader(stream, response.Header); var good = await SendContent(stream, response.ResponseAsyncEnumerable); await SendHeader(stream, new() { { "X-Status", good ? "200" : "500" } }); } else { await SendHeader(stream, response.Header); } }
public CustomException(ResponseCodes pResponseCode, string pMessage, string pDescription) : base(pMessage) { ResponseCode = pResponseCode; ResponseMessage = pMessage; Description = pDescription; }
/// <summary> /// Generates and queues the TransactionResponse with the given response code /// /// Throws InternalErrorException if queuing the response got us an error /// Throws IllegalUseException if the arguments are invalid /// </summary> /// <param name="originalTransaction"></param> /// <param name="responseCode">one of the response codes listed in RFC 4975</param> /// <param name="optionalComment">the comment as defined in RFC 4975 formal syntax, /// as the comment is optional, it can also be null if no comment /// is desired</param> private void GenerateAndQueueResponse(Transaction originalTransaction, ResponseCodes responseCode, string optionalComment) { TransactionResponse trResponse = new TransactionResponse(originalTransaction, responseCode, optionalComment, Direction.OUT); originalTransaction.Response = trResponse; AddPriorityTransaction(trResponse); }
private void Client_FailedAction(ResponseCodes code) { RunOnUIThread(() => { if (ResponseCodes.Bad_Login == code) { MessageBox.Show(this, "Failed to log in", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } else if (ResponseCodes.Unsecure_Password == code) { MessageBox.Show(this, "Unsecure password! Must have a length of at least 6 characters, contains at least 1 letter and 1 number", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } else if (ResponseCodes.Username_Taken == code) { MessageBox.Show(this, "The username is already taken", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } }); }
/// <summary> /// Creates the transaction response /// /// Throws IllegalUseException if at least one of the arguments is /// incompatible /// </summary> /// <param name="transaction">the original transaction that gave birth to this /// response</param> /// <param name="responseCode">the code, must be supported by the RFCs 4975 or 4976</param> /// <param name="comment">the comment as defined in RFC 4975 formal syntax, /// as the comment is optional, it can also be null if no comment /// is desired</param> /// <param name="direction">the direction of the transaction</param> public TransactionResponse(Transaction transaction, ResponseCodes responseCode, string comment, Direction direction) { // original transaction must be a SEND transaction if (transaction.TransactionType != TransactionType.SEND && transaction.TransactionType != TransactionType.NICKNAME) { throw new IllegalUseException(string.Format("Creating a Response with an original transaction that isn't a SEND or NICKNAME: {0}", transaction.ToString())); } TransactionType = TransactionType.RESPONSE; Direction = direction; TRResponseCode = responseCode; Comment = comment; // copy the values from the original transaction to this one Message = transaction.Message; TransactionId = transaction.TransactionId; TransactionManager = transaction.TransactionManager; transaction.Response = this; if (direction == Direction.IN) { CreateIncomingResponse(transaction, responseCode, comment); } else { CreateOutgoingResponse(transaction, responseCode, comment); } }
public Response(uint?_sourceID, uint?_destinationID, ResponseCodes _responsecode, string _messageIdentifier) { this.SourceID = _sourceID; this.DestinationID = _destinationID; this.ResponseCode = _responsecode; this.MessageIdentifer = _messageIdentifier; }
//====== Sign-up, sign-in methods - Методы работы с пользователями ====== // @Headers({ "Content-Type: application/json"}) // @POST("api/v1/register") // Call<ResponseCodes> register(@Body RequestRegisterUser requestRegisterUser); public async Task <ResponseCodes> RegisterAsync(RequestRegisterUser requestRegisterUser) { var uri = new Uri(baseUri + @"api/v1/register"); // Сформировать JSON данные string jsonContent = JsonConvert.SerializeObject(requestRegisterUser); HttpResponseMessage httpResponse = await cmd.PostAsync(uri, jsonContent); //var task = cmd.PostAsync(uri, jsonContent); //task.Wait(); //HttpResponseMessage httpResponse = task.Result; ResponseCodes responseCodes = new ResponseCodes(); if (httpResponse.IsSuccessStatusCode) { responseCodes = JsonConvert.DeserializeObject <ResponseCodes>(httpResponse.Content.ToString()); } else { responseCodes.Error = true; responseCodes.ErrCode = ""; responseCodes.ErrMsg = "Ошибка HttpClient."; } return(responseCodes); }
public static string GetResponse(ResponseCodes response, params string[] arguments) { switch (response) { case ResponseCodes.NextHop_OK: if (arguments.Length != 2) { throw new ArgumentOutOfRangeException(); } return(string.Format(RESPONSE_NEXTHOP_OK, arguments[0], arguments[1])); case ResponseCodes.UserTable_OK: if (arguments.Length != 1) { throw new ArgumentOutOfRangeException(); } return(string.Format(RESPONSE_USERTABLE_OK, arguments[0])); case ResponseCodes.OK: return(RESPONSE_OK); case ResponseCodes.None: return(RESPONSE_NONE); case ResponseCodes.UserEntry: if (arguments.Length != 3) { throw new ArgumentOutOfRangeException(); } return(string.Format(RESPONSE_NEXTHOP_OK, arguments[0], arguments[1], arguments[2])); default: return(String.Empty); } }
static void UpdateRecord() { Console.WriteLine(); int id = ParseUntilOk <int>( "Введите ID для записи (целое число)", "Неверный ввод, попробуйте ещё раз" ); DateTime dt = ParseUntilOk <DateTime>( "Введите дату и время (дд.ММ.гггг чч:мм:сс)", "Неверный ввод, попробуйте ещё раз" ); double val = ParseUntilOk <double>( "Введите значение (дробное число, десятич. разделитель - точка)", "Неверный ввод, попробуйте ещё раз" ); ResponseCodes respCode = Controller.UpdateRecord(id, dt, val); if (respCode == ResponseCodes.OK) { Console.WriteLine("OK"); } else if (respCode == ResponseCodes.NO_ID) { Console.WriteLine("Id уже существует"); } }
public static int GetFullResponseLength(ResponseCodes response, byte[] buffer, int offset) { switch (response) { case ResponseCodes.Setting: { SettingValue setting = (SettingValue)(buffer[offset] & 0xF); return(GetSettingResponseLength(setting)); } case ResponseCodes.Pixels: { PixelFormat format; byte width; byte height; byte bufferLength; int headerLen = BadgeResponses.DecodePixels(buffer, offset, out format, out width, out height, out bufferLength); return(headerLen + bufferLength); } case ResponseCodes.Memory: { byte numDWords; short address; byte bufferLength; int headerLen = BadgeResponses.DecodeMemory(buffer, offset, out numDWords, out address, out bufferLength); return(headerLen + bufferLength); } default: return(GetMinResponseLength(response)); } }
public PositionResponse(uint?_sourceID, uint?_destinationID, ResponseCodes _responsecode, string _messageIdentifier, Vector3 _position) { this.SourceID = _sourceID; this.DestinationID = _destinationID; this.ResponseCode = _responsecode; this.MessageIdentifer = _messageIdentifier; Position = _position; }
private void writeRedirectHeader(int status, string path) { string message = ResponseCodes.getMessage(status); write("HTTP/1.1 " + status + " " + message + "\r\n"); write("Location: " + path + "\r\n"); write("\r\n"); // altijd met een lege regel eindigen }
public PMSResponse <T> BuildErrorResponse(ResponseCodes code) { return(new PMSResponse <T> { Code = (int)code, Message = EnumManager.Instance.GetDescription(code) }); }
/// <summary> /// Constructor used to create the abort event /// </summary> /// <param name="message">message the message that got aborted</param> /// <param name="session">reason the reason, one of: CONTINUATIONFLAG; RESPONSE4XX /// <see cref="CONTINUATIONFLAG"/> /// <see cref="RESPONSE400"/> /// <see cref="RESPONSE403"/> /// <see cref="RESPONSE413"/> /// <see cref="RESPONSE415"/> /// <see cref="RESPONSE481"/> /// </param> /// <param name="reason"></param> /// <param name="extraReasonInfo">extraReasonInfo this can be the string that can be on the body of a REPORT or null if it doesn't exist</param> /// <param name="transaction"></param> public MessageAbortedEvent(Message message, Session session, ResponseCodes reason, string extraReasonInfo, Transaction transaction) : base() { Message = message; Session = session; Reason = reason; ExtraReasonInfo = extraReasonInfo; Transaction = transaction; }
public BatchedErrorResponse(ResponseCodes responseCode, string errorMessage, IEnumerable <T> data) : base(errorMessage, responseCode) { if (Data == null) { Data = new List <T>(); } Data.AddRange(data); }
public NodeAdditionResponse(uint?_sourceID, uint?_destinationID, ResponseCodes _responsecode, string _messageIdentifier, Vector3 _position, List <uint?> _neighbours) { this.SourceID = _sourceID; this.DestinationID = _destinationID; this.ResponseCode = _responsecode; this.MessageIdentifer = _messageIdentifier; Position = _position; this.Neighbours = _neighbours; }
/// <summary> /// Builds the service response /// </summary> /// <param name="code">ResponseCodes</param> /// <param name="data">Object of type T</param> /// <returns>SimplifyResponse object</returns> public PMSResponse <T> BuildResponse(ResponseCodes code, T data) { return(new PMSResponse <T> { Code = (int)code, Message = EnumManager.Instance.GetDescription(code), Data = data }); }
public MediaSiteResponse <T> BuildErrorResponse <T>(ResponseCodes code) { var curbsideResponse = new MediaSiteResponse <T> { Code = (int)code, Message = EnumManager.Instance.GetDescription(code) }; return(curbsideResponse); }
private void writeHeader(int status, String contentType, long contentLength) { string message = ResponseCodes.getMessage(status); write("HTTP/1.1 " + status + " " + message + "\r\n"); write("Content-Type: " + contentType + "\r\n"); write("Content-Length: " + contentLength + "\r\n"); write("Connection: close\r\n"); write("\r\n"); // altijd met een lege regel eindigen }
public ResponseCodes ResponseCodeGetEnum(int ResponseCodeValue) { /// converts response code enum to int value ResponseCodes _Results = ResponseCodes.OK; try { _Results = (ResponseCodes)(ResponseCodeValue); } catch { } return(_Results); }
/// <summary> /// Builds the service response /// </summary> /// <param name="code">ResponseCodes</param> /// <returns>MediaSiteResponse object</returns> public MediaSiteResponse BuildResponse(ResponseCodes code) { var mediasiteResponse = new MediaSiteResponse { Code = (int)code, Message = EnumManager.Instance.GetDescription(code) }; return(mediasiteResponse); }
/// <summary> /// Builds the service response /// </summary> /// <param name="code">ResponseCodes</param> /// <param name="data">Object of type T</param> /// <returns>MediaResponse object</returns> public MediaResponse <T> BuildResponse <T>(ResponseCodes code, T data) { var curbsideResponse = new MediaResponse <T> { Code = (int)code, Message = EnumManager.Instance.GetDescription(code), Data = data }; return(curbsideResponse); }
/// <summary> /// Builds the service response /// </summary> /// <param name="code">ResponseCodes</param> /// <param name="data">Object of type T</param> /// <returns>SimplifyResponse object</returns> public APIResponse <T> BuildResponse(ResponseCodes code, T data) { var peResonse = new APIResponse <T> { Code = (int)code, Message = EnumManager.Instance.GetDescription(code), Data = data }; return(peResonse); }
/// <summary> /// Is response code an indication to abort sending? /// </summary> /// <param name="code">the response code</param> /// <returns>true if the code indicates sender should abort sending.</returns> public static bool IsAbortCode(ResponseCodes code) { foreach (ResponseCodes ac in _abortCode) { if (ac == code) { return(true); } } return(false); }
public static string ToString(ResponseCodes code) { foreach (Code rc in rcSet) { if (code == rc.RCCode) { return(rc.Description); } } return("Unknown (non-MSRP) response code"); }
public static string GetResponse(ResponseCodes responseCode) { // Get response message string responseMessage = string.Empty; if (responseCode == ResponseCodes.Success) { responseMessage = "Success"; } if (responseCode == ResponseCodes.DatabaseInsertionError) { responseMessage = "Database Insertion Failed"; } if (responseCode == ResponseCodes.CannotDelete) { responseMessage = "Data Dependency on Table"; } if (responseCode == ResponseCodes.InvalidAcessToken) { responseMessage = "Access Token Not Valid"; } if (responseCode == ResponseCodes.NoResultFound) { responseMessage = "No results found for the provided parameters."; } if (responseCode == ResponseCodes.InvalidParams) { responseMessage = "Invalid Parameters"; } if (responseCode == ResponseCodes.UserDoesntExistForCompany) { responseMessage = "User Doesn't Exist For Company"; } if (responseCode == ResponseCodes.CompanyidNotProvided) { responseMessage = "Companyid Not Provided"; } if (responseCode == ResponseCodes.JobUpdationNotAllowed) { responseMessage = "Job not found or updation is not allowed for this job"; } if (responseCode == ResponseCodes.UserNotAuthorized) { responseMessage = "User not authorized to perform this action."; } if (responseCode == ResponseCodes.AlreadyExists) { responseMessage = "The given data already exists."; } return(responseMessage); }
/// <summary> /// Generates a report from libNS module that provides Rovio’s current status. /// </summary> /// <returns></returns> public RovioStatusReport GetReport() { RovioResponse reports = MovementControl(Commands.GetReport); ResponseCodes responses = (ResponseCodes)int.Parse(reports["responses"]); if (responses != ResponseCodes.SUCCESS) { throw new Exception("获取报告失败:" + responses); } report.Update(reports); return(report); }
public static string GetStringReponseForResponseCode(ResponseCodes code) { var message = string.Empty; switch (code) { case (ResponseCodes.Failure): return "Major failure occured. BOOOOOOM"; case (ResponseCodes.FieldsAreBlank): return "One or more of the fields was left blank."; case (ResponseCodes.BadUserNameFormat): return "Bad Login Name format: ex: [email protected]"; case (ResponseCodes.UserAlreadyExists): return "User already exists with that name."; case (ResponseCodes.BadPasswordLength): return String.Format("The password was the incorrect size. Min Length: {0} Max Length {1} ", Constants.MinPasswordLength, Constants.MaxPasswordLength); case (ResponseCodes.PasswordsDontMatch): return "The passwords do not match. Try again"; } return message; }
public static int GetFullResponseLength(ResponseCodes response, byte[] buffer, int offset) { switch(response) { case ResponseCodes.PixRect: { int width; int height; int rectBufferLength; int headerLen = BadgeResponses.DecodePixRect(buffer, offset, out width, out height, out rectBufferLength); return headerLen + rectBufferLength; } default: return GetMinResponseLength(response); } }
public static int GetMinResponseLength(ResponseCodes response) { switch(response) { case ResponseCodes.PixRect: return 2; case ResponseCodes.BufferState: return 2; default: return 1; } }