/// <summary> /// Handle the message. /// </summary> /// <param name="messageHandler"></param> /// <param name="message"></param> /// <returns></returns> private async Task HandleMessage(OnMessage messageHandler, BrokeredMessage message) { ServiceBusEventSource.Log.MessageReceived(Namespace, Path, message.MessageId, message.CorrelationId, message.DeliveryCount, message.Size); // Handle the message. await messageHandler(message) .ConfigureAwait(false); }
public void Start(uint credit, OnMessage onMessage) { Fx.AssertAndThrow(ErrorCode.ReceiverStartInvalidState, this.State < 0xff); this.credit = credit; this.flowThreshold = this.credit > 512u ? byte.MaxValue : (byte)(this.credit / 2); this.onMessage = onMessage; this.client.SendFlow(this.Handle, this.deliveryCount, credit); }
public WebSocket(Socket socket) { client = socket; System.Threading.ThreadStart ts; ts = new System.Threading.ThreadStart(ListenSocket); _clientThread = new System.Threading.Thread(ts); _clientThread.Start(); onmessage = GameChoose; }
public static OnMessage CombineSubscribers(OnMessage[] subscribers) { return (IMessage message) => { foreach (var subscriber in subscribers) { subscriber.Invoke(message); } }; }
/// <summary> /// Handle the message. /// </summary> /// <param name="messageHandler"></param> /// <param name="message"></param> /// <returns></returns> private async Task HandleMessage(OnMessage messageHandler, BrokeredMessage message) { try { ServiceBusEventSource.Log.MessageReceived(Namespace, Path, message.MessageId, message.CorrelationId); // Handle the message. await messageHandler(message); } catch (Exception exception) { ServiceBusEventSource.Log.MessageReceiverException(Namespace, Path, message.MessageId, message.CorrelationId, "OnMessage", exception.Message, exception.StackTrace); throw; } }
/// <summary> /// Handle the message. /// </summary> /// <param name="messageHandler"></param> /// <param name="message"></param> /// <returns></returns> private async Task HandleMessage(OnMessage messageHandler, BrokeredMessage message) { try { ServiceBusEventSource.Log.MessageReceived(Namespace, Path, message.MessageId, message.CorrelationId, message.DeliveryCount, message.Size); // Handle the message. await messageHandler(message) .ConfigureAwait(false); } catch (Exception exception) { ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path, "OnMessage", exception); throw; } }
public Task StartAsync(OnMessage messageHandler, OnMessageException exceptionHandler, OnMessageOptions options) { lock (_initializationLock) { if (_initialized) throw new MessageReceiverException("Message receiver has already been initialized."); if (messageHandler == null) throw new ArgumentNullException("messageHandler"); if (options == null) options = _defaultOptions; // Log. ServiceBusEventSource.Log.MessagePumpStart(GetType().Name, Namespace, Path, options.AutoRenewTimeout, options.MaxConcurrentCalls); // Initialize the handler options. var messageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions(); messageOptions.AutoComplete = options.AutoComplete; messageOptions.AutoRenewTimeout = options.AutoRenewTimeout; messageOptions.MaxConcurrentCalls = options.MaxConcurrentCalls; messageOptions.ExceptionReceived += (s, e) => { if (e.Exception != null) { // Log. ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path, e.Action, e.Exception); // Handle exception. if (exceptionHandler != null) exceptionHandler(e.Action, e.Exception); } }; // Mark receiver as initialized. _initialized = true; // Start. return OnStartAsync(messageHandler, messageOptions); } }
public MessageToRead RegisterMessageHandler(int msgID, OnMessage Handler) { if (ReadTable_Find(msgID)!=null) return null; MessageToRead msg = new MessageToRead(); msg.ID = msgID; msg.OnReciveMessage = Handler; Sorting.BinaryInsert<MessageToRead>(ref ReadTable,msg,MessageToRead.CompareByID); return msg; }
private void Channel_OnReceive(object sender, ChannelReceivedEventArgs e) { OnMessage?.Invoke(this, new TcpReceivedEventArgs(e.ChannelId, e.Message)); }
public void RaiseOnMessage(PubSubMessage message) { OnMessage?.Invoke(message); }
/// <summary> /// Start the handler. /// </summary> /// <returns></returns> internal override Task OnStartAsync(OnMessage messageHandler, Microsoft.ServiceBus.Messaging.OnMessageOptions messageOptions) { _client.OnMessageAsync(msg => HandleMessage(messageHandler, msg), messageOptions); return Task.FromResult(false); }
protected void RaiseOnMessage(string message) { OnMessage?.Invoke(this, message); }
public static extern void SetCallback(IntPtr pKmapi, OnMessage pCallback);
public void AddMessageEvent(OnMessage MsgEvent) { OnMessages.Add(MsgEvent); }
private async Task ProcessMessages(TimeSpan?visibilityTimeout = null, CancellationToken cancellationToken = default(CancellationToken)) { var runningTasks = new ConcurrentDictionary <Task, Task>(); var semaphore = new SemaphoreSlimEx(_minConcurrentTasks, _minConcurrentTasks, _maxConcurrentTasks); // Define the task pump var pumpTask = Task.Run(async() => { while (!cancellationToken.IsCancellationRequested) { await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false); var runningTask = Task.Run(async() => { if (cancellationToken.IsCancellationRequested) { return(false); } CloudQueueMessage message = null; try { message = await _cloudQueue.GetMessageAsync(visibilityTimeout, null, null, cancellationToken); } catch (Exception e) { _logger.ErrorException("An error occured when attempting to get a message from the queue", e); } if (message == null) { try { // The queue is empty OnQueueEmpty?.Invoke(cancellationToken); } #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body catch #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body { // Intentionally left empty. We ignore errors from OnQueueEmpty. } // False indicates that no message was processed return(false); } else { try { // Process the message OnMessage?.Invoke(message, cancellationToken); // Delete the processed message from the queue await _cloudQueue.DeleteMessageAsync(message); } catch (Exception ex) { var isPoison = (message.DequeueCount > _maxDequeueCount); OnError?.Invoke(message, ex, isPoison); if (isPoison) { await _cloudQueue.DeleteMessageAsync(message); } } // True indicates that a message was processed return(true); } }, CancellationToken.None); runningTasks.TryAdd(runningTask, runningTask); runningTask.ContinueWith(async t => { // Decide if we need to scale up or down if (!cancellationToken.IsCancellationRequested) { if (await t) { // The queue is not empty, therefore increase the number of concurrent tasks semaphore.TryIncrease(); } else { // The queue is empty, therefore reduce the number of concurrent tasks semaphore.TryDecrease(); } } // Complete the task semaphore.Release(); Task taskToBeRemoved; runningTasks.TryRemove(t, out taskToBeRemoved); }, TaskContinuationOptions.ExecuteSynchronously) .IgnoreAwait(); } }); // Run the task pump until canceled await pumpTask.UntilCancelled().ConfigureAwait(false); // Task pump has been canceled, wait for the currently running tasks to complete await Task.WhenAll(runningTasks.Values).UntilCancelled().ConfigureAwait(false); }
public Handler(OnMessage del) { _del = del; }
private void Client_OnPrivateMessage(SAEA.MessageSocket.Model.Business.PrivateMessage msg) { OnMessage?.Invoke(msg.Receiver, msg.Content); }
private void Client_OnChannelMessage(SAEA.MessageSocket.Model.Business.ChannelMessage msg) { OnMessage?.Invoke(_channelID, msg.Content); }
public async Task InvokeMessage(MessageEventArgs e) { await OnMessage.InvokeAsync(this, e); }
public static Task StartAsync(this IMessagePump pump, OnMessage messageHandler, OnMessageOptions options) { return pump.StartAsync(messageHandler, null, options); }
private void RpcHandleMessage(string message) { OnMessage?.Invoke($"\n{message}"); }
public static Task StartAsync(this IMessagePump pump, OnMessage messageHandler) { return pump.StartAsync(messageHandler, null, null); }
public void RaiseOnMessage(InboundMessage message) { OnMessage.Invoke(this, message); }
public void InvokeOnMessage(JToken obj) { OnMessage?.Invoke(obj); }
public void LoadLinks(string path) { OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Processing file \"{path}\"" }); int records = 0; int counterCompanies = 0; int counterBenef = 0; int counterBonds = 0; using (var sr = new StreamReader(path, true)) { var header = sr.ReadLine().Split(';'); var idx_entreprise_identifiant = header.GetFieldIndex(CsvColumnsName.EntrepriseIdentifiant); var idx_denomination_sociale = header.GetFieldIndex(CsvColumnsName.DenominationSociale); var idx_benef_nom = header.GetFieldIndex(CsvColumnsName.BenefNom); var idx_benef_prenom = header.GetFieldIndex(CsvColumnsName.BenefPrenom); var idx_benef_identifiant_valeur = header.GetFieldIndex(CsvColumnsName.BenefIdentifiantValeur); var idx_benef_denomination_sociale = header.GetFieldIndex(CsvColumnsName.BenefDenominationSociale); var idx_benef_categorie_code = header.GetFieldIndex(CsvColumnsName.BenefCategorieCode); var idx_benef_qualite_code = header.GetFieldIndex(CsvColumnsName.BenefQualiteCode); var idx_benef_specialite_code = header.GetFieldIndex(CsvColumnsName.BenefSpecialiteCode); var idx_benef_titre_code = header.GetFieldIndex(CsvColumnsName.BenefTitreCode); var idx_ligne_identifiant = header.GetFieldIndex(CsvColumnsName.LigneIdentifiant); var idx_date_avantage = header.GetFieldIndex(CsvColumnsName.AvantDateSignature); if (idx_date_avantage < 0) { idx_date_avantage = header.GetFieldIndex(CsvColumnsName.ConvDateSignature); } if (idx_date_avantage < 0) { idx_date_avantage = header.GetFieldIndex(CsvColumnsName.RemuDate); } using (var con = new SqlConnection(DbConnectionString)) { con.Open(); #region AJOUT DES EN-TÊTES MANQUANTS var membersToAdd = header.Except(_existingMembers.Select(x => x.Key)).ToList(); if (membersToAdd != null && membersToAdd.Any()) { foreach (var m in membersToAdd) { var member = new Member { Name = m }; member.Id = con.InsertMember(member); _existingMembers.Add(member.Name, member); } } #endregion string line = string.Empty; while (!sr.EndOfStream) { try { line = sr.ReadLine(); var csv = line.Split(';'); if (csv.Length == header.Length) { var date = csv[idx_date_avantage]?.Trim(); var dateSignature = default(DateTime); if (DateTime.TryParse(date, _cultureFr, DateTimeStyles.None, out dateSignature)) { if (dateSignature.Year == 2019) { var externalIdLink = csv[idx_ligne_identifiant].Trim(); if (!_existingReferences.ContainsKey(externalIdLink)) { Entity company = null; var externalId = csv[idx_entreprise_identifiant].Trim(); if (!_existingReferences.ContainsKey(externalId)) { var denomination = csv.TryGetValue(idx_denomination_sociale); company = new Entity() { Reference = externalId }; company.Id = con.InsertEntity(company); con.InsertMetadata(company.Id, _existingMembers[header[idx_entreprise_identifiant]].Id, externalId); con.InsertMetadata(company.Id, _existingMembers[header[idx_denomination_sociale]].Id, denomination); _existingReferences.Add(company.Reference, company); counterCompanies++; } else { company = _existingReferences[externalId]; } externalId = csv[idx_benef_identifiant_valeur].Trim(); if (string.IsNullOrEmpty(externalId) || "-;[0];[autre];[br];[so];n/a;na;nc;non renseigne;non renseigné;so;infirmier".Contains(externalId.ToLowerInvariant())) { externalId = csv.GetHashCodeBenef(); } Entity benef = null; if (!_existingReferences.ContainsKey(externalId)) { benef = new Entity() { Reference = externalId }; benef.Id = con.InsertEntity(benef); if (!"[etu][prs][vet]".Contains(csv[idx_benef_categorie_code]?.Trim().ToLowerInvariant())) { var brandName = csv[idx_benef_denomination_sociale]?.Trim(); con.InsertMetadata(benef.Id, _existingMembers[header[idx_benef_categorie_code]].Id, brandName); } else { var lastName = csv[idx_benef_nom]?.Trim(); var firstName = csv[idx_benef_prenom]?.Trim(); con.InsertMetadata(benef.Id, _existingMembers[header[idx_benef_prenom]].Id, firstName); con.InsertMetadata(benef.Id, _existingMembers[header[idx_benef_nom]].Id, lastName); } _existingReferences.Add(benef.Reference, benef); counterBenef++; } else { benef = _existingReferences[externalId]; } // remu_convention_liee // TODO not very nice for the moment. Should call a distinct parser for links depending on the datasource: declaration_avantage, declaration_remuneration, declaration_convention var idx_amount = header.GetFieldIndex(CsvColumnsName.AvantMontantTtc); var headerAmountName = CsvColumnsName.AvantMontantTtc; var idx_kind = header.GetFieldIndex(CsvColumnsName.AvantNature); if (idx_amount < 0) { idx_amount = header.GetFieldIndex(CsvColumnsName.ConvMontantTtc); headerAmountName = CsvColumnsName.ConvMontantTtc; idx_kind = header.GetFieldIndex(CsvColumnsName.AvantNature); } if (idx_amount < 0) { idx_amount = header.GetFieldIndex(CsvColumnsName.RemuMontantTtc); headerAmountName = CsvColumnsName.RemuMontantTtc; } var amount = csv[idx_amount]?.Trim(); var kind = csv.TryGetValue(idx_kind)?.Trim(); var entity = new Entity() { Reference = externalIdLink }; entity.Id = con.InsertEntity(entity); _existingReferences.Add(entity.Reference, entity); var link = new Link { Id = entity.Id, Kind = kind, Date = Convert.ToDateTime(date, _cultureFr), From = company, To = benef, }; con.InsertLink(link); con.InsertMetadata(link.Id, _existingMembers[headerAmountName].Id, Convert.ToDecimal(amount, _cultureFr).ToString()); counterBonds++; } } } } } catch (Exception e) { OnMessage?.Invoke(this, new MessageEventArgs { Message = $"{records} \"{path}\" {e.Message}: {line}" }); } _mainCounter++; records++; if (records % 10000 == 0) { OnMessage?.Invoke(this, new MessageEventArgs { Message = $"{records}: Added {counterCompanies} companies, {counterBenef} beneficiaries, {counterBonds} insterest bonds" }); } } } } OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Read {records} records" }); OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Added {counterCompanies} companies, {counterBenef} beneficiaries, {counterBonds} insterest bonds" }); OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Total {_existingReferences.Count} entities" }); }
private void _receiver_OnMessage(Sockets.Interface.IUserToken userToken, Sockets.Interface.ISocketProtocal msg) { OnMessage?.Invoke(Encoding.UTF8.GetString(msg.Content)); }
public void LoadProviders(string path) { OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Processing \"{path}\" file" }); int counter = 0; using (var sr = new StreamReader(path, true)) { using (var csv = new CustomCsvReader(sr, _configuration)) { csv.Configuration.Delimiter = ","; csv.Read(); csv.ReadHeader(); using (var con = new SqlConnection(DbConnectionString)) { con.Open(); #region AJOUT DES EN-TÊTES MANQUANTS var header = csv.Context.HeaderRecord; var membersToAdd = header.Except(_existingMembers.Select(x => x.Key)).ToList(); if (membersToAdd != null && membersToAdd.Any()) { foreach (var m in membersToAdd) { var member = new Member { Name = m }; member.Id = con.InsertMember(member); _existingMembers.Add(member.Name, member); } } #endregion while (csv.Read()) { var externalId = csv.GetField("identifiant"); if (!_existingReferences.ContainsKey(externalId)) { var entity = new Entity() { Reference = externalId }; entity.Id = con.InsertEntity(entity); for (int i = 0; i < csv.Context.HeaderRecord.Length; i++) { var col = csv.Context.HeaderRecord[i]; var id = con.InsertMetadata(entity.Id, _existingMembers[col].Id, csv[i].ToString()); } _existingReferences.Add(entity.Reference, entity); counter++; } _mainCounter++; } } } } OnMessage?.Invoke(this, new MessageEventArgs { Message = $"Found {_mainCounter} records in file \"{path}\"", Level = Level.Debug }); OnMessage?.Invoke(this, new MessageEventArgs { Message = $"There are {counter} new companies", Level = Level.Debug }); }
public void RpcReceive(string message) { OnMessage?.Invoke(this, message); }
public void Message(T msg) { OnMessage?.Invoke(msg); }
private void Adapter_OnObserve(object sender, ChannelObserverEventArgs e) { OnMessage?.Invoke(this, e); }
private void CallOnMessage(string message) { Task.Factory.StartNew(() => OnMessage?.Invoke(this, new OnMessageReceivedArgs { Message = message })); }
protected void MessageHandler(Message message) { SpinnerObj.ShowSpinner(target); OnMessage.InvokeAsync(message); }
public void ReceiveMessage(string message) { OnMessage?.Invoke(message); //Console.WriteLine(message); }
public MessageDelegate( OnMessage function ) { this.callback = function; }
public void InvokeMessage(string data) { OnMessage?.Invoke(data); }
internal abstract Task OnStartAsync(OnMessage messageHandler, Microsoft.ServiceBus.Messaging.OnMessageOptions messageOptions);
public void LogMessage(string message) => OnMessage?.Invoke(message);
public static Task StartAsync(this IMessagePump pump, OnMessage messageHandler, OnMessageException exception) { return pump.StartAsync(messageHandler, exception, null); }
void ProcessReceive(Object obj) { TaskHelper.Run(() => { var channelInfo = (ChannelInfo)obj; if (channelInfo == null) { return; } while (channelInfo.ClientSocket.Connected) { var data = new byte[_bufferSize]; var offset = 0; var size = channelInfo.Stream.Read(data, offset, _bufferSize); while (size > 0) { offset += size; size = channelInfo.Stream.Read(data, offset, _bufferSize); } if (!_concurrentDictionary.ContainsKey(channelInfo.ID)) { byte[] resData = null; var wsut = new WSUserToken(); var result = wsut.GetReplayHandShake(data, out resData); if (result) { channelInfo.Stream.Write(resData, 0, resData.Length); wsut.IsHandSharked = true; _concurrentDictionary[channelInfo.ID] = new WSCoder(); Clients.Add(channelInfo.ID); OnConnected?.Invoke(channelInfo.ID); } } else { var coder = _concurrentDictionary[channelInfo.ID]; coder.Unpack(data, (d) => { var wsProtocal = (WSProtocal)d; switch (wsProtocal.Type) { case (byte)WSProtocalType.Close: ReplyClose(channelInfo.Stream, wsProtocal); break; case (byte)WSProtocalType.Ping: ReplyPong(channelInfo.Stream, wsProtocal); break; case (byte)WSProtocalType.Binary: case (byte)WSProtocalType.Text: case (byte)WSProtocalType.Cont: OnMessage?.Invoke(channelInfo.ID, (WSProtocal)d); break; case (byte)WSProtocalType.Pong: break; default: var error = string.Format("收到未定义的Opcode={0}", d.Type); break; } }, (h) => { }, null); } } }); }
public void RemoveMessageEvent(OnMessage MsgEvent) { OnMessages.Add(MsgEvent); }
private Task OnReceive(ProtocolType protocol, EndPoint endPoint, TransportMessage message) { var payload = message.DeserializeMessage(); return(OnMessage?.Invoke(endPoint.ToUri(protocol), payload)); }
void DataChannel.IObserver.OnMessage(DataChannel.Buffer buffer) => _handler.Post(() => { var _buffer = new byte[buffer.Data.Remaining()]; buffer.Data.Get(_buffer, 0, _buffer.Length); OnMessage?.Invoke(this, new DataBuffer(_buffer, buffer.Binary)); });
private async Task Consumer_Received(object sender, BasicDeliverEventArgs eventArgs) { var body = Encoding.UTF8.GetString(eventArgs.Body.ToArray()); var message = JsonSerializer.Deserialize <EncryptedMessage>(body); await OnMessage?.Invoke(this, new EncryptedMessageEventArgs(message)); }
public void AddListener(string className, OnMessage eventListener) { if(connectionMaintainer == null) { connectionMaintainer = new ConnectionMaintainer(hostname, port); } if(!connectionMaintainer.eventListeners.ContainsKey(className)) { connectionMaintainer.eventListeners[className] = new List<OnMessage>(); } connectionMaintainer.eventListeners [className].Add (eventListener); }
internal static void HandleMessage(string message, Color color) { OnMessage?.Invoke(message, color); }
public static void WriteLine(string message) { Debug.WriteLine("*** LOG *** " + message); OnMessage?.Invoke(null, message + Environment.NewLine); }
private void _sender_OnMessage(Sockets.Interface.ISocketProtocal msg) { OnMessage?.Invoke(Encoding.UTF8.GetString(msg.Content)); }