private async Task StartBatching(CancellationToken token) { using (var buff = new MemoryStream()) while (await _batchBlock.OutputAvailableAsync(token)) { if (!_batchBlock.TryReceive(out var chunk)) { continue; } var keys = new byte[chunk.Length][]; for (var i = 0; i < chunk.Length; i++) { buff.SetLength(0); ProtoBuf.Serializer.Serialize(buff, chunk[i]); keys[i] = buff.ToArray(); } var message = new RequestMessageModel() { Keys = keys }; using (var send = _streamFactory.Create()) { ProtoBuf.Serializer.Serialize(send, message); await _client.SendAsync(send, token); } } }
public async Task <IActionResult> Encrypt([FromBody] RequestMessageModel model) { var message = await enigmaMachineAdapter.Encrypt(UserId, model.Message); return(Ok(message)); }
public async Task <IActionResult> SendMessageAsync(RequestMessageModel request) { var response = await _messageService.SendMessage(request); if (response.Errors.Any()) { return(BadRequest(response.Errors)); } return(Ok(response.Data)); }
public async Task <BaseResponse <Messages> > SendMessage(RequestMessageModel request) { var response = new BaseResponse <Messages>(); var toUser = await _userRepository.GetByUserNameAsync(request.ToUserName); if (toUser != null) { var entity = new Messages { FromId = new ObjectId(request.FromId), SendToId = toUser.Id, FromUserName = request.FromUserName, ToUserName = request.ToUserName, Message = request.Message }; var isBlocked = await _blockRepository.IsBlocked(new BlockList { UserId = entity.FromId, BlockedUserId = toUser.Id }); if (isBlocked == null) { var result = await _messageRepository.InsertAsync(entity); if (result.Id != default) { response.Data = result; return(response); } } else { response.Errors.Add("Blocklandığınız için mesaj gönderemezsiniz!"); return(response); } } response.Errors.Add("Kullanıcı bulunamadı!"); return(response); }
public static async Task Run([EventHubTrigger("MyAzureFunctionCallSP", Connection = "AzureEventHubConnectionString")] EventData[] events, ILogger log) { var exceptions = new List <Exception>(); /////////////////////Loop thru messages as is////////////////////////////////////////////////// foreach (EventData eventData in events) { var MainMessage = string.Empty; try { string ErrorsInObject = string.Empty; //Get the message from event hub///////////////////////////// string messageBody = Encoding.UTF8.GetString(eventData.Body.Array, eventData.Body.Offset, eventData.Body.Count); MainMessage = messageBody; /////Temp Logging log to DB as is: await DataBaseFunctions.InsertDBSTRIIMMessages(log, messageBody); //JSON message object collection schema List <RootObject> rootObjectCollection = new List <RootObject>(); // Deserilize to object collection. rootObjectCollection = ConvertMessageToObject(messageBody, ref ErrorsInObject); if (rootObjectCollection != null) { foreach (RootObject rootObject in rootObjectCollection) { // Start the logging collection for every loop as the the logging happens in TPMessageLog ErrorResponseMessages errorResponseMessage = new ErrorResponseMessages(); // serilize the object string JsonString = JsonConvert.SerializeObject(rootObject.data, Formatting.None); ////////////////////////////Alter input message: This is from ProcessTest Test data //////////////////////////// ///////////////THere is a reason to do this, this is helps in proper logging. ///For now this is hardcoded for a specific tagnumber. For message type 1 RequestRawMessageModel requestRawMessageModel = JsonConvert.DeserializeObject <RequestRawMessageModel>(JsonString); RequestMessageModel requestMessageModel = JsonConvert.DeserializeObject <RequestMessageModel>(requestRawMessageModel.REQUEST_MESSAGE); requestMessageModel.TagNumber = "015015018"; requestRawMessageModel.RequestMesssage = requestMessageModel; string ConvertMessage = JsonConvert.SerializeObject(requestRawMessageModel, Formatting.None); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This does not mean there is error, error object is same as logging. errorResponseMessage.RequestMessage = JsonString; if (ConvertMessage.Length > 0) { // Validate the message string ValidateMessage = StaticClasses.Validate.ValidateRequest(ConvertMessage); if (ValidateMessage == StaticClasses.StaticVars.SUCCESS) { errorResponseMessage.MessageValidation = "True"; //ALL MAIN PROCESS HAPPENS HERE/////////////////////////////////////////////////////////// ResponseMessage ResponseJSON = await TranscoreProcess.Process(requestRawMessageModel);/// //////////////////////////////////////////////////////////////////////////////////////// errorResponseMessage.ResponseMessage = ResponseJSON.JSONMessage; if (ResponseJSON.Error.Length > 0) { errorResponseMessage.MessageProcessStatus = false; errorResponseMessage.ErrorResponseMessage = errorResponseMessage.ErrorResponseMessage + " | " + ResponseJSON.Error; } else { //SEND TO RABBITMQ SendToQueue(ResponseJSON.JSONMessage, errorResponseMessage); } } else { errorResponseMessage.MessageValidation = "False"; log.LogInformation($"Invalid Message"); } } else { log.LogInformation($"Message Length is ZERO: {ConvertMessage}"); } string jsonMessageError = JsonConvert.SerializeObject(errorResponseMessage, Formatting.None); await DataBaseFunctions.InsertDB(requestRawMessageModel.CRM_REQUEST_ID, requestRawMessageModel.REQUEST_TYPE, jsonMessageError, errorResponseMessage.ResponseMessage, errorResponseMessage.RequestMessage, errorResponseMessage.ErrorResponseMessage); } // await InsertDB(log,0,jsonMessageError, "Success", "OutMessage"); log.LogInformation($"C# Event Hub trigger function processed a message: {messageBody}"); await Task.Yield(); } else { } } catch (Exception e) { await DataBaseFunctions.InsertDB(9999, 0, MainMessage, "", "", "Invalid Message"); // We need to keep processing the rest of the batch - capture this exception and continue. // Also, consider capturing details of the message that failed processing so it can be processed again later. exceptions.Add(e); } } // Once processing of the batch is complete, if any messages in the batch failed processing throw an exception so that there is a record of the failure. if (exceptions.Count > 1) { throw new AggregateException(exceptions); } if (exceptions.Count == 1) { throw exceptions.Single(); } }