public GitToolCommand(string name, string Command, CommandScope scope = CommandScope.Project, bool saveOnExecution = false)
 {
     this.Name       = name;
     this.Command    = Command;
     Scope           = scope;
     SaveOnExecution = saveOnExecution;
 }
Ejemplo n.º 2
0
 public ApplyMetadataCommand(string templateKey, string fileId, Dictionary <string, object> metadata,
                             CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User) : base(scope, accessLevel)
 {
     _templateKey = templateKey;
     _fileId      = fileId;
     _metadata    = metadata;
 }
        public override async Task <TResult> OnCommandAsync <TCommand, TResult>(Func <TCommand, CancellationToken, Task <TResult> > next, TCommand cmd, CancellationToken ct)
        {
            var command = (await _commands.AddAsync(new CommandEntity
            {
                ExternalId = cmd.Id,
                Name = typeof(TCommand).Name,
                Payload = JsonSerializer.Serialize(cmd),
                Result = null,
                CreatedOn = cmd.CreatedOn,
                CreatedBy = cmd.CreatedBy,
                ExecutionTime = TimeSpan.Zero
            }, ct)).Entity;

            TResult result;

            using (CommandScope.Begin(command.ExternalId, command.Id))
            {
                result = await next(cmd, ct);
            }

            command.Result        = result == null ? null : JsonSerializer.Serialize(result);
            command.ExecutionTime = DateTimeOffset.UtcNow - cmd.CreatedOn;

            return(result);
        }
Ejemplo n.º 4
0
        public static async Task <BoxFile> CreateSmallFile(string parentId = "0", CommandScope commandScope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User)
        {
            var createFileCommand = new CreateFileCommand(GetUniqueName("file"), GetSmallFilePath(), parentId, commandScope, accessLevel);

            await ExecuteCommand(createFileCommand);

            return(createFileCommand.File);
        }
Ejemplo n.º 5
0
        public static async Task <BoxFolder> CreateFolder(string parentId = "0", CommandScope commandScope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User)
        {
            var createFolderCommand = new CreateFolderCommand(GetUniqueName("folder"), parentId, commandScope, accessLevel);

            await ExecuteCommand(createFolderCommand);

            return(createFolderCommand.Folder);
        }
Ejemplo n.º 6
0
        public static async Task <BoxMetadataTemplate> CreateMetadataTemplate(Dictionary <string, object> metadata = null,
                                                                              CommandScope commandScope            = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin)
        {
            var createMetadataTemplateCommand = new CreateMetadataTemplateCommand(GetUniqueName("template_key", false), ToStringMetadataFields(metadata), commandScope, accessLevel);

            await ExecuteCommand(createMetadataTemplateCommand);

            return(createMetadataTemplateCommand.MetadataTemplate);
        }
Ejemplo n.º 7
0
        public static TCommand Execute <TCommand>(params object[] args)
            where TCommand : MonoCommand, new()
        {
            GameObject mgGameObject = MonoSingleton.GetMGGameObject();

            object[] attibutes = typeof(TCommand).GetCustomAttributes(true);

            bool         oneItemOnScene = false;
            CommandScope scope          = CommandScope.Application;

            foreach (Attribute eachAttribute in attibutes)
            {
                if (eachAttribute is SingletoneAttribute)
                {
                    oneItemOnScene = true;
                }
                else if (eachAttribute is MonoCommandScopeAttribute)
                {
                    MonoCommandScopeAttribute monoCommandScopeAttribute = (MonoCommandScopeAttribute)eachAttribute;

                    scope = monoCommandScopeAttribute.IsApplication ? CommandScope.Application : CommandScope.Scene;
                }
            }

            if (oneItemOnScene)
            {
                TCommand command = (TCommand)UnityEngine.Object.FindObjectOfType(typeof(TCommand));

                if (command != null)
                {
                    MonoLog.Log(MonoLogChannel.Core, "Found existing command " + command);

                    return(command);
                }
            }

            GameObject target = null;

            if (scope == CommandScope.Application)
            {
                target = new GameObject(typeof(TCommand).Name);
                target.transform.parent = mgGameObject.transform;

                UnityEngine.Object.DontDestroyOnLoad(target);
            }
            else
            {
                target = UIManager.CurrentSceneController.gameObject;
            }

            TCommand result = ExecuteOn <TCommand>(target, args);

            result.Scope = scope;

            return(result);
        }
Ejemplo n.º 8
0
 public ActionConfiguration(Trigger trigger, string glob, string workingDirectory, string command, string solutionRoot, string projectRoot, CommandScope scope)
 {
     this.Trigger = trigger;
     this.Glob = glob;
     this.RelativeWorkingDirectory = workingDirectory;
     this.Command = command;
     this.SolutionRoot = solutionRoot;
     this.ProjectRoot = projectRoot;
     this.Scope = scope;
 }
