internal ObjectTypeTreeNode(bool comNode, 
									ObjectInfo objInfo,
									MemberInfo member,
									bool useIntermediates) : this(comNode, objInfo)
		{

			PresentationInfo pi = PresentationMap.GetInfo(member.MemberType);


			// Needs an intermediate node for the base class type
			if (useIntermediates &&
				ComponentInspectorProperties.ShowBaseCategories &&
				!_objInfo.ObjParentType.Equals(member.DeclaringType))
			{
				PresentationInfo basePi = PresentationMap.GetInfo(PresentationMap.BASE_CLASS);
				_intermediateNodeTypes = new ArrayList();
				_intermediateNodeTypes.Add(basePi._intermediateNodeType);
			}
			else if (ComponentInspectorProperties.ShowObjectAsBaseClass &&
					 (ReflectionHelper.TypeEqualsObject(member.DeclaringType) ||
					  ReflectionHelper.TypeEqualsMarshalByRef(member.DeclaringType) ||
					  NoGoop.Win32.ActiveX.TypeEqualsComRoot(member.DeclaringType)))
			{
				PresentationInfo basePi = PresentationMap.GetInfo(PresentationMap.BASE_CLASS);
				_intermediateNodeTypes = new ArrayList();
				_intermediateNodeTypes.Add(basePi._intermediateNodeType);
			}

			if (useIntermediates && ComponentInspectorProperties.ShowMemberCategories)
			{
				if (_intermediateNodeTypes == null)
					_intermediateNodeTypes = new ArrayList();
				_intermediateNodeTypes.Add(pi._intermediateNodeType);
			}

			// We can cast a member which can be permanently remembered
			_castInfo = CastInfo.GetCastInfo(member);

			ImageIndex = pi._iconIndex;
			SelectedImageIndex = ImageIndex;
			_nodeOrder = pi._sortOrder;
		}
Exemplo n.º 2
0
		internal IDesigner GetDesigner(IComponent comp, ObjectInfo objInfo)
		{
			Console.WriteLine("Designer - GetDesigner - start  " + comp + " " + objInfo + " ");
			DesignerAttribute da = null;

			if (comp == null)
				return null;

			// For sites that are not ours, we don't treat them, unless
			// we are adding controls, we use our site instead
			if (comp.Site != null && !(comp.Site is DesignerSite)) {
				if (_addingControls) {
					comp.Site = null;
				} else {
					Console.WriteLine("Designer - GetDesigner - not ours " + comp.Site);
					return null;
				}
			}

			DesignerSite site = (DesignerSite)comp.Site;

			// Don't allow getting a designer for anything higher than the
			// design surface
			if (comp == _designSurfaceParent) {
				return null;
			}

			if (site == null) {
				String name;
				if (objInfo != null) {
					name = objInfo.ObjectName;
				} else {
					name = CompNumber.GetCompName(comp.GetType());
				}
				Console.WriteLine("Comp.name: ", name);
				site = (DesignerSite)_container.CreateSite(comp, name);
			}

			if (site.Designer != null) {
				return site.Designer;
			}

			IList attrs = Attribute.GetCustomAttributes(comp.GetType(), typeof(DesignerAttribute));
			bool found = false;
			foreach (Attribute attr in attrs) {
				da = attr as DesignerAttribute;
				Console.WriteLine("Designer - GetDesigner da " 
				                  + da.DesignerBaseTypeName 
				                  + " " + da.DesignerTypeName);
				if (da.DesignerBaseTypeName.StartsWith("System.ComponentModel.Design.IRootDesigner")) {
					found = true;
					break;
				}
			}

			// Just take the first one if we did not find a root designer
			if (!found && attrs.Count > 0) {
				da = attrs[0] as DesignerAttribute;
			}

			if (da != null) {
				Type t = GetType(da.DesignerTypeName);
				Console.WriteLine("DesignerType: " + t.FullName);
				IDesigner d = (IDesigner)Activator.CreateInstance(t);
				if (_addingControls) {
					d.Initialize(comp);
				}
				site.Designer = d;
				if (comp is Control) {
					site.DesignWindowTarget = ((Control)comp).WindowTarget;
				}
				Console.WriteLine("Designer  - GetDesigner " + site + " " + d);
				return d;
			}
			Console.WriteLine("Designer  - GetDesigner NOT FOUND " + comp);
			return null;
		}
		internal ObjectTypeTreeNode(bool comNode, ObjectInfo objInfo) : base(comNode, objInfo)
		{
			Text = GetName();
		}
Exemplo n.º 4
0
		// This is used to add a control to the design surface
		// when it was added to the object tree, this is not used
		// when the control is dragged directly to the design surface
		internal void AddControl(ObjectInfo objInfo, Control control)
		{
			// For some reason, property grid gets an error when
			// initially associated with the image panel, associated
			// it with another panel first.
			//if (control is PropertyGrid)
			//	ObjectBrowser._testPanel.Controls.Add(control);

			IDesigner designer = null;
			DesignerHost host = DesignerHost.Host;
			if (host.DesignMode) {
				host.AddingControls = true;
				designer = host.GetDesigner(control, objInfo);
				if (designer != null)
					designer.Initialize(control);

				// If no designer, can't add it to design surface
				if (designer != null)
					_designPanel.Controls.Add(control);
				host.AddingControls = false;
			} else {
				_nonDesignPanel.Controls.Add(control);
			}


			// FIXME - Hack
			//if (control is PropertyGrid)
			//	designer.Initialize(control);
		}
Exemplo n.º 5
0
		protected static void AddRunningObjs()
		{
			TraceUtil.WriteLineInfo(null, "AddRunningObjs");
			ObjectTreeNode tlNode = null;
			// Running objects - added to object tree
			if (_runningObjInfo == null) {
				_runningObjInfo = ObjectInfoFactory.GetObjectInfo(false, new ArrayList());
				_runningObjInfo.ObjectName = StringParser.Parse("${res:ComponentInspector.ComRunningObjectsTreeNode.Text}");
				tlNode = new ObjectTreeNode(true, _runningObjInfo);
				// The children are explicitly added here
				tlNode.ChildrenAlreadyAdded = true;
				tlNode.NodeOrder = 20;
				tlNode.AllowDelete = false;
				tlNode.IsDropTarget = false;
				ObjectBrowser.ObjTree.CreateControl();
				ObjectBrowser.ObjTree.Invoke(new BrowserTree.AddNodeInvoker(ObjectBrowser.ObjTree.AddNode),
					new Object[] { tlNode });
			} else {
				tlNode = ObjectTreeNode.FindObject(_runningObjInfo.Obj, !ObjectTreeNode.CREATE_OBJ);
				((ArrayList)_runningObjInfo.Obj).Clear();
				tlNode.InvalidateNode();
			}
			ProgressDialog progress = new ProgressDialog();
			progress.Setup(StringParser.Parse("${res:ComponentInspector.ProgressDialog.AddingRunningComObjectsDialogTitle}"),
						  StringParser.Parse("${res:ComponentInspector.ProgressDialog.AddingRunningComObjectsMessage}"),
						  ComObjectInfo.GetRunningObjectCount(),
						  ProgressDialog.HAS_PROGRESS_TEXT,
						  ProgressDialog.FINAL);
			progress.ShowIfNotDone();
			foreach (ComObjectInfo comObjInfo in ComObjectInfo.GetRunningObjects(progress)) {
				ObjectBrowser.ObjTree.Invoke(new ObjectTreeNode.AddObjectInvoker(tlNode.AddObject),
					new Object[] { comObjInfo });
			}
			tlNode.Expand();
			progress.Finished();
		}
Exemplo n.º 6
0
		protected void InvokeInternal(ObjectInfo parent,
									  IObjectNode objectNode,
									  Object[] parameterValues,
									  Object fieldPropValue,
									  bool setMember)
		{
			if (TraceUtil.If(this, TraceLevel.Verbose)) {
				Trace.WriteLine("Start invoke: " + _objMemberInfo);
				if (fieldPropValue != null)
					Trace.WriteLine("  fieldPropVal: " + fieldPropValue);
				if (parameterValues != null) {
					foreach (Object pval in parameterValues)
						Trace.WriteLine("  param: " + pval);
				}
			}

			switch (_objMemberInfo.MemberType) {
				case MemberTypes.Method:
				{
					MethodInfo m = (MethodInfo)_objMemberInfo;
					SetObject(m.Invoke(parent._obj, parameterValues));
					if (TraceUtil.If(this, TraceLevel.Verbose)) {
						Trace.WriteLine("Called: " + m 
										+ " on " + parent._obj 
										+ " return: " + _obj);
					}   
				}
				break;
				case MemberTypes.Property:
				{
					PropertyInfo p = (PropertyInfo)_objMemberInfo;

					if (setMember) {
						p.SetValue(parent._obj, fieldPropValue, parameterValues);
					}

					if (p.CanRead){
						SetObject(p.GetValue(parent._obj, parameterValues));
					} else {
						// Update the new property value, if we can't
						// read it from the property (on a set)
						if (setMember)
							SetObject(fieldPropValue);
					}   

					// Save these in case we need to set the property, 
					// like with the property propogation code below
					objectNode.CurrentPropIndexValues = parameterValues;

					if (TraceUtil.If(this, TraceLevel.Verbose)) {
						Trace.WriteLine("Property: " + p 
										+ " of " + parent._obj 
										+ " value: " + _obj);
					}
				}
				break;
				case MemberTypes.Field:
				{
					FieldInfo f = (FieldInfo)_objMemberInfo;
						
					if (parent._objType.IsValueType) {
						// This is a struct, its handled a little
						// different because of the inline value type
						// issue
						if (setMember) {
							StructAccessor.SetValue(objectNode, fieldPropValue);
						}
						SetObject(StructAccessor.GetValue(objectNode));
					} else {
						if (setMember)
							f.SetValue(parent._obj, fieldPropValue);
						SetObject(f.GetValue(parent._obj));
					}
					if (TraceUtil.If(this, TraceLevel.Verbose)) {
						Trace.WriteLine("Field: " + f
										+ " of " + parent._obj 
										+ " value: " + _obj);
					}
				}
				break;
				default:
				break;
			}

			// Everything worked, now lets handle any changes that
			// superiors need.
			if (!setMember)
				return;

			// If the parent member is a property, we want to do 
			// a SetProperty on it with the current value of its object
			// so that the SetProperty can process the most recently
			// changed values.  We need to do this up the line.
			while (true) {
				IObjectNode parentObjNode;
				parentObjNode = objectNode.ParentObjectNode;
				if (parentObjNode == null)
					break;

				// We hit an object node that has no member, we are done
				if (parentObjNode.ObjectInfo.ObjMemberInfo == null)
					break;

				// Look at enclosing property members only
				if (!(parentObjNode.ObjectInfo.ObjMemberInfo is
					  PropertyInfo))
					break;

				PropertyInfo propInfo = (PropertyInfo)parentObjNode.ObjectInfo.ObjMemberInfo;

				// Set the property
				try {
					propInfo.SetValue(parentObjNode.ParentObjectNode.Obj,
									  parentObjNode.Obj,
									  parentObjNode.CurrentPropIndexValues);
				} catch (Exception ex) {
					// A parent property might not have a set method
					// for example.
					TraceUtil.WriteLineInfo
						(this, "Exception in SetValue in property "
						 + "propagation for prop: " + propInfo 
						 + " ex: " + ex);
					break;
				}
				parentObjNode.DoDisplayValue();
				objectNode = parentObjNode;
			}
		}
Exemplo n.º 7
0
		// Returns true if it worked
		internal bool Invoke(ObjectInfo parent,
							 IObjectNode objectNode,
							 Object[] parameterValues,
							 Object fieldPropValue,
							 bool setMember,
							 bool autoInvoke,
							 bool ignoreException)
		{
			if (parent == null) {
				if (TraceUtil.If(this, TraceLevel.Info)) { 
					Trace.WriteLine("Invoke - No parent");
				}
				return false;
			}

			if (_objMemberInfo == null || parent._obj == null) {
				if (TraceUtil.If(this, TraceLevel.Info)) { 
					Trace.WriteLine(TraceLevel.Info, 
						 "Invoke - No parent object or MemberInfo");
				}
				// Don't show this message in the auto invoke case
				if (!ignoreException && !autoInvoke) {
					ErrorDialog.Show("This method/property/field cannot "
									+ "be invoked "
									+ NULL_PARENT_TEXT,
									"Parent Object Not Present",
									MessageBoxIcon.Error);
				}
				return false;
			}

			try {
				InvokeInternal(parent, objectNode, 
							   parameterValues, fieldPropValue,
							   setMember);
			} catch (Exception e) {
				if (TraceUtil.If(this, TraceLevel.Info))
					Trace.WriteLine("Exception on invoke: " + e);

				if (!ignoreException) {
					Exception showException = e;
					// Remove the useless wrapper exception
					if (showException is TargetInvocationException)
						showException = e.InnerException;

					String errorStr = 
						 "Exception invoking " + _objMemberInfo.MemberType 
						 + " " + _objMemberInfo.Name
						 + ".  ";
					if (!setMember && _objMemberInfo.MemberType != MemberTypes.Method) {
						errorStr += "This can occur when you click on "
						 + "an item in the object tree.  ";
					}

					errorStr += "It means that the "
						 + "underlying object raised an exception when the "
						 + _objMemberInfo.MemberType + " was invoked.";

					ErrorDialog.Show
						(showException, errorStr,
						 "Exception invoking " 
						 + _objMemberInfo.MemberType 
						 + " " + _objMemberInfo,
						 MessageBoxIcon.Error);
				}
				return false;
			}	

			return true;
		}
Exemplo n.º 8
0
        protected void InvokeInternal(ObjectInfo parent,
                                      IObjectNode objectNode,
                                      Object[] parameterValues,
                                      Object fieldPropValue,
                                      bool setMember)
        {
            if (TraceUtil.If(this, TraceLevel.Verbose))
            {
                Trace.WriteLine("Start invoke: " + _objMemberInfo);
                if (fieldPropValue != null)
                {
                    Trace.WriteLine("  fieldPropVal: " + fieldPropValue);
                }
                if (parameterValues != null)
                {
                    foreach (Object pval in parameterValues)
                    {
                        Trace.WriteLine("  param: " + pval);
                    }
                }
            }

            switch (_objMemberInfo.MemberType)
            {
            case MemberTypes.Method:
            {
                MethodInfo m = (MethodInfo)_objMemberInfo;
                SetObject(m.Invoke(parent._obj, parameterValues));
                if (TraceUtil.If(this, TraceLevel.Verbose))
                {
                    Trace.WriteLine("Called: " + m
                                    + " on " + parent._obj
                                    + " return: " + _obj);
                }
            }
            break;

            case MemberTypes.Property:
            {
                PropertyInfo p = (PropertyInfo)_objMemberInfo;

                if (setMember)
                {
                    p.SetValue(parent._obj, fieldPropValue, parameterValues);
                }

                if (p.CanRead)
                {
                    SetObject(p.GetValue(parent._obj, parameterValues));
                }
                else
                {
                    // Update the new property value, if we can't
                    // read it from the property (on a set)
                    if (setMember)
                    {
                        SetObject(fieldPropValue);
                    }
                }

                // Save these in case we need to set the property,
                // like with the property propogation code below
                objectNode.CurrentPropIndexValues = parameterValues;

                if (TraceUtil.If(this, TraceLevel.Verbose))
                {
                    Trace.WriteLine("Property: " + p
                                    + " of " + parent._obj
                                    + " value: " + _obj);
                }
            }
            break;

            case MemberTypes.Field:
            {
                FieldInfo f = (FieldInfo)_objMemberInfo;

                if (parent._objType.IsValueType)
                {
                    // This is a struct, its handled a little
                    // different because of the inline value type
                    // issue
                    if (setMember)
                    {
                        StructAccessor.SetValue(objectNode, fieldPropValue);
                    }
                    SetObject(StructAccessor.GetValue(objectNode));
                }
                else
                {
                    if (setMember)
                    {
                        f.SetValue(parent._obj, fieldPropValue);
                    }
                    SetObject(f.GetValue(parent._obj));
                }
                if (TraceUtil.If(this, TraceLevel.Verbose))
                {
                    Trace.WriteLine("Field: " + f
                                    + " of " + parent._obj
                                    + " value: " + _obj);
                }
            }
            break;

            default:
                break;
            }

            // Everything worked, now lets handle any changes that
            // superiors need.
            if (!setMember)
            {
                return;
            }

            // If the parent member is a property, we want to do
            // a SetProperty on it with the current value of its object
            // so that the SetProperty can process the most recently
            // changed values.  We need to do this up the line.
            while (true)
            {
                IObjectNode parentObjNode;
                parentObjNode = objectNode.ParentObjectNode;
                if (parentObjNode == null)
                {
                    break;
                }

                // We hit an object node that has no member, we are done
                if (parentObjNode.ObjectInfo.ObjMemberInfo == null)
                {
                    break;
                }

                // Look at enclosing property members only
                if (!(parentObjNode.ObjectInfo.ObjMemberInfo is
                      PropertyInfo))
                {
                    break;
                }

                PropertyInfo propInfo = (PropertyInfo)parentObjNode.ObjectInfo.ObjMemberInfo;

                // Set the property
                try {
                    propInfo.SetValue(parentObjNode.ParentObjectNode.Obj,
                                      parentObjNode.Obj,
                                      parentObjNode.CurrentPropIndexValues);
                } catch (Exception ex) {
                    // A parent property might not have a set method
                    // for example.
                    TraceUtil.WriteLineInfo
                        (this, "Exception in SetValue in property "
                        + "propagation for prop: " + propInfo
                        + " ex: " + ex);
                    break;
                }
                parentObjNode.DoDisplayValue();
                objectNode = parentObjNode;
            }
        }
