コード例 #1
0
        /// <summary>
        /// Process parameters and create the filter list.
        /// </summary>
        protected override void InitializeFilters()
        {
            ProcessParameter(PublicFilter, !Force.IsPresent);
            ProcessParameter(AbstractFilter, Abstract.IsPresent);
            ProcessParameter(InterfaceFilter, Interface.IsPresent);
            ProcessParameter(ValueTypeFilter, ValueType.IsPresent);
            ProcessParameter <Type>(ParentFilter, InheritsType);
            ProcessParameter <Type>(ImplementsFilter, ImplementsInterface);
            ProcessNameParameters();

            if (FilterScript != null)
            {
                var filter = new ReflectionFilter(
                    (type, criteria) =>
                {
                    return(LanguagePrimitives.IsTrue(
                               FilterScript.InvokeWithContext(
                                   null,
                                   new List <PSVariable>()
                    {
                        new PSVariable("_", type)
                    },
                                   type)));
                });
                ProcessParameter(filter, true);
            }
        }
コード例 #2
0
    void UseObjectWithMachine()
    {
        // I hit a machine
        // do some stuff to update the machine and
        bool shouldAttachObject = false;

        switch (m_MachineHit.transform.tag)
        {
        case "Core":
            CoreScript core = GetHitComponent <CoreScript>(m_MachineHit);
            if (IsHoldingWithTag("PowerCell"))
            {
                shouldAttachObject = core.AddPower(m_Object, GetHeldCellCharge());
            }
            else if (IsHoldingWithTag("CoolingCell"))
            {
                shouldAttachObject = core.AddCooling(m_Object, GetHeldCellCharge());
            }
            break;

        case "Filter":
            FilterScript filter = GetHitComponent <FilterScript>(m_MachineHit);
            if (IsHoldingWithTag("FilterPickup"))
            {
                shouldAttachObject = filter.InsertFilter(m_Object);
            }
            break;

        case "Refiner":
            RefinerScript refiner = GetHitComponent <RefinerScript>(m_MachineHit);
            if (IsHoldingWithTag("PowerCell"))
            {
                shouldAttachObject = refiner.InsertCell(m_Object);
            }
            break;

        case "Radiator":
            RadiatorScript radiator = GetHitComponent <RadiatorScript>(m_MachineHit);
            if (IsHoldingWithTag("CoolingCell"))
            {
                shouldAttachObject = radiator.InsertCell(m_Object);
            }
            break;
        }
        // should only destroy if the interaction makes sense
        if (shouldAttachObject)
        {
            AttachObject();
        }
    }
コード例 #3
0
        /// <summary>
        /// Process input parameters and create the filter set.
        /// </summary>
        protected override void InitializeFilters()
        {
            _flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
            if (Force.IsPresent)
            {
                _flags |= BindingFlags.NonPublic;
            }

            if (Static.IsPresent && !Instance.IsPresent)
            {
                _flags &= ~BindingFlags.Instance;
            }

            if (Instance.IsPresent && !Static.IsPresent)
            {
                _flags &= ~BindingFlags.Static;
            }

            if (!Not.IsPresent)
            {
                ProcessParameter(SpecialNameFilter, !IncludeSpecialName.IsPresent);
            }

            ProcessName(Name, WildcardNameFilter, RegexNameFilter);
            ProcessParameter <Type>(ParameterTypeFilter, ParameterType);
            ProcessParameter <Type>(ReturnTypeFilter, ReturnType);
            ProcessParameter((m, fc) => m is MethodInfo method ? method.IsAbstract : false, Abstract.IsPresent);
            ProcessParameter((m, fc) => m is MethodInfo method ? method.IsVirtual : false, Virtual.IsPresent);

            if (FilterScript != null)
            {
                var filter = new ReflectionFilter(
                    (type, criteria) =>
                {
                    return(LanguagePrimitives.IsTrue(
                               FilterScript.InvokeWithContext(
                                   null,
                                   new List <PSVariable>()
                    {
                        new PSVariable("_", type)
                    },
                                   type)));
                });
                ProcessParameter(filter, true);
            }
        }
コード例 #4
0
 /// <summary>
 /// Process parameters and create the filter list.
 /// </summary>
 protected override void InitializeFilters()
 {
     ProcessName(Name, WildcardNameFilter, RegexNameFilter);
     ProcessName(FullName, WildcardNamespaceFilter, RegexNamespaceFilter);
     if (FilterScript != null)
     {
         var filter = new ReflectionFilter(
             (ns, criteria) =>
         {
             return(LanguagePrimitives.IsTrue(
                        FilterScript.InvokeWithContext(
                            null,
                            new List <PSVariable>()
             {
                 new PSVariable("_", ns)
             },
                            ns)));
         });
         ProcessParameter(filter, true);
     }
 }