Ejemplo n.º 9
0
        public static async Task <Tuple <BoxFile, string> > CreateSmallFileWithMetadata
            (string parentId          = "0", Dictionary <string, object> metadata = null,
            CommandScope commandScope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin)
        {
            var createFileCommand = new CreateFileCommand(GetUniqueName("file"), GetSmallFilePath(), parentId, commandScope, accessLevel);

            await ExecuteCommand(createFileCommand);

            var createMetadataTemplateCommand = new CreateMetadataTemplateCommand(GetUniqueName("template_key", false), ToStringMetadataFields(metadata), commandScope, accessLevel);

            await ExecuteCommand(createMetadataTemplateCommand);

            var applyMetadataCommand = new ApplyMetadataCommand(createMetadataTemplateCommand.TemplateKey, createFileCommand.FileId, metadata, commandScope, accessLevel);

            await ExecuteCommand(applyMetadataCommand);

            return(Tuple.Create(createFileCommand.File, createMetadataTemplateCommand.TemplateKey));
        }
Ejemplo n.º 10
0
        private int GetCommandKey(SlackBotCommand command)
        {
            int          commandId = CommandTypeRegistry.GetCommandId(command.Name);
            CommandScope scope     = CommandTypeRegistry.GetCommandType(command.Name).GetCommandScope();

            object preKey = null;

            switch (scope)
            {
            case CommandScope.Global:
                preKey = commandId; break;

            case CommandScope.Channel:
                preKey = new Tuple <int, string>(commandId, command.Channel.id); break;

            case CommandScope.User:
                preKey = new Tuple <int, string, string>(commandId, command.Channel.id, command.User.id); break;
            }

            return(preKey.GetHashCode());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// A commandlet represents the abstract idea of the typical IRC command represented with a start-character (!) and a string for identify. All the parsing will be done
        /// by the bot, you only get exactly the events you registered to. For example: you can register an event which is only thrown if used in a private message by certain users,
        /// or in a certain channel.
        /// </summary>
        /// <param name="command">the command string including initial charakter. like "!example" </param>
        /// <param name="helptext">A help for this certain command which should be displayed by the !help command</param>
        /// <param name="handler">The name of the method which should be called, can be private</param>
        /// <param name="owner">this (the class where this command is provided)</param>
        /// <param name="scope">Should the event be fired by Channelmessages or Privatemessages or Both</param>
        /// <param name="accessString">globally unique string which identifies a restricted function, something like: plugin_function, can be done manually too, via bot.acl.*</param>
        /// <param name="channelList">Only usefull if the Scope is Public! The Handler will only be called if the request was made in a certain channel. No restriction == null</param>
        public Commandlet(string command, string helptext, EventHandler<IrcEventArgs> handler, object owner, CommandScope scope = CommandScope.Both, string accessString = null, List<string> channelList = null)
        {
            Command = command;
            HelpText = helptext;

            if (owner is AbstractPlugin)
            {
                var plugin = owner as AbstractPlugin;
                Handler = null;
                HandlerName = handler.Method.Name;
                Owner = plugin.FullName;
                SourcePlugin = plugin.FullName;
            }
            else
            {
                Handler = handler;
                Owner = owner;
                SourcePlugin = "Core";
            }

            Scope = scope;
            AccessString = accessString;
            this.channelList = channelList;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// A commandlet represents the abstract idea of the typical IRC command represented with a start-character (!) and a string for identify. All the parsing will be done
        /// by the bot, you only get exactly the events you registered to. For example: you can register an event which is only thrown if used in a private message by certain users,
        /// or in a certain channel.
        /// </summary>
        /// <param name="command">the command string including initial charakter. like "!example" </param>
        /// <param name="helptext">A help for this certain command which should be displayed by the !help command</param>
        /// <param name="handler">The name of the method which should be called, can be private</param>
        /// <param name="owner">this (the class where this command is provided)</param>
        /// <param name="scope">Should the event be fired by Channelmessages or Privatemessages or Both</param>
        /// <param name="accessString">globally unique string which identifies a restricted function, something like: plugin_function, can be done manually too, via bot.acl.*</param>
        /// <param name="channelList">Only usefull if the Scope is Public! The Handler will only be called if the request was made in a certain channel. No restriction == null</param>
        public Commandlet(string command, string helptext, EventHandler <IrcEventArgs> handler, object owner, CommandScope scope = CommandScope.Both, string accessString = null, List <string> channelList = null)
        {
            Command  = command;
            HelpText = helptext;

            if (owner is AbstractPlugin)
            {
                var plugin = owner as AbstractPlugin;
                Handler      = null;
                HandlerName  = handler.Method.Name;
                Owner        = plugin.FullName;
                SourcePlugin = plugin.FullName;
            }
            else
            {
                Handler      = handler;
                Owner        = owner;
                SourcePlugin = "Core";
            }

            Scope            = scope;
            AccessString     = accessString;
            this.channelList = channelList;
        }
Ejemplo n.º 13
0
        private static void Main(string[] args)
        {
            // context initialization if necessary
            var context = new CommandContext
            {
                Context = new Dictionary <string, object>
                {
                    ["team"] = new List <string>()
                }
            };

            // init command executor
            var runner = new CommandRunner(context);

            // init command/transaction scope
            using (var scope = new CommandScope())
            {
                scope.Init()
                .Add(new AddShipCommand("Black Cuttlefish"))
                .Add(new AddTeamCommand("John Silver"))
                .Add(new AddTeamCommand("Capitan Smollet"))
                .Add(new AddTeamCommand("Doctor Livcy"))
                .Add(new AddTeamCommand("Billi Bonc"))
                .Add(new AddTeamCommand("Jim"))
                .Add(new AddRegattaCommand(Guid.NewGuid().ToString()))
                .Add(new FailureCommand())
                .Run(runner)
                // with fluent, we can do something like this
                .Init()
                .Add(new AddTeamCommand("Billi Bonc"))
                .Add(new AddTeamCommand("Jim"))
                .Add(new AddRegattaCommand(Guid.NewGuid().ToString()))
                .Add(new FailureCommand())
                .Run(runner);
            }
        }
 public GitToolCommand(string name, string Command, CommandScope scope = CommandScope.Project)
 {
     this.Name = name;
     this.Command = Command;
     Scope = scope;
 }
 public ActionConfigurationBuilder WithScope(CommandScope scope)
 {
     this.scope = scope;
     return this;
 }
Ejemplo n.º 16
0
        public static async Task <BoxRetentionPolicy> CreateRetentionPolicy(string folderId = "0", CommandScope commandScope = CommandScope.Test)
        {
            var createRetentionPolicyCommand = new CreateRetentionPolicyCommand(folderId, GetUniqueName("policy"), commandScope);

            await ExecuteCommand(createRetentionPolicyCommand);

            return(createRetentionPolicyCommand.Policy);
        }
Ejemplo n.º 17
0
 public CreateWebLinkCommand(string name, string parentFolderId,
                             CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User) : base(scope, accessLevel)
 {
     _name           = name;
     _parentFolderId = parentFolderId;
 }
 public GitToolCommand(string name, string Command, CommandScope scope = CommandScope.Project)
 {
     this.Name    = name;
     this.Command = Command;
     Scope        = scope;
 }
Ejemplo n.º 19
0
        public void Should_be_able_to_parse_valid_command_scope(string configValue, CommandScope parsedValue)
        {
            var input = this.CreateConfig(config =>
                config.WithAction(action =>
                    action.WithScope(configValue)));

            var configuration = this.Parser.Parse("", "", input).Single();

            Assert.That(configuration.Scope, Is.EqualTo(parsedValue));
        }
Ejemplo n.º 20
0
 public CreateMetadataTemplateCommand(string templateKey, List <BoxMetadataTemplateField> metadataFields,
                                      CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin) : base(scope, accessLevel)
 {
     TemplateKey     = templateKey;
     _metadataFields = metadataFields;
 }
Ejemplo n.º 21
0
 public CreateFolderCommand(string folderName, string parentId = "0", CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User) : base(scope, accessLevel)
 {
     _folderName = folderName;
     _parentId   = parentId;
 }
Ejemplo n.º 22
0
 public CommandBase(CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User)
 {
     Scope       = scope;
     AccessLevel = accessLevel;
 }
Ejemplo n.º 23
0
 public CreateFileCommand(string fileName, string filePath, string folderId = "0", CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.User) : base(scope, accessLevel)
 {
     _fileName = fileName;
     _filePath = filePath;
     _folderId = folderId;
 }
Ejemplo n.º 24
0
 public void iDetach(CommandReceiver commandScope)
 {
     m_Owner = null;
 }
Ejemplo n.º 25
0
        //public ICommandListenerLinked<CommandReciver>	m_ParentValidator;

        //////////////////////////////////////////////////////////////////////////
        public void iAttach(CommandReceiver commandScope)
        {
            m_Owner = commandScope as CommandScope;
        }
 public AddCollaborationExemptCommand(string userId, CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin)
     : base(scope, accessLevel)
 {
     _userId = userId;
 }
Ejemplo n.º 27
0
 public CreateRetentionPolicyCommand(string folderId, string policyName, CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin) : base(scope, accessLevel)
 {
     _policyName = policyName;
     _folderId   = folderId;
 }
Ejemplo n.º 28
0
 public CreateEnterpriseUserCommand(string name, string externalAppUserId,
                                    CommandScope scope = CommandScope.Test, CommandAccessLevel accessLevel = CommandAccessLevel.Admin) : base(scope, accessLevel)
 {
     _name = name;
     _externalAppUserId = externalAppUserId;
 }
Ejemplo n.º 29
0
 public DeleteFileCommand(string fileId, CommandScope scope = CommandScope.Test) : base(scope)
 {
     _fileId = fileId;
 }
Ejemplo n.º 30
0
 public DeleteFolderCommand(string folderId, CommandScope scope = CommandScope.Test) : base(scope)
 {
     _folderId = folderId;
 }