Exemplo n.º 9
0
        // Returns true if it worked
        internal bool Invoke(ObjectInfo parent,
                             IObjectNode objectNode,
                             Object[] parameterValues,
                             Object fieldPropValue,
                             bool setMember,
                             bool autoInvoke,
                             bool ignoreException)
        {
            if (parent == null)
            {
                if (TraceUtil.If(this, TraceLevel.Info))
                {
                    Trace.WriteLine("Invoke - No parent");
                }
                return(false);
            }

            if (_objMemberInfo == null || parent._obj == null)
            {
                if (TraceUtil.If(this, TraceLevel.Info))
                {
                    Trace.WriteLine(TraceLevel.Info,
                                    "Invoke - No parent object or MemberInfo");
                }
                // Don't show this message in the auto invoke case
                if (!ignoreException && !autoInvoke)
                {
                    ErrorDialog.Show("This method/property/field cannot "
                                     + "be invoked "
                                     + NULL_PARENT_TEXT,
                                     "Parent Object Not Present",
                                     MessageBoxIcon.Error);
                }
                return(false);
            }

            try {
                InvokeInternal(parent, objectNode,
                               parameterValues, fieldPropValue,
                               setMember);
            } catch (Exception e) {
                if (TraceUtil.If(this, TraceLevel.Info))
                {
                    Trace.WriteLine("Exception on invoke: " + e);
                }

                if (!ignoreException)
                {
                    Exception showException = e;
                    // Remove the useless wrapper exception
                    if (showException is TargetInvocationException)
                    {
                        showException = e.InnerException;
                    }

                    String errorStr =
                        "Exception invoking " + _objMemberInfo.MemberType
                        + " " + _objMemberInfo.Name
                        + ".  ";
                    if (!setMember && _objMemberInfo.MemberType != MemberTypes.Method)
                    {
                        errorStr += "This can occur when you click on "
                                    + "an item in the object tree.  ";
                    }

                    errorStr += "It means that the "
                                + "underlying object raised an exception when the "
                                + _objMemberInfo.MemberType + " was invoked.";

                    ErrorDialog.Show
                        (showException, errorStr,
                        "Exception invoking "
                        + _objMemberInfo.MemberType
                        + " " + _objMemberInfo,
                        MessageBoxIcon.Error);
                }
                return(false);
            }

            return(true);
        }
		// Allocates the correct type of node
		// Expects an ObjectInfo object
		public override BrowserTreeNode AllocateChildNode(ObjectInfo objInfo)
		{
			return new ObjectTreeNode(_node.IsComNode, objInfo);
		}
Exemplo n.º 11
0
		// Adds an object to this node, might or might not be a new object
		internal bool AddObject(ObjectInfo newObjInfo)
		{
			IList list = (IList)Obj;
			try {
				list.Add(newObjInfo.Obj);
			} catch (Exception ex) {
				ErrorDialog.Show(ex,
								"Exception adding object to list",
								MessageBoxIcon.Error);
				return false;
			}
			InvalidateNode();
			return true;
		}
Exemplo n.º 12
0
		internal ObjectTreeNode(bool comNode, ObjectInfo objInfo) : this(comNode)
		{
			_objInfo = objInfo;
			_isObjectContainer = 
				typeof(IList).IsAssignableFrom(ObjType);
			_isDropTarget = _isObjectContainer;
			SetTypeHandler();
			DoDisplayValue();
			PostConstructor();
		}
Exemplo n.º 13
0
		public virtual BrowserTreeNode AllocateChildNode(ObjectInfo objInfo)
		{
			throw new Exception("Must override me");
		}
Exemplo n.º 14
0
        // This is used for the case of a class outside of a type
        // libarary
        protected Type GetTypeForClass()
        {
            Type type = null;

            // See if we have type lib information from the registry
            if (_typeLibString != null)
            {
                return(GetTypeFromTypeLib
                           (TypeLibrary.GetTypeLib(new Guid(_typeLibString),
                                                   _typeLibVersion)));
            }


            // Have to try and create the object and get the type lib
            // information from the created object

            if (TraceUtil.If(this, TraceLevel.Info))
            {
                TraceUtil.WriteLineInfo(this,
                                        "Attempting to create obj for: "
                                        + this);
            }


            IntPtr comObj;
            int    result = ActiveX.CoCreateInstance(ref _guid,
                                                     (IntPtr)0,
                                                     ActiveX.CLSCTX_SERVER,
                                                     ref ActiveX.IUnknownIID,
                                                     out comObj);

            if (result == 0)
            {
                ComObjectInfo objInfo = null;
                try
                {
                    // Wrap our object info stuff and get the type
                    objInfo = new ComObjectInfo(comObj);
                    type    = GetTypeFromTypeLib(objInfo.TypeLib);
                }
                catch (Exception ex)
                {
                    _typeFailedException =
                        new Exception("Unable to determine CLR type for "
                                      + GetName(), ex);
                    throw _typeFailedException;
                }
                finally
                {
                    try
                    {
                        // Clean up the object info, if we made it that
                        // far
                        if (objInfo != null)
                        {
                            Object o = objInfo.Obj;
                            ObjectInfo.RemoveObjectInfo(o);
                            while (true)
                            {
                                int count = Marshal.ReleaseComObject(o);
                                TraceUtil.WriteLineInfo
                                    (this,
                                    "final Marshal.ReleaseComObject count: "
                                    + count);
                                if (count <= 0)
                                {
                                    break;
                                }
                            }
                        }
                        while (true)
                        {
                            int count = Marshal.Release(comObj);
                            TraceUtil.WriteLineInfo
                                (this, "final Marshal.Release count: "
                                + count);

                            if (count <= 0)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        TraceUtil.WriteLineWarning
                            (this, "error on cleanup: " + ex);
                        // We tried...
                    }
                    ActiveX.CoFreeUnusedLibraries();
                }


                return(type);
            }

            _typeFailedException =
                new Exception("Unable to determine CLR type because "
                              + "I can't create a COM object (0x"
                              + result.ToString("X")
                              + ") from CLSID: " + _guidStr);
            throw _typeFailedException;
        }