/// <summary> /// Intercept method calls /// </summary> /// <param name="myMessage"> /// Contains information about the method being called /// </param> /// <returns> /// A <see cref="ReturnMessage"/>. /// </returns> public override IMessage Invoke(IMessage myMessage) { IMethodCallMessage callMessage = myMessage as IMethodCallMessage; if (null == callMessage) { Debug.WriteLine("Message type not implemented: " + myMessage.GetType().ToString()); return null; } MethodInfo method = callMessage.MethodBase as MethodInfo; if (null == method) { Debug.WriteLine("Unrecognized Invoke call: " + callMessage.MethodBase.ToString()); return null; } object returnValue = null; object[] outArgs = null; int outArgsCount = 0; string methodName = method.Name; Type returnType = method.ReturnType; BindingFlags flags = BindingFlags.InvokeMethod; int argCount = callMessage.ArgCount; object invokeObject; Type invokeType; Type byValType; object[] args; object arg; COMWrapper[] originalArgs; COMWrapper wrapper; ParameterModifier[] argModifiers = null; ParameterInfo[] parameters = null; ParameterInfo parameter; if ("Dispose" == methodName && 0 == argCount && typeof(void) == returnType) { this.Dispose(); } else if ("ToString" == methodName && 0 == argCount && typeof(string) == returnType) { returnValue = this.ToString(); } else if ("GetType" == methodName && 0 == argCount && typeof(System.Type) == returnType) { returnValue = this._InterceptType; } else if ("GetHashCode" == methodName && 0 == argCount && typeof(int) == returnType) { returnValue = this.GetHashCode(); } else if ("Equals" == methodName && 1 == argCount && typeof(bool) == returnType) { returnValue = this.Equals(callMessage.Args[0]); } else if (1 == argCount && typeof(void) == returnType && (methodName.StartsWith("add_") || methodName.StartsWith("remove_"))) { bool removeHandler = methodName.StartsWith("remove_"); methodName = methodName.Substring(removeHandler ? 7 : 4); Delegate handler = callMessage.InArgs[0] as Delegate; if (null == handler) return new ReturnMessage(new ArgumentNullException("handler"), callMessage); try { if (removeHandler) RemoveEventHandler(methodName, handler); else AttachEventHandler(methodName, handler); } catch (Exception ex) { return new ReturnMessage(ex, callMessage); } } else { invokeObject = this._COMObject; invokeType = this._COMType; if (methodName.StartsWith("get_")) { // Property Get methodName = methodName.Substring(4); flags = BindingFlags.GetProperty; args = callMessage.InArgs; } else if (methodName.StartsWith("set_")) { // Property Set methodName = methodName.Substring(4); flags = BindingFlags.SetProperty; args = callMessage.InArgs; } else { args = callMessage.Args; if (null != args && 0 != args.Length) { // Modifiers for ref / out parameters argModifiers = new ParameterModifier[1]; argModifiers[0] = new ParameterModifier(args.Length); parameters = method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { parameter = parameters[i]; if (parameter.IsOut || parameter.ParameterType.IsByRef) { argModifiers[0][i] = true; outArgsCount++; } } if (0 == outArgsCount) argModifiers = null; } } // Un-wrap wrapped COM objects before passing to the method if (null == args || 0 == args.Length) { originalArgs = null; } else { originalArgs = new COMWrapper[args.Length]; for (int i = 0; i < args.Length; i++) { if (null != args[i] && RemotingServices.IsTransparentProxy(args[i])) { wrapper = RemotingServices.GetRealProxy(args[i]) as COMWrapper; if (null != wrapper) { originalArgs[i] = wrapper; args[i] = wrapper._COMObject; } } else if (0 != outArgsCount && argModifiers[0][i]) { byValType = GetByValType(parameters[i].ParameterType); if (byValType.IsInterface) { // If we're passing a COM object by reference, and // the parameter is null, we need to pass a // DispatchWrapper to avoid a type mismatch exception. if (null == args[i]) args[i] = new DispatchWrapper(null); } else if (typeof(Decimal) == byValType) { // If we're passing a decimal value by reference, // we need to pass a CurrencyWrapper to avoid a // type mismatch exception. // http://support.microsoft.com/?kbid=837378 args[i] = new CurrencyWrapper(args[i]); } } } } try { returnValue = invokeType.InvokeMember(methodName, flags, null, invokeObject, args, argModifiers, null, null); } catch (Exception ex) { return new ReturnMessage(ex, callMessage); } // Handle enum and interface return types if (null != returnValue) { if (returnType.IsInterface) { // Wrap the returned value in an intercepting COM wrapper if (Marshal.IsComObject(returnValue)) returnValue = COMWrapper.Wrap(returnValue, returnType); } else if (returnType.IsEnum) { // Convert to proper Enum type returnValue = Enum.Parse(returnType, returnValue.ToString()); } } // Handle out args if (0 != outArgsCount) { outArgs = new object[args.Length]; for (int i = 0; i < parameters.Length; i++) { if (!argModifiers[0][i]) continue; arg = args[i]; if (null == arg) continue; parameter = parameters[i]; wrapper = null; byValType = GetByValType(parameter.ParameterType); if (typeof(Decimal) == byValType) { if (arg is CurrencyWrapper) arg = ((CurrencyWrapper)arg).WrappedObject; } else if (byValType.IsEnum) { arg = Enum.Parse(byValType, arg.ToString()); } else if (byValType.IsInterface) { if (Marshal.IsComObject(arg)) { wrapper = originalArgs[i]; if (null != wrapper && wrapper._COMObject != arg) { wrapper.Dispose(); wrapper = null; } if (null == wrapper) wrapper = new COMWrapper(arg, byValType); arg = wrapper.GetTransparentProxy(); } } outArgs[i] = arg; } } } return new ReturnMessage(returnValue, outArgs, outArgsCount, callMessage.LogicalCallContext, callMessage); }
/// <summary> /// Exporte la feuille en DXF /// Le nom de la feuille correspond au nom du fichier /// </summary> /// <param name="CheminDossier"></param> /// <param name="NomDuFichierAlternatif"></param> public void ExporterEn(Extension_e TypeExport, String CheminDossier, String NomDuFichierAlternatif = "") { Log.Methode(cNOMCLASSE); Activer(); ZoomEtendu(); String Ext = ""; ExportPdfData OptionsPDF = null; switch (TypeExport) { case Extension_e.cDXF: Ext = ".dxf"; _Dessin.Modele.SW.GestOptions.DxfDwg_ExporterToutesLesFeuilles = swDxfMultisheet_e.swDxfActiveSheetOnly; break; case Extension_e.cDWG: Ext = ".dwg"; _Dessin.Modele.SW.GestOptions.DxfDwg_ExporterToutesLesFeuilles = swDxfMultisheet_e.swDxfActiveSheetOnly; break; case Extension_e.cPDF: Ext = ".pdf"; OptionsPDF = _Dessin.Modele.SW.SwSW.GetExportFileData((int)swExportDataFileType_e.swExportPdfData); DispatchWrapper[] Wrapper = new DispatchWrapper[1]; Wrapper[0] = new DispatchWrapper((Object)SwFeuille); OptionsPDF.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, Wrapper); break; } String CheminFichier = this.Nom; int Erreur = 0; int Warning = 0; if (!String.IsNullOrEmpty(NomDuFichierAlternatif)) CheminFichier = NomDuFichierAlternatif; CheminFichier = Path.Combine(CheminDossier, CheminFichier + Ext); Dessin.Modele.SwModele.Extension.SaveAs(CheminFichier, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Silent, OptionsPDF, Erreur, Warning); Log.Message(CheminFichier); }
static public DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] Objects) { var ArraySize = 0; ArraySize = Objects.GetUpperBound(0); var d = new DispatchWrapper[ArraySize + 1]; var ArrayIndex = 0; for (ArrayIndex = 0; ArrayIndex <= ArraySize; ArrayIndex++) { d[ArrayIndex] = new DispatchWrapper(Objects[ArrayIndex]); } return d; }
/// <include file='doc\Hierarchy.uex' path='docs/doc[@for="HierarchyNode.GetProperty1"]/*' /> public virtual object GetProperty(int propId) { __VSHPROPID id = (__VSHPROPID)propId; object result = null; switch (id) { case __VSHPROPID.VSHPROPID_Expandable: result = (this.firstChild != null); break; case __VSHPROPID.VSHPROPID_Caption: result = this.Caption; break; case __VSHPROPID.VSHPROPID_Name: result = this.Caption; break; case __VSHPROPID.VSHPROPID_ExpandByDefault: result = false; break; case __VSHPROPID.VSHPROPID_IconHandle: result = GetIconHandle(false); break; case __VSHPROPID.VSHPROPID_OpenFolderIconHandle: result = GetIconHandle(true); break; case __VSHPROPID.VSHPROPID_NextVisibleSibling: goto case __VSHPROPID.VSHPROPID_NextSibling; case __VSHPROPID.VSHPROPID_NextSibling: result = (this.nextSibling != null) ? this.nextSibling.hierarchyId : NativeMethods.VSITEMID_NIL; break; case __VSHPROPID.VSHPROPID_FirstChild: goto case __VSHPROPID.VSHPROPID_FirstVisibleChild; case __VSHPROPID.VSHPROPID_FirstVisibleChild: result = (this.firstChild != null) ? this.firstChild.hierarchyId : NativeMethods.VSITEMID_NIL; break; case __VSHPROPID.VSHPROPID_Parent: if (this.parentNode != null) result = new IntPtr((int)this.parentNode.hierarchyId); // see bug 176470 break; case __VSHPROPID.VSHPROPID_ParentHierarchyItemid: if (_parentHierarchy != null) result = (int)_parentHierarchyItemId; // TODO: VS requires VT_I4 | VT_INT_PTR break; case __VSHPROPID.VSHPROPID_ParentHierarchy: result = _parentHierarchy; break; case __VSHPROPID.VSHPROPID_Root: result = Marshal.GetIUnknownForObject(this.projectMgr); break; case __VSHPROPID.VSHPROPID_Expanded: result = this.isExpanded; break; case __VSHPROPID.VSHPROPID_BrowseObject: result = this.projectMgr.GetNodeProperties(this); if (result != null) result = new DispatchWrapper(result); break; case __VSHPROPID.VSHPROPID_EditLabel: result = GetEditLabel(); break; case __VSHPROPID.VSHPROPID_SaveName: result = this.Url; break; case __VSHPROPID.VSHPROPID_ItemDocCookie: if (this.docCookie != IntPtr.Zero) return this.docCookie; break; case __VSHPROPID.VSHPROPID_ExtObject: result = GetAutomationObject(); break; } if (propId != lastTracedProperty) { string trailer = (result == null) ? "null" : result.ToString(); CCITracing.TraceCall(this.hierarchyId + "," + id.ToString() + " = " + trailer); lastTracedProperty = propId; // some basic filtering here... } return result; }
private static DispatchWrapper[] ObjectArrayToDispatchWrapperArray(object[] objects) { int arraySize = objects.GetUpperBound(0); var d = new DispatchWrapper[arraySize + 1]; for (int arrayIndex = 0; arrayIndex <= arraySize; arrayIndex++) { d[arrayIndex] = new DispatchWrapper(objects[arrayIndex]); } return d; }
/// <summary> /// Gets the value of the specified property. /// </summary> /// <param name="propertyId">The Id of the property to retrieve.</param> /// <param name="propertyValue">The value of the specified property, or null if the property is not supported.</param> /// <returns>true if the property is supported; otherwise false.</returns> public virtual bool GetProperty(__VSHPROPID propertyId, out object propertyValue) { propertyValue = null; bool supported = true; // Get the property from the node. switch (propertyId) { case __VSHPROPID.VSHPROPID_BrowseObject: if (this.Properties != null) { propertyValue = new DispatchWrapper(this.Properties); } break; case __VSHPROPID.VSHPROPID_Caption: propertyValue = this.Caption; break; case __VSHPROPID.VSHPROPID_ItemDocCookie: // We cast it to an IntPtr because some callers expect a VT_INT propertyValue = (IntPtr)this.DocumentCookie; break; case __VSHPROPID.VSHPROPID_EditLabel: if (this.CaptionEditable) { propertyValue = this.Caption; } else { supported = false; } break; case __VSHPROPID.VSHPROPID_Expandable: propertyValue = this.Expandable; break; case __VSHPROPID.VSHPROPID_ExpandByDefault: propertyValue = this.ExpandByDefault; break; case __VSHPROPID.VSHPROPID_Expanded: propertyValue = this.Expanded; break; case __VSHPROPID.VSHPROPID_FirstChild: case __VSHPROPID.VSHPROPID_FirstVisibleChild: propertyValue = (this.FirstChild != null ? this.FirstChild.HierarchyId : NativeMethods.VSITEMID_NIL); break; case __VSHPROPID.VSHPROPID_IconHandle: propertyValue = this.GetImageHandle(this.Image); if ((IntPtr)propertyValue == IntPtr.Zero) { supported = false; propertyValue = null; } break; case __VSHPROPID.VSHPROPID_Name: propertyValue = this.Caption; break; case __VSHPROPID.VSHPROPID_NextSibling: case __VSHPROPID.VSHPROPID_NextVisibleSibling: propertyValue = (this.NextSibling != null ? this.NextSibling.HierarchyId : NativeMethods.VSITEMID_NIL); break; case __VSHPROPID.VSHPROPID_Parent: propertyValue = (this.Parent != null ? this.Parent.HierarchyId : NativeMethods.VSITEMID_NIL); break; case __VSHPROPID.VSHPROPID_SaveName: propertyValue = this.SaveName; break; case __VSHPROPID.VSHPROPID_TypeGuid: propertyValue = this.VisualStudioTypeGuid; break; default: supported = false; break; } return supported; }