Beispiel #1
0
        /// <summary>
        /// Returns null if memberName is not a member in the adapter or
        /// the corresponding PSMemberInfo
        /// </summary>
        /// <param name="obj">object to retrieve the PSMemberInfo from</param>
        /// <param name="memberName">name of the member to be retrieved</param>
        /// <returns>The PSMemberInfo corresponding to memberName from obj</returns>
        protected override T GetMember <T>(object obj, string memberName)
        {
            ComProperty prop;

            if (_comTypeInfo.Properties.TryGetValue(memberName, out prop))
            {
                if (prop.IsParameterized)
                {
                    if (typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty)))
                    {
                        return(new PSParameterizedProperty(prop.Name, this, obj, prop) as T);
                    }
                }
                else if (typeof(T).IsAssignableFrom(typeof(PSProperty)))
                {
                    return(new PSProperty(prop.Name, this, obj, prop) as T);
                }
            }

            ComMethod method;

            if (typeof(T).IsAssignableFrom(typeof(PSMethod)) &&
                (_comTypeInfo != null) && (_comTypeInfo.Methods.TryGetValue(memberName, out method)))
            {
                PSMethod mshMethod = new PSMethod(method.Name, this, obj, method);
                return(mshMethod as T);
            }

            return(null);
        }
Beispiel #2
0
        public override PSMemberInfo Copy()
        {
            PSMethod destiny = new PSMethod(base.name, this.adapter, this.baseObject, this.adapterData, this.isSpecial);

            base.CloneBaseProperties(destiny);
            return(destiny);
        }
Beispiel #3
0
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ManagementObject    baseObject  = method.baseObject as ManagementObject;
            WMIMethodCacheEntry adapterData = (WMIMethodCacheEntry)method.adapterData;

            return(this.AuxillaryInvokeMethod(baseObject, adapterData, arguments));
        }
Beispiel #4
0
        public override PSMemberInfo Copy()
        {
            PSMethod psMethod = new PSMethod(this.name, this.adapter, this.baseObject, this.adapterData, this.isSpecial);

            this.CloneBaseProperties((PSMemberInfo)psMethod);
            return((PSMemberInfo)psMethod);
        }
Beispiel #5
0
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ParameterInformation[] arguments1 = new ParameterInformation[arguments.Length];
            for (int index = 0; index < arguments.Length; ++index)
            {
                arguments1[index] = new ParameterInformation(typeof(object), false, (object)null, false);
            }
            MethodInformation[] methods = new MethodInformation[1]
            {
                new MethodInformation(false, false, arguments1)
            };
            object[] newArguments;
            Adapter.GetBestMethodAndArguments(method.Name, methods, arguments, out newArguments);
            DirectoryEntry baseObject = (DirectoryEntry)method.baseObject;
            Exception      exception;

            try
            {
                return(baseObject.Invoke(method.Name, newArguments));
            }
            catch (DirectoryServicesCOMException ex)
            {
                exception = (Exception)ex;
            }
            catch (TargetInvocationException ex)
            {
                exception = (Exception)ex;
            }
            catch (COMException ex)
            {
                exception = (Exception)ex;
            }
            return((DirectoryEntryAdapter.dotNetAdapter.GetDotNetMethod <PSMethod>(method.baseObject, method.name) ?? throw exception).Invoke(arguments));
        }
Beispiel #6
0
 protected override T GetMember <T>(object obj, string memberName)
 {
     if (this._comTypeInfo.Properties.ContainsKey(memberName))
     {
         ComProperty adapterData = this._comTypeInfo.Properties[memberName];
         if (adapterData.IsParameterized)
         {
             if (typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty)))
             {
                 return(new PSParameterizedProperty(adapterData.Name, this, obj, adapterData) as T);
             }
         }
         else if (typeof(T).IsAssignableFrom(typeof(PSProperty)))
         {
             return(new PSProperty(adapterData.Name, this, obj, adapterData) as T);
         }
     }
     if ((typeof(T).IsAssignableFrom(typeof(PSMethod)) && (this._comTypeInfo != null)) && this._comTypeInfo.Methods.ContainsKey(memberName))
     {
         ComMethod method  = this._comTypeInfo.Methods[memberName];
         PSMethod  method2 = new PSMethod(method.Name, this, obj, method);
         return(method2 as T);
     }
     return(default(T));
 }
