Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 3
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public async Task DoSomethingElse(CoreMessage message)
 {
 }
Ejemplo n.º 5
0
 /// <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)
 }
Ejemplo n.º 6
0
 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));
     });
 }
Ejemplo n.º 7
0
 public async Task RunAsync(CoreMessage message, CommandInfo command)
 {
     await message.SendLocaleAsync("UsageCommand", command.Name, GetUsage(command));
 }
Ejemplo n.º 8
0
 private async Task RunAsync(CoreMessage message, string command, object?[] parameters)
 {
     await Task.FromResult(true);
 }
Ejemplo n.º 9
0
 public Task RunAsync(CoreMessage message)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 private static TimeSpan Difference(CoreMessage message, CoreMessage response)
 {
     return((response.EditedTimestamp ?? response.Timestamp) - (message.EditedTimestamp ?? message.Timestamp));
 }
Ejemplo n.º 11
0
        public async Task RunAsync(CoreMessage message)
        {
            var response = await message.SendLocaleAsync("Ping");

            await response.EditLocaleAsync("Pong", Difference(message, response).Milliseconds);
        }
Ejemplo n.º 12
0
 public Task <bool> RunAsync(CoreMessage message, CommandInfo command)
 {
     return(Task.FromResult(!Client.Owners.Contains(message.AuthorId)));
 }
Ejemplo n.º 13
0
 public Task <Dictionary <string, object> > GetMicroServiceDataItemsAsync(CoreMessage coreMessage)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 14
0
 public Task <bool> SendServiceOutputToTopicAsync(List <Item> items, CoreMessage coreMessage)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 15
0
 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!");
 }
Ejemplo n.º 16
0
 public void AddStudentData(CoreMessage msg)
 {
     messages.Add(msg);
 }
Ejemplo n.º 17
0
 public void AddMessage(CoreMessage msg)
 {
     messageList.Add(msg);
 }
Ejemplo n.º 18
0
 public void Submit(CoreMessage message)
 {
     messageQueue.Send(message);
 }
Ejemplo n.º 19
0
 public void QueueMessage(CoreMessage msg)
 {
     _frameworkMessenger.Report(string.Concat("Core Message:", msg.ToString()));
     _messageQueue.Enqueue(msg);
 }
Ejemplo n.º 20
0
 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);
 }
Ejemplo n.º 21
0
 public void Submit(CoreMessage message)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 22
0
 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);
 }
Ejemplo n.º 24
0
 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}");
 }
Ejemplo n.º 26
0
 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()}");
 }
Ejemplo n.º 27
0
 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!");
 }
Ejemplo n.º 28
0
 public async Task RunAsync(CoreMessage message,
                            [Argument(Rest = true)] string content = "I got absolutely nothing!")
 {
     await message.SendAsync($"A string! {content}");
 }
Ejemplo n.º 29
0
 /// <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);
 }
Ejemplo n.º 30
0
 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);
 }