コード例 #1
0
ファイル: MonitorForm.cs プロジェクト: aaronmorgenegg/cs5200
        private void _refreshTimer_Tick(object sender, EventArgs e)
        {
            Log.Debug($"Send a GetStatusMessage to {_serverEndPoint}");
            var msg = new GetStatusMessage();

            ComputeServerEndPoint();
            _comm.Send(msg, _serverEndPoint);
            _expectingStatusMessage = true;
        }
コード例 #2
0
        public Task <MediaStatus> GetStatusAsync(ISender sender)
        {
            var msg = new GetStatusMessage()
            {
                MediaSessionId = Status?.First().MediaSessionId
            };

            return(SendAndSetSessionIdAsync(sender, msg, false));
        }
コード例 #3
0
ファイル: Worker.cs プロジェクト: aaronmorgenegg/cs5200
        private Message ProcessGetStatusMessage(GetStatusMessage getStatusMessage)
        {
            if (!getStatusMessage.IsValid)
            {
                return(null);
            }

            Log.InfoFormat("Process GetStatusMessage");

            var statusMessage = new StatusMessage()
            {
                ActiveGameCount = Game.ActiveGameCount
            };

            var nextId  = 1;
            var players = Player.KnownPlayers;

            Log.Debug($"Number of player {players.Count}");

            foreach (var s in players)
            {
                var info = new StatusMessage.PlayerInfo()
                {
                    Id             = nextId++,
                    Alias          = s.Alias,
                    GameCount      = s.GameCount,
                    GuessCount     = s.GuessCount,
                    HintCount      = s.HintCount,
                    ExitCount      = s.ExitCount,
                    HeartbeatCount = s.HeartbeatCount,
                    HighScore      = s.HighScore,
                    LastMessage    = s.LastMessage
                };
                Log.InfoFormat($"Process add Player to StatusMessage {info}");

                statusMessage.Students.Add(info);
            }
            Message reply = statusMessage;

            return(reply);
        }
コード例 #4
0
        public void Start()
        {
            var returnedData = NodeCommunicationClient.Send(
                _configuration.ConfigurationToolAddress,
                _configuration.User,
                _configuration.Password,
                new SingleValueMessage {
                Value = CONFIG
            },
                Command.REQ,
                nameof(ConfigurationTool));

            var name = MessagePackSerializer.Deserialize <SingleValueMessage>(returnedData.Content).Value;

            name = name.Substring(0, name.Length - 4);

            while (true)
            {
                Console.Write($"{name}> ");
                var command = Console.ReadLine();

                var      msgCommand = Command.UNKNOWN;
                IMessage content    = null;

                //Local commands
                if (clear.IsMatch(command))
                {
                    Console.Clear();
                    continue;
                }

                //Add user
                if (addUser.IsMatch(command))
                {
                    var groups = addUser.Match(command).Groups.Select(a => a.Value).ToList();
                    msgCommand = Command.CONF_ADD_USER;
                    var addUserMsg = new AddUserMessage
                    {
                        Level    = int.Parse(groups[3]),
                        Username = groups[1],
                        Password = groups[2]
                    };
                    content = addUserMsg;
                }
                //Set user level
                else if (setUserLevel.IsMatch(command))
                {
                    var groups = setUserLevel.Match(command).Groups.Select(a => a.Value).ToList();
                    msgCommand = Command.CONF_SET_USER_LEVEL;
                    var setUserLevelMsg = new SetUserLevelMessage
                    {
                        User     = groups[1],
                        NewLevel = int.Parse(groups[2])
                    };
                    content = setUserLevelMsg;
                }
                //Remove user
                else if (removeUser.IsMatch(command))
                {
                    var userName = removeUser.Match(command).Groups[1].Value;
                    msgCommand = Command.CONF_REMOVE_USER;
                    var removeUserMsg = new SingleValueMessage {
                        Value = userName
                    };
                    content = removeUserMsg;
                }
                //Upload file
                else if (putProgram.IsMatch(command) || putPipeline.IsMatch(command))
                {
                    var isProgram = putProgram.IsMatch(command);

                    var groups = isProgram
                        ? putProgram.Match(command).Groups.Select(a => a.Value).ToList()
                        : putPipeline.Match(command).Groups.Select(a => a.Value).ToList();

                    msgCommand = isProgram ? Command.CONF_PUT_PROGRAM : Command.CONF_PUT_PIPELINE;
                    var putMsg = new PutMessage
                    {
                        TargetName = groups[2],
                        TargetType = isProgram ? TargetTypes.PROGRAM : TargetTypes.PIPELINE,
                        Content    = File.ReadAllBytes(groups[1]),
                        Runtime    = groups[3]
                    };
                    content = putMsg;
                }
                //Distribute program/pipeline to child
                else if (distribute.IsMatch(command))
                {
                    var groups = distribute.Match(command).Groups.Select(a => a.Value).ToList();

                    msgCommand = Command.CONF_DISTRIBUTE;
                    var distributeMsg = new DistributeMessage
                    {
                        File   = groups[1],
                        Target = groups[2]
                    };
                    content = distributeMsg;
                }
                //Get status
                else if (getStatus.IsMatch(command))
                {
                    var groups = getStatus.Match(command).Groups.Select(a => a.Value).ToList();

                    msgCommand = Command.CONF_GET_STATUS;
                    var statusTarget = StatusTarget.All;
                    switch (groups[1].First().ToString().ToUpper())
                    {
                    case "A":
                        statusTarget = StatusTarget.All;
                        break;

                    case "N":
                        statusTarget = StatusTarget.Nodes;
                        break;

                    case "S":
                        statusTarget = StatusTarget.Self;
                        break;
                    }

                    var getStatusMsg = new GetStatusMessage
                    {
                        Target     = statusTarget,
                        StatusInfo = new List <Status>()
                    };
                    content = getStatusMsg;
                }
                //Ok?
                else if (ok.IsMatch(command))
                {
                    msgCommand = Command.OK;
                    var okMsg = new EmptyMessage();
                    content = okMsg;
                }
                //Fail!
                else if (fail.IsMatch(command))
                {
                    msgCommand = Command.FAIL;
                    var failMsg = new EmptyMessage();
                    content = failMsg;
                }

                if (msgCommand != Command.UNKNOWN)
                {
                    var response = NodeCommunicationClient.Send(
                        _configuration.ConfigurationToolAddress,
                        _configuration.User,
                        _configuration.Password,
                        content,
                        msgCommand,
                        CONFIG);

                    if (response.Message.Command == Command.OK)
                    {
                        switch (msgCommand)
                        {
                        case Command.CONF_GET_STATUS:
                            var statusMessage =
                                MessagePackSerializer.Deserialize <GetStatusMessage>(response.Content);
                            Console.WriteLine();
                            statusMessage.StatusInfo.ForEach(stat =>
                            {
                                Console.WriteLine($"{stat.Name}");
                                Console.WriteLine($"{stat.Name} - " + (stat.Up ? "UP" : "DOWN") + "\n",
                                                  stat.Up ? Log.Green : Log.Red);
                            });
                            break;

                        case Command.OK:
                            Console.WriteLine("Ok!", Log.Green);
                            break;

                        case Command.FAIL:
                            Console.WriteLine(":(", Log.Red);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine(
                            $"Execution at node failed!:\n{MessagePackSerializer.Deserialize<SingleValueMessage>(response.Content).Value}",
                            Log.Red);
                    }
                }
                else
                {
                    Console.WriteLine($"Unknown command: {command}!", Log.Red);
                }
            }
        }