public void Send(ProudSession session, CoreMessage message) { using (var ms = new PooledMemoryStream(_pipe.Service.ArrayPool)) using (var w = new BinaryWriter(ms)) { var @out = _protocol.Serialize(session, message); using (var ms2 = new PooledMemoryStream(_pipe.Service.ArrayPool)) { @out.Serialize(ms2); var segment = ms2.ToSegment(); w.Write((ushort)43981); w.Write((ushort)0); w.Write(segment.Count); w.Write(0); w.Write(0); w.Write(segment.Array, segment.Offset, segment.Count); segment = ms.ToSegment(); _socket.SendTo(segment.Array, segment.Offset, segment.Count, SocketFlags.None, session.UdpEndPoint); } } }
/// <summary> /// The PrepareOutputMessage /// </summary> /// <param name="items">The items<see cref="List{Item}"/></param> /// <param name="coreMessage">The coreMessage<see cref="CoreMessage"/></param> /// <returns>The <see cref="IntegrationEvent"/></returns> private IntegrationEvent PrepareOutputMessage(IEnumerable <Item> items, CoreMessage coreMessage) { Dictionary <string, object> properties = GetUserProperties(coreMessage); IntegrationEvent integrationEvent = GetIntegrationEvent(coreMessage); ServiceOutput serviceOutput = new ServiceOutput(); IEnumerable <Item> result = items.Select(s => new Item { ItemId = s.ItemId, InlineData = s.InlineData, SourceLabel = s.SourceLabel, ItemPath = s.ItemPath, SourceReference = SourceReference(properties), ItemLocation = BusinessValidationConstants.EXTERNAL, ItemType = BusinessValidationConstants.EXTERNALINTERFACE }); serviceOutput.Items = result.ToList(); integrationEvent.Body.ServiceOutput = serviceOutput; return(integrationEvent); }
public void LoopOne() { // Verify bots and handle messages List <string> bots; lock (this._bots) bots = new List <string>(this._bots.Keys); foreach (string bot in bots) { lock (this._bots) { if (!this._bots[bot].Enabled) { continue; } if (!this._bots[bot].ProcessRunning) { if (this._bots[bot].Process != null) { switch (this._bots[bot].Process.ExitCode) { case ExitCodes.SHUTDOWN: this._bots[bot].Enabled = false; Core.Output("Core", bot + " has shutdown and marked disabled"); break; case ExitCodes.RESTART: this._bots[bot].Enabled = true; Core.Output("Core", bot + " has shutdown pending a restart"); this.StartShell(bot); break; default: Core.Output("Core", bot + " has terminated with the exit code " + this._bots[bot].Process.ExitCode); this.StartShell(bot); break; } } } else if (this._bots[bot].Communication != null) { if (this._bots[bot].Communication.IdleTime.TotalMinutes > 5) { Core.Output("Core", bot + " hasn't pinged for over 5 minutes"); this.StartShell(bot); } } else { if (((TimeSpan)(DateTime.Now - this._bots[bot].ProcessStartTime)).TotalMinutes > 1) { Core.Output("Core", bot + " hasn't connected within 1 minute"); this.StartShell(bot); } } } } // Process core messages lock (this._queue) { while (this._queue.Count > 0) { CoreMessage message = this._queue.Dequeue(); bool enabled; lock (this._bots) { if (!this._bots.ContainsKey(message.Target)) { continue; } enabled = this._bots[message.Target].ProcessRunning; } switch (message.Command) { case CoreCommand.Restart: if (enabled) { this.StopShell(message.Target); } this.StartShell(message.Target); break; case CoreCommand.Shutdown: if (enabled) { this.StopShell(message.Target); } break; case CoreCommand.Start: if (!enabled) { this.StartShell(message.Target); } break; } } } }
public async Task DoSomethingElse(CoreMessage message) { }
/// <summary> /// Receives the data form the service and can process the data (not done yet because no complex logic required) /// </summary> /// <param name="message"></param> private void NewMessageReceived(CoreMessage message) { messages.Add(message); //store message in list for further processing frontEndInformer(message); //send info to FrontEnd(GUI) }
private void NewMessageReceived(CoreMessage message) { App.Current.Dispatcher.Invoke(() => { Messages.Add(String.Format("Received message from \"{0}\" at \"{1}\"\r\n\t{2}", message.Source, message.Date.ToShortTimeString(), message.Data)); }); }
public async Task RunAsync(CoreMessage message, CommandInfo command) { await message.SendLocaleAsync("UsageCommand", command.Name, GetUsage(command)); }
private async Task RunAsync(CoreMessage message, string command, object?[] parameters) { await Task.FromResult(true); }
public Task RunAsync(CoreMessage message) { throw new NotImplementedException(); }
private static TimeSpan Difference(CoreMessage message, CoreMessage response) { return((response.EditedTimestamp ?? response.Timestamp) - (message.EditedTimestamp ?? message.Timestamp)); }
public async Task RunAsync(CoreMessage message) { var response = await message.SendLocaleAsync("Ping"); await response.EditLocaleAsync("Pong", Difference(message, response).Milliseconds); }
public Task <bool> RunAsync(CoreMessage message, CommandInfo command) { return(Task.FromResult(!Client.Owners.Contains(message.AuthorId))); }
public Task <Dictionary <string, object> > GetMicroServiceDataItemsAsync(CoreMessage coreMessage) { throw new System.NotImplementedException(); }
public Task <bool> SendServiceOutputToTopicAsync(List <Item> items, CoreMessage coreMessage) { throw new System.NotImplementedException(); }
private async Task RunAsync(CoreMessage message, string command, Exception exception) { Client.Logger.Error("[ARGUMENTS]: {Name} | {Exception}", command, exception); await message.SendAsync("Whoops! Something while processing arguments!"); }
public void AddStudentData(CoreMessage msg) { messages.Add(msg); }
public void AddMessage(CoreMessage msg) { messageList.Add(msg); }
public void Submit(CoreMessage message) { messageQueue.Send(message); }
public void QueueMessage(CoreMessage msg) { _frameworkMessenger.Report(string.Concat("Core Message:", msg.ToString())); _messageQueue.Enqueue(msg); }
public async Task RunAsync(CoreMessage message) { Client.Logger.Information( "Received Message [{Id}] from {Username} with content '{Content}'.", message.Id, (await message.GetAuthorAsync())?.Username ?? "??", message.Content); }
public void Submit(CoreMessage message) { throw new NotImplementedException(); }
public async Task RunAsync(CoreMessage message, [Argument(Minimum = -5)] int number) { await message.SendAsync($"A number! {number.ToString()}"); }
private async Task RunAsync(CoreMessage message, string command) { await Task.FromResult(true); }
public async Task RunAsync(CoreMessage message, DateTime time, string content = "Something, you did not specify what") { await message.SendAsync( $"Alright! Reminder added. I'll remember you \"{content}\" at {time.ToShortDateString()}"); }
private async Task RunAsync(CoreMessage message, string command, ArgumentException exception) { await message.SendAsync($"Argument Error: {exception.InnerException?.Message ?? exception.Message}"); }
public async Task RunAsync(CoreMessage message, string content, int[] integers) { await message.SendAsync( $"With the content of {content}, you have given me {integers.Length} number(s), with a sum of {integers.Sum()}"); }
private async Task RunAsync(CoreMessage message, string command, object?[] parameters, Exception exception) { Client.Logger.Error("[COMMANDS]: {Name} | {Exception}", command, exception); await message.SendAsync("Whoops! Something happened while processing the command!"); }
public async Task RunAsync(CoreMessage message, [Argument(Rest = true)] string content = "I got absolutely nothing!") { await message.SendAsync($"A string! {content}"); }
/// <summary> /// Service logic /// The service informs the Service Manager via a delegater /// this design was choosen to remove the logic from the service implementation /// </summary> /// <param name="message"></param> /// <returns></returns> public bool TransmitMessage(CoreMessage message) { Informer(message); return(true); }
private void NewMessageReceived(CoreMessage message) { Console.WriteLine(String.Format("Received message from \"{0}\" at \"{1}\"\r\n\t{2}", message.Source, message.Date.ToShortTimeString(), message.Data)); client.TransmitMessageAsync(message); }