Exemplo n.º 1
0
    private string getHelp(string cmd)
    {
      if (cmd.IsNullOrEmpty()) return string.Empty;

      var target = Cmdlets.FirstOrDefault(c => c.Name.EqualsOrdIgnoreCase(cmd));
      if (target == null)  return string.Empty;

      var result = new StringBuilder(1024);
      result.AppendLine(AppRemoteTerminal.MARKUP_PRAGMA);
      result.AppendLine("<push>");

      string help;
      using (var inst = Activator.CreateInstance(target, this, null) as Cmdlet)
      {
        try
        {
          App.DependencyInjector.InjectInto(inst);
          help = inst.GetHelp();
        }
        catch (Exception error)
        {
          help = "Error getting help: " + error.ToMessageWithType();
        }
        result.AppendLine("<f color=white><j width=8 dir=right text=\"{0}\"><f color=gray> - {1}".Args(cmd, help));
      }
      result.AppendLine("<pop>");

      return result.ToString();
    }
Exemplo n.º 2
0
        protected virtual string DoExecute(IConfigSectionNode command)
        {
            var cname = command.Name.ToLowerInvariant();

            var tp = Cmdlets.FirstOrDefault(cmd => cmd.Name.EqualsIgnoreCase(cname));

            if (tp == null)
            {
                return(Sky.StringConsts.RT_CMDLET_DONTKNOW_ERROR.Args(cname));
            }

            //Check cmdlet security
            Permission.AuthorizeAndGuardAction(App, tp);
            Permission.AuthorizeAndGuardAction(App, tp.GetMethod(nameof(Execute)));

            var cmdlet = Activator.CreateInstance(tp, this, command) as Cmdlet;

            if (cmdlet == null)
            {
                throw new SkyException(Sky.StringConsts.RT_CMDLET_ACTIVATION_ERROR.Args(cname));
            }

            using (cmdlet)
            {
                App.DependencyInjector.InjectInto(cmdlet);
                return(cmdlet.Execute());
            }
        }
 public void SetModule(ModuleObject moduleObject)
 {
     module = moduleObject;
     foreach (CmdletObject cmdlet in module.Cmdlets)
     {
         Cmdlets.Add(new OnlinePublishEntry {
             Cmdlet = cmdlet
         });
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a deep clone of the module data object.
 /// </summary>
 public object Clone()
 {
     return(new ModuleData()
     {
         Guid = Guid,
         Variables = (string[])Variables?.Clone(),
         Aliases = (JsonCaseInsensitiveStringDictionary <string>)Aliases?.Clone(),
         Cmdlets = (JsonCaseInsensitiveStringDictionary <CmdletData>)Cmdlets?.Clone(),
         Functions = (JsonCaseInsensitiveStringDictionary <FunctionData>)Functions?.Clone(),
     });
 }
Exemplo n.º 5
0
 public NeoCmdSnapIn()
 {
     foreach (var type in typeof(NeoCmdSnapIn).Assembly.GetTypes())
     {
         var attr = type.GetCustomAttribute <CmdletAttribute>();
         if (attr != null)
         {
             Cmdlets.Add(new CmdletConfigurationEntry(attr.VerbName + "-" + attr.NounName, type, attr.HelpUri));
         }
     }
 }         // ctor
 public SharpSvnSnapIn()
     : base()
 {
     foreach (Type t in typeof(SharpSvnSnapIn).Assembly.GetTypes())
     {
         CmdletConfigurationEntry entry = GetEntry(t);
         if (entry != null)
         {
             Cmdlets.Add(entry);
         }
     }
 }