Esempio n. 1
0
 internal virtual IEnumerable <T> ApplyClientSideFilter(IEnumerable <T> objectList)
 {
     if (this.CmdletSessionInfo.CmdletParameters.Contains("Filter"))
     {
         string str = this.CmdletSessionInfo.CmdletParameters["Filter"].ToString();
         if (str != "objectClass -like \"*\"")
         {
             List <T>                    ts            = new List <T>();
             ADFactoryBase <T>           aDFactoryBase = this;
             ConvertSearchFilterDelegate convertSearchFilterDelegate = new ConvertSearchFilterDelegate(aDFactoryBase.BuildSearchFilter);
             VariableExpressionConverter variableExpressionConverter = new VariableExpressionConverter(new EvaluateVariableDelegate(this.CmdletSessionInfo.CmdletBase.GetVariableValue));
             QueryParser                 queryParser = new QueryParser(str, variableExpressionConverter, convertSearchFilterDelegate);
             str = ADOPathUtil.ChangeNodeToWhereFilterSyntax(queryParser.FilterExpressionTree);
             StringBuilder stringBuilder = new StringBuilder("$args[0] | Where-Object -filterScript { ");
             stringBuilder.Append(str);
             stringBuilder.Append(" } ");
             object[] objArray = new object[1];
             objArray[0] = objectList;
             Collection <PSObject> pSObjects = this.CmdletSessionInfo.CmdletBase.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.None, null, objArray);
             foreach (PSObject pSObject in pSObjects)
             {
                 ts.Add((T)pSObject.BaseObject);
             }
             return(ts);
         }
         else
         {
             DebugLogger.LogInfo("ADFactoryBase", string.Format("Filter: Found MatchAnyObject filter: {0}", str));
             return(objectList);
         }
     }
     else
     {
         return(objectList);
     }
 }
 private bool GetADDCBeginFilterCSRoutine()
 {
     if (base.ParameterSetName == "Filter")
     {
         StringBuilder stringBuilder = null;
         this._cmdletParameters["Properties"] = this.ConstructPropertyListFromSet(AttributeSet.Extended);
         this._factory.SetCmdletSessionInfo(this.GetCmdletSessionInfo());
         this.ValidateParameters();
         base.BuildPropertySet();
         string str = this._cmdletParameters["Filter"].ToString();
         if (str != "objectClass -like \"*\"")
         {
             var f = this._factory;
             ConvertSearchFilterDelegate convertSearchFilterDelegate = new ConvertSearchFilterDelegate(f.BuildSearchFilter);
             VariableExpressionConverter variableExpressionConverter = new VariableExpressionConverter(new EvaluateVariableDelegate(this.EvaluateFilterVariable));
             QueryParser queryParser = new QueryParser(str, variableExpressionConverter, convertSearchFilterDelegate);
             str = ADOPathUtil.ChangeNodeToWhereFilterSyntax(queryParser.FilterExpressionTree);
             DebugLogger.LogInfo("GetADDomainController", string.Format("Filter: Converted where filter: {0}", str));
             stringBuilder = new StringBuilder("Where-Object -inputObject $args[0] -filterScript { ");
             stringBuilder.Append(str);
             stringBuilder.Append(" } ");
         }
         else
         {
             DebugLogger.LogInfo("GetADDomainController", string.Format("Filter: Found MatchAnyObject filter: {0}", str));
         }
         IEnumerable <ADDomainController> allDomainControllers = this._factory.GetAllDomainControllers(this._propertiesRequested);
         if (allDomainControllers != null)
         {
             if (stringBuilder != null)
             {
                 foreach (ADDomainController allDomainController in allDomainControllers)
                 {
                     try
                     {
                         object[] objArray = new object[1];
                         objArray[0] = allDomainController;
                         base.InvokeCommand.InvokeScript(stringBuilder.ToString(), false, PipelineResultTypes.Output, null, objArray);
                     }
                     catch (RuntimeException runtimeException1)
                     {
                         RuntimeException runtimeException = runtimeException1;
                         object[]         message          = new object[1];
                         message[0] = runtimeException.Message;
                         string str1 = string.Format(CultureInfo.CurrentCulture, "Filtering failed:  {0}", message);
                         DebugLogger.LogError("GetADDomainController", str1);
                         base.WriteError(new ErrorRecord(runtimeException, "0", ErrorCategory.ReadError, str));
                     }
                 }
             }
             else
             {
                 foreach (ADDomainController aDDomainController in allDomainControllers)
                 {
                     base.WriteObject(aDDomainController);
                 }
             }
             return(false);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }