示例#1
0
        public void Main()
        {
            object eval;

            if (PropertyName == "$item")
            {
                eval = FilterTarget;
            }
            else
            {
                var evalProp = FilterTarget.GetType().GetProperty(PropertyName);
                if (evalProp == null)
                {
                    return;
                }
                if (evalProp.GetGetMethod() == null)
                {
                    return;
                }

                eval = evalProp.GetValue(FilterTarget, null);
                if (eval == null)
                {
                    return;
                }
            }

            if (eval is string == false && (Operator == FilterOperators.Contains || Operator == FilterOperators.NotContains))
            {
                throw new ArgException("The Contains and NotContains operators can only be applied to properties of type string");
            }

            object comparison = Value;

            try
            {
                if (eval.GetType() != typeof(string))
                {
                    if (ArgRevivers.CanRevive(eval.GetType()))
                    {
                        comparison = ArgRevivers.Revive(eval.GetType(), "", comparison + "");
                    }
                }
            }
            catch (Exception ex)
            {
                PowerLogger.LogLine("Unable to convert a string to:" + eval.GetType().FullName);
                return;
            }

            if (FilterLogic.FilterAcceptsObject(eval, Operator, comparison))
            {
                ArgPipeline.Push(FilterTarget);
            }
        }
示例#2
0
 /// <summary>
 /// Non enumerable objects pass through.  Enumerable objects are enumerated and each item is passed through.
 /// </summary>
 /// <param name="o">The object to process</param>
 protected override void OnObjectReceived(object o)
 {
     if (o is IEnumerable == false)
     {
         ArgPipeline.Push(o);
     }
     else
     {
         foreach (var item in (IEnumerable)o)
         {
             ArgPipeline.Push(item);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Writes the table and optionally passes the objects through
        /// </summary>
        protected override void BeforeSetDrainedToTrue()
        {
            bool wrapped = false;

            if (commandLine.Length == 0)
            {
                wrapped     = true;
                commandLine = new string[] { "item" };
                elements    = elements.Select(e => (object)new { item = e }).ToList();
            }

            DocumentRenderer renderer = new DocumentRenderer();
            var template = "{{ table elements " + string.Join(" ", commandLine) + " !}}";
            var result   = renderer.Render(template, new { elements = elements });

            result.WriteLine();
            if (TableWritten != null)
            {
                TableWritten(template, elements, result);
            }

            if (passThrough == false)
            {
                return;
            }

            if (wrapped)
            {
                foreach (var item in elements)
                {
                    ArgPipeline.Push(item.GetType().GetProperty("item").GetValue(item, null), this);
                }
            }
            else
            {
                foreach (var item in elements)
                {
                    ArgPipeline.Push(item, this);
                }
            }
        }
示例#4
0
 /// <summary>
 /// Use this method to push an object to the given pipeline stage's next stage.  You should only use this
 /// for advanced scenarios where you're processing objects on a thread that was not created for you by
 /// PowerArgs.  If you're doing that and find the need to use this method, cool :).
 /// </summary>
 /// <param name="o">The object to push</param>
 /// <param name="current">The current pipeline stage.  The object is pushed to the next stage.</param>
 public static void Push(object o, PipelineStage current)
 {
     if (o == null)
     {
         if (ConsoleOutInterceptor.Instance.IsInitialized)
         {
             return;
         }
         ConsoleString.WriteLine("null object pushed through the pipeline", ConsoleColor.Yellow);
     }
     else if (current != null && current.NextStage != null && current.Manager != null)
     {
         current.Manager.Push(o, current);
     }
     else
     {
         ArgPipeline.FireObjectExited(o);
         if (ConsoleOutInterceptor.Instance.IsInitialized)
         {
             return;
         }
         PipelineOutputFormatter.Format(o).WriteLine();
     }
 }
示例#5
0
 /// <summary>
 /// Pushes the list of stored objects through the pipeline
 /// </summary>
 protected override void BeforeSetDrainedToTrue()
 {
     ArgPipeline.Push(objects, this);
 }