コード例 #1
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (PackageLogic.Instance.PackagesCollection.Packages.Count > 0)
            {
                List <Packages.Package> packagesToList = new List <Packages.Package>();

                foreach (var pkg in PackageLogic.Instance.PackagesCollection.Packages)
                {
                    bool isLoaded = PackageLogic.Instance.LoadedPackages.Contains(pkg);
                    bool add      = true;
                    if (LoadedOnly.IsPresent && !isLoaded)
                    {
                        add = false;
                    }

                    if (add)
                    {
                        packagesToList.Add(pkg);
                    }
                }

                if (!string.IsNullOrWhiteSpace(Filter))
                {
                    packagesToList = packagesToList.Where(e => e.Name.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) > -1).ToList();
                }

                base.Out.Object.Write(TableRecords.CreatePackageRecordList(packagesToList.ToArray()));
            }
            else
            {
                base.Out.Object.Write(TableRecords.CreatePackageRecordList());
            }
        }
コード例 #2
0
 public override void Invoke(CommandInvocationContext context)
 {
     VariableContextLogic.Instance.CurrentContext
         = VariableContextLogic.Instance.VariableContextCollection.Contexts
           .FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase));
     base.Out.Object.Table(TableRecords.CreateVariableContextRecordList(VariableContextLogic.Instance.CurrentContext));
 }
コード例 #3
0
            protected internal override void createHistoryCleanupJob(CommandContext commandContext)
            {
                monitor.sync();

                base.createHistoryCleanupJob(commandContext);
                spy = Context.CommandInvocationContext;

                monitor.sync();
            }
コード例 #4
0
 public override void Invoke(CommandInvocationContext context)
 {
     if (base.Confirm(string.Format("The module '{0}' will be uninstalled", ModuleName)))
     {
         if (base.Host.Modules.Uninstall(ModuleName, base.Out))
         {
             base.Out.Standard.WriteLine(string.Format("Module '{0}' has been installed", ModuleName));
         }
     }
 }
コード例 #5
0
        public override void Invoke(CommandInvocationContext context)
        {
            var pkg = PackageLogic.Instance.PackagesCollection.Packages
                      .FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase));

            base.Out.Standard.WriteLine();
            base.Out.Standard.WriteLine(string.Format("     Package:        {0}", pkg.Name));
            base.Out.Standard.WriteLine(string.Format("     Is Loaded:      {0}", PackageLogic.Instance.LoadedPackages.Contains(pkg)));
            base.Out.Object.Table(TableRecords.CreatePackageModuleTableRecordList(pkg.Modules.ToArray()));
        }
コード例 #6
0
        public override void Invoke(CommandInvocationContext context)
        {
            var asm = Util.LoadAssembly(Assembly);

            if (asm == null)
            {
                base.Out.Error.WriteLine(string.Format("Could not load assembly from assembly string '{0}'", Assembly));
                return;
            }

            Package pkg = PackageLogic.Instance.PackagesCollection.Packages.FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase));

            List <string> modulesToInstall = null;

            if (!string.IsNullOrWhiteSpace(Modules))
            {
                modulesToInstall = new List <string>(Modules.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            }

            int count = 0;

            foreach (var type in asm.GetTypes())
            {
                if (type.GetInterface(typeof(IModule).FullName) != null)
                {
                    var  module = (IModule)Activator.CreateInstance(type);
                    bool add    = true;
                    if (modulesToInstall != null && !modulesToInstall.Contains(module.Name, StringComparer.OrdinalIgnoreCase))
                    {
                        add = false;
                    }

                    if (add)
                    {
                        base.Out.Verbose.WriteLine(string.Format("Adding module '{0}' from type '{1}'", module.Name, type));
                        if (AddModule(pkg, module))
                        {
                            count++;
                        }
                    }
                }
            }

            PackageLogic.Instance.Save();

            if (count > 0)
            {
                base.Out.Object.Table(TableRecords.CreatePackageRecordList(pkg));
            }
            else
            {
                base.Out.Standard.WriteLine("No modules could be found to load");
            }
        }
