/// <summary> Non-generic version of Set. You probably want to use Set. </summary> /// <param name="type"> the type to save the data as </param> /// <param name="key"> what the data is labeled as within the file </param> /// <param name="value"> the value to save </param> public void SetNonGeneric(Type type, string key, object value) { if (value == null) { throw new Exception("you can't serialize null"); } if (value.GetType() != type) { throw new InvalidCastException($"{value} is not of type {type}!"); } if (!KeyExists(key)) { var newnode = new KeyNode(indentation: 0, key, file: this); TopLevelNodes.Add(key, newnode); TopLevelLines.Add(newnode); } var node = TopLevelNodes[key]; NodeManager.SetNodeData(node, value, type, Style); if (AutoSave) { SaveAllData(); } }
public void Realloc(KeyNode <K> node, int length) { DoFree(node.Offset, node.Length); node.Offset = DoAlloc(length); node.Length = length; }
/// <summary> Non-generic version of SetAtPath. You probably want to use SetAtPath. </summary> public void SetAtPathNonGeneric(Type type, object value, params string[] path) { if (value != null && value.GetType() != type) { throw new InvalidCastException($"{nameof(value)} is not of type {type}!"); } if (path.Length < 1) { throw new ArgumentException($"{nameof(path)} must have a length greater than 0"); } if (!KeyExists(path[0])) { var newnode = new KeyNode(indentation: 0, key: path[0], file: this); TopLevelNodes.Add(path[0], newnode); TopLevelLines.Add(newnode); } var topNode = TopLevelNodes[path[0]]; for (int i = 1; i < path.Length; i++) { topNode = topNode.GetChildAddressedByName(path[i]); } NodeManager.SetNodeData(topNode, value, type, Style); if (AutoSave) { SaveAllData(); } }
private void GenerateCurrencyKeys() { AddToDictionary(new RegionMarker { Description = " #region Currency Keys" }); var jsonResponse = PoeNinjaDataService.FetchCurrencyJsonResponseAsync(PoeNinjaDataService.CurrencyType.Currency).Result; foreach(var detail in jsonResponse.CurrencyDetails) { detail.Name = detail.Name.Trim(); var keyNode = new KeyNode { Description = detail.Name, Key = FormatStringToKey(detail.Name), }; keyNode.Attributes.Add($"[Name(Name = \"{detail.Name}\")]"); keyNode.Attributes.Add($"[Currency]"); if(detail.PoeTradeId != -1) { keyNode.Attributes.Add($"[PoeTrade(Id = {detail.PoeTradeId})]"); } if(detail.Id != -1) { keyNode.Attributes.Add($"[PoeNinja(Id = {detail.Id})]"); } AddToDictionary(keyNode); } AddToDictionary(new RegionMarker { Description = " #endregion Currency Keys" }); }
protected void AssignKey() { KeyNode selectedKeyNode = (KeyNode)commandNodeView.NodeSelection.SelectedNode; String s = "Select the key to associate with\n\"" + selectedKeyNode.CommandString + "\"\nPress ESC to cancel"; Gtk.Label label = new Gtk.Label(s); label.Justify = Justification.Center; label.HeightRequest = 70; Dialog dialog = new Dialog("Assign a key", this, Gtk.DialogFlags.DestroyWithParent); dialog.TypeHint = WindowTypeHint.Splashscreen; dialog.Modal = true; dialog.VBox.Add(label); dialog.HasSeparator = false; dialog.KeyPressEvent += delegate(object o, Gtk.KeyPressEventArgs args) { bool alreadyAssigned = false; string keyAssigned = ""; if (args.Event.KeyValue != (uint)Gdk.Key.Escape) { foreach (KeyNode node in keyNodeStore) { if (node.Key == (Gdk.Key)args.Event.KeyValue) { alreadyAssigned = true; keyAssigned = node.CommandString; break; } } if (!alreadyAssigned) { selectedKeyNode.Key = (Gdk.Key)args.Event.KeyValue; SaveKeyCommand(selectedKeyNode.KeyCommand, selectedKeyNode.Key); } else { label.Text = "Key already assigned to \n\"" + keyAssigned + "\""; } } if (!alreadyAssigned) { Gtk.Application.Invoke(delegate { dialog.Destroy(); }); } else { Timer timer = new Timer(1500); timer.Elapsed += delegate { label.Text = s; timer.Stop(); }; timer.Start(); } }; Gtk.Application.Invoke(delegate { dialog.ShowAll(); }); }
void Gather(KeyNode <K> node) { if (node != null) { Add(Allocation.New(node)); Gather(node.Left); Gather(node.Right); } }
private void ResetChildren() { this.Nodes.Clear(); key = new KeyNode(layer.keys.First(), form); code = new CodeNode(layer.code, form); this.Nodes.Clear(); this.Nodes.Add(key); this.Nodes.Add(code); }
//Delete registry value. public static bool DeleteRegistryString(SSRegistryMainNode RegType, string strPath, string strName) { if (RegType == SSRegistryMainNode.Default) { RegType = SSRegistryMainNode.CurrentUser; } try { Microsoft.Win32.RegistryKey KeyNode; switch (RegType) { case SSRegistryMainNode.ClassesRoot: KeyNode = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentConfig: KeyNode = Microsoft.Win32.Registry.CurrentConfig.OpenSubKey(strPath, true); break; case SSRegistryMainNode.CurrentUser: KeyNode = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; case SSRegistryMainNode.LocalMachine: KeyNode = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(strPath, true); break; case SSRegistryMainNode.Users: KeyNode = Microsoft.Win32.Registry.Users.OpenSubKey(strPath, true); break; default: KeyNode = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(strPath, true); break; } if (KeyNode == null) { return(false); } KeyNode.DeleteValue(strName, false); KeyNode.Close(); return(true); } catch { //m_objError.WriteErrorLog("DeleteRegistryString", "delete data from regedit error.", ""); return(false); } }
public void CreateKeyNodeTest() { KeyNode node = new KeyNode(); node.Key = 1; node.Left = new KeyNode(); node.Right = new KeyNode(); Assert.AreEqual(1, node.Key); Assert.AreNotEqual(null, node.Left); Assert.AreNotEqual(null, node.Right); }
private static void SetDictionaryNodeGeneric <TKey, TValue>(Node node, Dictionary <TKey, TValue> dictionary, FileStyle style, bool forceArrayMode = false) { bool keyIsBase = BaseTypesManager.IsBaseType(typeof(TKey)); if (keyIsBase && !forceArrayMode && !style.AlwaysArrayDictionaries) { // we might have switched between standard and array dictionary storage, and if so, children need to be reset if (node.ChildNodeType != NodeChildrenType.key) { node.ClearChildren(newChildrenType: NodeChildrenType.key); } var CurrentKeys = new List <string>(capacity: dictionary.Count); foreach (var key in dictionary.Keys) { var value = dictionary[key]; string keyAsText = BaseTypesManager.SerializeBaseType <TKey>(key, style); if (!Utilities.IsValidKey(keyAsText)) { SetDictionaryNodeGeneric(node, dictionary, style, forceArrayMode: true); return; } CurrentKeys.Add(keyAsText); KeyNode child = node.GetChildAddressedByName(keyAsText); NodeManager.SetNodeData <TValue>(child, value, style); } // make sure that old data in the file is deleted when a new dictionary is saved. // node.ClearChildren() is not used because we want to keep comments and whitespace intact as much as possible. foreach (var key in node.GetChildKeys()) { if (!CurrentKeys.Contains(key)) { node.RemoveChild(key); } } } else // save dictionary as KeyValuePair<TKey, TValue>[] { // we might have switched between standard and array dictionary storage, and if so, children need to be reset if (node.ChildNodeType != NodeChildrenType.list) { node.ClearChildren(newChildrenType: NodeChildrenType.list); } var array = GetWritableKeyValuePairArray(dictionary); NodeManager.SetNodeData(node, array, array.GetType(), style); } }
//导入时的对longbeat的处理 public void DealImportLongBeat(ref KeyNode[] TMP, KeyNode key) { if (key.itemType == ItemType.LongBeatStart) { int num = (int)((key.EndTime - key.StartTime) / DeltaTime); KeyNode LongBeatEnd = new KeyNode(); LongBeatEnd.StartTime = key.EndTime; LongBeatEnd.EndTime = key.EndTime; LongBeatEnd.PathWay = key.PathWay; //LongBeat.Part = key.Part + num; LongBeatEnd.itemType = ItemType.LongBeatEnd; LongBeatEnd.index = key.index + num; TMP[key.index + num] = LongBeatEnd; } }
private IEnumerable <ListNode> GetDictionaryNodes(IEnumerable <ElementNode> elementNodes) { foreach (var g in elementNodes.SelectMany(n => n.Keys).GroupBy(k => k.ParentIndex)) { KeyNode key = g.First(); KeyNode parentKey = g.FirstOrDefault(n => n.ChildIndex == null); yield return(new ListNode() { ParentKey = parentKey, KeyType = key.Type, Metadata = key.Metadata, Index = key.ParentIndex, }); } }
private IEnumerable <KeyNode> GetChildKeys(MetadataNode itemNode) { IList <MetadataNode> allNodes = itemNode.Tree().ToList(); IReferenceMetadata metadata = itemNode.GetMetadata <IReferenceMetadata>(); IEnumerable <IReference> references = metadata?.References.Where(r => r.HasFlag(ReferenceFlags.Child)) ?? Array.Empty <IReference>(); foreach (IReference reference in references.Where(this.IsValidJoinReference)) { KeyNode childKey = this.CreateKey(allNodes, reference); if (childKey != null) { yield return(childKey); } } }
//输入歌曲数据后刷新界面,初始化这首歌的节点 public void Init() { len = Music.length; BarTime = 240 / BPM; bar = Convert.ToInt32(len / BarTime); DeltaTime = BarTime / 32; CurrentTime = OffsetTime; CurrentValue = 0;//把滑动条归零 FinalList.Clear(); //临时时间变量,用来给4轨道初始化,初始化时间 float TimeCounter = OffsetTime; List1 = new KeyNode[bar * 32]; List2 = new KeyNode[bar * 32]; List3 = new KeyNode[bar * 32]; List4 = new KeyNode[bar * 32]; for (int i = 0; i < bar * 32; i++) { List1[i] = new KeyNode(); List2[i] = new KeyNode(); List3[i] = new KeyNode(); List4[i] = new KeyNode(); List1[i].StartTime = TimeCounter; List2[i].StartTime = TimeCounter; List3[i].StartTime = TimeCounter; List4[i].StartTime = TimeCounter; List1[i].EndTime = TimeCounter; List2[i].EndTime = TimeCounter; List3[i].EndTime = TimeCounter; List4[i].EndTime = TimeCounter; TimeCounter += DeltaTime; } IsInit = true; //初始化纹理颜色 BlackStyle.normal.background = Texture2D.blackTexture; Style1.normal.background = BlackStyle.normal.background; WhiteStyle.normal.background = EditorGUIUtility.whiteTexture; pages = 1;//页数 //设置音频 Asource = Root.GetComponent <AudioSource>(); Asource.clip = Music; }
private IEnumerable<ValueNode> GetAllKeyedValues(KeyNode combo) { foreach (var ratingsByUser in _ratingsByUser) { var allMoviesByUser = ratingsByUser.Select(r => r.ImdbId); if (!combo.ListContainsKey(allMoviesByUser)) continue; // User has not seen both movies. double score1 = ratingsByUser.First(r => r.ImdbId == combo.Movie1).Rating; double score2 = ratingsByUser.First(r => r.ImdbId == combo.Movie2).Rating; foreach (var rating in ratingsByUser) { if(rating.ImdbId == combo.Movie1 || rating.ImdbId == combo.Movie2) continue; yield return new ValueNode(score1, score2, rating.ImdbId, rating.Rating); } } }
/// <summary> /// 利用存储一个临时变量来判断是不是start后面会有end /// </summary> /// <param name="Tmp"></param> /// <param name="ListX"></param> /// <param name="index"></param> /// <returns></returns> public bool DealLongBeat(ref KeyNode Tmp, KeyNode[] ListX, int index) { if (ListX[index].itemType == ItemType.LongBeatStart) { if (Tmp.HaveNext == true) { if (EditorUtility.DisplayDialog("错误", "请仔细检查,前一个LongBeatStart与没有对应的End,必须配合使用", "确定", "取消")) { Debug.LogError("LongBeatStart与End必须配合使用"); return(false); } } else { Tmp = ListX[index]; Tmp.HaveNext = true; } return(true); } else if (ListX[index].itemType == ItemType.LongBeatEnd) { if (Tmp != null && Tmp.HaveNext == false) { if (EditorUtility.DisplayDialog("错误", "请仔细检查,前面必须有LongBeatStart才能有End,不能重复两个End必须配合使用", "OK")) { Debug.LogError("请仔细检查,LongBeatStart与End必须配合使用"); return(false); } } else { //long类型的end是在这里设置时间 Tmp.EndTime = index * DeltaTime + OffsetTime; Tmp.HaveNext = false; } return(false); } else { return(true); } }
//private void AddToDictionary( // PoeNinjaDataService.ItemJsonResponse.Line line, // string attribute, // bool useNameForKeyGeneration = true, // bool useBaseTypeForKeyGeneration = false) //{ // line.Name = line.Name.Trim(); // var keyNode = new KeyNode // { // Description = line.Name, // Key = FormatStringToKey(line, useNameForKeyGeneration, useBaseTypeForKeyGeneration), // }; // keyNode.Attributes.Add($"[Name(Name = \"{line.Name}\")]"); // if(line.Id != -1) // { // keyNode.Attributes.Add($"[{attribute}(PoeNinjaId = \"{line.Id}\")]"); // keyNode.Attributes.Add($"[PoeNinja]"); // } // else // { // keyNode.Attributes.Add($"[{attribute}()]"); // } // AddToDictionary(keyNode); //} private void AddToDictionary(KeyNode keyNode) { if(!KeyDictionary.ContainsKey(keyNode.Key)) { KeyDictionary.Add(keyNode.Key, keyNode); return; } var existing = (KeyNode)KeyDictionary[keyNode.Key]; foreach(var a in keyNode.Attributes) { if(existing.Attributes.Any(o => o.Equals(a, StringComparison.OrdinalIgnoreCase))) { continue; } existing.Attributes.Add(a); } }
/// <summary> Non-generic version of Set. You probably want to use Set. </summary> /// <param name="type"> the type to save the data as </param> /// <param name="key"> what the data is labeled as within the file </param> /// <param name="value"> the value to save </param> public void SetNonGeneric(Type type, string key, object value) { if (value != null && !type.IsAssignableFrom(value.GetType())) { throw new InvalidCastException($"Expected type {type}, but the object is of type {value.GetType()}"); } if (!KeyExists(key)) { var newnode = new KeyNode(indentation: 0, key, file: this); TopLevelNodes.Add(key, newnode); TopLevelLines.Add(newnode); } var node = TopLevelNodes[key]; NodeManager.SetNodeData(node, value, type, Style); if (AutoSave) { SaveAllData(); } }
private KeyNode CreateKey(IEnumerable <MetadataNode> nodes, IReference reference) { IList <MetadataNode> keyValue = reference.Key.Properties.Select(m => this.FindNode(nodes, m)).ToList(); if (keyValue.All(n => n?.Column != null)) { IReference parentReference = reference.HasFlag(ReferenceFlags.Parent) ? reference : reference.Other; KeyNode keyNode = new KeyNode(reference) { Value = keyValue, ParentIndex = this.GetKeyIndex(parentReference), }; if (reference.HasFlag(ReferenceFlags.Child)) { keyNode.ChildIndex = this.GetKeyIndex(parentReference.Other); } return(keyNode); } return(null); }
private bool ClassType(NamespaceNode ns) { if (Keyword(ParserConstants.ClassKeyword)) { var name = NameExpected(); CheckDuplicateGlobalType(ns, name); Token abstractOrSealed; if (!Keyword(ParserConstants.AbstractKeyword, out abstractOrSealed)) { Keyword(ParserConstants.SealedKeyword, out abstractOrSealed); } var baseClassQName = default(QualifiableNameNode); if (Keyword(ParserConstants.ExtendsKeyword)) { baseClassQName = QualifiableNameExpected(); } List<KeyNode> keyList = null; if (Keyword(ParserConstants.KeyKeyword)) { keyList = new List<KeyNode>(); while (true) { var key = new KeyNode { NameExpected() }; while (true) { if (Token('.')) { key.Add(NameExpected()); } else { break; } } keyList.Add(key); if (!Token(',')) { break; } } } TokenExpected('{'); var cls = new ClassTypeNode(ns, name, abstractOrSealed, baseClassQName, keyList); while (Property(ns, cls)) ; TokenExpected('}'); ns.GlobalTypeMap.Add(name, cls); return true; } return false; }
//导出 void Exp() { KeyNode Tmpkeynode = new KeyNode(); Tmpkeynode.HaveNext = false; for (int i = 0; i < bar * 32; i++) { //对每个轨道做longbeat检查,然后存入final if (List1[i].itemType != ItemType.None) { if (DealLongBeat(ref Tmpkeynode, List1, i)) { List1[i].PathWay = 1; List1[i].Bar = (i / 32) + 1; List1[i].Beat = (i % 32) / 8 + 1; List1[i].Part = (i % 32) % 8 + 1; List1[i].index = i; FinalList.Add(List1[i]); } } if (List2[i].itemType != ItemType.None) { if (DealLongBeat(ref Tmpkeynode, List2, i)) { //DealLongBeat(ref Tmpkeynode, i); List2[i].PathWay = 2; List2[i].Bar = (i / 32) + 1; List2[i].Beat = (i % 32) / 8 + 1; List2[i].Part = (i % 32) % 8 + 1; List2[i].index = i; FinalList.Add(List2[i]); } } if (List3[i].itemType != ItemType.None) { if (DealLongBeat(ref Tmpkeynode, List3, i)) { //DealLongBeat(ref Tmpkeynode, i); List3[i].PathWay = 3; List3[i].Bar = (i / 32) + 1; List3[i].Beat = (i % 32) / 8 + 1; List3[i].Part = (i % 32) % 8 + 1; List3[i].index = i; FinalList.Add(List3[i]); } } if (List4[i].itemType != ItemType.None) { if (DealLongBeat(ref Tmpkeynode, List4, i)) { //DealLongBeat(ref Tmpkeynode, i); List4[i].PathWay = 4; List4[i].Bar = (i / 32) + 1; List4[i].Beat = (i % 32) / 8 + 1; List4[i].Part = (i % 32) % 8 + 1; List4[i].index = i; FinalList.Add(List4[i]); } } } if (Tmpkeynode.HaveNext == true) { if (EditorUtility.DisplayDialog("错误", "LongBeatStart与LongBeatEnd必须配合使用", "确定", "清除")) { Debug.LogError("LongBeatStart与End必须配合使用"); return; } else { FinalList.Clear(); } } else { //序列化歌曲信息 MusicInfo music = new MusicInfo(); music.keyNodes = FinalList; music.DeltaTime = DeltaTime; music.Speed = Speed; music.Len = len; music.OffsetTime = OffsetTime; music.BarTime = BarTime; string json = JsonConvert.SerializeObject(music); string path = Directory.GetCurrentDirectory() + "/" + "Assets/RawRes/OutputData/" + Music.name + ".json"; if (Directory.Exists(path)) { Directory.Delete(path); } FileModule.Instance.WriteText(path, json); AssetDatabase.Refresh(); } FinalList.Clear(); }
public void Parse_ValidInput_ParsesCorrectly() { // Arrange var connectionString = "Server=.;Database=econera.diet.tracking;Trusted_Connection=True;"; var provider = "sqlserver"; var filePath = "c:/temp/mysqlite.json"; var commandText = $"sd --connection \"{connectionString}\" --provider {provider} -f {filePath}"; var lexer = new Lexer { Producers = new ILexicalTokenProducer[] { new WhiteSpaceProducer(), new CliKeyProducer(), new CliWordProducer(), new JsonStringProducer(), new FilePathProducer(), }, }; var root = new TermNode("sd"); var idleNode = new IdleNode(); var connectionKeyNode = new KeyNode(new[] { "-c", "--connection" }, "connection", true); var connectionValueNode = new KeyValueNode("connection"); var providerKeyNode = new KeyNode(new[] { "-p", "--provider" }, "provider", true); var providerValueNode = new KeyValueNode("provider"); var fileKeyNode = new KeyNode(new[] { "-f", "--file" }, "file", true); var fileValueNode = new KeyValueNode("file"); var endNode = EndNode.Instance; root.AddLink(idleNode); idleNode.AddLink(connectionKeyNode); idleNode.AddLink(providerKeyNode); idleNode.AddLink(fileKeyNode); connectionKeyNode.AddLink(connectionValueNode); providerKeyNode.AddLink(providerValueNode); fileKeyNode.AddLink(fileValueNode); connectionValueNode.AddLink(idleNode); connectionValueNode.AddLink(endNode); providerValueNode.AddLink(idleNode); providerValueNode.AddLink(endNode); fileValueNode.AddLink(idleNode); fileValueNode.AddLink(endNode); var parser = new Parser { Root = root, }; // Act var tokens = lexer.Tokenize(commandText.AsMemory()); var result = new CliParsingResult(); parser.Parse(tokens, result); // Assert Assert.That(result.Command, Is.EqualTo("sd")); Assert.That(result.KeyValues, Has.Count.EqualTo(3)); Assert.That(result.KeyValues, Does.ContainKey("connection")); Assert.That(result.KeyValues["connection"].Single(), Is.EqualTo(connectionString)); Assert.That(result.KeyValues, Does.ContainKey("provider")); Assert.That(result.KeyValues["provider"].Single(), Is.EqualTo(provider)); Assert.That(result.KeyValues, Does.ContainKey("file")); Assert.That(result.KeyValues["file"].Single(), Is.EqualTo(filePath)); }
private void AddToDictionary( PoeNinjaDataService.ItemJsonResponse.Line line, GenerateItemKeysSetting settings) { // ignore any items with less then the minimum required number of links if(settings.AddLinksProperty && line.Links < settings.MinimumNumberOfLinks) { return; } // ignore any items with less then the minimum required gem level if(settings.AddGemLevelProperty && line.GemLevel < settings.MinimumGemLevel) { return; } line.Name = line.Name.Trim(); var keyNode = new KeyNode { Description = line.Name, Key = FormatStringToKey(line, settings), }; keyNode.Attributes.Add($"[Name(Name = \"{line.Name}\")]"); var attributeProperties = new List<string>(); if(line.Id != -1) { keyNode.Attributes.Add($"[PoeNinja]"); attributeProperties.Add($"PoeNinjaId = {line.Id}"); } if(settings.AddUniqueProperty) { attributeProperties.Add($"Unique = true"); } if(settings.AddMapTierProperty) { attributeProperties.Add($"MapTier = {line.MapTier}"); } if(settings.AddLinksProperty) { attributeProperties.Add($"Links = {line.Links}"); } if(settings.AddGemLevelProperty) { attributeProperties.Add($"GemLevel = {line.GemLevel}"); } if(settings.AddGemQualityProperty) { attributeProperties.Add($"Quality = {line.GemQuality}"); } var attribute = $"[{settings.AttributeTypeName}"; if(attributeProperties.Count > 0) { attribute += $"("; attribute += string.Join(", ", attributeProperties); attribute += $")"; } attribute += "]"; keyNode.Attributes.Add(attribute); AddToDictionary(keyNode); }
public void Free(KeyNode <K> node) { DoFree(node.Offset, node.Length); }
public static Allocation New <K>(KeyNode <K> node) { return(new Allocation(node.Offset, node.Offset + node.Length)); }
public void Alloc(KeyNode <K> node) { node.Offset = DoAlloc(node.Length); }