internal static IEnumerator Find(Type T, int Offset, int Top, ScriptNode Where, Variables Variables, string[] Order, ScriptNode Node) { object[] FindParameters = new object[] { Offset, Top, Convert(Where, Variables), Order }; object Obj = FindMethod.MakeGenericMethod(T).Invoke(null, FindParameters); if (!(Obj is Task Task)) { throw new ScriptRuntimeException("Unexpected response.", Node); } PropertyInfo PI = Task.GetType().GetRuntimeProperty("Result"); if (PI == null) { throw new ScriptRuntimeException("Unexpected response.", Node); } Obj = PI.GetValue(Task); if (!(Obj is IEnumerable Enumerable)) { throw new ScriptRuntimeException("Unexpected response.", Node); } return(Enumerable.GetEnumerator()); }
/// <summary> /// Finds objects matching filter conditions in <paramref name="Where"/>. /// </summary> /// <param name="Offset">Offset at which to return elements.</param> /// <param name="Top">Maximum number of elements to return.</param> /// <param name="Where">Filter conditions.</param> /// <param name="Variables">Current set of variables.</param> /// <param name="Order">Order at which to order the result set.</param> /// <param name="Node">Script node performing the evaluation.</param> /// <returns>Enumerator.</returns> public async Task <IResultSetEnumerator> Find(int Offset, int Top, ScriptNode Where, Variables Variables, KeyValuePair <VariableReference, bool>[] Order, ScriptNode Node) { object[] FindParameters = new object[] { Offset, Top, Convert(Where, Variables, this.Name), Convert(Order) }; object Obj = FindMethod.MakeGenericMethod(this.type).Invoke(null, FindParameters); if (!(Obj is Task Task)) { throw new ScriptRuntimeException("Unexpected response.", Node); } await Task; PropertyInfo PI = Task.GetType().GetRuntimeProperty("Result"); if (PI is null) { throw new ScriptRuntimeException("Unexpected response.", Node); } Obj = PI.GetValue(Task); if (!(Obj is IEnumerable Enumerable)) { throw new ScriptRuntimeException("Unexpected response.", Node); } return(new SynchEnumerator(Enumerable.GetEnumerator())); }
private void BinarySearch(ref List <Product> list, FindMethod find, int left, int right) { if (left > right) { return; } int middle = (left + right) / 2; Product item = products[middle]; int compare_result = find(item); if (compare_result == 0) { list.Add(item); return; } else { if (compare_result == 1) { BinarySearch(ref list, find, left, middle); } else { BinarySearch(ref list, find, middle + 1, right); } } return; }
private FrameworkElement findLogicalAncestor(ParameterDic pm, FrameworkElement sender) { switch (FindMethod) { case UIEventHub.FindMethodType.Name: string name = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? ""; return(UITools.FindLogicalAncestor <FrameworkElement>(sender, ele => name.Equals(ele.Name))); case UIEventHub.FindMethodType.Type: string type = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? ""; return(UITools.FindLogicalAncestor <FrameworkElement>(sender, ele => ele.GetType().Name.Equals(type, StringComparison.CurrentCultureIgnoreCase))); case UIEventHub.FindMethodType.Level: int level = pm.GetValue <int>(FindParameterKey, -1); if (level == -1) { return(null); } FrameworkElement current = sender; for (int i = 0; i < level; i++) { if (current != null) { current = LogicalTreeHelper.GetParent(current) as FrameworkElement; } } return(current); default: throw new NotSupportedException(FindMethod.ToString()); } }
public void ToXml(XmlWriter writer) { writer.WriteStartElement("Finder"); writer.WriteAttributeString("FindMethod", FindMethod.ToString()); writer.WriteAttributeString("FindName", FindName); writer.WriteAttributeString("FindValue", FindValue); writer.WriteAttributeString("Regex", Regex?"1":"0"); writer.WriteEndElement(); }
private FrameworkElement findLogicalChild(ParameterDic pm, FrameworkElement sender) { switch (FindMethod) { case UIEventHub.FindMethodType.Name: string name = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? ""; return(UITools.FindLogicalChild <FrameworkElement>(sender, ele => name.Equals(ele.Name))); case UIEventHub.FindMethodType.Type: string type = pm.ReplaceVariableInsideBracketed(FindParameterKey) ?? ""; return(UITools.FindLogicalChild <FrameworkElement>(sender, ele => ele.GetType().Name.Equals(type, StringComparison.CurrentCultureIgnoreCase))); default: throw new NotSupportedException(FindMethod.ToString()); } }
public void Search(FindArgs args) { _searchText = args.SearchText; _searchRegex = args.SearchRegex; _method = args.Method; _matchCase = args.MatchCase; _matchWholeWord = args.MatchWholeWord; _probeFilesOnly = args.ProbeFilesOnly; _panel = args.Panel; _includeFilter = new FilePatternFilter(args.IncludeExtensions); _excludeFilter = new FilePatternFilter(args.ExcludeExtensions); _thread = new Thread(new ThreadStart(ThreadProc)); _thread.Name = "Find in Probe Files"; _thread.Start(); }
public string ToAttribute() { string result; string finder = FindMethod.ToString() != "Href" ? FindMethod.ToString() : "Url"; string findvalue = FindValue.Replace("\"", "\\\""); if (string.IsNullOrEmpty(FindName)) { result = "FindBy(" + finder + " = \"" + findvalue + "\")"; } else { result = "FindBy(" + finder + " = \"" + FindName + "\", \"" + findvalue + "\")"; } return(result); }
public static KnapsackProblemData LoadData(string filename) { var lines = File.ReadAllLines(filename); var data = new KnapsackProblemDataParser(); FindMethod f = FindConstraint; foreach (var line in lines) { f = f(line.Trim(), data); if (f == null) { break; } } return(new KnapsackProblemData(data.Resources.ToArray(), data.MaxWeight, data.Solution.ToArray())); }
public override string ToString() { string result; string finder = FindMethod.ToString() != "Href" ? FindMethod.ToString() : "Url"; string findvalue = ""; try { findvalue = FindValue != null?FindValue.Replace("\"", "\\\"") : ""; } catch (Exception) { } if (string.IsNullOrEmpty(FindName)) { result = "Find.By" + finder + "(\"" + findvalue + "\")"; } else { result = "Find.By" + finder + "(\"" + FindName + "\", \"" + findvalue + "\")"; } return(result); }
=> new MethodRefBuilder(module, typeRef, FindMethod(typeRef, methodName, genericArity, paramTypes ?? throw new ArgumentNullException(nameof(paramTypes))));
/// <summary> /// Lock a gameobject, and look at it. /// So the object will seems like it /// "approach/further away" to the object. /// </summary> /// <param name="method"> method to find. </param> public void LockOnInit(FindMethod method) { JCS_2DLiveObject closestliveObj = null; switch (method) { case FindMethod.CLOSEST: closestliveObj = FindClosest(); break; case FindMethod.CLOSEST_RIGHT: closestliveObj = FindClosestRight(); break; case FindMethod.CLOSEST_LEFT: closestliveObj = FindClosestLeft(); break; case FindMethod.CLOSEST_TOP: closestliveObj = FindClosestTop(); break; case FindMethod.CLOSEST_BOTTOM: closestliveObj = FindClosestBottom(); break; } // no object found! if (closestliveObj == null) { return; } Vector3 newLookPoint = closestliveObj.transform.position; // look at the target object this.transform.LookAt(newLookPoint); // rotate back to original point. if (mRotateBack90) { this.transform.Rotate(0, -90, 0); } if (mAttackerInfo.Attacker != null) { if (mDirection == State.NONE) { if (JCS_Mathf.IsNegative(mAttackerInfo.Attacker.localScale.x)) { mDirection = State.NEGATIVE; } else { mDirection = State.POSITIVE; } } // 我們規定所有的圖往一邊, 所以只檢查一邊. if (mDirection == State.NEGATIVE) { this.transform.Rotate(0, 0, 180); } } #if (UNITY_EDITOR) // print out the name. if (JCS_GameSettings.instance.DEBUG_MODE) { JCS_Debug.PrintName(closestliveObj.transform); } #endif }
public extern Component FindComponentByName(string name, FindMethod findMethod = FindMethod.Recursive);
public extern SceneNode FindChildByName(string name, FindMethod findMethod = FindMethod.Recursive);
public void FindNextBytes(IHexDataContext hex, byte[] findBytes, FindMethod method) => FindNextBytes(hex, findBytes, method, false, -1, -1);
public void FindNextBytes(IHexDataContext hex, byte[] findBytes, FindMethod findMethod, bool isBlockSearch, int blockSize, int blockOffset) { if (findBytes == null || findBytes.Length == 0) { LoggerService.Current?.WriteCallerLine($"{nameof(findBytes)} can't be null or empty."); return; } if (isBlockSearch && (blockSize <= 0 || blockOffset < 0)) { throw new ArgumentException($"Invalid Argument(s):{nameof(blockSize)} or {nameof(blockOffset)}"); } long pos = (hex.FocusPosition == -1 ? 0 : hex.FocusPosition) + 1; var dialog = DialogService.Current.CreateLoadingDialog(); dialog.WindowTitle = findMethod == FindMethod.Text ? ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("SearchingForText") : ServiceProvider.Current?.GetInstance <ILanguageService>()?.FindResourceString("SearchingForHex"); dialog.DoWork += (sender, e) => { if (isBlockSearch) { pos = hex.Stream.SearchBlock(pos, blockSize, blockOffset, findBytes, index => { dialog.ReportProgress((int)(index * 100 / hex.Stream.Length)); }, () => dialog.CancellationPending); } else { pos = hex.Stream.Search(pos, findBytes, index => { dialog.ReportProgress((int)(index * 100 / hex.Stream.Length)); }, () => dialog.CancellationPending); } }; dialog.RunWorkerCompleted += (sender, e) => { if (e.Cancelled) { return; } if (pos == -1) { MsgBoxService.Show(LanguageService.FindResourceString("CannotFindTheContent")); return; } if (hex.BytePerLine <= 0) { LoggerService.WriteCallerLine($"{nameof(hex.BytePerLine)} can't be less than zero."); MsgBoxService.Show("Un expected error"); return; } hex.Position = pos / hex.BytePerLine * hex.BytePerLine; hex.FocusPosition = pos; }; dialog.ShowDialog(); }
private void btnOk_Click(object sender, EventArgs e) { try { _searchText = cmbSearchText.Text; if (string.IsNullOrEmpty(_searchText)) return; _method = cmbMethod.GetEnumValue<FindMethod>(); _matchCase = chkMatchCase.Checked; _matchWholeWord = chkMatchWholeWord.Checked; _onlyProbeFiles = chkOnlyProbeFiles.Checked; _includeExtensions = string.IsNullOrWhiteSpace(txtIncludeExtensions.Text) ? "*" : txtIncludeExtensions.Text; _excludeExtensions = txtExcludeExtensions.Text; switch (_method) { case FindMethod.RegularExpression: try { _regex = new Regex(_searchText, chkMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase); } catch (Exception ex) { Errors.Show(this, ex, "Invalid regular expression."); _regex = null; return; } break; case FindMethod.CodeFriendly: _regex = GenerateCodeFriendlyRegex(); break; default: _regex = null; break; } var mru = new List<string>(); mru.Add(_searchText); foreach (string item in cmbSearchText.Items) { if (item != _searchText && mru.Count < k_maxMru) mru.Add(item); } SaveMru(mru.ToArray()); ProbeNppPlugin.Instance.Settings.FindInProbeFiles.Method = _method; ProbeNppPlugin.Instance.Settings.FindInProbeFiles.MatchCase = _matchCase; ProbeNppPlugin.Instance.Settings.FindInProbeFiles.MatchWholeWord = _matchWholeWord; ProbeNppPlugin.Instance.Settings.FindInProbeFiles.OnlyProbeFiles = _onlyProbeFiles; ProbeNppPlugin.Instance.Settings.FindInProbeFiles.IncludeExtensions = _includeExtensions; ProbeNppPlugin.Instance.Settings.FindInProbeFiles.ExcludeExtensions = _excludeExtensions; DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { Errors.Show(this, ex); } }
public List <Product> Find(ref List <Product> list, CompareMethod compare_by, FindMethod find) { Sort(compare_by); BinarySearch(ref list, find, 0, products.Length - 1); return(list); }