public SolverEngine(ReaderEngine engine, SolvingMethod method, int length) { _isInitialized = true; _readerEngine = engine; _solverMethod = method; _caseLength = length; if (_readerEngine == ReaderEngine.Python) { _scriptReader = new PythonScriptReader(); } else if (_readerEngine == ReaderEngine.CSharp) { _scriptReader = new BuiltInFunctions(); } else if (_readerEngine == ReaderEngine.FSharp) { } else if (_readerEngine == ReaderEngine.Ruby) { } else if (_readerEngine == ReaderEngine.BuiltIn) { } }
public FreshScript(string fileName, IScriptReader parent) { this.parent = parent; lines = new List<string>(); functions = new List<FreshScriptFunction>(); localVariables = new VariableLibrary(caseSensitive); activeVariableLibrary = localVariables; //test code string testLine = "var tezt = \"Game 1 (testing)\" && (yeah && test);"; string variableName, operation, valueString; if (ParseVariableLineForFirstOperation(testLine, out variableName, out operation, out valueString)) { } //int x =0; //int y = 1; //y+ +; //end test code lines = LoadFile(fileName, 0); OutputLinesForDebug(fileName + ".txt"); ProcessBaseLines(); }
public FlowTestClient( ITestChannel testChannel ) { _scriptReader = new ScriptReader(new MessageProvider()); _testChannel = testChannel; _engineProcessor = new EngineProcessor(testChannel); }
public SolverEngine(ReaderEngine engine, SolvingMethod method, int length) { _randomGenerator = new Random(DateTime.Now.Millisecond); _solvedData = new List<ICustomer>(); _carhopses = new List<Carhops>(); _globalList = new FutureEventList(); _isInitialized = true; _readerEngine = engine; _solverMethod = method; _caseLength = length; if (_readerEngine == ReaderEngine.Python) { _scriptReader = new PythonScriptReader(); } else if (_readerEngine == ReaderEngine.BuiltIn) { _scriptReader = new BuiltInFunctions(); } }
static void Main(string[] args) { //Unity dependency injection var container = new UnityContainer(); container.RegisterType <IPaths, DefaultPaths>(); container.RegisterType <IScriptReader, XmlScriptReader>(); container.RegisterType <IPluginsManager, PluginsManager>(new ContainerControlledLifetimeManager()); IPaths paths = container.Resolve <IPaths>(); IScriptReader reader = container.Resolve <IScriptReader>(); IPluginsManager pluginsManager = container.Resolve <IPluginsManager>(); Sequencer sequencer = container.Resolve <Sequencer>(); // --------------------------------------------- try { Console.WriteLine("\n ---------- READING SEQUENCE FILE -------- "); Script script = reader.LoadFromFile(paths.ScriptsFolder + "sequence1.xml"); Console.WriteLine(script.ToString()); Console.WriteLine("\n ------------ LOADING PLUGINS ---------- "); pluginsManager.LoadPlugins(script.GetUniqueListOfCommands()); Console.WriteLine("\n ------------ EXECUTING SEQUENCE --------- "); sequencer.Execute(script); } catch (Exception ex) { Console.WriteLine("\nEXCEPTION: " + ex.Message); } Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); }
/// <summary> /// A fluent method to inject a <see cref="IScriptReader"/> instance. /// </summary> /// <param name="scriptReader"> /// The <see cref="IScriptReader"/> instance. /// </param> /// <returns> /// The fluent instance. /// </returns> public ScriptPipelineBuilder UseScriptReader(IScriptReader scriptReader) { _scriptReader = scriptReader; return(this); }
/// <summary>設定オブジェクトとスクリプトの実行担当を受け取ってインスタンスを初期化します。</summary> /// <param name="reader">スクリプトが実行できるオブジェクト</param> /// <param name="setting">スクリプトの実行設定</param> /// <param name="characterName">キャラ名</param> public ScriptStateManager(IScriptReader reader, IScriptRoutineSetting setting, string characterName) { ScriptReader = reader; ScriptRoutineSetting = setting; _characterName = characterName; }
private ReportTableRowList Method1(int length, IScriptReader scriptReader) { var list = new ReportTableRowList(); int cumulativeLifeTime = 0; while (length > 0) { int randomLifeTimeNumber = scriptReader.GenerateNumber(0, 100); int mappedLifeTimeValue = scriptReader.MapLifeTime(randomLifeTimeNumber); int randomDelayNumber = scriptReader.GenerateNumber(0, 100); int mappedDelayTimeValue = scriptReader.MapDelayTime(randomDelayNumber); cumulativeLifeTime += mappedLifeTimeValue; list.PushRow(new ReportTableRowClass(randomLifeTimeNumber, mappedLifeTimeValue, cumulativeLifeTime, randomDelayNumber, mappedDelayTimeValue)); length--; } return list; }
public VariablesFile(IScriptReader parent, bool caseSensetiveVaraibleNames) { this.parent = parent; lines = new List<ScriptLine>(); variables = new VariableLibrary(caseSensetiveVaraibleNames); }
private void MixedMethod(int length, IScriptReader scriptReader) { throw new NotImplementedException(); }
private void Method2(int length, IScriptReader scriptReader) { var generator = new GenerateName(); var able = new Able {IsIdle = true}; var baker = new Baker {IsIdle = true}; var charlie = new Charlie {IsIdle = true}; _carhopses.Add(able); _carhopses.Add(baker); _carhopses.Add(charlie); var fel = new FutureEventList(); var customersQueue = new Queue<ICustomer>(length); int totalTime = 0; for (int i = 0; i < length; i++) { int randomNumber = i == 0 ? 0 : Math.Abs(scriptReader.GetNormal(5, 5)); totalTime += randomNumber; var customer = new Customer(totalTime, Math.Abs(scriptReader.GetNormal(10, 6)), generator) {ArrivalTimeNumber = randomNumber}; var felItem = new FutureEventListRow { Time = totalTime, Customer = customer, EventType = EventType.Arrival }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); } while (fel.Length > 0) { FutureEventListRow nearestEvent = fel.GetNearestEvent(); int currentTime = nearestEvent.Time; if (nearestEvent.EventType == EventType.Arrival) { var nState = new State(!able.IsIdle, !baker.IsIdle, !charlie.IsIdle); nearestEvent.Customer.OnArrivalSystemState = nState; if (nState.IsAnyAvailable()) { var availables = new List<Carhops>(); if (!nState.GetFirstStatus()) availables.Add(able); if (!nState.GetSecondStatus()) availables.Add(baker); if (!nState.GetThirdStatus()) availables.Add(charlie); Carhops selectedCarhops = null; int numb = 0; switch (availables.Count) { case 1: selectedCarhops = availables[0]; break; case 2: numb = _randomGenerator.Next(0, 20)/10; if (numb >= 0 && numb < 1) selectedCarhops = availables[0]; else if (numb >= 1 && numb < 2) selectedCarhops = availables[1]; break; case 3: numb = _randomGenerator.Next(0, 30)/10; if (numb >= 0 && numb < 1) selectedCarhops = availables[0]; else if (numb >= 1 && numb < 2) selectedCarhops = availables[1]; else if (numb >= 2 && numb < 3) selectedCarhops = availables[2]; break; default: break; } if (selectedCarhops != null) { nearestEvent.Customer.ServiceProvider = selectedCarhops; selectedCarhops.CurrentCustomer = nearestEvent.Customer; var felItem = new FutureEventListRow { Time = nearestEvent.Customer.ServiceTime + currentTime, Customer = nearestEvent.Customer, EventType = EventType.Departure, }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); selectedCarhops.IsIdle = false; } else { customersQueue.Enqueue(nearestEvent.Customer); } } else { customersQueue.Enqueue(nearestEvent.Customer); } } else if (nearestEvent.EventType == EventType.Departure) { Carhops currentCarhop = nearestEvent.Customer.ServiceProvider; currentCarhop.IsIdle = true; var enCustomer = new Customer(nearestEvent.Customer.ArrivalTime, nearestEvent.Customer.ServiceTime, generator) { ServiceProvider = nearestEvent.Customer.ServiceProvider, DepartureTime = currentTime, ArrivalTimeNumber = nearestEvent.Customer.ArrivalTimeNumber, OnArrivalSystemState = nearestEvent.Customer.OnArrivalSystemState }; enCustomer.WaitTime = enCustomer.DepartureTime - (enCustomer.ArrivalTime + enCustomer.ServiceTime); var nState = new State(!able.IsIdle, !baker.IsIdle, !charlie.IsIdle); enCustomer.AfterDepartureState = nState; if (enCustomer.WaitTime < 0) throw new InvalidDataException(); _solvedData.Add(enCustomer); if (customersQueue.Count > 0) { // his work is done! ICustomer firstInQueue = customersQueue.Dequeue(); firstInQueue.ServiceProvider = currentCarhop; currentCarhop.CurrentCustomer = firstInQueue; currentCarhop.IsIdle = false; var felItem = new FutureEventListRow { Time = firstInQueue.ServiceTime + currentTime, Customer = firstInQueue, EventType = EventType.Departure }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); } else { if (nearestEvent.Customer.ServiceProvider is Able) { able.IsIdle = true; able.CurrentCustomer = null; } else if (nearestEvent.Customer.ServiceProvider is Baker) { baker.IsIdle = true; baker.CurrentCustomer = null; } else if (nearestEvent.Customer.ServiceProvider is Charlie) { charlie.IsIdle = true; charlie.CurrentCustomer = null; } } } fel.RemoveFirstElement(); } }
private void Method1(int length, IScriptReader scriptReader) { var generator = new GenerateName(); var able = new Able {IsIdle = true}; var baker = new Baker {IsIdle = true}; var charlie = new Charlie {IsIdle = true}; _carhopses.Add(able); _carhopses.Add(baker); _carhopses.Add(charlie); var fel = new FutureEventList(); var customersQueue = new Queue<ICustomer>(length); int totalTime = 0; for (int i = 0; i < length; i++) { int randomNumber = i == 0 ? 0 : Math.Abs(scriptReader.GetNormal(5, 5)); totalTime += randomNumber; var customer = new Customer(totalTime, Math.Abs(scriptReader.GetNormal(10, 6)), generator) {ArrivalTimeNumber = randomNumber}; var felItem = new FutureEventListRow { Time = totalTime, Customer = customer, EventType = EventType.Arrival }; fel.PushEventRow(felItem); _globalList .PushEventRow(felItem); } while (fel.Length > 0) { FutureEventListRow nearestEvent = fel.GetNearestEvent(); int currentTime = nearestEvent.Time; if (nearestEvent.EventType == EventType.Arrival) { var nState = new State(!able.IsIdle, !baker.IsIdle, !charlie.IsIdle); nearestEvent.Customer.OnArrivalSystemState = nState; if (able.IsIdle) { nearestEvent.Customer.ServiceProvider = able; able.CurrentCustomer = nearestEvent.Customer; var felItem = new FutureEventListRow { Time = nearestEvent.Customer.ServiceTime + currentTime, Customer = nearestEvent.Customer, EventType = EventType.Departure, }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); able.IsIdle = false; } else if (baker.IsIdle) { nearestEvent.Customer.ServiceProvider = baker; baker.CurrentCustomer = nearestEvent.Customer; var felItem = new FutureEventListRow { Time = nearestEvent.Customer.ServiceTime + currentTime, Customer = nearestEvent.Customer, EventType = EventType.Departure }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); baker.IsIdle = false; } else if (charlie.IsIdle) { nearestEvent.Customer.ServiceProvider = charlie; charlie.CurrentCustomer = nearestEvent.Customer; var felItem = new FutureEventListRow { Time = nearestEvent.Customer.ServiceTime + currentTime, Customer = nearestEvent.Customer, EventType = EventType.Departure }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); charlie.IsIdle = false; } else { customersQueue.Enqueue(nearestEvent.Customer); } } else if (nearestEvent.EventType == EventType.Departure) { Carhops currentCarhop = nearestEvent.Customer.ServiceProvider; currentCarhop.IsIdle = true; var enCustomer = new Customer(nearestEvent.Customer.ArrivalTime, nearestEvent.Customer.ServiceTime, generator) { ServiceProvider = nearestEvent.Customer.ServiceProvider, DepartureTime = currentTime, ArrivalTimeNumber = nearestEvent.Customer.ArrivalTimeNumber, OnArrivalSystemState = nearestEvent.Customer.OnArrivalSystemState }; enCustomer.WaitTime = enCustomer.DepartureTime - (enCustomer.ArrivalTime + enCustomer.ServiceTime); var nState = new State(!able.IsIdle, !baker.IsIdle, !charlie.IsIdle); enCustomer.AfterDepartureState = nState; if (enCustomer.WaitTime < 0) throw new InvalidDataException(); _solvedData.Add(enCustomer); if (customersQueue.Count > 0) { // his work is done! ICustomer firstInQueue = customersQueue.Dequeue(); firstInQueue.ServiceProvider = currentCarhop; currentCarhop.CurrentCustomer = firstInQueue; currentCarhop.IsIdle = false; var felItem = new FutureEventListRow { Time = firstInQueue.ServiceTime + currentTime, Customer = firstInQueue, EventType = EventType.Departure }; fel.PushEventRow(felItem); _globalList.PushEventRow(felItem); } else { if (nearestEvent.Customer.ServiceProvider is Able) { able.IsIdle = true; able.CurrentCustomer = null; } else if (nearestEvent.Customer.ServiceProvider is Baker) { baker.IsIdle = true; baker.CurrentCustomer = null; } else if (nearestEvent.Customer.ServiceProvider is Charlie) { charlie.IsIdle = true; charlie.CurrentCustomer = null; } } } fel.RemoveFirstElement(); } }
public VariablesFile(string fileName, IScriptReader parent, bool caseSensetiveVaraibleNames) : this(parent, caseSensetiveVaraibleNames) { LoadFile(fileName); }
/// <summary>Process the test cases using the TextScriptReader object.</summary> /// <param name="theReader">Object that parses the script that drives test selection.</param> public void ProcessScript(IScriptReader theReader) { this.logEngine.WriteHeaders(); TestInfo info = theReader.GetNextTest(); while (info.IsValid) { this.ProcessCase(info); info = theReader.GetNextTest(); } this.logEngine.WriteSummaries(); }
private ReportTableRowList Method2(int length, IScriptReader scriptReader) { var list = new ReportTableRowList(); int cumulativeLifeTime = 0; while (length > 0) { int randomDelayNumber = scriptReader.GenerateNumber(1, 100); int mappedDelayTimeValue = scriptReader.MapDelayTime(randomDelayNumber); int life1 = scriptReader.MapLifeTime(scriptReader.GenerateNumber(1, 100)); int life2 = scriptReader.MapLifeTime(scriptReader.GenerateNumber(1, 100)); int life3 = scriptReader.MapLifeTime(scriptReader.GenerateNumber(1, 100)); int firstFailure = new List<int> {life1, life2, life3}.Min(); cumulativeLifeTime += firstFailure; list.PushRow(new ReportTableRowClass(life1, life2, life3, firstFailure, cumulativeLifeTime, randomDelayNumber, mappedDelayTimeValue)); length--; } return list; }
public ScriptLine(string line, VariablesFile script, IScriptReader parentScriptReader) { Content = line; Type = LineType.Comment;//untill proven wrong if (line.Trim().Length == 0 || line.Trim().Substring(0, 2).Equals(VariablesFile.SCRIPT_COMMENT)) { //comment or blank - ignore } else { if (line.Substring(0, 3).ToUpper().Equals(VariablesFile.SCRIPT_COMMAND_VARIABLE)) { //variable definition line = line.Substring(3).Trim(); // string varName = line.Substring(0, line.IndexOf("=")).Trim(); string varValue = line.Substring(line.IndexOf("=") + 1).Trim(); Variable = new Variable(varName,varValue); Type = LineType.Variable;//untill proven wrong } else if (line.Substring(0, 4).ToUpper().Equals(VariablesFile.SCRIPT_COMMAND_LOAD)) { line = line.Substring(4).Trim(); //should preserver this files path so a sibling file can use relative pathing script.LoadFile(line); Type = LineType.Command;//untill proven wrong } else { //continue to write code for cmds - script language - borring!!!! if (parentScriptReader != null) parentScriptReader.ParseScriptLine(line); } } }