private void MyClient_OnPowerMessageProcessed(object sender, PowerMessage mess) { Console.WriteLine("{0, -20}: {1}", mess.messType, mess.details); switch (mess.messType) { case MessageType.TasksList: foreach (PowerTaskFunc powerFunc in availableTasks.Values) { Console.WriteLine("\t{0}: {1}", powerFunc.taskName, powerFunc.discription); } break; } }
public void SetPower(byte power) { var milliseconds = (DateTime.UtcNow - new DateTime(1970, 1, 1)).Milliseconds; var powerMessage = new PowerMessage() { AccessCode = accessCode, P = power, TeamId = teamName, TimeStamp = milliseconds }; var message = serializer.Serialize(powerMessage); lock (powerLock) { client.Publish(teamName, RoutingKeyNames.Power, message); } }
private void Client_OnTaskFinished(object sender, PowerTask task, PowerMessage mess, bool success) { runOnUIThread(() => { lock (listBoxRunningTasks) { foreach (var item in listBoxRunningTasks.Items) { if (((TaskItem)item).taskId == task.taskId) { listBoxRunningTasks.Items.Remove(item); break; } } tasksStack.Remove(task.taskId); if (tasksStack.Count == 0) { watchingTaskId = -1; } else { watchingTaskId = tasksStack.Keys.First(); int index = 0; foreach (var item in listBoxRunningTasks.Items) { if (((TaskItem)item).taskId == watchingTaskId) { listBoxRunningTasks.SelectedIndex = index; } index++; } } } }); }
void Awake() { instance = this; tween = GetComponent <TweenAlpha>(); label = transform.Find("Sprite/Label").GetComponent <UILabel>(); }
public void launchListeningLoop() { while (sessionActive) { PowerMessage mess; try { mess = PowerMessage.Deserialize(stream); //Console.WriteLine("{0}: {1} | {2}", mess.messType, mess.details, mess.value); } catch (IOException e) { OnError(this, "The server gone away..", e); return; } catch (Exception e) { OnError(this, "We have a problem, Houston.. But we continue", e); continue; } switch (mess.messType) { case MessageType.Greeting: //greet(); break; case MessageType.EndSession: sessionActive = false; break; case MessageType.AuthInitResult: if (mess.details != Details.UserExists) { new PowerMessage(MessageType.RegistrationRequest, xmlPublicKey).Serialize(stream); } break; case MessageType.RegistrationResult: if (mess.details == Details.AccessDenied) { throw new Exception("Registration refused"); } new PowerMessage(MessageType.AuthInit, xmlPublicKey).Serialize(stream); break; case MessageType.AuthToken: byte[] token = (byte[])mess.value; byte[] signedToken = provider.SignData(token, "SHA256"); new PowerMessage(MessageType.AuthToken, signedToken).Serialize(stream); break; case MessageType.AuthTokenResult: if (mess.details == Details.Authorised) { authorized = true; new PowerMessage(MessageType.TasksList).Serialize(stream); } if (OnAuthFinished != null) { OnAuthFinished(this, authorized); } break; case MessageType.TasksList: if (mess.details != Details.OK) { break; } availableTasks = (Dictionary <string, PowerTaskFunc>)mess.value; OnTasksListGot(this, availableTasks); break; case MessageType.TaskInitResult: if (mess.details != Details.Accepted) { throw new Exception("Task " + ((int)mess.value).ToString() + " wasn't accepted"); } PowerTaskIds ids = (PowerTaskIds)mess.value; if (initTasksCallback.ContainsKey(ids.clientId)) { initTasksCallback[ids.clientId](ids.taskId); //Console.WriteLine("Task \"{2}{0}\" initialized as \"{2}{1}\" on server", ids.clientId, ids.taskId, ids.taskName); } break; case MessageType.TaskError: PowerTaskError taskError = (PowerTaskError)mess.value; if (runningTasksError.ContainsKey(taskError.taskId)) { runningTasksError[taskError.taskId](taskError); } if (taskError.fatal) { OnTaskFinished(this, taskError, mess, false); } break; case MessageType.TaskProgress: PowerTaskProgress taskProgress = (PowerTaskProgress)mess.value; if (runningTasksProgress.ContainsKey(taskProgress.taskId)) { runningTasksProgress[taskProgress.taskId](taskProgress); } break; case MessageType.TaskComplete: PowerTaskResult taskComplete = (PowerTaskResult)mess.value; if (runningTasksComplete.ContainsKey(taskComplete.taskId)) { runningTasksComplete[taskComplete.taskId](taskComplete); } OnTaskFinished(this, taskComplete, mess, false); break; case MessageType.TaskResult: PowerTaskResult taskResult = (PowerTaskResult)mess.value; if (runningTasksResult.ContainsKey(taskResult.taskId)) { runningTasksResult[taskResult.taskId](taskResult); } break; } OnPowerMessageProcessed(this, mess); } }
private void Client_OnPowerMessageProcessed(object sender, PowerMessage mess) { runOnUIThread(() => { switch (mess.messType) { case MessageType.TasksList: listBoxAvailableTasks.Items.Clear(); foreach (PowerTaskFunc taskFunc in client.availableTasks.Values) { ListBoxItem item = new ListBoxItem(); item.Content = taskFunc.taskName; item.PreviewMouseDown += (it, arg) => { textBoxChosenTaskToRun.Text = taskNameToRun = taskFunc.taskName; }; listBoxAvailableTasks.Items.Add(item); } break; case MessageType.TaskResult: int valuesCount = 0; PowerTaskResult res = (PowerTaskResult)mess.value; int[][] spectr = ((int[][])(res).result); foreach (int[] arr in spectr) { valuesCount += arr.Length; } tasksStack[res.taskId] += "Got " + valuesCount.ToString() + " values\n"; if (watchingTaskId == res.taskId) { textBoxTaskOutput.Text = tasksStack[res.taskId]; textBoxTaskOutput.ScrollToEnd(); } break; case MessageType.TaskProgress: PowerTaskProgress progress = (PowerTaskProgress)mess.value; if (watchingTaskId == progress.taskId) { progressBarRunningTask.Value = progress.progress * 100; } break; default: bool itIs = mess.value is PowerTask; if (itIs) { PowerTask task = (PowerTask)mess.value; Console.WriteLine("{0}: {1} | {2}", mess.messType, mess.value, task.taskName); if (!tasksStack.ContainsKey(task.taskId)) { return; } tasksStack[task.taskId] += mess.details.ToString(); textBoxTaskOutput.Text = tasksStack[task.taskId]; textBoxTaskOutput.ScrollToEnd(); } break; } }); }