/// <summary>
        ///     The object retrieves its serialization info.
        /// </summary>
        public WMIAssocGroupNode(SerializationInfo info, StreamingContext context)
        {
            try
            {
                try
                {
                    rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res",                          // Name of the resource.
                                             ".",                                                     // Use current directory.
                                             null);
                }
                catch (Exception)
                {
                    //do nothing, will use static RM
                }


                //De-serialize string data mambers
                String associationPath = info.GetString("associationPath");
                String targetClass     = info.GetString("targetClass");
                String targetRole      = info.GetString("targetRole");


                //De-serialize strings necessary to restore the source object
                String sourcePath   = info.GetString("sourcePath");
                String sourceNS     = info.GetString("sourceNS");
                String sourceServer = info.GetString("sourceServer");

                //Restore SWbemObject for "source"
                ISWbemLocator wbemLocator = WmiHelper.WbemLocator;                //(ISWbemLocator)(new SWbemLocator());

                ISWbemServices wbemServices = wbemLocator.ConnectServer(sourceServer,
                                                                        sourceNS,
                                                                        "",                                             //user: blank defaults to current logged-on user
                                                                        "",                                             //password: blank defaults to current logged-on user
                                                                        "",                                             //locale: blank for current locale
                                                                        "",                                             //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                                        0,                                              //flags: reserved
                                                                        null);                                          //context info: not needed here

                ISWbemObject sourceInst = wbemServices.Get(sourcePath,
                                                           (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                                           null);


                theComp = new AssocGroupComponent(sourceInst,
                                                  associationPath,
                                                  targetClass,
                                                  targetRole);
            }

            catch (Exception exc)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
                throw (exc);
            }
        }
Example #2
0
 //
 // CONSTRUCTORS
 //
 // <doc>
 // <desc>
 //     Main constructor.
 //     Parameters:
 //	string server (in, machine name)
 //	string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass")
 // </desc>
 // </doc>
 public WMIAssocGroupNode(AssocGroupComponent compIn,
                          string user, string pw)
 {
     try
     {
         theComp   = compIn;
         connectAs = user;
         password  = pw;
     }
     catch (Exception exc)
     {
         MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
         throw (exc);
     }
 }
        //
        // CONSTRUCTORS
        //
        // <doc>
        // <desc>
        //     Main constructor.
        //     Parameters:
        //	string server (in, machine name)
        //	string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass")
        // </desc>
        // </doc>
        public WMIAssocGroupNode(AssocGroupComponent compIn)
        {
            try
            {
                try
                {
                    rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res",                          // Name of the resource.
                                             ".",                                                     // Use current directory.
                                             null);
                }
                catch (Exception)
                {
                    //do nothing, will use static RM
                }

                theComp = compIn;
            }
            catch (Exception exc)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
                throw (exc);
            }
        }
Example #4
0
        //
        // METHODS
        //

        // <doc>
        // <desc>
        //     Create associator nodes under this node.
        //     The children of this node are of type WMIAssocGroupNode.
        //     Each WMIAssocGroupNode groups instances that belong to the same class;
        //     are related to this one through the same association class,
        //     and play the same role.
        // </desc>
        // </doc>
        public override Node[] CreateChildren()
        {
            try
            {
                //do not look for associators of a new instance
                if (this.IsNewInstance)
                {
                    return(null);
                }

                //BUGBUG: wmi raid 2855
                //for Beta1, we are going to disable the ability to expand
                //references of Win32_ComputerSystem

                if (className.ToUpper() == "WIN32_COMPUTERSYSTEM" &&
                    nsName.ToUpper() == "ROOT\\CIMV2")
                {
                    return(null);
                }

                //First, get association instances related to this

                GetRelationshipOptions opts = new GetRelationshipOptions(null,              //context
                                                                         TimeSpan.MaxValue, //timeout
                                                                         50,                //block size
                                                                         false,             //rewindable
                                                                         true,              //return immediately
                                                                         true,              //use amended
                                                                         true,              //locatable
                                                                         false,             //prototype only
                                                                         false,             //direct read
                                                                         string.Empty,      //RELATIONSHIP CLASS
                                                                         string.Empty,      //relationship qualifier
                                                                         string.Empty,      //this role
                                                                         false              //classes only
                                                                         );

                ManagementObjectCollection assocInstances = mgmtObj.GetRelationships(opts);

                if (assocInstances == null)
                {
                    return(null);
                }

                //assocGroups will contain a list of unique association/class/role groupings
                ArrayList assocGroups = new ArrayList();

                ManagementObjectCollection.ManagementObjectEnumerator enumAssocInstances =
                    assocInstances.GetEnumerator();
                while (enumAssocInstances.MoveNext())
                {
                    ManagementObject curObj = (ManagementObject)enumAssocInstances.Current;

                    AssocGroupComponent comp = new AssocGroupComponent(curObj, mgmtObj);
                    if (!assocGroups.Contains(comp))                    //this relies on our implementation of "Equald" in AssocGroupComponent class
                    {
                        assocGroups.Add(comp);
                    }
                }

                Node[] childNodes = new Node[assocGroups.Count];

                Object[] arAssocGroups = assocGroups.ToArray();

                for (int i = 0; i < arAssocGroups.Length; i++)
                {
                    childNodes[i] = new WMIAssocGroupNode((AssocGroupComponent)arAssocGroups[i], connectAs, password);
                }

                return(childNodes);
            }
            catch (Exception exc)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
                return(null);
            }
        }