using System.Collections.Generic;
using System.Diagnostics;
private static void survey(string uri)
Model model = new Model();
model.States = new List<StateDef>();
model.States.Add(new StateDef());
model.States[0].Name = "NullState";
model.Transitions = new List<StateTransition>();
model.Transitions.Add(new StateTransition());
model.Transitions[0].Begin = model.States[0];
model.Transitions[0].Action.Name = "browse";
model.Transitions[0].Action.Params = new List<StateActionParam>();
model.Transitions[0].Action.Params.Add(new StateActionParam());
model.Transitions[0].Action.Params[0].Name = "uri";
model.Transitions[0].Action.Params[0].Value = uri;
var defaultActionArgs = uri;
var htmlText = HttpRequest.Get(uri);
model.States.Add(new StateDef());
model.States[1].Name = removeSpaces(getTitle(htmlText));
model.Transitions[0].End = model.States[1];
var json = JsonConvert.SerializeObject(model);
using (var sw = new StreamWriter(file))
private static object getTitle(object htmlText)
throw new NotImplementedException();
private static string removeSpaces(object p)
throw new NotImplementedException();
private static void parse(Model model, string htmlText)
var items = XPath.Search("<input>");
var items2 = XPath.Search("<input type='text'");
Console.WriteLine("Here are the text/button inputs on the page {0}", title);
var uiElems = new Dictionary<string, List<string>>();
uiElems.Add("textBox", new List<string>());
uiElems.Add("button", new List<string>());
if (i.Attributes["type"] != null)
if (i.Attributes["type"].Equals("text"))
string ident = getIdent(i,"text");
Console.WriteLine("textbox: {0}", ident);
uiElems["textBox"].Add(ident);
else if (i.Attributes["type"].Equals("button"))
string ident = getIdent(i, "button");
Console.WriteLine("button: {0}", ident);
uiElems["button"].Add(ident);
Console.WriteLine("Please enter values into input fields. Confirm with 'y'.");
var key = Console.ReadKey();
if (key.KeyChar.ToString().ToLower() == "y")
Console.WriteLine("Any more pages to visit (i.e. 'y')?");
if (key.KeyChar.ToString().ToLower() == "y")
Console.WriteLine("Please indicate the id or name of the element to click to proceed to the next page (i.e. name=x):");
var ident = Console.ReadLine();
var htmlText = click(ident);
private static string getIdent(object i, string type)
if (i.Attributes.Contains("id"))
ident = string.Format("id={0}", i.Attributes["id"]);
else if (i.Attributes.Contains("name"))
ident = string.Format("name={0}", i.Attributes["name"]);
else throw new InvalidOperationException(string.Format("Error: Can't find 'id' nor 'name' attribute for {0} input element", type));
private static object click(string ident)
throw new NotImplementedException();
private static void getValues(Dictionary<string, List<string>> uiElems)
throw new NotImplementedException();
public static void Main(string[] args)
private static void testCases()
private static void verify(object expect, object actual)
var expectedList = (List<int>)expect;
var actualList = (List<int>)actual;
if (expectedList.Count != actualList.Count) { Console.WriteLine("Error: Mismatch list count"); return; }
for(var i=0; i<expectedList.Count; i++)
if (e != a) { Console.WriteLine("Error: Mismatch, Expected={0}, Actual={1}",e,a); return; }
private static object model(object t)
var output = new List<object>();
private static object solve(object t)
var output = new List<object>();
var o = capture(i.End.Flags);
private static object clone(List<Flag> flags)
throw new NotImplementedException();
private static void set(List<Flag> flags)
throw new NotImplementedException();
private static void ensure(StateDef begin)
private static object capture(List<Flag> flags)
throw new NotImplementedException();
private static object execute(StateAction action)
throw new NotImplementedException();
private static IEnumerable<object> read()
var model = ModelReader.Read(FileType.Json, file);
foreach (var p in model.Paths)
private static List<int> generate(int count = 10)
var list = new List<int>();
for (int i = 0; i < count; i++)
list.Add(r.Next(int.MaxValue));
internal class StateActionParam
public string Name { get; internal set; }
public string Value { get; internal set; }
public static Model Read(FileType type, string file)
throw new NotImplementedException();
public List<Flag> Flags { get; set; }
public List<StateDef> States { get; set; }
public List<StateAction> Actions { get; set; }
public List<StatePath> Paths { get; set; }
public List<StateTransition> Transitions { get; internal set; }
public int Id { get; set; }
public string Name { get; set; }
public object Value { get; set; }
public override bool Equals(object obj)
if (other == null) return false;
return this.Id == other.Id && this.Name == other.Name && this.Value == other.Value;
public override int GetHashCode()
return base.GetHashCode();
public int Id { get; set; }
public string Name { get; set; }
public List<Flag> Flags { get; set; }
public override bool Equals(object obj)
var other = (StateDef)obj;
if (other == null) return false;
if (other.Flags == null || other.Flags.Count == 0) return false;
if (Flags.Count != other.Flags.Count) return false;
var map2 = new Dictionary<int, Flag>();
foreach(var f in other.Flags)
if (!map2.ContainsKey(f.Id)) { return false; }
if (f != f2) return false;
public override int GetHashCode()
return base.GetHashCode();
public string Name { get; set; }
internal List<StateActionParam> Params { get; set; }
public class StatePath : List<StateTransition>
public class StateTransition
public StateDef Begin { get; set; }
public StateDef End { get; set; }
public StateAction Action { get; set; }