internal CliNamespaceDictionary(CliAssembly owner, INamespaceParent parent, CliNamespaceKeyedTree info) : base(info.Keys) { this.owner = owner; this.info = info; this.parent = parent; }
public NamespaceSymbol(INamespaceParent parent, Identifier name, Func<NamespaceSymbol, IEnumerable<INamespaceMember>> members) { Parent = Guard.NotNull(parent, "parent"); Name = Guard.NotNull(name, "name"); Members = Guard.NotNull(members, "members")(this).ToArray(); }
public Namespace CloneProperties(INamespaceParent parent, string name) { Namespace ns = parent.Catalogue.CreateNamespace(parent, name); ns.CopyMembers(this, false); return(ns); }
internal Namespace(INamespaceParent parent, string name, string[] enabledEvents, string[] mixedEvents, Interner interner) : base(parent, name) { // Check. const string method = ".ctor"; if (parent == null) { throw new NullParameterException(typeof(Namespace), method, "parent"); } if (!CatalogueName.IsName(name)) { throw new InvalidParameterFormatException(typeof(Namespace), method, "name", name, Constants.Validation.CompleteNamePattern); } // Collections. InitialiseCollections(2); _enabledEvents = Util.InternStringArray(interner, enabledEvents); _mixedEvents = Util.InternStringArray(interner, mixedEvents); CheckEventOverlap(); }
/// <summary> /// Searches for the namespace without loading collections. /// </summary> /// <param name="nsName">The namespace name to find.</param> /// <param name="bestFound">The namespace being searched for, if found, otherwise the closest parent /// that was found (which may be the Catalogue).</param> /// <param name="remainingPath">The path of the namespace searched for relative to bestFound.</param> /// <returns>True if the namespace was found, otherwise false.</returns> private bool GetNamespaceOptional(string nsName, out INamespaceParent bestFound, out string remainingPath) { Debug.Assert(nsName != null, "nsName != null"); bestFound = _searchRoot as INamespaceParent; if (bestFound == null) { remainingPath = null; return(false); } string[] nsParts = nsName.Split('.'); Debug.Assert(nsParts.Length > 0, "nsParts.Length > 0"); int index = 0; bool ignoreCase = Options.IgnoreCase; while (index < nsParts.Length) { Namespace child = bestFound.Namespaces.GetItem(nsParts[index], ignoreCase, false); if (child == null) { remainingPath = bestFound.Namespaces.IsLoaded ? null : string.Join(".", nsParts, index, nsParts.Length - index); return(false); } bestFound = child; index++; } Debug.Assert(bestFound != null, "bestFound != null"); remainingPath = null; return(true); }
public Namespace Clone(INamespaceParent parent, string name) { Namespace ns = parent.Catalogue.CreateNamespace(parent, name); ns.CopyMembers(this, false); ns.CopyChildCollections(this); return(ns); }
public static void Copy(Catalogue toCatalogue, Namespace ns, ReadOnlyOption readOnlyOption, bool isReferenced, bool iterate) { INamespaceParent parent = toCatalogue.EnsureNamespaceParent(ns.Parent.FullName); // Clone the source namespace, so that CopyElement can modify it by calling PushAllEnabledEventsToChildren(). CopyElement(parent, ns.Clone(ns.Parent, ns.Name), iterate); }
private static Namespace CreateNamespace(INamespaceParent parent, ManagementBaseObject config) { // Get the properties. var name = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.EnabledEventsProperty); var mixedEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.MixedEventsProperty); string[] enabledEventsArray = SplitString(enabledEvents, Constants.Module.ListSeparator); string[] mixedEventsArray = SplitString(mixedEvents, Constants.Module.ListSeparator); return(parent.Catalogue.CreateNamespace(parent, name, enabledEventsArray, mixedEventsArray)); }
public override Namespace[] GetNamespaces(INamespaceParent parent) { // Search. var namespaces = new ArrayList(); var searcher = new ManagementObjectSearcher(_scope, GetChildQuery(Constants.Wmi.Namespace.Class, parent.FullName)); using (ManagementObjectCollection configs = searcher.Get()) { foreach (ManagementObject config in configs) { namespaces.Add(CreateNamespace(parent, config)); } } return((Namespace[])namespaces.ToArray(typeof(Namespace))); }
// Namespace public virtual Namespace[] GetNamespaces(INamespaceParent parent) { return(new Namespace[0]); }
public Namespace GetNamespace(INamespaceParent parent, string relativeName, bool ignoreCase) { // WMI is very slow, so do everything possible to minimise WMI access. We need to load all the // namespaces in the hierarchy (from the parent to the one being sought), because any of them // may have enabled events. Get them all in one query. // Build a query that gets all the namespaces we need (if they exist). string[] nsParts = relativeName.Split('.'); string parentFullName = parent.FullName; string queryString = BuildQueryStringForNamespaces(nsParts, parentFullName); // WQL is case-insensitive, so if ignoreCase is false use the Hashtable created below to filter. Hashtable namespaces = ignoreCase ? new Hashtable(StringComparer.InvariantCultureIgnoreCase) : new Hashtable(); var searcher = new ManagementObjectSearcher(_scope, new ObjectQuery(queryString)); // Read the namespaces returned and store them temporarily in a Hasthable. We cannot create // Namespace objects as we go, because they may be returned out of order (ie. children before parents). using (ManagementObjectCollection configs = searcher.Get()) { foreach (ManagementObject config in configs) { var details = new NamespaceDetails(); var nsName = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.NameProperty); var nsParentName = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.ParentProperty); var enabledEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.EnabledEventsProperty); var mixedEvents = (string)WmiUtil.GetPropertyValue(config, Constants.Wmi.Namespace.MixedEventsProperty); details._enabledEvents = SplitString(enabledEvents, Constants.Module.ListSeparator); details._mixedEvents = SplitString(mixedEvents, Constants.Module.ListSeparator); namespaces.Add(CatalogueName.GetFullNameUnchecked(nsParentName, nsName), details); } } // Now that we have all the details create the hierarchy of Namespace objects. Catalogue catalogue = parent.Catalogue; Namespace ns = null; foreach (string nsName in nsParts) { string nsFullName = CatalogueName.GetFullNameUnchecked(parentFullName, nsName); var details = (NamespaceDetails)namespaces[nsFullName]; if (details == null) { return(null); // One of the namespaces in the path was not found in WMI. } ns = catalogue.CreateNamespace(parent, nsName, details._enabledEvents, details._mixedEvents); parent.AddIfNotLoaded(ns); parentFullName = nsFullName; parent = ns; } return(ns); }
public static bool AddEventStatesForChildNamespaces(INamespaceParent parent, string[] eventsToCheck, IList enabled, IList disabled, IList mixed) { IEnumerator enumerator = parent.Namespaces.GetEnumerator(); if (enumerator.MoveNext()) { // When processing the first namespace just set our states from its states. var childNs = (Namespace)enumerator.Current; ReadOnlyStringList childEnabled = childNs.EnabledEvents; ReadOnlyStringList childMixed = childNs.MixedEvents; foreach (string eventName in eventsToCheck) { if (childEnabled.Contains(eventName)) { enabled.Add(eventName); } else if (childMixed.Contains(eventName)) { mixed.Add(eventName); } else { disabled.Add(eventName); } } } else { return(false); // No namespaces to process. } while (enumerator.MoveNext()) { // For subsequent children look for states that change our state for an event from enabled or // disabled to mixed. Once an event is in "mixed" state that won't change. var childNs = (Namespace)enumerator.Current; ReadOnlyStringList childEnabled = childNs.EnabledEvents; ReadOnlyStringList childMixed = childNs.MixedEvents; int index = 0; while (index < enabled.Count) { var eventName = (string)enabled[index]; if (!childEnabled.Contains(eventName)) { // This event was enabled for all children so far, but not for this one - now it's mixed. enabled.RemoveAt(index); mixed.Add(eventName); } else { index++; } } index = 0; while (index < disabled.Count) { var eventName = (string)disabled[index]; if (childEnabled.Contains(eventName) || childMixed.Contains(eventName)) { // This event was disabled for all children so far, but not for this one - now it's mixed. disabled.RemoveAt(index); mixed.Add(eventName); } else { index++; } } } return(true); }
// Namespace public Namespace CreateNamespace(INamespaceParent parent, string name, string[] enabledEvents, string[] mixedEvents) { return(new Namespace(parent, _interner.Intern(name), enabledEvents, mixedEvents, _interner)); }
private static void CopyElement(INamespaceParent parent, Namespace ns, bool iterate) { bool mergeEventStates = false; // Check whether the namespace already exists. Namespace thisNamespace = parent.Namespaces[ns.Name]; if (thisNamespace == null) { // Doesn't exist so create new clone. thisNamespace = ns.CloneProperties(parent, ns.Name); parent.Namespaces.Add(thisNamespace); } else { if (thisNamespace.IsEnsured) { // Already exists, so copy details if "ensured". thisNamespace.CopyProperties(ns); } else { // If "ns" has any children then the event states on "thisNamespace" need to be merged from // "ns", since we may be adding sources. mergeEventStates = (ns.Sources.Count > 0 || ns.Namespaces.Count > 0); } } string[] eventsToUpdate = null; if (mergeEventStates) { // The status of all events that are enabled or mixed on either target or source needs to be // merged. To do this first push the "enabled" status right down to the source level then, // after the children of the source namespace are added to this (target) namespace update // the event states on the namespace from the states of the children. eventsToUpdate = Util.AddRangeUnique( Util.AddRangeUnique(thisNamespace.EnabledEventsInternal, thisNamespace.MixedEventsInternal), Util.AddRangeUnique(ns.EnabledEventsInternal, ns.MixedEventsInternal)); if (eventsToUpdate != null && eventsToUpdate.Length != 0) { thisNamespace.PushAllEnabledEventsToChildren(); ns.PushAllEnabledEventsToChildren(); } } // Iterate. if (iterate) { foreach (Source source in ns.Sources) { CopyElement(thisNamespace, source); } foreach (Namespace childNamespace in ns.Namespaces) { CopyElement(thisNamespace, childNamespace, true); } } if (mergeEventStates && eventsToUpdate != null && eventsToUpdate.Length > 0) { // Don't go up to the parent at all in this case - we're traversing from bottom up already. thisNamespace.UpdateEventStates(eventsToUpdate); } }
public Namespace CreateNamespace(INamespaceParent parent, string name) { return(new Namespace(parent, _interner.Intern(name))); }
internal Namespace(INamespaceParent parent, string name) : this(parent, name, null, null, null) { }
public CliNamespaceDeclaration(CliAssembly owningAssembly, INamespaceParent parent, CliNamespaceKeyedTreeNode namespaceInfo) { this.owningAssembly = owningAssembly; this.namespaceInfo = namespaceInfo; this.parent = parent; }
public NewNamespaceWizard(INamespaceParent parent) { m_parent = parent; m_namespace = null; }