private INode BuildGraph (XmlDocument graph, StringValueDictionary<INode> nodes) { INode root = null; var xmlStack = new LinkedList<StackEntry>(); foreach (var child in graph.ChildNodes.Cast<XmlNode>()) { if (child.NodeType == XmlNodeType.Element) { xmlStack.AddLast(new StackEntry { Child = child, Parent = null }); break; } } while (xmlStack.Count > 0) { var current = xmlStack.First.Value; xmlStack.RemoveFirst(); var node = ResolveNode(current.Child, nodes); if (current.Parent == null) root = node; else current.Parent.AddChild(node); foreach (var child in current.Child.ChildNodes.Cast<XmlNode>()) { if (child.NodeType == XmlNodeType.Element) xmlStack.AddLast(new StackEntry { Child = child, Parent = node }); } } return root; }
public void BeginWrite(INode root) { _NextNodeID = 1; _Nodes = new StringValueDictionary <INode>(); _NodeIDs = new Dictionary <INode, string>(); _Writer.WriteStartElement("graph"); }
public void CloneTest() { var dic1 = StringValueDictionary.FromObject(new Dictionary <string, object>() { { "Id", 1 }, { "Name", "Tom" } }); var dic2 = dic1.Clone(); Assert.False(ReferenceEquals(dic1, dic2)); Assert.True(dic1 == dic2); }
public void ImplicitConvertTest() { var abc = new { Id = 1, Name = "Tom" }; var stringValueDictionary = StringValueDictionary.FromObject(abc); Dictionary <string, string> dictionary = stringValueDictionary !; Assert.Equal(stringValueDictionary.Count, dictionary.Count); var dic2 = StringValueDictionary.FromObject(dictionary); Assert.Equal(dic2, stringValueDictionary); Assert.True(dic2 == stringValueDictionary); }
public void EqualsTest() { var abc = new { Id = 1, Name = "Tom" }; var dic1 = StringValueDictionary.FromObject(abc); var dic2 = StringValueDictionary.FromObject(new Dictionary <string, object>() { { "Name", "Tom" }, { "Id", 1 }, }); Assert.True(dic1 == dic2); Assert.Equal(dic1, dic2); }
public static StringValueDictionary <string> CombineTranslatedDictionaries(this List <StringValueDictionary <string> > list, string defaultValue) { var result = new StringValueDictionary <string>(defaultValue); foreach (var item in list) { lock (ResultLock) { result.Merge(item); } } return(result); }
private async Task LoadLabels(int languageId, string module, string type) { using (var persistence = new PersistenceLayer()) { var translationLabelDefinition = await persistence .Get <TranslationLabelDefinition>() .Include(x => x.TranslationLabels) .Where(x => x.Module == module && x.Type == type) .ToListAsync(); var definitions = translationLabelDefinition .Select(x => new { TranslationLabelDefinition = x, TranslationLabel = x.TranslationLabels .FirstOrDefault(y => y.Language_Id == languageId) }); var dictionary = new StringValueDictionary <string>(DefaultLabelValue); foreach (var definition in definitions) { var transDef = definition.TranslationLabelDefinition; dictionary.Add($"{transDef.Module}:{transDef.Type}:{transDef.Key}", definition?.TranslationLabel?.Label ?? DefaultLabelValue); } lock (DictionaryLanguagesLock) { if (!DictionaryLanguages.ContainsKey(languageId)) { DictionaryLanguages.Add(languageId, new StringValueDictionary <StringValueDictionary <StringValueDictionary <string> > >()); } if (!DictionaryLanguages[languageId].ContainsKey(module)) { DictionaryLanguages[languageId].Add(module, new StringValueDictionary <StringValueDictionary <string> >()); } if (!DictionaryLanguages[languageId][module].ContainsKey(type)) { DictionaryLanguages[languageId][module].Add(type, new StringValueDictionary <string>(DefaultLabelValue)); } DictionaryLanguages[languageId][module][type] = dictionary; } } }
public void DistinctTest() { var abc = new { Id = 1, Name = "Tom" }; var dic1 = StringValueDictionary.FromObject(abc); var dic2 = StringValueDictionary.FromObject(new Dictionary <string, object>() { { "Id", 1 }, { "Name", "Tom" }, }); var set = new HashSet <StringValueDictionary>(); set.Add(dic1); set.Add(dic2); Assert.Single(set); }
private INode BuildGraph(XmlDocument graph, StringValueDictionary <INode> nodes) { INode root = null; var xmlStack = new LinkedList <StackEntry>(); foreach (var child in graph.ChildNodes.Cast <XmlNode>()) { if (child.NodeType == XmlNodeType.Element) { xmlStack.AddLast(new StackEntry { Child = child, Parent = null }); break; } } while (xmlStack.Count > 0) { var current = xmlStack.First.Value; xmlStack.RemoveFirst(); var node = ResolveNode(current.Child, nodes); if (current.Parent == null) { root = node; } else { current.Parent.AddChild(node); } foreach (var child in current.Child.ChildNodes.Cast <XmlNode>()) { if (child.NodeType == XmlNodeType.Element) { xmlStack.AddLast(new StackEntry { Child = child, Parent = node }); } } } return(root); }
public void BeginWrite(INode root) { _NextNodeID = 1; _Nodes = new StringValueDictionary<INode>(); _NodeIDs = new Dictionary<INode, string>(); _Writer.WriteStartElement("graph"); }
private INode ResolveNode(XmlNode node, StringValueDictionary<INode> nodes) { return nodes[node.Attributes.GetNamedItem("key").Value]; }
private INode ResolveNode(XmlNode node, StringValueDictionary <INode> nodes) { return(nodes[node.Attributes.GetNamedItem("key").Value]); }