本文整理汇总了C#中IGraphNode类的典型用法代码示例。如果您正苦于以下问题:C# IGraphNode类的具体用法?C# IGraphNode怎么用?C# IGraphNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IGraphNode类属于命名空间,在下文中一共展示了IGraphNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindImmediateDependent
private IDictionary<LibraryDescription, ISet<LibraryDescription>> FindImmediateDependent(IGraphNode<LibraryDescription> root)
{
var result = new Dictionary<LibraryDescription, ISet<LibraryDescription>>();
root.DepthFirstPreOrderWalk(
visitNode: (node, ancestors) =>
{
ISet<LibraryDescription> slot;
if (!result.TryGetValue(node.Item, out slot))
{
slot = new HashSet<LibraryDescription>();
result.Add(node.Item, slot);
}
// first item in the path is the immediate parent
if (ancestors.Any())
{
slot.Add(ancestors.First().Item);
}
return true;
});
// removing the root package
result.Remove(root.Item);
return result;
}
示例2: PrintHierarchyInternal
private static void PrintHierarchyInternal(IGraphNode node, int indentation, StringBuilder builder)
{
PrintIndentation(indentation, builder);
builder.Append(node.Guid + " ");
PrintIndentation(indentation, builder);
builder.Append(node.Name ?? "<untitled>");
builder.Append(": [");
builder.Append(node.Content.GetType().Name);
builder.Append("] = ");
if (node.Content.IsReference)
{
if (node.Content.Value != null)
{
builder.Append(node.Content.Value.ToString().Replace(Environment.NewLine, " "));
builder.Append(" > ");
}
builder.Append("Reference -> ");
builder.Append(node.Content.Reference);
}
else if (node.Content.Value == null)
{
builder.Append("(null)");
}
else
{
builder.Append(node.Content.Value.ToString().Replace(Environment.NewLine, " "));
}
builder.AppendLine();
foreach (var child in node.Children)
{
PrintHierarchyInternal(child, indentation + 4, builder);
}
}
示例3: QuantumConsistencyException
/// <summary>
/// Initializes a new instance of the QuantumConsistencyException class.
/// </summary>
/// <param name="expected">A string representing the expected result.</param>
/// <param name="observed">A string representing the observed result.</param>
/// <param name="node">The node that is related to this error.</param>
public QuantumConsistencyException(string expected, string observed, IGraphNode node)
: base(GetMessage(expected, observed))
{
Expected = expected ?? "(NullMessage)";
Observed = observed ?? "(NullMessage)";
Node = node;
}
示例4: TestCollectionObjectContentNode
/// <summary>
/// Tests the validity of a node that is an object that is a collection
/// </summary>
/// <param name="node">The node to validate.</param>
/// <param name="obj">The value represented by this node.</param>
/// <param name="isReference">Indicate whether the node is expected to contain an enumerable reference to the collection items.</param>
public static void TestCollectionObjectContentNode(IGraphNode node, object obj, bool isReference)
{
if (node == null) throw new ArgumentNullException(nameof(node));
if (obj == null) throw new ArgumentNullException(nameof(obj));
// Check that the content is of the expected type.
Assert.IsInstanceOf<ObjectContent>(node.Content);
// Check that the content is properly referencing its node.
Assert.AreEqual(node, node.Content.OwnerNode);
// A node with an ObjectContent should have the same name that the type of its content.
Assert.AreEqual(obj.GetType().Name, node.Name);
// A node with an ObjectContent should be a root node.
Assert.IsNull(node.Parent);
// A node with an ObjectContent should have the related object as value of its content.
Assert.AreEqual(obj, node.Content.Retrieve());
if (isReference)
{
// A node with an ObjectContent representing a collection of reference types should contain an enumerable reference.
Assert.AreEqual(true, node.Content.IsReference);
Assert.IsInstanceOf<ReferenceEnumerable>(node.Content.Reference);
}
else
{
// A node with an ObjectContent representing a collection of primitive or struct types should not contain a refernce.
Assert.AreEqual(false, node.Content.IsReference);
}
// A node with an ObjectContent representing a collection should not have any child.
Assert.AreEqual(0, node.Children.Count);
}
示例5: ObservableModelNode
/// <summary>
/// Initializes a new instance of the <see cref="ObservableModelNode"/> class.
/// </summary>
/// <param name="ownerViewModel">The <see cref="ObservableViewModel"/> that owns the new <see cref="ObservableModelNode"/>.</param>
/// <param name="baseName">The base name of this node. Can be null if <see cref="index"/> is not. If so a name will be automatically generated from the index.</param>
/// <param name="isPrimitive">Indicate whether this node should be considered as a primitive node.</param>
/// <param name="modelNode">The model node bound to the new <see cref="ObservableModelNode"/>.</param>
/// <param name="graphNodePath">The <see cref="GraphNodePath"/> corresponding to the given <see cref="modelNode"/>.</param>
/// <param name="index">The index of this content in the model node, when this node represent an item of a collection. <c>null</c> must be passed otherwise</param>
protected ObservableModelNode(ObservableViewModel ownerViewModel, string baseName, bool isPrimitive, IGraphNode modelNode, GraphNodePath graphNodePath, object index = null)
: base(ownerViewModel, baseName, index)
{
if (modelNode == null) throw new ArgumentNullException(nameof(modelNode));
if (baseName == null && index == null)
throw new ArgumentException("baseName and index can't be both null.");
this.isPrimitive = isPrimitive;
SourceNode = modelNode;
// By default we will always combine items of list of primitive items.
CombineMode = index != null && isPrimitive ? CombineMode.AlwaysCombine : CombineMode.CombineOnlyForAll;
SourceNodePath = graphNodePath;
// Override display name if available
var memberDescriptor = GetMemberDescriptor() as MemberDescriptorBase;
if (memberDescriptor != null)
{
if (index == null)
{
var displayAttribute = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<DisplayAttribute>(memberDescriptor.MemberInfo);
if (!string.IsNullOrEmpty(displayAttribute?.Name))
{
DisplayName = displayAttribute.Name;
}
IsReadOnly = !memberDescriptor.HasSet;
}
}
}
示例6: IsCyclic
/// <summary>
/// Returns true if graph node is cyclic.
/// </summary>
/// <param name="node">Graph node.</param>
/// <param name="path">Path from a graph node to this <paramref name="graph node"/>.</param>
/// <param name="acyclicNodes">Nodes from which a cycle does not exist.</param>
/// <returns>Returns true if graph node is cyclic.</returns>
private static bool IsCyclic(IGraphNode node, ISet<string> path, ISet<string> acyclicNodes)
{
node.ThrowIfArgumentNull(nameof(node));
node.Id.ThrowIfArgumentNull(nameof(node.Id));
node.Neighbors.ThrowIfArgumentNull(nameof(node.Neighbors));
if (acyclicNodes.Contains(node.Id))
{
return false;
}
if (path.Contains(node.Id))
{
return true;
}
path.Add(node.Id);
foreach (var neighbor in node.Neighbors)
{
if (IsCyclic(neighbor, path, acyclicNodes))
{
return true;
}
}
path.Remove(node.Id);
acyclicNodes.Add(node.Id);
return false;
}
示例7: FindTargetReference
protected override ObjectReference FindTargetReference(IGraphNode sourceNode, IGraphNode targetNode, ObjectReference sourceReference)
{
if (sourceReference.Index.IsEmpty)
return targetNode.Content.Reference as ObjectReference;
// Special case for objects that are identifiable: the object must be linked to the base only if it has the same id
if (sourceReference.ObjectValue != null)
{
if (sourceReference.Index.IsEmpty)
{
return targetNode.Content.Reference.AsObject;
}
var sourceAssetNode = (AssetNode)sourceNode;
if (sourceAssetNode.IsNonIdentifiableCollectionContent)
return null;
// Enumerable reference: we look for an object with the same id
var targetReference = targetNode.Content.Reference.AsEnumerable;
var sourceIds = CollectionItemIdHelper.GetCollectionItemIds(sourceNode.Content.Retrieve());
var targetIds = CollectionItemIdHelper.GetCollectionItemIds(targetNode.Content.Retrieve());
var itemId = sourceIds[sourceReference.Index.Value];
var targetKey = targetIds.GetKey(itemId);
return targetReference.FirstOrDefault(x => Equals(x.Index.Value, targetKey));
}
// Not identifiable - default applies
return base.FindTargetReference(sourceNode, targetNode, sourceReference);
}
示例8: GetAllChildNodes
private static IEnumerable<IGraphNode> GetAllChildNodes(IGraphNode graphNode)
{
var processedNodes = new HashSet<IGraphNode>();
var nodeStack = new Stack<IGraphNode>();
nodeStack.Push(graphNode);
while (nodeStack.Count > 0)
{
var node = nodeStack.Pop();
processedNodes.Add(node);
// We don't want to include the initial node
if (node != graphNode)
yield return node;
// Add child nodes
node.Children.ForEach(x => nodeStack.Push(x));
// Add object reference target node
var objectReference = node.Content.Reference as ObjectReference;
if (objectReference?.TargetNode != null)
nodeStack.Push(objectReference.TargetNode);
// Add enumerable reference target nodes
var enumerableReference = node.Content.Reference as ReferenceEnumerable;
enumerableReference?.Select(x => x.TargetNode).NotNull().ForEach(x => nodeStack.Push(x));
}
}
示例9: GraphNodeToObject
public object GraphNodeToObject(IGraphNode node, Type type)
{
var seq = (ISequenceGraphNode) node;
Type elemType = null;
if (type.IsArray)
elemType = type.GetElementType();
else if (TypeTools.IsAssignableToGenericType(type, typeof(IList<>)))
elemType = TypeTools.GetGenericArguments(type)[0];
var elements = seq.Select(n => n?.RebuildObject(elemType));
if (type.IsArray)
{
var a = Array.CreateInstance(elemType, seq.Length);
int i = 0;
foreach (var e in elements)
a.SetValue(e, i++);
return a;
}
var instance = (IList)Activator.CreateInstance(type);
foreach (var e in elements)
instance.Add(e);
return instance;
}
示例10: GetRenderContent
public IEnumerable<string> GetRenderContent(IGraphNode<LibraryDescription> root)
{
var dict = FindImmediateDependent(root);
var libraries = dict.Keys.OrderBy(description => description.Identity.Name);
var results = new List<string>();
var gacOrFrameworkReferences = libraries.Where(library => library.Identity.IsGacOrFrameworkReference);
if (gacOrFrameworkReferences.Any())
{
results.Add("Framework references:");
RenderLibraries(gacOrFrameworkReferences, dict, results);
results.Add(string.Empty);
}
var otherReferences = libraries.Where(library => !library.Identity.IsGacOrFrameworkReference);
var referencesGroups = otherReferences.GroupBy(reference => reference.Type);
foreach (var group in referencesGroups)
{
results.Add(string.Format("{0} references:", group.Key));
RenderLibraries(group, dict, results);
results.Add(string.Empty);
}
return results;
}
示例11: UnregisterNode
protected virtual void UnregisterNode(IGraphNode node)
{
node.Content.PrepareChange += ContentPrepareChange;
node.Content.FinalizeChange += ContentFinalizeChange;
node.Content.Changing -= ContentChanging;
node.Content.Changed -= ContentChanged;
}
示例12: GraphNodeToObject
public object GraphNodeToObject(IGraphNode node, Type objectType)
{
var n = node as IStringGraphNode;
if (n != null)
return Name.BuildName(n.Value);
return Name.BuildName(((IPrimitiveGraphNode)node).Value);
}
示例13: Walk
public void Walk(IGraphNode<LibraryDescription> root)
{
_assemblyFilePaths = new HashSet<string>(StringComparer.Ordinal);
_dependencyAssemblySources = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);
_dependencyPackageSources = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);
var libraries = new HashSet<LibraryDescription>();
root.DepthFirstPreOrderWalk(visitNode: (node, _) => VisitLibrary(node, _, libraries));
_reports.Information.WriteLine("\n[Target framework {0} ({1})]\n",
_framework.ToString(), VersionUtility.GetShortFrameworkName(_framework));
foreach (var assemblyFilePath in _assemblyFilePaths.OrderBy(assemblyName => assemblyName))
{
_reports.Information.WriteLine(assemblyFilePath);
if (_showDetails)
{
var assemblyName = Path.GetFileNameWithoutExtension(assemblyFilePath);
HashSet<string> packagesSources;
if (_dependencyPackageSources.TryGetValue(assemblyName, out packagesSources) && packagesSources.Any())
{
_reports.Information.WriteLine(" by package: {0}", string.Join(", ", packagesSources));
}
HashSet<string> assemblySources;
if (_dependencyAssemblySources.TryGetValue(assemblyName, out assemblySources) && assemblySources.Any())
{
_reports.Information.WriteLine(" by assembly: {0}", string.Join(", ", assemblySources));
}
}
}
}
示例14: Render
public void Render(IGraphNode<LibraryDependency> root)
{
// tuples of <Library Name, Requested Version, Actual Version>
var results = new HashSet<Tuple<string, string, string>>();
root.DepthFirstPreOrderWalk(
(node, ancestors) =>
{
var dependency = node.Item;
if (IsLibraryMismatch(dependency))
{
results.Add(Tuple.Create(
dependency.Library.Identity.Name,
dependency.LibraryRange.VersionRange?.MinVersion.ToString(),
dependency.Library.Identity.Version?.ToString()));
}
return true;
});
if (results.Any())
{
var format = GetFormat(results, padding: 2);
RenderTitle(format);
RenderMismatches(format, results);
}
}
示例15: Walk
public ISet<string> Walk(IGraphNode<Library> root)
{
var assemblies = new HashSet<string>();
var libraries = new HashSet<Library>();
root.DepthFirstPreOrderWalk(visitNode: (node, _) => VisitLibrary(node, _, libraries, assemblies));
return assemblies;
}