コード例 #7
0
        public override void Invoke(CommandInvocationContext context)
        {
            var asm = LoadAssembly();

            List <string> modulesToInstall = null;

            if (!string.IsNullOrWhiteSpace(Modules))
            {
                modulesToInstall = new List <string>(Modules.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            }

            bool success = true;
            int  count   = 0;

            foreach (var type in asm.GetTypes())
            {
                if (type.GetInterface(typeof(IModule).FullName) != null)
                {
                    var  module  = (IModule)Activator.CreateInstance(type);
                    bool install = true;
                    if (modulesToInstall != null && !modulesToInstall.Contains(module.Name, StringComparer.OrdinalIgnoreCase))
                    {
                        install = false;
                    }

                    if (install)
                    {
                        base.Out.Verbose.WriteLine(string.Format("Loading module '{0}' from type '{1}'", module.Name, type));
                        if (!base.Host.Modules.Install(type, base.Out) && success)
                        {
                            success = false;
                        }
                        count++;
                    }
                }
            }

            if (success)
            {
                if (count > 0)
                {
                    base.Out.Standard.WriteLine("Modules loaded successfully");
                }
                else
                {
                    base.Out.Standard.WriteLine("No modules could be found to load");
                }
            }
            else
            {
                base.Out.Warning.WriteLine("The module installation finished with errors");
            }
        }
コード例 #8
0
        public override void Invoke(CommandInvocationContext context)
        {
            var commands = base.Host.Commands.ToList();

            if (!string.IsNullOrWhiteSpace(Filter))
            {
                commands = commands.Where(c => c.CommandName.ToUpper().Contains(Filter.ToUpper())).ToList();
            }

            List <dynamic> commandData = new List <dynamic>();

            foreach (var command in commands)
            {
                var module = base.Host.Modules.Where(m => m.CommandTypes.Contains(command.InputCommandType)).FirstOrDefault();

                bool add = true;
                if (!string.IsNullOrEmpty(Module) && !module.Name.Equals(Module))
                {
                    add = false;
                }

                if (add)
                {
                    if (Full.IsPresent)
                    {
                        commandData.Add(new
                        {
                            Name      = command.CommandName,
                            Aliases   = string.Join(", ", command.Aliases),
                            Module    = module == null ? string.Empty : module.Name,
                            Synopsis  = command.Synopsis ?? string.Empty,
                            @Type     = command.InputCommandType.FullName,
                            @Assembly = string.Format("{0}{1}{2}",
                                                      command.InputCommandType.Assembly,
                                                      Environment.NewLine,
                                                      command.InputCommandType.Assembly.CodeBase.Replace("file:///", string.Empty))
                        });
                    }
                    else
                    {
                        commandData.Add(new
                        {
                            Name     = command.CommandName,
                            Aliases  = string.Join(", ", command.Aliases),
                            Module   = module == null ? string.Empty : module.Name,
                            Synopsis = command.Synopsis ?? string.Empty
                        });
                    }
                }
            }

            base.Out.Object.Table(commandData);
        }
コード例 #9
0
        public override void Invoke(CommandInvocationContext context)
        {
            var ctx = new VariableContext()
            {
                Name        = Name,
                Description = Description
            };

            VariableContextLogic.Instance.VariableContextCollection.Contexts.Add(ctx);
            VariableContextLogic.Instance.Save();

            base.Out.Object.Table(TableRecords.CreateVariableContextRecordList(ctx));
        }
コード例 #10
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (string.IsNullOrEmpty(Context) && VariableContextLogic.Instance.CurrentContext == null)
            {
                base.Out.Error.WriteLine("There is no context set or specified - please specify or set a context first");
            }
            else
            {
                var ctx = VariableContextLogic.Instance.CurrentContext;
                if (!string.IsNullOrWhiteSpace(Context))
                {
                    ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase));
                }

                base.Out.Object.Table(TableRecords.CreateVariableRecordList(ctx.Variables.ToArray()));
            }
        }
コード例 #11
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (base.Host.Modules.Count > 0)
            {
                List <IModule> moduleList = new List <IModule>();
                foreach (var module in base.Host.Modules)
                {
                    moduleList.Add(module);
                }

                base.Out.Object.Table(Component.Modules.TableRecords.CreateModuleTableRecordList(moduleList.ToArray()));
            }
            else
            {
                base.Out.Object.Table(Component.Modules.TableRecords.CreateModuleTableRecordList());
            }
        }
コード例 #12
0
        public override void Invoke(CommandInvocationContext context)
        {
            var contextsToApply = new List <VariableContext>();

            if (!AllContexts.IsPresent) // apply to specified or default context
            {
                VariableContext ctx = null;
                if (string.IsNullOrEmpty(Context)) // try to use the current context
                {
                    if (VariableContextLogic.Instance.CurrentContext == null)
                    {
                        base.Out.Error.WriteLine("There is no context currently loaded and no context specified. Please load a context or specify a context using the 'Context' parameter first.");
                        return;
                    }

                    ctx = VariableContextLogic.Instance.CurrentContext;
                    base.Out.Verbose.WriteLine(string.Format("No context was specified - using the current context '{0}'", ctx.Name));
                }
                else // try to or use the specified context
                {
                    ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase));
                }

                contextsToApply.Add(ctx);
            }
            else // load all to apply to
            {
                base.Out.Verbose.WriteLine("Applying variable to all contexts");
                contextsToApply.AddRange(VariableContextLogic.Instance.VariableContextCollection.Contexts);
            }

            // apply to contexts

            var records = new List <VariableContextVariable>();

            foreach (var ctxToApply in contextsToApply)
            {
                var rec = ctxToApply.Variables.FirstOrDefault(v => v.Name.Equals(Name));
                if (rec != null)
                {
                    records.Add(rec);
                }
            }

            base.Out.Object.Table(TableRecords.CreateVariableRecordList(records.ToArray()));
        }
コード例 #13
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (VariableContextLogic.Instance.VariableContextCollection.Contexts.Count > 0)
            {
                var contextsToList = new List <VariableContext>(VariableContextLogic.Instance.VariableContextCollection.Contexts);

                if (!string.IsNullOrWhiteSpace(Filter))
                {
                    contextsToList = contextsToList.Where(e => e.Name.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) > -1).ToList();
                }

                base.Out.Object.Write(TableRecords.CreateVariableContextRecordList(contextsToList.ToArray()));
            }
            else
            {
                base.Out.Object.Write(TableRecords.CreateVariableContextRecordList());
            }
        }
コード例 #14
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (base.Confirm("The module will be removed."))
            {
                var pkg = PackageLogic.Instance.PackagesCollection.Packages
                          .FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase));

                pkg.Modules.Remove(pkg.Modules.FirstOrDefault(m => m.Name.Equals(Module, StringComparison.OrdinalIgnoreCase)));

                PackageLogic.Instance.Save();

                base.Out.Object.Table(TableRecords.CreatePackageRecordList(pkg));

                if (PackageLogic.Instance.LoadedPackages.Contains(pkg))
                {
                    base.Out.Warning.WriteLine("This package is currently loaded and must be reloaded before the changes will take effect");
                }
            }
        }
コード例 #15
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (PackageLogic.Instance.PackagesCollection.Packages
                .Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)))
            {
                base.Out.Warning.WriteLine(string.Format("The package name '{0}' is already being used by another package", Name));
            }
            else
            {
                var newPkg = new Packages.Package()
                {
                    Name = Name
                };

                PackageLogic.Instance.PackagesCollection.Packages.Add(newPkg);
                PackageLogic.Instance.Save();

                base.Out.Object.Write(TableRecords.CreatePackageRecordList(newPkg));
            }
        }
コード例 #16
0
        public override void Invoke(CommandInvocationContext context)
        {
            var ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase));

            if (VariableContextLogic.Instance.CurrentContext == ctx && !Force.IsPresent)
            {
                base.Out.Warning.WriteLine("The context is loaded. Unload the context, or use the 'Force' switch");
            }
            else
            {
                if (base.Confirm("The context along with all associated variables will be deleted. This cannot be undone.", Component.ConfirmationResult.No))
                {
                    VariableContextLogic.Instance.VariableContextCollection.Contexts.Remove(ctx);
                    VariableContextLogic.Instance.Save();

                    base.Out.Standard.WriteLine("Variable context deleted.");
                }
                else
                {
                    base.Out.Standard.WriteLine("The variable context has NOT been deleted.");
                }
            }
        }
コード例 #17
0
        public override void Invoke(CommandInvocationContext context)
        {
            var def = base.Host.Commands.FirstOrDefault(c => c.CommandName.Equals(CommandName, StringComparison.OrdinalIgnoreCase) ||
                                                        c.Aliases.Contains(CommandName, StringComparer.OrdinalIgnoreCase));

            WriteHeaderHelp(def);
            WriteSyntax(def);
            WriteParameters(def);
            WriteSwitches(def);

            var cmd = Host.CommandActivatorContainer.Get(def.InputCommandType);

            if (Details.IsPresent)
            {
                WriteDetails(cmd);
            }
            if (Examples.IsPresent)
            {
                WriteExamples(cmd);
            }

            base.Out.Standard.WriteLine();
        }
