Exemple #1
0
            public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaData commandMetaData)
            {
                global::Improbable.Gdk.Core.Empty?rawResponse = null;
                if (op.StatusCode == StatusCode.Success)
                {
                    rawResponse = global::Improbable.Gdk.Core.Empty.Serialization.Deserialize(op.Response.SchemaData.Value.GetObject());
                }

                var internalRequestId = new InternalCommandRequestId(op.RequestId);
                var commandContext    = commandMetaData.GetContext <global::Improbable.Gdk.Core.Empty>(ComponentId, 1, internalRequestId);

                commandMetaData.RemoveRequest(ComponentId, 1, internalRequestId);

                var response = new PlayerHeartbeat.ReceivedResponse(
                    commandContext.SendingEntity,
                    new EntityId(op.EntityId),
                    op.Message,
                    op.StatusCode,
                    rawResponse,
                    commandContext.Request,
                    commandContext.Context,
                    commandContext.RequestId);

                diff.AddCommandResponse(response, ComponentId, 1);
            }
        private CommandMetaData metaDataCommandFrom(IMacroCommand macroCommand)
        {
            var commandMetaData = new CommandMetaData {
                Discriminator = Constants.Serialization.MACRO_COMMAND
            };

            macroCommand.All().Each(childCommand => commandMetaData.AddCommand(MapFrom(childCommand)));
            return(commandMetaData);
        }
Exemple #3
0
        public void AddCommand(string name, Command command, CommandMetaData metaData = null)
        {
            if (_commands.TryGetValue(name, out var otherCommand))
            {
                throw new Exception($"Cannot add command '{name}', it already exists: {otherCommand}");
            }
            _commands.Add(name, command);
            _infos.Add(command, metaData ?? new CommandMetaData(null, null));

            if (Debug)
            {
                UnityEngine.Debug.Log($"Added command: {command}");
            }
        }
 protected override void Context()
 {
     base.Context();
     _macroCommand = new CommandMetaData {
         Discriminator = SerializationConstants.MacroCommand
     };
     _subCommands = new List <CommandMetaData>
     {
         new CommandMetaData(),
         new CommandMetaData(),
         new CommandMetaData()
     };
     A.CallTo(() => _commandMetaDataRepository.AllChildrenOf(_macroCommand)).Returns(_subCommands);
 }
        public static ICommandHandlerBuilder <CommandMessage <TMessage> > RequiresRole <TMessage>(this ICommandHandlerBuilder <CommandMessage <TMessage> > source, string roleName)
            where TMessage : class
        {
            return(source.Pipe(next => async(message, ct) =>
            {
                var metadata = CommandMetaData.FromDictionary(message.Metadata);
                if (metadata.HasRole(roleName))
                {
                    return await next(message, ct);
                }

                throw new InsufficientRights();
            }));
        }
Exemple #6
0
        public ICommand MapFrom(CommandMetaData commandMetaData)
        {
            var command = commandFrom(commandMetaData);

            command.CommandType         = commandMetaData.CommandType;
            command.Id                  = new CommandId(commandMetaData.CommandId, commandMetaData.CommandInverseId);
            command.InternalId          = commandMetaData.Id;
            command.Comment             = commandMetaData.Comment;
            command.Description         = commandMetaData.Description;
            command.ObjectType          = commandMetaData.ObjectType;
            command.CommandType         = commandMetaData.CommandType;
            command.ExtendedDescription = commandMetaData.ExtendedDescription;
            command.Visible             = commandMetaData.Visible;
            command.Loaded              = false;
            commandMetaData.Properties.Values.Each(p => command.AddExtendedProperty(p.Name, p.Value));
            return(command);
        }
Exemple #7
0
        private ICommand commandFrom(CommandMetaData commandMetaData)
        {
            var command = commandFrom(commandMetaData.Discriminator);

            var macroCommand = command as OSPSuiteMacroCommand <IOSPSuiteExecutionContext>;

            if (macroCommand == null)
            {
                return(command);
            }

            foreach (var childMetaData in _commandMetaDataRepository.AllChildrenOf(commandMetaData))
            {
                macroCommand.Add(MapFrom(childMetaData));
            }

            return(macroCommand);
        }
            public void AddResponseToDiff(CommandResponseOp op, ViewDiff diff, CommandMetaData commandMetaData)
            {
                global::Improbable.TestSchema.SomeType?rawResponse = null;
                if (op.StatusCode == StatusCode.Success)
                {
                    rawResponse = global::Improbable.TestSchema.SomeType.Serialization.Deserialize(op.Response.SchemaData.Value.GetObject());
                }

                var commandContext = commandMetaData.GetContext <global::Improbable.TestSchema.SomeType>(ComponentId, 1, op.RequestId);

                commandMetaData.RemoveRequest(ComponentId, 1, op.RequestId);

                var response = new BarCommand.ReceivedResponse(
                    commandContext.SendingEntity,
                    new EntityId(op.EntityId),
                    op.Message,
                    op.StatusCode,
                    rawResponse,
                    commandContext.Request,
                    commandContext.Context,
                    commandContext.RequestId);

                diff.AddCommandResponse(response, ComponentId, 1);
            }
            public void Serialize(MessagesToSend messages, SerializedMessagesToSend serializedMessages, CommandMetaData commandMetaData)
            {
                var storage = (CmdCommandsToSendStorage)messages.GetCommandSendStorage(ComponentId, 1);

                var requests = storage.GetRequests();

                for (int i = 0; i < requests.Count; ++i)
                {
                    ref readonly var request = ref requests[i];
        public static void SendCommand(this Control control, List <ConnectionRow> connections, bool errorsInRow, CommandMetaData commandMetaData, params object[] args)
        {
            using (ProgressDialog dialog = new ProgressDialog()
            {
                ProgressMessage = $"Sending command to {connections.Count} devices.",
                Style = ProgressBarStyle.Marquee,
                CancelButtonEnabled = false,
            })
            {
                Thread thread = new Thread(() =>
                {
                    Parallel.ForEach(connections,
                                     (connection) =>
                    {
                        string messageString = "";
                        CommunicationProcessResult result;

                        do
                        {
                            Reporter reporter      = new Reporter();
                            CommandProcess process = new CommandProcess(connection.Connection, reporter, new CommandCallback(commandMetaData.GetMessage(args)), 100, 3);

                            result = process.Send();

                            StringBuilder fullMessageString = new StringBuilder();

                            fullMessageString.AppendLine("Error while communicating with " + connection.Connection.Settings.GetDeviceDescriptor() + ".");
                            fullMessageString.AppendLine();

                            fullMessageString.Append("Failed to confirm command: " + commandMetaData.OscAddress);

                            messageString = fullMessageString.ToString();

                            if (result != CommunicationProcessResult.Success && errorsInRow == true)
                            {
                                connection.SetError(messageString);
                            }
                        }while (result != CommunicationProcessResult.Success &&
                                errorsInRow == false && dialog.InvokeShowError(messageString, MessageBoxButtons.RetryCancel) == DialogResult.Retry);
                    });

                    control.Invoke(new MethodInvoker(dialog.Close));
                });

                thread.Start();

                dialog.ShowDialog(control);
            }
        }
Exemple #11
0
        public virtual ApprovalCommandBase GetCommandById(Guid commandId)
        {
            CommandMetaData byCommandId = _commandMetaDataRepository.GetByCommandId(commandId);

            return(byCommandId == null ? (ApprovalCommandBase)null : this.GetApprovalCommand(byCommandId.Type, byCommandId.CommandId));
        }