using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TradeIdeas.Logging;
using static TIProAutoTradeExtension.ChromiumPositionsControl;
namespace TIProAutoTradeExtension
{
public static class AutoTradeExtensions
{
///
/// Try to find the first non-null position that matches the supplied predicate.
/// Returns success if it finds any or failure otherwise.
/// On success, it returns the first match found in the foundPosition output parameter.
///
///
///
///
///
public static bool TryFind(this List chartPositions, Predicate match, out ChartPosition foundPosition)
{
foundPosition = null;
if (chartPositions != null && match != null)
{
foreach (var position in chartPositions)
{
try
{
if (position != null && match(position))
{
foundPosition = position;
break;
}
}
catch (Exception ex)
{
TILogger.Error($"Error procesing position: {ex.Message}", ex, "PositionsGrid", data: position);
}
}
return foundPosition != null;
}
else
return false;
}
///
/// Finds all non-null positions that match the supplied predicate.
/// Returns success if it finds any or failure otherwise.
/// On success it returns the matching list in the obtainedPositions output parameter.
///
///
///
///
///
public static bool TryFindAll(this List chartPositions, Predicate match, out List obtainedPositions)
{
obtainedPositions = null;
if (chartPositions != null && match != null)
{
var matchesPositions = new List();
foreach (var position in chartPositions)
{
try
{
if (position != null && match(position))
{
matchesPositions.Add(position);
}
}
catch (Exception ex)
{
TILogger.Error($"Error procesing position: {ex.Message}", ex, "PositionsGrid", data: position);
}
}
if (matchesPositions.Count > 0)
obtainedPositions = matchesPositions.ToList();
return matchesPositions.Count > 0;
}
else
return false;
}
}
}