Beispiel #7
0
        protected override Collection <string> MethodDefinitions(PSMethod method)
        {
            WMIMethodCacheEntry adapterData = (WMIMethodCacheEntry)method.adapterData;

            return(new Collection <string> {
                adapterData.MethodDefinition
            });
        }
Beispiel #8
0
        /// <summary>
        /// Called after a non null return from GetMember to return the overloads
        /// </summary>
        /// <param name="method">the return of GetMember</param>
        /// <returns></returns>
        protected override Collection <String> MethodDefinitions(PSMethod method)
        {
            WMIMethodCacheEntry methodEntry = (WMIMethodCacheEntry)method.adapterData;
            Collection <string> returnValue = new Collection <string>();

            returnValue.Add(methodEntry.MethodDefinition);

            return(returnValue);
        }
Beispiel #9
0
        /// <summary>
        /// Called after a non null return from GetMember to try to call
        /// the method with the arguments
        /// </summary>
        /// <param name="method">the non empty return from GetMethods</param>
        /// <param name="arguments">the arguments to use</param>
        /// <returns>the return value for the method</returns>
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ParameterInformation[] parameters = new ParameterInformation[arguments.Length];

            for (int i = 0; i < arguments.Length; i++)
            {
                parameters[i] = new ParameterInformation(typeof(System.Object), false, null, false);
            }

            MethodInformation[] methodInformation = new MethodInformation[1];
            methodInformation[0] = new MethodInformation(false, false, parameters);

            object[] newArguments;
            GetBestMethodAndArguments(method.Name, methodInformation, arguments, out newArguments);

            DirectoryEntry entry = (DirectoryEntry)method.baseObject;

            // First try to invoke method on the native adsi object. If the method
            // call fails, try to invoke dotnet method with same name, if one available.
            // This will ensure dotnet methods are exposed for DE objects.
            // The problem is in GetMember<T>(), DE adapter cannot check if a requested
            // method is available as it doesn't have access to native adsi object's
            // method metadata. So GetMember<T> returns PSMethod assuming a method
            // is available. This behavior will never give a chance to dotnet adapter
            // to resolve method call. So the DE adapter owns calling dotnet method
            // if one available.
            Exception exception;

            try
            {
                return(entry.Invoke(method.Name, newArguments));
            }
            catch (DirectoryServicesCOMException dse)
            {
                exception = dse;
            }
            catch (TargetInvocationException tie)
            {
                exception = tie;
            }
            catch (COMException ce)
            {
                exception = ce;
            }

            // this code is reached only on exception
            // check if there is a dotnet method, invoke the dotnet method if available
            PSMethod dotNetmethod = s_dotNetAdapter.GetDotNetMethod <PSMethod>(method.baseObject, method.name);

            if (null != dotNetmethod)
            {
                return(dotNetmethod.Invoke(arguments));
            }
            // else
            throw exception;
        }
Beispiel #10
0
        /// <summary>
        /// Called after a non null return from GetMember to try to call
        /// the method with the arguments
        /// </summary>
        /// <param name="method">the non empty return from GetMethods</param>
        /// <param name="arguments">the arguments to use</param>
        /// <returns>the return value for the method</returns>
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ManagementObject mgmtObject = method.baseObject as ManagementObject;

            Diagnostics.Assert(mgmtObject != null,
                               "Object is not of ManagementObject type");

            WMIMethodCacheEntry methodEntry = (WMIMethodCacheEntry)method.adapterData;

            return(AuxillaryInvokeMethod(mgmtObject, methodEntry, arguments));
        }
Beispiel #11
0
        protected virtual string MethodToString(PSMethod method)
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (string methodDefinition in this.MethodDefinitions(method))
            {
                stringBuilder.Append(methodDefinition);
                stringBuilder.Append(", ");
            }
            stringBuilder.Remove(stringBuilder.Length - 2, 2);
            return(stringBuilder.ToString());
        }
Beispiel #12
0
 internal object BaseMethodInvoke(PSMethod method, params object[] arguments)
 {
     try
     {
         return(this.MethodInvoke(method, arguments));
     }
     catch (TargetInvocationException ex)
     {
         Exception innerException = ex.InnerException == null ? (Exception)ex : ex.InnerException;
         throw new MethodInvocationException("CatchFromBaseAdapterMethodInvokeTI", innerException, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
         {
             (object)method.Name,
             (object)arguments.Length,
             (object)innerException.Message
         });
     }
     catch (FlowControlException ex)
     {
         throw;
     }
     catch (ScriptCallDepthException ex)
     {
         throw;
     }
     catch (PipelineStoppedException ex)
     {
         throw;
     }
     catch (Exception ex)
     {
         if (ex is MethodException)
         {
             throw;
         }
         else
         {
             CommandProcessorBase.CheckForSevereException(ex);
             if (method.baseObject is SteppablePipeline && (method.Name.Equals("Begin", StringComparison.OrdinalIgnoreCase) || method.Name.Equals("Process", StringComparison.OrdinalIgnoreCase) || method.Name.Equals("End", StringComparison.OrdinalIgnoreCase)))
             {
                 throw;
             }
             else
             {
                 throw new MethodInvocationException("CatchFromBaseAdapterMethodInvoke", ex, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
                 {
                     (object)method.Name,
                     (object)arguments.Length,
                     (object)ex.Message
                 });
             }
         }
     }
 }
        protected override string MethodToString(PSMethod method)
        {
            StringBuilder builder = new StringBuilder();

            foreach (string str in this.MethodDefinitions(method))
            {
                builder.Append(str);
                builder.Append(", ");
            }
            builder.Remove(builder.Length - 2, 2);
            return(builder.ToString());
        }
Beispiel #14
0
        /// <summary>
        /// Returns the string representation of the method in the object
        /// </summary>
        /// <returns>the string representation of the method in the object</returns>
        protected override string MethodToString(PSMethod method)
        {
            StringBuilder returnValue = new StringBuilder();

            foreach (string overload in MethodDefinitions(method))
            {
                returnValue.Append(overload);
                returnValue.Append(", ");
            }
            returnValue.Remove(returnValue.Length - 2, 2);
            return(returnValue.ToString());
        }
Beispiel #15
0
        /// <summary>
        ///  Invokes the method on object
        /// </summary>
        /// <param name="method">represents the instance of the method we want to invoke</param>
        /// <param name="arguments">parameters to be passed to the method</param>
        /// <returns>returns the value of method call</returns>
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            try
            {
                object[] newarguments;
                var      methods    = ComUtil.GetMethodInformationArray(_typeInfo, _methods, false);
                var      bestMethod = (ComMethodInformation)Adapter.GetBestMethodAndArguments(Name, methods, arguments, out newarguments);

                object returnValue = ComInvoker.Invoke(method.baseObject as IDispatch,
                                                       bestMethod.DispId, newarguments,
                                                       ComInvoker.GetByRefArray(bestMethod.parameters,
                                                                                newarguments.Length,
                                                                                isPropertySet: false),
                                                       COM.INVOKEKIND.INVOKE_FUNC);
                Adapter.SetReferences(newarguments, bestMethod, arguments);
                return(bestMethod.ReturnType != typeof(void) ? returnValue : AutomationNull.Value);
            }
            catch (TargetInvocationException te)
            {
                //First check if this is a severe exception.
                CommandProcessorBase.CheckForSevereException(te.InnerException);

                var innerCom = te.InnerException as COMException;
                if (innerCom == null || innerCom.HResult != ComUtil.DISP_E_MEMBERNOTFOUND)
                {
                    string message = te.InnerException == null ? te.Message : te.InnerException.Message;
                    throw new MethodInvocationException(
                              "ComMethodTargetInvocation",
                              te,
                              ExtendedTypeSystem.MethodInvocationException,
                              method.Name, arguments.Length, message);
                }
            }
            catch (COMException ce)
            {
                if (ce.HResult != ComUtil.DISP_E_UNKNOWNNAME)
                {
                    throw new MethodInvocationException(
                              "ComMethodCOMException",
                              ce,
                              ExtendedTypeSystem.MethodInvocationException,
                              method.Name, arguments.Length, ce.Message);
                }
            }
            return(null);
        }
Beispiel #16
0
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            Type         type       = method.baseObject.GetType();
            BindingFlags invokeAttr = BindingFlags.IgnoreCase | BindingFlags.InvokeMethod;

            try
            {
                object[]             newArguments;
                ComMethodInformation methodAndArguments = (ComMethodInformation)Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])ComUtil.GetMethodInformationArray(this.typeInfo, this.methods, false), arguments, out newArguments);
                object obj = type.InvokeMember(this.Name, invokeAttr, (Binder)null, method.baseObject, newArguments, ComUtil.GetModifiers(methodAndArguments.parameters), CultureInfo.CurrentCulture, (string[])null);
                Adapter.SetReferences(newArguments, (MethodInformation)methodAndArguments, arguments);
                return(methodAndArguments.ReturnType != typeof(void) ? obj : (object)AutomationNull.Value);
            }
            catch (TargetInvocationException ex)
            {
                CommandProcessorBase.CheckForSevereException(ex.InnerException);
                if (ex.InnerException is COMException innerException)
                {
                    if (innerException.ErrorCode == -2147352573)
                    {
                        goto label_9;
                    }
                }
                string str = ex.InnerException == null ? ex.Message : ex.InnerException.Message;
                throw new MethodInvocationException("ComMethodTargetInvocation", (Exception)ex, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
                {
                    (object)method.Name,
                    (object)arguments.Length,
                    (object)str
                });
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode != -2147352570)
                {
                    throw new MethodInvocationException("ComMethodCOMException", (Exception)ex, "ExtendedTypeSystem", "MethodInvocationException", new object[3]
                    {
                        (object)method.Name,
                        (object)arguments.Length,
                        (object)ex.Message
                    });
                }
            }
label_9:
            return((object)null);
        }
Beispiel #17
0
 protected override PSMemberInfoInternalCollection <T> GetMembers <T>(
     object obj)
 {
     using (ComAdapter.tracer.TraceMethod())
     {
         ComTypeInfo typeInfo = this.GetTypeInfo();
         PSMemberInfoInternalCollection <T> internalCollection = new PSMemberInfoInternalCollection <T>();
         if (typeInfo != null)
         {
             bool flag1 = typeof(T).IsAssignableFrom(typeof(PSProperty));
             bool flag2 = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty));
             if (flag1 || flag2)
             {
                 foreach (ComProperty comProperty in typeInfo.Properties.Values)
                 {
                     if (comProperty.IsParameterized)
                     {
                         if (flag2)
                         {
                             internalCollection.Add(new PSParameterizedProperty(comProperty.Name, (Adapter)this, obj, (object)comProperty) as T);
                         }
                     }
                     else if (flag1)
                     {
                         internalCollection.Add(new PSProperty(comProperty.Name, (Adapter)this, obj, (object)comProperty) as T);
                     }
                 }
             }
             if (typeof(T).IsAssignableFrom(typeof(PSMethod)))
             {
                 foreach (ComMethod comMethod in typeInfo.Methods.Values)
                 {
                     PSMethod psMethod = new PSMethod(comMethod.Name, (Adapter)this, obj, (object)comMethod);
                     if (!internalCollection.hashedMembers.Contains((object)comMethod.Name))
                     {
                         internalCollection.Add(psMethod as T);
                     }
                 }
             }
         }
         return(internalCollection);
     }
 }
Beispiel #18
0
 internal string BaseMethodToString(PSMethod method)
 {
     try
     {
         return(this.MethodToString(method));
     }
     catch (Exception ex)
     {
         CommandProcessorBase.CheckForSevereException(ex);
         if (ex is ExtendedTypeSystemException)
         {
             throw;
         }
         else
         {
             throw this.NewException(ex, "CatchFromBaseMethodToString", "CatchFromBaseMethodToStringTI", "ExceptionRetrievingMethodString", (object)method.Name);
         }
     }
 }
Beispiel #19
0
        /// <summary>
        /// Retrieves all the members available in the object.
        /// The adapter implementation is encouraged to cache all properties/methods available
        /// in the first call to GetMember and GetMembers so that subsequent
        /// calls can use the cache.
        /// In the case of the .NET adapter that would be a cache from the .NET type to
        /// the public properties and fields available in that type.
        /// In the case of the DirectoryEntry adapter, this could be a cache of the objectClass
        /// to the properties available in it.
        /// </summary>
        /// <param name="obj">object to get all the member information from</param>
        /// <returns>all members in obj</returns>
        protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj)
        {
            PSMemberInfoInternalCollection <T> collection = new PSMemberInfoInternalCollection <T>();

            bool lookingForProperties = typeof(T).IsAssignableFrom(typeof(PSProperty));
            bool lookingForParameterizedProperties = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty));

            if (lookingForProperties || lookingForParameterizedProperties)
            {
                foreach (ComProperty prop in _comTypeInfo.Properties.Values)
                {
                    if (prop.IsParameterized)
                    {
                        if (lookingForParameterizedProperties)
                        {
                            collection.Add(new PSParameterizedProperty(prop.Name, this, obj, prop) as T);
                        }
                    }
                    else if (lookingForProperties)
                    {
                        collection.Add(new PSProperty(prop.Name, this, obj, prop) as T);
                    }
                }
            }

            bool lookingForMethods = typeof(T).IsAssignableFrom(typeof(PSMethod));

            if (lookingForMethods)
            {
                foreach (ComMethod method in _comTypeInfo.Methods.Values)
                {
                    if (collection[method.Name] == null)
                    {
                        PSMethod mshmethod = new PSMethod(method.Name, this, obj, method);
                        collection.Add(mshmethod as T);
                    }
                }
            }

            return(collection);
        }
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            object[]  objArray;
            Exception exception = null;

            ParameterInformation[] informationArray = new ParameterInformation[arguments.Length];
            for (int i = 0; i < arguments.Length; i++)
            {
                informationArray[i] = new ParameterInformation(typeof(object), false, null, false);
            }
            MethodInformation[] methods = new MethodInformation[] { new MethodInformation(false, false, informationArray) };
            Adapter.GetBestMethodAndArguments(method.Name, methods, arguments, out objArray);
            DirectoryEntry baseObject = (DirectoryEntry)method.baseObject;

            try
            {
                return(baseObject.Invoke(method.Name, objArray));
            }
#if !MONO
            catch (DirectoryServicesCOMException exception2)
            {
                exception = exception2;
            }
#endif
            catch (TargetInvocationException exception3)
            {
                exception = exception3;
            }
            catch (COMException exception4)
            {
                exception = exception4;
            }
            PSMethod dotNetMethod = dotNetAdapter.GetDotNetMethod <PSMethod>(method.baseObject, method.name);
            if (dotNetMethod == null)
            {
                throw exception;
            }
            return(dotNetMethod.Invoke(arguments));
        }
Beispiel #21
0
        /// <summary>
        /// Returns the first PSMemberInfo whose name matches the specified <see cref="MemberNamePredicate"/>.
        /// </summary>
        protected override T GetFirstMemberOrDefault <T>(object obj, MemberNamePredicate predicate)
        {
            bool lookingForProperties = typeof(T).IsAssignableFrom(typeof(PSProperty));
            bool lookingForParameterizedProperties = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty));

            if (lookingForProperties || lookingForParameterizedProperties)
            {
                foreach (ComProperty prop in _comTypeInfo.Properties.Values)
                {
                    if (prop.IsParameterized &&
                        lookingForParameterizedProperties &&
                        predicate(prop.Name))
                    {
                        return(new PSParameterizedProperty(prop.Name, this, obj, prop) as T);
                    }

                    if (lookingForProperties && predicate(prop.Name))
                    {
                        return(new PSProperty(prop.Name, this, obj, prop) as T);
                    }
                }
            }

            bool lookingForMethods = typeof(T).IsAssignableFrom(typeof(PSMethod));

            if (lookingForMethods)
            {
                foreach (ComMethod method in _comTypeInfo.Methods.Values)
                {
                    if (predicate(method.Name))
                    {
                        var mshMethod = new PSMethod(method.Name, this, obj, method);
                        return(mshMethod as T);
                    }
                }
            }

            return(null);
        }
Beispiel #22
0
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            Type         type       = method.baseObject.GetType();
            BindingFlags invokeAttr = BindingFlags.InvokeMethod | BindingFlags.IgnoreCase;

            try
            {
                object[] objArray;
                ComMethodInformation[] informationArray  = ComUtil.GetMethodInformationArray(this.typeInfo, this.methods, false);
                ComMethodInformation   methodInformation = (ComMethodInformation)Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[])informationArray, arguments, out objArray);
                object obj2 = type.InvokeMember(this.Name, invokeAttr, null, method.baseObject, objArray, ComUtil.GetModifiers(methodInformation.parameters), CultureInfo.CurrentCulture, null);
                Adapter.SetReferences(objArray, methodInformation, arguments);
                if (methodInformation.ReturnType != typeof(void))
                {
                    return(obj2);
                }
                return(AutomationNull.Value);
            }
            catch (TargetInvocationException exception)
            {
                CommandProcessorBase.CheckForSevereException(exception.InnerException);
                COMException innerException = exception.InnerException as COMException;
                if ((innerException == null) || (innerException.ErrorCode != -2147352573))
                {
                    string str = (exception.InnerException == null) ? exception.Message : exception.InnerException.Message;
                    throw new MethodInvocationException("ComMethodTargetInvocation", exception, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, str });
                }
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode != -2147352570)
                {
                    throw new MethodInvocationException("ComMethodCOMException", exception3, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, exception3.Message });
                }
            }
            return(null);
        }
Beispiel #23
0
        protected override PSMemberInfoInternalCollection <T> GetMembers <T>(object obj)
        {
            PSMemberInfoInternalCollection <T> internals = new PSMemberInfoInternalCollection <T>();
            bool flag  = typeof(T).IsAssignableFrom(typeof(PSProperty));
            bool flag2 = typeof(T).IsAssignableFrom(typeof(PSParameterizedProperty));

            if (flag || flag2)
            {
                foreach (ComProperty property in this._comTypeInfo.Properties.Values)
                {
                    if (property.IsParameterized)
                    {
                        if (flag2)
                        {
                            internals.Add(new PSParameterizedProperty(property.Name, this, obj, property) as T);
                        }
                    }
                    else if (flag)
                    {
                        internals.Add(new PSProperty(property.Name, this, obj, property) as T);
                    }
                }
            }
            if (typeof(T).IsAssignableFrom(typeof(PSMethod)))
            {
                foreach (ComMethod method in this._comTypeInfo.Methods.Values)
                {
                    if (internals[method.Name] == null)
                    {
                        PSMethod method2 = new PSMethod(method.Name, this, obj, method);
                        internals.Add(method2 as T);
                    }
                }
            }
            return(internals);
        }
Beispiel #24
0
 internal object InvokeMethod(PSMethod method, object[] arguments)
 {
     Type type = method.baseObject.GetType();
     BindingFlags invokeAttr = BindingFlags.InvokeMethod | BindingFlags.IgnoreCase;
     try
     {
         object[] objArray;
         ComMethodInformation[] informationArray = ComUtil.GetMethodInformationArray(this.typeInfo, this.methods, false);
         ComMethodInformation methodInformation = (ComMethodInformation) Adapter.GetBestMethodAndArguments(this.Name, (MethodInformation[]) informationArray, arguments, out objArray);
         object obj2 = type.InvokeMember(this.Name, invokeAttr, null, method.baseObject, objArray, ComUtil.GetModifiers(methodInformation.parameters), CultureInfo.CurrentCulture, null);
         Adapter.SetReferences(objArray, methodInformation, arguments);
         if (methodInformation.ReturnType != typeof(void))
         {
             return obj2;
         }
         return AutomationNull.Value;
     }
     catch (TargetInvocationException exception)
     {
         CommandProcessorBase.CheckForSevereException(exception.InnerException);
         COMException innerException = exception.InnerException as COMException;
         if ((innerException == null) || (innerException.ErrorCode != -2147352573))
         {
             string str = (exception.InnerException == null) ? exception.Message : exception.InnerException.Message;
             throw new MethodInvocationException("ComMethodTargetInvocation", exception, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, str });
         }
     }
     catch (COMException exception3)
     {
         if (exception3.ErrorCode != -2147352570)
         {
             throw new MethodInvocationException("ComMethodCOMException", exception3, ExtendedTypeSystem.MethodInvocationException, new object[] { method.Name, arguments.Length, exception3.Message });
         }
     }
     return null;
 }
 protected override Collection<string> MethodDefinitions(PSMethod method)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #26
0
        protected override Collection <string> MethodDefinitions(PSMethod method)
        {
            ComMethod adapterData = (ComMethod)method.adapterData;

            return(adapterData.MethodDefinitions());
        }
 protected override object MethodInvoke(PSMethod method, object[] arguments)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Beispiel #28
0
 protected override object MethodInvoke(PSMethod method, PSMethodInvocationConstraints invocationConstraints, object[] arguments)
 {
     return(this.MethodInvoke(method, arguments));
 }
Beispiel #29
0
 protected abstract Collection <string> MethodDefinitions(PSMethod method);
Beispiel #30
0
 public override PSMemberInfo Copy()
 {
     PSMethod destiny = new PSMethod(base.name, this.adapter, this.baseObject, this.adapterData, this.isSpecial);
     base.CloneBaseProperties(destiny);
     return destiny;
 }
Beispiel #31
0
        /// <summary>
        /// Called after a non null return from GetMethodData to try to call
        /// the method with the arguments
        /// </summary>
        /// <param name="method">the non empty return from GetMethods</param>
        /// <param name="arguments">the arguments to use</param>
        /// <returns>the return value for the method</returns>
        protected override object MethodInvoke(PSMethod method, object[] arguments)
        {
            ComMethod commethod = (ComMethod)method.adapterData;

            return(commethod.InvokeMethod(method, arguments));
        }
Beispiel #32
0
        /// <summary>
        ///  Invokes the method on object
        /// </summary>
        /// <param name="method">represents the instance of the method we want to invoke</param>
        /// <param name="arguments">parameters to be passed to the method</param>
        /// <returns>returns the value of method call</returns>
        internal object InvokeMethod(PSMethod method, object[] arguments)
        {
            try
            {
                object[] newarguments;
                var methods = ComUtil.GetMethodInformationArray(_typeInfo, _methods, false);
                var bestMethod = (ComMethodInformation)Adapter.GetBestMethodAndArguments(Name, methods, arguments, out newarguments);

                object returnValue = ComInvoker.Invoke(method.baseObject as IDispatch,
                                                       bestMethod.DispId, newarguments,
                                                       ComInvoker.GetByRefArray(bestMethod.parameters,
                                                                                newarguments.Length,
                                                                                isPropertySet: false),
                                                       COM.INVOKEKIND.INVOKE_FUNC);
                Adapter.SetReferences(newarguments, bestMethod, arguments);
                return bestMethod.ReturnType != typeof(void) ? returnValue : AutomationNull.Value;
            }
            catch (TargetInvocationException te)
            {
                //First check if this is a severe exception.
                CommandProcessorBase.CheckForSevereException(te.InnerException);

                var innerCom = te.InnerException as COMException;
                if (innerCom == null || innerCom.HResult != ComUtil.DISP_E_MEMBERNOTFOUND)
                {
                    string message = te.InnerException == null ? te.Message : te.InnerException.Message;
                    throw new MethodInvocationException(
                        "ComMethodTargetInvocation",
                        te,
                        ExtendedTypeSystem.MethodInvocationException,
                        method.Name, arguments.Length, message);
                }
            }
            catch (COMException ce)
            {
                if (ce.HResult != ComUtil.DISP_E_UNKNOWNNAME)
                {
                    throw new MethodInvocationException(
                        "ComMethodCOMException",
                        ce,
                        ExtendedTypeSystem.MethodInvocationException,
                        method.Name, arguments.Length, ce.Message);
                }
            }
            return null;
        }
Beispiel #33
0
 protected override Collection <string> MethodDefinitions(PSMethod method) => new Collection <string>()
 {
     ((BaseWMIAdapter.WMIMethodCacheEntry)method.adapterData).MethodDefinition
 };
Beispiel #34
0
 protected override object MethodInvoke(PSMethod method, object[] arguments) => this.AuxillaryInvokeMethod(method.baseObject as ManagementObject, (BaseWMIAdapter.WMIMethodCacheEntry)method.adapterData, arguments);
Beispiel #35
0
        /// <summary>
        /// Called after a non null return from GetMethodData to return the overloads
        /// </summary>
        /// <param name="method">the return of GetMethodData</param>
        /// <returns></returns>
        protected override Collection <String> MethodDefinitions(PSMethod method)
        {
            ComMethod commethod = (ComMethod)method.adapterData;

            return(commethod.MethodDefinitions());
        }