Esempio n. 1
0
            private void HandlePing(Event e)
            {
                this.Count++;
                PingEvent ping = (PingEvent)e;

                this.Logger.WriteLine("Server handling ping");
                this.Logger.WriteLine("Server sending pong back to caller");
                this.SendEvent(ping.Caller, new PongEvent());

                if (this.Count == 3)
                {
                    this.RaiseGotoStateEvent <Complete>();
                }
            }
Esempio n. 2
0
        private static void RunConsole(RemoteSite siteConfig, string[] args)
        {
            if (ParseCommandLine(args))
            {
                relay.StartAsync().Wait();
                timer.Start();
                _isRunning = true;

                while (_isRunning)
                {
                    Console.TreatControlCAsInput = true;
                    Console.WriteLine("Press \"p\" to send a Ping test, Ctrl-C to end.");
                    var key = Console.ReadKey(true);
                    switch (key.Key)
                    {
                    case ConsoleKey.P:
                        WriteConsoleStatus("Sending ping...");
                        _pingTest = new PingEvent(DateTime.Now);
                        relay.Send(new RelayMessage
                        {
                            Operation  = SiteOperation.Ping,
                            ApiKey     = OrgApiCalls.ApiKey,
                            DestSiteId = siteConfig.Id
                        });
                        break;

                    case ConsoleKey.Escape:
                    case ConsoleKey.C:
                        if (key.Key == ConsoleKey.C && key.Modifiers != ConsoleModifiers.Control)
                        {
                            break;
                        }

                        Console.WriteLine("Stop the relay agent? (Y or N)");
                        if (Console.ReadKey().Key == ConsoleKey.Y)
                        {
                            WriteConsoleStatus("Received shutdown command.");
                            _isRunning = false;
                        }
                        break;
                    }
                }
                relay.Stop();
            }
        }
Esempio n. 3
0
 public bool Ping()
 {
     // assume the remote process registers an event proxy, check for the ping invocation
     if (PingEventHandler != null)
     {
         foreach (Delegate invocation in PingEventHandler.GetInvocationList())
         {
             PingEvent pingEvent = null;
             try
             {
                 pingEvent = (PingEvent)invocation;
                 pingEvent();
                 return(true); // ping invocation found and invocation succeeded
             }
             catch (Exception e)
             {
                 Console.WriteLine("Ping error\n" + e.ToString());
                 PingEventHandler -= pingEvent;
             }
         }
     }
     return(false); // ping invocation not found, or it was found but the invocation failed
 }
Esempio n. 4
0
        public static void CheckHighLoad(Notification notify, string projectName)
        {
            PingEvent pr = (PingEvent)notify.Event;

            if (pr.CPULoad >= Properties.Settings.Default.HighCPULoad &&
                pr.RAMLoad >= Properties.Settings.Default.HighRAMLoad)
            {
                SendDebugEmail($"ALERT! HIGH RAM and CPU USAGE of {projectName} GNS3", $@"
					<b>cpu_usage_percent: {pr.CPULoad}<br>
					memory_usage_percent: {pr.RAMLoad}</b>"                    );
            }
            else if (pr.CPULoad >= Properties.Settings.Default.HighCPULoad)
            {
                SendDebugEmail($"ALERT! HIGH CPU USAGE of {projectName} GNS3", $@"
				<b>cpu_usage_percent: {pr.CPULoad}</b><br>
				memory_usage_percent: {pr.RAMLoad}"                );
            }
            else if (pr.RAMLoad >= Properties.Settings.Default.HighRAMLoad)
            {
                SendDebugEmail($"ALERT! HIGH RAM USAGE of {projectName} GNS3", $@"
					cpu_usage_percent: {pr.CPULoad}<br>
					<b>memory_usage_percent: {pr.RAMLoad}</b>"                    );
            }
        }
Esempio n. 5
0
        private object ConvertPayload()
        {
            switch (Event)
            {
            case PingEvent.EventString:
                return(PingEvent.FromJson(PayloadText));

            case CommitCommentEvent.EventString:
                return(CommitCommentEvent.FromJson(PayloadText));

            case CreateEvent.EventString:
                return(CreateEvent.FromJson(PayloadText));

            case DeleteEvent.EventString:
                return(DeleteEvent.FromJson(PayloadText));

            case DeploymentEvent.EventString:
                return(DeploymentEvent.FromJson(PayloadText));

            case DeploymentStatusEvent.EventString:
                return(DeploymentStatusEvent.FromJson(PayloadText));

            case ForkEvent.EventString:
                return(ForkEvent.FromJson(PayloadText));

            case GollumEvent.EventString:
                return(GollumEvent.FromJson(PayloadText));

            case InstallationEvent.EventString:
                return(InstallationEvent.FromJson(PayloadText));

            case InstallationRepositoriesEvent.EventString:
                return(InstallationRepositoriesEvent.FromJson(PayloadText));

            case IssueCommentEvent.EventString:
                return(IssueCommentEvent.FromJson(PayloadText));

            case IssuesEvent.EventString:
                return(IssuesEvent.FromJson(PayloadText));

            case LabelEvent.EventString:
                return(LabelEvent.FromJson(PayloadText));

            case MemberEvent.EventString:
                return(MemberEvent.FromJson(PayloadText));

            case MembershipEvent.EventString:
                return(MembershipEvent.FromJson(PayloadText));

            case MilestoneEvent.EventString:
                return(MilestoneEvent.FromJson(PayloadText));

            case OrganizationEvent.EventString:
                return(OrganizationEvent.FromJson(PayloadText));

            case OrgBlockEvent.EventString:
                return(OrgBlockEvent.FromJson(PayloadText));

            case PageBuildEvent.EventString:
                return(PageBuildEvent.FromJson(PayloadText));

            case ProjectCardEvent.EventString:
                return(ProjectCardEvent.FromJson(PayloadText));

            case ProjectColumnEvent.EventString:
                return(ProjectColumnEvent.FromJson(PayloadText));

            case ProjectEvent.EventString:
                return(ProjectEvent.FromJson(PayloadText));

            case PublicEvent.EventString:
                return(PublicEvent.FromJson(PayloadText));

            case PullRequestEvent.EventString:
                return(PullRequestEvent.FromJson(PayloadText));

            case PullRequestReviewEvent.EventString:
                return(PullRequestReviewEvent.FromJson(PayloadText));

            case PullRequestReviewCommentEvent.EventString:
                return(PullRequestReviewCommentEvent.FromJson(PayloadText));

            case PushEvent.EventString:
                return(PushEvent.FromJson(PayloadText));

            case ReleaseEvent.EventString:
                return(ReleaseEvent.FromJson(PayloadText));

            case RepositoryEvent.EventString:
                return(RepositoryEvent.FromJson(PayloadText));

            case StatusEvent.EventString:
                return(StatusEvent.FromJson(PayloadText));

            case WatchEvent.EventString:
                return(WatchEvent.FromJson(PayloadText));

            default:
                throw new NotImplementedException(
                          $"Event Type: `{Event}` is not implemented. Want it added? Open an issue at https://github.com/promofaux/GithubWebhooks");
            }
        }
Esempio n. 6
0
 public void Apply(PingEvent e)
 {
     PingIds.Add(e.PingId);
 }
Esempio n. 7
0
 public virtual void Ping()
 {
     PingEvent?.Invoke(this, new HookedEventArgs());
 }
Esempio n. 8
0
 public Simulation(float speed, float time)
 {
     onPing     = new PingEvent();
     this.speed = speed;
     this.time  = time;
 }
Esempio n. 9
0
        private static void Relay_PingEvent(object sender, PingEvent e)
        {
            var span = e.EndTime - _pingTest.StartTime;

            WriteConsoleStatus("{0} (elapsed time {1} milliseconds)", e.Message, span.Milliseconds);
        }
        public void BasicSerializationTest()
        {
            byte[] data = EventsSerializer.SerializeEvent(new PingEvent());

            PingEvent pingEvent = EventsSerializer.DeserializeEvent <PingEvent>(data);
        }
Esempio n. 11
0
 public void OnPingEvent(int count)
 {
     PingEvent?.Invoke(count);
 }
Esempio n. 12
0
        public IServerEvent ReadAndParse(TcpClient client)
        {
            TcpConnector connector = client.Connector;

            byte[] header      = new byte[16];
            int    receiveSize = connector.Receive(header);

            if (receiveSize <= 0)
            {
                return(new ConnectionCloseEvent(connector));
            }
            // magicの照合
            bool isMagicCorrect = header.Take(2).SequenceEqual(magicNumber);

            if (!isMagicCorrect)
            {
                return(new UnknownEvent("Invalid magic."));
            }
            // bodyの取得
            var bodyLen = BitConverter.ToUInt32(header, 8);

            byte[] body = new byte[bodyLen];
            connector.Receive(body);
            // hash magicの照合
            var hashMagicBytes     = hashAlgorithm.ComputeHash(body.Concat(header).ToArray());
            var hashMagic          = BitConverter.ToUInt32(hashMagicBytes.Reverse().ToArray(), 0);
            var isHashMagicCorrect = hashMagic == this.hashMagic;

            if (!isHashMagicCorrect)
            {
                return(new UnknownEvent("Invalid hash algorithm magic."));
            }
            // event名の取得
            var          eventName = BinUtil.BytesToString(header.Skip(2).Take(6).ToArray());
            IServerEvent serverEvent;

            switch (eventName)
            {
            case "WELCOM":
                serverEvent = new WelcomeEvent();
                break;

            case "ROOMS ":
                serverEvent = new RoomsEvent(body, client);
                break;

            case "1ROOM ":
                serverEvent = new Room1Event(body);
                break;

            case "ROOMDL":
                serverEvent = new RoomDeleteEvent();
                break;

            case "PING  ":
                serverEvent = new PingEvent(body);
                break;

            case "START ":
                serverEvent = new StartEvent(body);
                break;

            case "READY ":
                serverEvent = new ReadyEvent(body);
                break;

            case "OKAY  ":
                serverEvent = new OkEvent(body);
                break;

            case "PLAY  ":
                serverEvent = new PlayEvent(body);
                break;

            case "ACTION":
                serverEvent = new ActionEvent(body);
                break;

            case "FINISH":
                serverEvent = new FinishEvent();
                break;

            case "ERROR!":
                serverEvent = new ErrorEvent();
                break;

            default:
                serverEvent = new UnknownEvent("Unknown event received");
                break;
            }

            return(serverEvent);
        }
 public void OnPingEvent(PingEvent e)
 {
     PingEvent?.Invoke(this, e);
 }
Esempio n. 14
0
 public void Apply(PingEvent e)
 {
     PingsReceived++;
 }