public static void SetValueIndex(ValueIndex Index, string Scheme, string SubGroup, string Settings, string Value) { if (!IsUserAnAdmin()) { throw new System.UnauthorizedAccessException("User must be an administrator to modify value indexes"); } List <string> error = new List <string>(); var p = new Process { StartInfo = new ProcessStartInfo { FileName = "powercfg.exe", Arguments = $"{(Index == ValueIndex.AC ? "/SETACVALUEINDEX" : "/SETDCVALUEINDEX")} {Scheme} {SubGroup} {Settings} {Value}", UseShellExecute = false, RedirectStandardError = true, CreateNoWindow = true } }; p.Start(); while (!p.StandardError.EndOfStream) { string line = p.StandardError.ReadLine(); error.Add(line); } bool exited = p.WaitForExit(5000); if (!exited) { throw new System.TimeoutException($"Timeout setting {SubGroup} {Settings} value index: {String.Join(",", error.ToArray())}"); } if (p.ExitCode != 0) { throw new System.ArgumentException($"Could not set {SubGroup} {Settings} value index: {String.Join(",", error.ToArray())}"); } }
static void AddValue(Message message, ValueIndex index, string data) { var newIndex = index.Clone() as ValueIndex; message.AddValue(newIndex, data); }
void Parse(Message message, int depth, List<char> separators, ValueIndex index, string data) { if (separators.Count == 0) return; int currentLevel = depth - separators.Count(); if (string.IsNullOrEmpty(data)) { AddValue(message, index, null); index.Increment(currentLevel); return; } if (separators == null || separators.Count == 0) return; var currentSeparator = separators.First(); var nextSeparators = separators.Count == 1 ? separators : separators.Skip(1).ToList(); var splits = Split(currentSeparator, data); if (splits.Count == 1 && separators.Count == 1) { AddValue(message, index, data); index.Increment(currentLevel); return; } for (int i = 0; i < splits.Count; i++) { Parse(message, depth, nextSeparators, index, splits[i]); index.Increment(currentLevel); } }
private void FillStructure() { _InFillStructure = true; if (!(_DataSource == null || string.IsNullOrEmpty(_ValueMember) || string.IsNullOrEmpty(_DisplayMember) || string.IsNullOrEmpty(_ParentLinkMember) || string.IsNullOrEmpty(_IsSelectableMember))) { this.BeginUpdate(); this.Nodes.Clear(); ValueIndex.Clear(); CheckedNodes = new List <gTreeNode>(); // TODO: Implement Sorting //_DataSource.DefaultView.Sort = _SortByMember; // ================================================ foreach (var DataItem in _DataSource) { Object parentLinkValue = DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null); if (parentLinkValue == null || Convert.ToInt32(parentLinkValue) == 0) { Font nodeFont = default(System.Drawing.Font); if (!(bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null)) { nodeFont = new System.Drawing.Font(this.Font, FontStyle.Italic); } else { nodeFont = new System.Drawing.Font(this.Font, FontStyle.Regular); } gTreeNode newNode = new gTreeNode(DataItem.GetType().GetProperty(_DisplayMember).GetValue(DataItem, null) as string, DataItem.GetType().GetProperty(_ValueMember).GetValue(DataItem, null), DataItem, (bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null), nodeFont); this.Nodes.Add(newNode); ValueIndex.Add(newNode.Key, newNode.FullPath); } } bool NodesAdded = false; do { NodesAdded = false; foreach (var DataItem in _DataSource) { Object parentLinkValue = DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null); if (parentLinkValue != null && ValueIndex.ContainsKey(parentLinkValue)) { Font nodeFont = default(System.Drawing.Font); if (!(bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null)) { nodeFont = new System.Drawing.Font(this.Font, FontStyle.Italic); } else { nodeFont = new System.Drawing.Font(this.Font, FontStyle.Regular); } gTreeNode newNode = new gTreeNode(DataItem.GetType().GetProperty(_DisplayMember).GetValue(DataItem, null) as string, DataItem.GetType().GetProperty(_ValueMember).GetValue(DataItem, null), DataItem, (bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null), nodeFont); if (!ValueIndex.ContainsKey(newNode.Key)) { FindGTreeNode(ValueIndex[DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null)]).Nodes.Add(newNode); ValueIndex.Add(newNode.Key, newNode.FullPath); NodesAdded = true; } } } } while (NodesAdded); this.EndUpdate(); } else { this.Nodes.Clear(); } this.SelectedNode = null; _InFillStructure = false; }