Ejemplo n.º 1
0
        private static void aliceProgressWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var progressTimer = new Stopwatch();

            progressTimer.Start();

            var taskProgressInfo = new HyperNodeTaskProgressInfo();

            using (var alice = new HyperNodeClient("Alice"))
            {
                var request = (HyperNodeMessageRequest)e.Argument;
                ICommandResponseSerializer serializer = new NetDataContractResponseSerializer <GetCachedTaskProgressInfoResponse>();

                while (!taskProgressInfo.IsComplete && progressTimer.Elapsed <= TimeSpan.FromMinutes(2))
                {
                    var aliceResponse = alice.ProcessMessage(request);

                    var targetResponse = aliceResponse;
                    if (string.IsNullOrWhiteSpace(targetResponse?.CommandResponseString))
                    {
                        break;
                    }

                    var commandResponse = (GetCachedTaskProgressInfoResponse)serializer.Deserialize(targetResponse.CommandResponseString);
                    taskProgressInfo = commandResponse.TaskProgressInfo ?? new HyperNodeTaskProgressInfo();
                    if (!commandResponse.TaskProgressCacheEnabled)
                    {
                        taskProgressInfo.Activity.Add(
                            new HyperNodeActivityItem(ClientAgentName)
                        {
                            EventDescription = "Warning: Task progress cache is not enabled for HyperNode \'Alice\'."
                        }
                            );

                        // Make sure we exit the loop, since we're not going to get anything useful in this case.
                        taskProgressInfo.IsComplete = true;
                    }

                    ((BackgroundWorker)sender).ReportProgress(Convert.ToInt32(taskProgressInfo.ProgressPercentage), taskProgressInfo);

                    Task.Delay(500).Wait();
                }
            }

            progressTimer.Stop();

            e.Result = taskProgressInfo;
        }
Ejemplo n.º 2
0
        private void btnRefreshCommandList_Click(object sender, EventArgs e)
        {
            try
            {
                cboCommandNames.DataSource = null;

                var serializer = new NetDataContractResponseSerializer <GetNodeStatusResponse>();
                var msg        = new HyperNodeMessageRequest(ClientAgentName)
                {
                    CommandName = SystemCommandName.GetNodeStatus
                };

                using (var client = new HyperNodeClient("Alice"))
                {
                    var response = client.ProcessMessage(msg);

                    // TODO: Recursively find the response we're actually interested in

                    if (!string.IsNullOrWhiteSpace(response.CommandResponseString))
                    {
                        if (((ICommandResponseSerializer)serializer).Deserialize(response.CommandResponseString) is GetNodeStatusResponse commandResponse)
                        {
                            cboCommandNames.DataSource = commandResponse.Commands.Select(c => c.CommandName).OrderBy(cn => cn).ToList();
                        }
                    }
                    else
                    {
                        MessageBox.Show(response.RespondingNodeName + " did not send back a command response string.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }