Exemplo n.º 1
0
 public override void BeforeParse(ArgHook.HookContext context)
 {
     context.SetProperty("Year", 2013);
     context.SetProperty("Year", 2013);
     context.SetProperty("Name", "Adam");
     context.SetProperty("Name", "Adam");
 }
Exemplo n.º 2
0
            public override void AfterPopulateProperties(ArgHook.HookContext context)
            {
                Assert.IsTrue(context.HasProperty("Year"));
                Assert.IsTrue(context.HasProperty("Name"));

                var year = context.GetProperty <int>("Year");
                var name = context.GetProperty <string>("Name");

                Assert.AreEqual(2013, year);
                Assert.AreEqual("Adam", name);

                context.ClearProperty("Year");
                context.SetProperty <string>("Name", null);

                Assert.IsFalse(context.HasProperty("Year"));
                Assert.IsFalse(context.HasProperty("Name"));

                Assert.IsNull(context.GetProperty <string>("Name"));

                try
                {
                    context.GetProperty <int>("Year");
                    Assert.Fail("An exception should have been thrown");
                }
                catch (KeyNotFoundException)
                {
                    // Throw for value types, return null for reference types
                }

                WasRun = true;
            }
        internal PipelineStage CreateNextStage(ArgHook.HookContext context, string[] commandLine, ICommandLineArgumentsDefinitionFactory factory)
        {
            PipelineStage     next;
            CommandLineAction inProcAction;

            if (Stages.Count == 0)
            {
                next = new RootPipelineStage(commandLine);
            }
            else if (commandLine[0].StartsWith(ArgPipeline.PipelineStageActionIndicator) && ArgPipelineActionStage.TryCreateActionStage(commandLine, out next))
            {
                // do nothing, next is populated
            }
            else if (TryParseStageAction(context.Definition, commandLine[0], out inProcAction))
            {
                next = new InProcessPipelineStage(context.Definition, commandLine);
            }
            else if (ExternalPipelineProvider.TryLoadOutputStage(commandLine, out next) == false)
            {
                throw new UnexpectedArgException("The pipeline action '" + string.Join(" ", commandLine) + "' is not valid.  If you want to support piping between processes, learn how to here (TODO URL)");
            }

            next.CommandLineDefinitionFactory = factory;

            this.AddStage(next);
            return(next);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Makes sure that 'MustBeRevivable' is false for pipeline only arguments
 /// </summary>
 /// <param name="context">the processing context</param>
 public override void BeforeValidateDefinition(ArgHook.HookContext context)
 {
     EnforceOmittingFromUsageIfPipelineOnly(context);
     if (PipelineOnly)
     {
         context.CurrentArgument.MustBeRevivable = false;
     }
 }
Exemplo n.º 5
0
        private ArgPipelineManager GetPipelineManagerFromContext(ArgHook.HookContext context)
        {
            if (ContextHasPipelineManager(context) == false)
            {
                context.SetProperty("ArgPipelineManager", new ArgPipelineManager(Mode));
            }

            return(context.GetProperty <ArgPipelineManager>("ArgPipelineManager"));
        }
Exemplo n.º 6
0
        /// <summary>
        /// This is the main hook point where the pipeline features get injected.  This method is responsible for creating the pipeline if needed.  It is also
        /// responsible for connecting to an external program if this program was launched by another program's pipeline manager.  It is also responsible for
        /// supporting any pipeline stage actions (e.g. $filter) that are not supported if the [ArgPipeline] metadata is omitted from the root definition.
        /// </summary>
        /// <param name="context">The processing context</param>
        public override void BeforeParse(ArgHook.HookContext context)
        {
            ExternalPipelineInputStage externalStage;

            if (ExternalPipelineProvider.TryLoadInputStage(context.Definition, context.CmdLineArgs, out externalStage) && externalStage.IsProgramLaunchedByExternalPipeline)
            {
                externalStage.CommandLineDefinitionFactory = this.commandLineDeinitionFactory;
                while (externalStage.IsDrained == false)
                {
                    Thread.Sleep(10);
                }
                PowerLogger.LogLine("Input stage drained");
                context.CancelAllProcessing();
                return;
            }
            else if (context.CmdLineArgs.Contains(PowerArgsPipeIndicator))
            {
                ValidatePipeline(context);
                List <List <string> > stageCommandLines = new List <List <string> >();
                stageCommandLines.Add(new List <string>());

                for (int i = 0; i < context.CmdLineArgs.Length; i++)
                {
                    var arg = context.CmdLineArgs[i];
                    if (arg == PowerArgsPipeIndicator)
                    {
                        stageCommandLines.Add(new List <string>());
                    }
                    else
                    {
                        stageCommandLines.Last().Add(arg);
                    }
                }

                context.CmdLineArgs = stageCommandLines.First().ToArray();

                var manager = GetPipelineManagerFromContext(context);

                for (int i = 0; i < stageCommandLines.Count; i++)
                {
                    var args = stageCommandLines[i];
                    if (args.Count == 0)
                    {
                        throw new ArgException("Missing action after pipeline indicator: " + PowerArgsPipeIndicator);
                    }
                    manager.CreateNextStage(context, args.ToArray(), this.commandLineDeinitionFactory);
                }

                context.CmdLineArgs = manager.Stages[0].CmdLineArgs.ToArray();
            }
            else
            {
                // do nothing
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// If the given context contains the pipeline manager then this method will make sure the
        /// pipeline is drained before returning.
        /// </summary>
        /// <param name="context">The processing context</param>
        public override void AfterInvoke(ArgHook.HookContext context)
        {
            context.Definition.Clean();
            if (ContextHasPipelineManager(context) == false)
            {
                return;
            }
            var manager = GetPipelineManagerFromContext(context);

            manager.Drain();
        }
        public override void BeforeInvoke(ArgHook.HookContext context)
        {
            var action = context.SpecifiedAction;
            var storageAccountNameArgument = action.FindMatchingArgument("StorageAccountName");
            var storageAccountKeyArgument  = action.FindMatchingArgument("StorageAccountKey");

            if (storageAccountNameArgument != null && storageAccountKeyArgument != null)
            {
                CommandLineStorageConfigProvider.CommandLineAccountName = "" + storageAccountNameArgument.RevivedValue;
                CommandLineStorageConfigProvider.CommandLineAccountKey  = "" + storageAccountKeyArgument.RevivedValue;
                SharedStorageAccount.Reset(new CommandLineStorageConfigProvider());
            }
        }
 public override void AfterCancel(ArgHook.HookContext context)
 {
     AfterCancelCalled = true;
 }
Exemplo n.º 10
0
 public override void BeforeInvoke(ArgHook.HookContext context)
 {
     context.CancelAllProcessing();
 }
Exemplo n.º 11
0
 public override void BeforePrepareUsage(ArgHook.HookContext context)
 {
     context.Definition.ExeName = "UnitTests";
 }
Exemplo n.º 12
0
 private static bool ContextHasPipelineManager(ArgHook.HookContext context)
 {
     return(context.HasProperty("ArgPipelineManager"));
 }