static CoflnetUser() { // register commands commandController = new CommandController(persistenceCommands); commandController.RegisterCommand <GetUserKeyValue> (); commandController.RegisterCommand <SetUserKeyValue> (); }
/// <summary> /// Adds additional <see cref="CommandController"> to search for commands. /// Will shift other fallback back. /// </summary> /// <param name="fallback">Controller to add</param> public void AddFallback(CommandController fallback) { if (Fallback != null) { fallback.AddFallback(Fallback); } Fallback = fallback; }
/// <summary> /// Initializes the <see cref="T:Coflnet.<see cref="Entity"/>"/> class. /// </summary> static Entity() { globalCommands = new CommandController(); globalCommands.RegisterCommand <ReturnResponseCommand> (); globalCommands.RegisterCommand <GetResourceCommand>(); globalCommands.RegisterCommand <CreationResponseCommand>(); globalCommands.RegisterCommand <SubscribeCommand>(); }
/// <summary> /// Initializes a new instance of the <see cref="T:Coflnet.ExternalCommand"/> class. /// </summary> /// <param name="request">CommandRegisterRequest instance.</param> /// <param name="controller">CommandController which to take the commands from.</param> public ExternalCommand(CommandRegisterRequest request, CommandController controller) { foreach (var item in request.bodyCommands) { commands.Add(controller.GetCommand(item.Key), item.Value); } settings = request.settings; slug = request.Slug; }
/// <summary> /// Adds Add,AddRange,Remove,RemoveAt,RemoveRange,Insert,InsertRange and Clear commands for any list on any entitys /// </summary> /// <param name="controller">The controller of the <see cref="Entity"/> to add the commands to</param> /// <param name="prefix">The prefix for the commands, usually the attribute name</param> /// <param name="ListGetter">A function that returns the actual list to operate on, given the target <see cref="Entity"/> </param> /// <param name="Converter">A function that converts the data given in the <see cref="CommandData"/> content to the List type</param> /// <param name="localPropagation">Set to true if commands don't have to pass the managing server first to be applied locally</param> /// <typeparam name="R">The target <see cref="Entity"/> type</typeparam> /// <typeparam name="T">The type of the list elements</typeparam> public static void AddCommands(CommandController controller, string prefix, Func <CommandData, List <T> > ListGetter, Func <CommandData, T> Converter = null, bool localPropagation = false) { controller.RegisterCommand(new GetCommand(prefix, ListGetter)); // commands have no plural s prefix = prefix.Trim('s'); controller.RegisterCommand(new RemoteCollectionAddCommand <T>(prefix, ListGetter, localPropagation)); controller.RegisterCommand(new RemoteListRemoveCommand <T>(prefix, ListGetter, Converter)); controller.RegisterCommand(new RemoteListRemoveAtCommand <T>(prefix, ListGetter, Converter)); controller.RegisterCommand(new RemoteCollectionClearCommand <T>(prefix, ListGetter, localPropagation)); controller.RegisterCommand(new RemoteListAddRangeCommand <T>(prefix, ListGetter, null)); controller.RegisterCommand(new RemoteListRemoveRangeCommand <T>(prefix, ListGetter, Converter)); controller.RegisterCommand(new RemoteListInsertRangeCommand <T>(prefix, ListGetter, Converter)); controller.RegisterCommand(new RemoteListInsertCommand <T>(prefix, ListGetter, Converter)); }
static Device() { commandController = new CommandController(persistenceCommands); commandController.RegisterCommand <DeviceInstalledCommand>(); //commandController.RegisterCommand<AddUserCommand>(); commandController.RegisterCommand <RemoveUserCommand>(); // Add commands for the users list RemoteList <Reference <CoflnetUser> > .AddCommands (commandController, nameof(Users), m => m.GetTargetAs <Device>().Users , m => new Reference <CoflnetUser>(m.GetAs <EntityId>())); // Add commands for the installed apps list RemoteList <string> .AddCommands (commandController, nameof(InstalledApps), m => m.GetTargetAs <Device>().InstalledApps); }
public void ExecuteNextCommand() { if (queuedCommand.Count > 0) { sleeping = false; CommandItem item = NextCommandItem(); try { CommandController.ExecuteCommandInCurrentThread(item.command, item.data); } catch (Exception ex) { Track.instance.Error(item.data.Type, MessagePack.MessagePackSerializer.SerializeToJson(item), ex.ToString()); } } else { if (isStopping) { return; } if (!sleeping) { long time = (DateTime.UtcNow - startTime).Ticks; } sleeping = true; ManualResetEvent resetEvent = new ManualResetEvent(false); resetEvent.WaitOne(); resetEvent.Set(); resetEvent.Reset(); Thread.Sleep(100); } ExecuteNextCommand(); }
static ReceiveableResource() { persistenceCommands = new CommandController(globalCommands); persistenceCommands.RegisterCommand <GetMessages> (); persistenceCommands.RegisterCommand <ReceiveConfirm>(); }
static Installation() { _commands = new CommandController(persistenceCommands); _commands.RegisterCommand <CreateUser>(); }
static DistributionResource() { _commandController = new CommandController(); _commandController.RegisterCommand <Distribute> (); }
public CommandController(CommandController fallback) : this() { this.Fallback = fallback; }
/// <summary> /// Executes a command instruction with a given CommandController. /// </summary> /// <param name="data">Data passed from a connected device.</param> /// <param name="controller">Controller to search for the command.</param> public void ExecuteCommand(CommandData data, CommandController controller) { ExecuteCommand(controller.GetCommand(data.Type), data); }