/// <summary> /// The full and original text of the command. /// </summary> /// <param name="commandText">The command text.</param> /// <param name="transactionList">The transaction list.</param> /// <param name="siteList"></param> /// <param name="systemClock"></param> public BaseAction(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) { CommandText = commandText; TransactionList = transactionList; SiteList = siteList; systemClock = systemClock; }
public Dump(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) : base(commandText, transactionList, siteList, systemClock) { string[] info = commandText.Split(new[] { '(', ')' }); DumpFull = info[1].Trim().Equals(String.Empty); if (info.Count() == 3) DumpObject = info[1]; }
public BeginTransaction(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) : base(commandText, transactionList, siteList, systemClock) { string[] info = commandText.Split(new[] {'(', ')'}); if (info.Length != 3) throw new Exception("Invalid command format: " + commandText); Transaction = new Transaction(info[1], systemClock) {IsReadOnly = info[0].ToLower().Equals("beginro")}; transactionList.AddTransaction(Transaction); }
/// <summary> /// Initializes a new instance of the <see cref="Fail"/> class. /// </summary> /// <param name="commandText">The command text.</param> /// <param name="transactionList">The transaction list.</param> /// <param name="siteList"></param> /// <param name="systemClock"></param> public Fail(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) : base(commandText, transactionList, siteList, systemClock) { string[] info = commandText.Split(new[] { '(', ')' }); if (info.Length != 3) throw new Exception("Invalid command format: " + commandText); Site = siteList.GetSite(int.Parse(info[1])); if (Site == null) throw new Exception("Site not found:" + info[1]); }
public EndTransaction(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) : base(commandText, transactionList, siteList, systemClock) { string[] info = commandText.Split(new[] {'(', ')'}); if (info.Length != 3) throw new Exception("Invalid command format: " + commandText); Transaction = transactionList.GetTransaction(info[1]); if (Transaction == null) throw new Exception("Transaction not found: " + commandText); }
private static void Main(string[] args) { _systemClock = new SystemClock(); _siteList = new SiteList(_systemClock); _transactionList = new TransactionList(_systemClock); State.output = new List<string>(); State.Clock = _systemClock; InitializeSites(); GetFile(); List<string> file = ReadFile(); var errors = new List<String>(); _executionPlan = InputParser.ReadInput(file, _transactionList, _siteList, _systemClock, ref errors); Debug.WriteLine("System starting..."); if (errors.Count == 0) { //main execution loop foreach (ExecutionEntity currentEntity in _executionPlan) { foreach (BaseAction tempAction in currentEntity.Actions) { ProcessEntity(tempAction); } ProcessPausedTransactions(); _systemClock.Tick(); } } else { Console.WriteLine("Execution stopped, errors encountered: "); foreach (String error in errors) { Console.WriteLine(error); } } foreach (String outpt in State.output) Console.WriteLine(outpt); FileOutput.WriteFile(_fileName, State.output); Console.ReadLine(); }
public Write(string commandText, TransactionList transactionList, SiteList siteList, SystemClock systemClock) : base(commandText, transactionList, siteList, systemClock) { string[] info = commandText.Split(new[] { '(', ')' }); if (info.Length != 3) throw new Exception("Invalid command format: " + commandText); string[] parameters = info[1].Split(','); parameters = InputParser.TrimStringList(parameters); Transaction = transactionList.GetTransaction(parameters[0]); if (Transaction == null) throw new Exception("Transaction not found: " + commandText); VariableId = parameters[1]; Value = parameters[2]; }
/// <summary> /// Reads the file input and converts it into a list of execution plans. /// </summary> /// <param name="fileInput">The file input.</param> /// <param name="transactionList">The transaction list.</param> /// <param name="siteList">The site list.</param> /// <param name="systemClock">The system clock.</param> /// <param name="errorList">The error list.</param> /// <returns></returns> public static List<ExecutionEntity> ReadInput(List<string> fileInput, TransactionList transactionList, SiteList siteList, SystemClock systemClock, ref List<String> errorList) { var entities = new List<ExecutionEntity>(); foreach (String currentLine in fileInput) { List<string> lineElements = BreakLine(currentLine); var tempExecutionEntiy = new ExecutionEntity(); foreach (String tempElement in lineElements) { BaseAction result = StringToAction(tempElement, transactionList, siteList, systemClock, ref errorList); if (result != null) tempExecutionEntiy.AddAction(result); } entities.Add(tempExecutionEntiy); } //initialized all used variables at each site foreach (ExecutionEntity currentEntity in entities) { foreach (BaseAction tempAction in currentEntity.Actions) { if (tempAction is Read) { siteList.GetRunningSitesWithVariable(((Read)tempAction).VariableId); } else if (tempAction is Write) { siteList.GetRunningSitesWithVariable(((Write)tempAction).VariableId); } } } return entities; }
public static BaseAction StringToAction(String lineElement, TransactionList transactionList, SiteList siteList, SystemClock systemClock, ref List<String> errorList) { lineElement = lineElement.Trim(); string command = lineElement.Split('(').FirstOrDefault(); if (String.IsNullOrEmpty(command)) { errorList.Add("Invalid Command Format: " + lineElement); return null; } command = command.ToLower(); if (command.Equals("begin") || command.Equals("beginro")) return new BeginTransaction(lineElement, transactionList, siteList, systemClock); if (command.Equals("end")) return new EndTransaction(lineElement, transactionList, siteList, systemClock); if (command.Equals("r")) return new Read(lineElement, transactionList, siteList, systemClock); if (command.Equals("w")) return new Write(lineElement, transactionList, siteList, systemClock); if (command.Equals("fail")) return new Fail(lineElement, transactionList, siteList, systemClock); if (command.Equals("recover")) return new Recover(lineElement, transactionList, siteList, systemClock); if (command.Equals("dump")) return new Dump(lineElement, transactionList, siteList, systemClock); errorList.Add("Couldn't interpret: " + lineElement); return null; }