/// <summary> /// Uploads the specified file name with the field specified. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="fieldSelector">The field selector.</param> /// <param name="conditions">The conditions.</param> public abstract void Upload(string fileName, string fieldSelector, API.Point offset, MatchConditions conditions);
public static dynamic DeserializeArguments(Type type, Dictionary<string, dynamic> arguments) { var result = Activator.CreateInstance(type); var properties = type.GetProperties(); foreach (var property in properties) { var argumentKey = arguments.Keys.FirstOrDefault(x => x.Equals(property.Name, StringComparison.InvariantCultureIgnoreCase)); if (argumentKey != null) { var value = arguments[argumentKey]; // Nullable properties if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { var args = property.PropertyType.GetGenericArguments(); // Nullable<Enum> if (args.First().IsEnum) { property.SetValue(result, Enum.Parse(args.First(), value), null); } // Nullable<int> if (args.First() == typeof(Int32)) { property.SetValue(result, Int32.Parse(value), null); } } // Handle expressions else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Expression<>)) { var args = property.PropertyType.GetGenericArguments(); var firstArg = args.First(); // Expression<Func<,>> if (firstArg.IsGenericType && firstArg.GetGenericTypeDefinition() == typeof(Func<,>)) { var paramArgs = firstArg.GetGenericArguments(); // parse parameters from expression var variablesSection = value.Substring(0, value.IndexOf("=>")).Trim(' ', '(', ')').Replace(" ", ""); string[] variables = variablesSection.Split(','); var exprString = value.Substring(value.IndexOf("=>") + 2).Trim(); int i = 0; List<ParameterExpression> parameters = new List<ParameterExpression>(); foreach (var paramArg in paramArgs) { // last arg is return type if (paramArg == paramArgs.Last()) break; parameters.Add(Expression.Parameter(paramArg, variables[i])); if (variables.Length < i) { i++; } } var expr = DynamicExpressionBuilder.ParseLambda( parameters.ToArray(), paramArgs.Last(), exprString ); property.SetValue(result, expr, null); } } // Handle normal enumerations else if (property.PropertyType.IsEnum) { property.SetValue(result, Enum.Parse(property.PropertyType, value), null); } // string -> API.Point else if (property.PropertyType == typeof(API.Point)) { API.Point point = new API.Point() { X = Int32.Parse(value.Substring(0, value.IndexOf(','))), Y = Int32.Parse(value.Substring(value.IndexOf(',') + 1)) }; property.SetValue(result, point, null); } // string -> API.Size else if (property.PropertyType == typeof(API.Size)) { API.Size size = new API.Size() { Width = Int32.Parse(value.Substring(0, value.IndexOf(','))), Height = Int32.Parse(value.Substring(value.IndexOf(',') + 1)) }; property.SetValue(result, size, null); } // Arrays else if (property.PropertyType.IsArray) { property.SetValue(result, value, null); } // List<string> (deserializes as JArray) else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First() == typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { List<string> listInstance = new List<string>(); foreach (var item in value) { listInstance.Add(item.ToString()); } property.SetValue(result, listInstance, null); } // List<int> (deserializes as JArray) else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First() == typeof(Int32) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { List<int> listInstance = new List<int>(); foreach (var item in value) { listInstance.Add(Int32.Parse(item.ToString())); } property.SetValue(result, listInstance, null); } // List<Enum> else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First().IsEnum && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { dynamic listInstance = Activator.CreateInstance(property.PropertyType); foreach (var item in value) { listInstance.Add(Enum.Parse(property.PropertyType.GetGenericArguments().First(), item.ToString())); } property.SetValue(result, listInstance, null); } // Handle IConvertible types else { property.SetValue(result, Convert.ChangeType(value, property.PropertyType), null); } } } return result; }
/// <summary> /// Hovers the within. /// </summary> /// <param name="selector">The selector.</param> /// <param name="point">The point.</param> public abstract void HoverWithin(string selector, API.Point point);
/// <summary> /// Hovers over the point (X, Y coordinates). /// </summary> /// <param name="point">The point.</param> public abstract void HoverPoint(API.Point point);
/// <summary> /// Uploads the specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="fieldSelector">The field selector.</param> /// <param name="offset">The offset.</param> public void Upload(string fileName, string fieldSelector, API.Point offset) { Upload(fileName, fieldSelector, offset, MatchConditions.Visible); }
public override void ClickPoint(API.Point point) { MouseControl.Click(point); }
public override void ClickPoint(API.Point point) { this.ClickWithin("body", point); }
public override void HoverPoint(API.Point point) { this.HoverWithin("body", point); }
public static dynamic DeserializeArguments(Type type, Dictionary <string, dynamic> arguments) { var result = Activator.CreateInstance(type); var properties = type.GetProperties(); foreach (var property in properties) { var argumentKey = arguments.Keys.FirstOrDefault(x => x.Equals(property.Name, StringComparison.InvariantCultureIgnoreCase)); if (argumentKey != null) { var value = arguments[argumentKey]; // Nullable properties if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { var args = property.PropertyType.GetGenericArguments(); // Nullable<Enum> if (args.First().IsEnum) { property.SetValue(result, Enum.Parse(args.First(), value), null); } // Nullable<int> if (args.First() == typeof(Int32)) { property.SetValue(result, Int32.Parse(value), null); } } // Handle expressions else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericTypeDefinition() == typeof(Expression <>)) { var args = property.PropertyType.GetGenericArguments(); var firstArg = args.First(); // Expression<Func<,>> if (firstArg.IsGenericType && firstArg.GetGenericTypeDefinition() == typeof(Func <,>)) { var paramArgs = firstArg.GetGenericArguments(); // parse parameters from expression var variablesSection = value.Substring(0, value.IndexOf("=>")).Trim(' ', '(', ')').Replace(" ", ""); string[] variables = variablesSection.Split(','); var exprString = value.Substring(value.IndexOf("=>") + 2).Trim(); int i = 0; List <ParameterExpression> parameters = new List <ParameterExpression>(); foreach (var paramArg in paramArgs) { // last arg is return type if (paramArg == paramArgs.Last()) { break; } parameters.Add(Expression.Parameter(paramArg, variables[i])); if (variables.Length < i) { i++; } } var expr = DynamicExpressionBuilder.ParseLambda( parameters.ToArray(), paramArgs.Last(), exprString ); property.SetValue(result, expr, null); } } // Handle normal enumerations else if (property.PropertyType.IsEnum) { property.SetValue(result, Enum.Parse(property.PropertyType, value), null); } // string -> API.Point else if (property.PropertyType == typeof(API.Point)) { API.Point point = new API.Point() { X = Int32.Parse(value.Substring(0, value.IndexOf(','))), Y = Int32.Parse(value.Substring(value.IndexOf(',') + 1)) }; property.SetValue(result, point, null); } // string -> API.Size else if (property.PropertyType == typeof(API.Size)) { API.Size size = new API.Size() { Width = Int32.Parse(value.Substring(0, value.IndexOf(','))), Height = Int32.Parse(value.Substring(value.IndexOf(',') + 1)) }; property.SetValue(result, size, null); } // Arrays else if (property.PropertyType.IsArray) { property.SetValue(result, value, null); } // List<string> (deserializes as JArray) else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First() == typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { List <string> listInstance = new List <string>(); foreach (var item in value) { listInstance.Add(item.ToString()); } property.SetValue(result, listInstance, null); } // List<int> (deserializes as JArray) else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First() == typeof(Int32) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { List <int> listInstance = new List <int>(); foreach (var item in value) { listInstance.Add(Int32.Parse(item.ToString())); } property.SetValue(result, listInstance, null); } // List<Enum> else if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments().First().IsEnum&& typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { dynamic listInstance = Activator.CreateInstance(property.PropertyType); foreach (var item in value) { listInstance.Add(Enum.Parse(property.PropertyType.GetGenericArguments().First(), item.ToString())); } property.SetValue(result, listInstance, null); } // Handle IConvertible types else { property.SetValue(result, Convert.ChangeType(value, property.PropertyType), null); } } } return(result); }
/// <summary> /// Sets the cursor position to the specified point (X, Y coordinates). /// </summary> /// <param name="point">The point.</param> public static void SetPosition(API.Point point) { SetCursorPos(point.X, point.Y); }
/// <summary> /// Clicks the specified point (X, Y coordinates). /// </summary> /// <param name="point">The point.</param> public static void Click(API.Point point) { SetPosition(point); MouseEvent(MouseEvent_LeftButtonDown, point.X, point.Y, 0, 0); MouseEvent(MouseEvent_LeftButtonUp, point.X, point.Y, 0, 0); }