コード例 #18
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (PackageLogic.Instance.PackagesCollection.Packages.Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)))
            {
                if (PackageLogic.Instance.LoadedPackages.Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)) &&
                    !Force.IsPresent)
                {
                    base.Out.Warning.WriteLine("The package is loaded. Unload the package, or use the 'Force' switch to unload the package before removing.");
                }
                else
                {
                    if (base.Confirm("The package along with all associated modules will be deleted. This cannot be undone.", Component.ConfirmationResult.No))
                    {
                        var pkg = PackageLogic.Instance.PackagesCollection.Packages.FirstOrDefault(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase));

                        if (PackageLogic.Instance.LoadedPackages.Exists(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            PackageLogic.Instance.Unload(pkg, base.Host.Modules, base.Out);
                            base.Out.Standard.WriteLine("Package unloaded.");
                        }

                        PackageLogic.Instance.Remove(pkg, base.Host.Modules, base.Out);
                        PackageLogic.Instance.Save();

                        base.Out.Standard.WriteLine("Package deleted.");
                    }
                    else
                    {
                        base.Out.Standard.WriteLine("The package has NOT been deleted.");
                    }
                }
            }
            else
            {
                base.Out.Standard.WriteLine("Package could not be found.");
            }
        }
コード例 #19
0
 public override void Invoke(CommandInvocationContext context)
 {
     VariableContextLogic.Instance.DiscardChanges();
     Process.Start(new ProcessStartInfo(VariableContextLogic.FILE_PATH_VARIABLES));
     base.Out.Warning.WriteLine("Any changes made to the variables context file will require a restart of the application to take effect. Also, any updates made to the file from within the console may overwrite your changes.");
 }
コード例 #20
0
 public override void Invoke(CommandInvocationContext context)
 {
     base.Host.Clear();
 }
コード例 #21
0
 public override void Invoke(CommandInvocationContext context)
 {
     Process.Start(new ProcessStartInfo("explorer.exe", new UserAssemblyRepository().UserAssemblyDirectoryPath));
 }
コード例 #22
0
 public override void Invoke(CommandInvocationContext context)
 {
     Out.Standard.WriteLine(_dep.Id);
 }
コード例 #23
0
 public override void Invoke(CommandInvocationContext context)
 {
     PackageLogic.Instance.Load(PackageLogic.Instance.PackagesCollection.Packages
                                .FirstOrDefault(e => e.Name.Equals(Package, StringComparison.OrdinalIgnoreCase)), base.Host.Modules, base.Out);
 }
コード例 #24
0
        public override void Invoke(CommandInvocationContext context)
        {
            var contextsToApply = new List <VariableContext>();

            if (!AllContexts.IsPresent) // apply to specified or default context
            {
                VariableContext ctx = null;
                if (string.IsNullOrEmpty(Context)) // try to use the current context
                {
                    if (VariableContextLogic.Instance.CurrentContext == null)
                    {
                        base.Out.Error.WriteLine("There is no context currently loaded and no context specified. Please load a context or specify a context using the 'Context' parameter first.");
                        return;
                    }

                    ctx = VariableContextLogic.Instance.CurrentContext;
                    base.Out.Verbose.WriteLine(string.Format("No context was specified - using the current context '{0}'", ctx.Name));
                }
                else // try to create and / or use the specified context
                {
                    ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase));
                    if (ctx == null && base.Confirm(string.Format("The context '{0}' does not exist and will be created", Context), Component.ConfirmationResult.Yes))
                    {
                        ctx = new VariableContext()
                        {
                            Name = Context
                        };
                        VariableContextLogic.Instance.VariableContextCollection.Contexts.Add(ctx);
                        VariableContextLogic.Instance.Save();
                    }

                    if (ctx == null)
                    {
                        base.Out.Error.WriteLine("The variable could not be set because the context was not created");
                        return;
                    }
                }

                contextsToApply.Add(ctx);
            }
            else // load all to apply to
            {
                base.Out.Verbose.WriteLine("Applying variable to all contexts");
                contextsToApply.AddRange(VariableContextLogic.Instance.VariableContextCollection.Contexts);
            }

            // apply to contexts

            foreach (var ctxToApply in contextsToApply)
            {
                if (ctxToApply.Variables.Any(v => v.Name.Equals(Name)))
                {
                    if (AllContexts.IsPresent)
                    {
                        base.Out.Verbose.WriteLine(string.Format("Updating variable '{0}' for context '{1}' with value '{2}'"
                                                                 , Name, ctxToApply.Name, Value));
                    }
                    else
                    {
                        base.Out.Verbose.WriteLine(string.Format("Updating variable '{0}' with value '{1}'"
                                                                 , Name, Value));
                    }

                    ctxToApply.Variables.FirstOrDefault(v => v.Name.Equals(Name)).Value = Value;
                }
                else
                {
                    if (AllContexts.IsPresent)
                    {
                        base.Out.Verbose.WriteLine(string.Format("Creating variable '{0}' for context '{1}' with value '{2}'"
                                                                 , Name, ctxToApply.Name, Value));
                    }
                    else
                    {
                        base.Out.Verbose.WriteLine(string.Format("Creating variable '{0}' with value '{1}"
                                                                 , Name, Value));
                    }

                    ctxToApply.Variables.Add(new VariableContextVariable()
                    {
                        Name  = Name,
                        Value = Value
                    });
                }
            }

            VariableContextLogic.Instance.Save();

            base.Out.Object.Table(TableRecords.CreateVariableRecordList(new VariableContextVariable()
            {
                Name  = Name,
                Value = Value
            }));
        }