コード例 #5
0
        /// <summary>
        /// Writes the Filterscript to XML Filepath
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="script"></param>
        /// <returns></returns>
        public bool WriteFilterScript(string fileName, FilterScript script)
        {
            var settings = new XmlWriterSettings
            {
                Indent             = true,
                OmitXmlDeclaration = true
            };

            var xml = new StringBuilder();

            using (var writer = XmlWriter.Create(xml, settings))
            {
                writer.WriteDocType("FilterScript", null, null, null);

                var nsSerializer = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });

                XmlSerializer xmlSerializer = new XmlSerializer(typeof(FilterScript));
                xmlSerializer.Serialize(writer, script, nsSerializer);
            }

            File.WriteAllText(fileName, xml.ToString());

            return(true);
        }
コード例 #6
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (FilterScript.Expression != null)
            {
                targetCommand.AddParameter("FilterScript", FilterScript.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Value.Expression != null)
            {
                targetCommand.AddParameter("Value", Value.Get(context));
            }

            if (EQ.Expression != null)
            {
                targetCommand.AddParameter("EQ", EQ.Get(context));
            }

            if (CEQ.Expression != null)
            {
                targetCommand.AddParameter("CEQ", CEQ.Get(context));
            }

            if (NE.Expression != null)
            {
                targetCommand.AddParameter("NE", NE.Get(context));
            }

            if (CNE.Expression != null)
            {
                targetCommand.AddParameter("CNE", CNE.Get(context));
            }

            if (GT.Expression != null)
            {
                targetCommand.AddParameter("GT", GT.Get(context));
            }

            if (CGT.Expression != null)
            {
                targetCommand.AddParameter("CGT", CGT.Get(context));
            }

            if (LT.Expression != null)
            {
                targetCommand.AddParameter("LT", LT.Get(context));
            }

            if (CLT.Expression != null)
            {
                targetCommand.AddParameter("CLT", CLT.Get(context));
            }

            if (GE.Expression != null)
            {
                targetCommand.AddParameter("GE", GE.Get(context));
            }

            if (CGE.Expression != null)
            {
                targetCommand.AddParameter("CGE", CGE.Get(context));
            }

            if (LE.Expression != null)
            {
                targetCommand.AddParameter("LE", LE.Get(context));
            }

            if (CLE.Expression != null)
            {
                targetCommand.AddParameter("CLE", CLE.Get(context));
            }

            if (Like.Expression != null)
            {
                targetCommand.AddParameter("Like", Like.Get(context));
            }

            if (CLike.Expression != null)
            {
                targetCommand.AddParameter("CLike", CLike.Get(context));
            }

            if (NotLike.Expression != null)
            {
                targetCommand.AddParameter("NotLike", NotLike.Get(context));
            }

            if (CNotLike.Expression != null)
            {
                targetCommand.AddParameter("CNotLike", CNotLike.Get(context));
            }

            if (Match.Expression != null)
            {
                targetCommand.AddParameter("Match", Match.Get(context));
            }

            if (CMatch.Expression != null)
            {
                targetCommand.AddParameter("CMatch", CMatch.Get(context));
            }

            if (NotMatch.Expression != null)
            {
                targetCommand.AddParameter("NotMatch", NotMatch.Get(context));
            }

            if (CNotMatch.Expression != null)
            {
                targetCommand.AddParameter("CNotMatch", CNotMatch.Get(context));
            }

            if (Contains.Expression != null)
            {
                targetCommand.AddParameter("Contains", Contains.Get(context));
            }

            if (CContains.Expression != null)
            {
                targetCommand.AddParameter("CContains", CContains.Get(context));
            }

            if (NotContains.Expression != null)
            {
                targetCommand.AddParameter("NotContains", NotContains.Get(context));
            }

            if (CNotContains.Expression != null)
            {
                targetCommand.AddParameter("CNotContains", CNotContains.Get(context));
            }

            if (In.Expression != null)
            {
                targetCommand.AddParameter("In", In.Get(context));
            }

            if (CIn.Expression != null)
            {
                targetCommand.AddParameter("CIn", CIn.Get(context));
            }

            if (NotIn.Expression != null)
            {
                targetCommand.AddParameter("NotIn", NotIn.Get(context));
            }

            if (CNotIn.Expression != null)
            {
                targetCommand.AddParameter("CNotIn", CNotIn.Get(context));
            }

            if (Is.Expression != null)
            {
                targetCommand.AddParameter("Is", Is.Get(context));
            }

            if (IsNot.Expression != null)
            {
                targetCommand.AddParameter("IsNot", IsNot.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }