Exemple #1
0
        private async void WebSocketClient_OnQueueMessage(QueueMessage message)
        {
            RobotCommand command = null;

            try
            {
                command = Newtonsoft.Json.JsonConvert.DeserializeObject <RobotCommand>(message.data.ToString());
                var data = JObject.Parse(command.data.ToString());
                if (command.command == "invoke")
                {
                    var workflow = GetWorkflowById(command.workflowid);
                    if (workflow == null)
                    {
                        throw new Exception("Unknown workflow " + command.workflowid);
                    }
                    var param = new Dictionary <string, object>();
                    foreach (var k in data)
                    {
                        switch (k.Value.Type)
                        {
                        case JTokenType.Integer: param.Add(k.Key, k.Value.Value <int>()); break;

                        case JTokenType.Float: param.Add(k.Key, k.Value.Value <float>()); break;

                        case JTokenType.Boolean: param.Add(k.Key, k.Value.Value <bool>()); break;

                        case JTokenType.Date: param.Add(k.Key, k.Value.Value <DateTime>()); break;

                        case JTokenType.TimeSpan: param.Add(k.Key, k.Value.Value <TimeSpan>()); break;

                        default: param.Add(k.Key, k.Value.Value <string>()); break;
                        }
                    }
                    await workflow.Run(param, message.replyto, message.correlationId, onIdle);

                    command.command = "invokesuccess";
                }
            }
            catch (Exception ex)
            {
                command         = new RobotCommand();
                command.command = "error";
                command.data    = JObject.FromObject(ex);
            }
            // string data = Newtonsoft.Json.JsonConvert.SerializeObject(command);
            if (message.replyto != message.queuename)
            {
                await global.webSocketClient.QueueMessage(message.replyto, command, message.correlationId);
            }
        }
Exemple #2
0
 private void onIdle(WorkflowInstance instance, EventArgs e)
 {
     if (!string.IsNullOrEmpty(instance.queuename) && !string.IsNullOrEmpty(instance.correlationId))
     {
         RobotCommand command = new RobotCommand();
         var          data    = JObject.FromObject(instance.Parameters);
         command.command    = "invoke" + instance.state;
         command.workflowid = instance.WorkflowId;
         command.data       = data;
         _ = global.webSocketClient.QueueMessage(instance.queuename, command, instance.correlationId);
     }
     else
     {
         if (instance.state != "idle")
         {
             GenericTools.restore(GenericTools.mainWindow);
         }
     }
 }