/// <summary> /// The value of that element is the index of the first item of y to which the cell is identical. /// </summary> /// <param name="element">AType to search for.</param> /// <param name="arguments">Instead of class variables.</param> /// <returns></returns> private AType Classify(AType element, FindArguments arguments) { int resultIndex; if (arguments.Items.IsArray) { // check if the given left argument of the function contains the element for (resultIndex = 0; resultIndex < arguments.Items.Length; resultIndex++) { if (ComparisonToleranceCompareTo(arguments.Items[resultIndex], element)) { break; } } } else if (ComparisonToleranceCompareTo(arguments.Items, element)) { resultIndex = 0; } else { // item not found resultIndex = arguments.Items.Length; } return(AInteger.Create(resultIndex)); }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { FindArguments args = (FindArguments)e.Argument; int length = args.packetLog.Length; for (int i = 0; i < length; ++i) { if (backgroundWorker.CancellationPending) { e.Cancel = true; break; } else { int percent = (i * 100) / length; if (args.filter.IsMatch(args.packetLog[i].Frame)) { backgroundWorker.ReportProgress(percent, args.packetLog[i]); } else { backgroundWorker.ReportProgress(percent); } } } }
protected void btnFind_Click(object sender, EventArgs e) { FindArguments findArgs = new FindArguments(); findArgs.Where = txtWhere.Text; Map1.Find(findArgs); }
protected void btnFind_Click(object sender, EventArgs e) { FindArguments findArgs = new FindArguments(); if (!string.IsNullOrEmpty(txtWhat.Text)) { findArgs.What = txtWhat.Text; } if (!string.IsNullOrEmpty(txtWhere.Text)) { findArgs.Where = txtWhere.Text; } Map1.Find(findArgs); }
private void btnFind_Click(object sender, EventArgs e) { if (backgroundWorker.IsBusy) { backgroundWorker.CancelAsync(); } else { if ((comboBoxEncoding.SelectedItem == null) || (comboBoxMode.SelectedItem == null)) { MessageBox.Show(this, CANAPE.Properties.Resources.FindPacketForm_SelectModeEncoding, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (textBoxValue.Text.Length == 0) { MessageBox.Show(CANAPE.Properties.Resources.FindPacketForm_SpecifySearch, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { // Start find FindArguments args = new FindArguments(); packetLogControl.ClearLog(); lock (_packetLog) { args.packetLog = _packetLog.ToArray(); } args.filter = CreateFilter(); btnFind.Text = CANAPE.Properties.Resources.FindPacketForm_CancelButtonText; backgroundWorker.RunWorkerAsync(args); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, CANAPE.Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// <summary> /// If the cell rank > 1, first step is check the shape of actual cell equal to determined cell shape. /// If different we throw Length error. The second step is classify the cell. /// </summary> /// <param name="cell"></param> /// <param name="arguments">Instead of class variables.</param> /// <returns></returns> private AType MultipleItemsWalking(AType cell, FindArguments arguments) { if (arguments.CellShape.Count == cell.Shape.Count) { if (!arguments.CellShape.SequenceEqual(cell.Shape)) { throw new Error.Length(LengthErrorText); } return(Classify(cell, arguments)); } else { AType result = AArray.Create(ATypes.AInteger); foreach (AType item in cell) { result.AddWithNoUpdate(MultipleItemsWalking(item, arguments)); } result.UpdateInfo(); return(result); } }
/// <summary> /// Prepare the left side and determine the cellshape. /// </summary> /// <param name="left"></param> /// <param name="right"></param> private FindArguments PrepareVariables(AType left, AType right) { // Error if the arguments: // - are not from the same general type // - and one of them is a Null if (!Utils.IsSameGeneralType(left, right) && !(left.Type == ATypes.ANull || right.Type == ATypes.ANull)) { throw new Error.Type(TypeErrorText); } FindArguments arguments = new FindArguments() { Items = left, CellShape = (left.Rank > 1 && left.Length > 0) ? left[0].Shape : new List <int>() }; if (right.Rank < arguments.CellShape.Count) { throw new Error.Rank(RankErrorText); } return(arguments); }
/// <summary> /// If the cell rank > 1, first step is check the shape of actual cell equal to determined cell shape. /// If different we throw Length error. The second step is classify the cell. /// </summary> /// <param name="cell"></param> /// <param name="arguments">Instead of class variables.</param> /// <returns></returns> private AType MultipleItemsWalking(AType cell, FindArguments arguments) { if (arguments.CellShape.Count == cell.Shape.Count) { if (!arguments.CellShape.SequenceEqual(cell.Shape)) { throw new Error.Length(LengthErrorText); } return Classify(cell, arguments); } else { AType result = AArray.Create(ATypes.AInteger); foreach (AType item in cell) { result.AddWithNoUpdate(MultipleItemsWalking(item, arguments)); } result.UpdateInfo(); return result; } }
/// <summary> /// Prepare the left side and determine the cellshape. /// </summary> /// <param name="left"></param> /// <param name="right"></param> private FindArguments PrepareVariables(AType left, AType right) { // Error if the arguments: // - are not from the same general type // - and one of them is a Null if (!Utils.IsSameGeneralType(left, right) && !(left.Type == ATypes.ANull || right.Type == ATypes.ANull)) { throw new Error.Type(TypeErrorText); } FindArguments arguments = new FindArguments() { Items = left, CellShape = (left.Rank > 1 && left.Length > 0) ? left[0].Shape : new List<int>() }; if (right.Rank < arguments.CellShape.Count) { throw new Error.Rank(RankErrorText); } return arguments; }
public override AType Execute(AType right, AType left, Aplus environment = null) { FindArguments arguments = PrepareVariables(left, right); return(MultipleItemsWalking(right, arguments)); }
/// <summary> /// The value of that element is the index of the first item of y to which the cell is identical. /// </summary> /// <param name="element">AType to search for.</param> /// <param name="arguments">Instead of class variables.</param> /// <returns></returns> private AType Classify(AType element, FindArguments arguments) { int resultIndex; if (arguments.Items.IsArray) { // check if the given left argument of the function contains the element for (resultIndex = 0; resultIndex < arguments.Items.Length; resultIndex++) { if (ComparisonToleranceCompareTo(arguments.Items[resultIndex], element)) { break; } } } else if (ComparisonToleranceCompareTo(arguments.Items, element)) { resultIndex = 0; } else { // item not found resultIndex = arguments.Items.Length; } return AInteger.Create(resultIndex); }