コード例 #25
0
 public override void Invoke(CommandInvocationContext context)
 {
     PackageLogic.Instance.Unload(PackageLogic.Instance.LoadedPackages
                                  .FirstOrDefault(e => e.Name.Equals(Name, StringComparison.OrdinalIgnoreCase)), base.Host.Modules, base.Out);
     base.Out.Standard.WriteLine("Package unloaded.");
 }
コード例 #26
0
 public override void Invoke(CommandInvocationContext context)
 {
     base.Out.Object.Table(TableRecords.CreateModuleTableRecordList(false, AssemblyUtil.GetAssemblyModules(Assembly).ToArray()));
 }
コード例 #27
0
        public override void Invoke(CommandInvocationContext context)
        {
            if (base.Confirm(string.Format("The variable '{0}' will be deleted - this cannot be undone", Name), Component.ConfirmationResult.Yes))
            {
                var contextsToApply = new List <VariableContext>();

                if (!AllContexts.IsPresent) // apply to specified or default context
                {
                    VariableContext ctx = null;
                    if (string.IsNullOrEmpty(Context)) // try to use the current context
                    {
                        if (VariableContextLogic.Instance.CurrentContext == null)
                        {
                            base.Out.Error.WriteLine("There is no context currently loaded and no context specified. Please load a context or specify a context using the 'Context' parameter first.");
                            return;
                        }

                        ctx = VariableContextLogic.Instance.CurrentContext;
                        base.Out.Verbose.WriteLine(string.Format("No context was specified - using the current context '{0}'", ctx.Name));
                    }
                    else // try to or use the specified context
                    {
                        ctx = VariableContextLogic.Instance.VariableContextCollection.Contexts.FirstOrDefault(c => c.Name.Equals(Context, StringComparison.OrdinalIgnoreCase));
                    }

                    contextsToApply.Add(ctx);
                }
                else // load all to apply to
                {
                    base.Out.Verbose.WriteLine("Applying variable to all contexts");
                    contextsToApply.AddRange(VariableContextLogic.Instance.VariableContextCollection.Contexts);
                }

                // apply to contexts

                foreach (var ctxToApply in contextsToApply)
                {
                    if (ctxToApply.Variables.Any(v => v.Name.Equals(Name)))
                    {
                        if (AllContexts.IsPresent)
                        {
                            base.Out.Verbose.WriteLine(string.Format("Deleting variable '{0}' for context '{1}'"
                                                                     , Name, ctxToApply.Name));
                        }
                        else
                        {
                            base.Out.Verbose.WriteLine(string.Format("Deleting variable '{0}'"
                                                                     , Name));
                        }

                        ctxToApply.Variables.Remove(ctxToApply.Variables.FirstOrDefault(v => v.Name.Equals(Name)));
                    }
                }

                VariableContextLogic.Instance.Save();
            }
            else
            {
                base.Out.Standard.WriteLine("The variable was NOT deleted.");
            }
        }
コード例 #28
0
 public abstract void Invoke(CommandInvocationContext context);