//constructor used for testing purpose only public ExpressionBuilder( IParenthesize parenthesizer, string expression, int type ) : this(parenthesizer) { if (type < 0 || type > 5) { throw new ArgumentException("Invalid Key Type."); } var typeTable = new Dictionary <int, KeyType>() { { 0, KeyType.Value }, { 1, KeyType.Unary }, { 2, KeyType.Binary }, { 3, KeyType.Left }, { 4, KeyType.Right }, { 5, KeyType.Empty }, }; if (expression != null) { Buffer.Add(expression); } KeyHistory.Add(typeTable[type]); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Status,DateIssued,DateReturned,PaidAmount,IsArchive,LastModifiedDate")] KeyHistory keyHistory) { if (id != keyHistory.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(keyHistory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!KeyHistoryExists(keyHistory.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(keyHistory)); }
public void AddValue(decimal input) { if (!CanAddValue()) { throw new InvalidOperationException("Operands Must be Separated by Operators."); } Buffer.Add(input.ToString()); KeyHistory.Add(KeyType.Value); }
public async Task <ActionResult> Delete(int id, KeyHistory keyHistory) { KeyHistory item = await _context.KeyHistory.FindAsync(id); item.IsArchive = true; _context.KeyHistory.Update(item); //_context.KeyHistory.Remove(item); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("ID,Status,DateIssued,DateReturned,PaidAmount,IsArchive,LastModifiedDate")] KeyHistory keyHistory) { if (ModelState.IsValid) { _context.Add(keyHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(keyHistory)); }
public bool CanAddValue() { //value input after another value, unary operators or right parenthesis is not allowed var invalidTypes = new HashSet <KeyType>() { KeyType.Value, KeyType.Unary, KeyType.Right }; return(!invalidTypes.Contains(KeyHistory.Last())); }
public async Task <IActionResult> OnPostAsync(int?id, string ownerName = "") { if (id == null) { return(NotFound()); } var user = _context.Owner.FirstOrDefault(x => x.User.UserID == HttpContext.Session.GetInt32("SessionUserID")); Key.LastModifiedBy = user != null ? user.Initials : "SYS"; Key.LastModifiedDate = DateTime.Now; _context.Attach(Key).State = EntityState.Modified; if (KeyHistoryExists(Key.KeyID, Key.KeyHistory.KeyHistoryID)) { Key.LastModifiedBy = user != null ? user.Initials : "SYS"; Key.KeyHistory.LastModifiedDate = DateTime.Now; if ((Key.KeyHistory?.Status == "Returned" || Key.KeyHistory?.Status == "Lost") && Key.KeyHistory?.DateReturned == null) { Key.KeyHistory.DateReturned = DateTime.Now; } if (Key.KeyHistory?.Status == "Active") { Key.KeyHistory.DateReturned = null; } Key.KeyHistory.OwnerID = _context.Owner.FirstOrDefault(x => x.FullName == ownerName).OwnerID; _context.Attach(Key.KeyHistory).State = EntityState.Modified; } else { KeyHistory keyHistory = Key.KeyHistory; _context.KeyHistory.Add(keyHistory); } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!KeyExists(Key.KeyID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
private void AddLeftParenthesis(string input) { //left parenthesis cannot immediately follow a value or unary operator if (KeyHistory.Last() == KeyType.Value || KeyHistory.Last() == KeyType.Unary) { throw new InvalidOperationException("Missing Operators."); } //left parenthesis cannot immediately follow right parenthesis if (KeyHistory.Last() == KeyType.Right) { throw new InvalidOperationException("Mismatched Parentheses."); } Buffer.Add(input); KeyHistory.Add(KeyType.Left); }
public async Task <ActionResult> Edit(int?id, KeyHistory keyHistory) { if (id != keyHistory.KeyHistoryId) { return(NotFound()); } var identityUser = await _userManager.GetUserAsync(HttpContext.User); var loggedInUser = _context.Owner.Find(identityUser.OwnerId); keyHistory.LastModifiedBy = loggedInUser.FullName; keyHistory.LastModifiedDate = DateTime.Now; _context.Update(keyHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void AddBinary(string input) { //consecutive binary operator input is not allowed if (KeyHistory.Last() == KeyType.Binary) { throw new InvalidOperationException("Missing Operand."); } /* * when binary operator input follows left parenthesis or nothing, * a value of zero will be added as default operand */ if (KeyHistory.Last() == KeyType.Left || KeyHistory.Last() == KeyType.Empty) { AddValue(0); } Buffer.Add(input); KeyHistory.Add(KeyType.Binary); }
private void AddRightParenthesis(string input) { //right parenthesis cannot immediately follow binary operator if (KeyHistory.Last() == KeyType.Binary) { throw new InvalidOperationException("Missing Operand."); } //parentheses must match if (MissingParentheses(Expression) < 1) { throw new InvalidOperationException("Mismatched Parentheses."); } if (KeyHistory.Last() == KeyType.Left) { AddValue(0); } Buffer.Add(input); KeyHistory.Add(KeyType.Right); }
public async Task <ActionResult> Create(KeyHistory keyHistory) { if (ModelState.IsValid) { var identityUser = await _userManager.GetUserAsync(HttpContext.User); var loggedInUser = _context.Owner.Find(identityUser.OwnerId); keyHistory.Status = "Active"; keyHistory.IsArchive = false; keyHistory.LastModifiedBy = loggedInUser.FullName; keyHistory.LastModifiedDate = DateTime.Now; _context.KeyHistory.Add(keyHistory); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LotsSelect"] = new SelectList(_context.Lot.OrderBy(u => u.LotNumber), "LotId", "LotNumber", keyHistory.LotId); return(View()); }
/// <summary> /// Parses the string table out of the binary packet /// </summary> /// <param name="stringData"></param> /// <param name="numEntries"></param> /// <returns></returns> private Dictionary <int, StringTableRow> ParseTable(byte[] stringData, int numEntries) { var stream = new BitStream(stringData); var bitsPerIndex = (int)(Math.Log(this.MaxEntries) / Math.Log(2)); var keyHistory = new KeyHistory(); var map = new Dictionary <int, StringTableRow>(); bool mysteryFlag = stream.ReadBool(); int index = -1; while (map.Count < numEntries) { // figure out if we are consecutive indexing or not if (stream.ReadBool()) { index++; } else { index = stream.ReadBits(bitsPerIndex); } var name = ""; if (stream.ReadBool()) { if (mysteryFlag && stream.ReadBool()) { throw new InvalidDataException("There's a problem with the Mystery Flags."); } // check if we're referencing the key history if (stream.ReadBool()) { // the index of the key in history they we're using int basis = stream.ReadBits(5); // the number of characters from the history key to use int length = stream.ReadBits(5); if (basis > keyHistory.Length) { // the key requested is invalid, so just use the data provided name += stream.ReadString(StringTable.MaxNameLength); } else { string s = keyHistory[basis]; if (length > s.Length) { name += s + stream.ReadString(StringTable.MaxNameLength); } else { // just use the first n characters of the history string and get the rest of the string from the stream /* * i.e. * keyHistory[basis] == "cfg/cpu_level_0_pc.txt" * length = 14 * name = "cfg/cpu_level_" + *read stream* (i.e. "1_pc.txt") */ name += s.Substring(0, length) + stream.ReadString(StringTable.MaxNameLength - length); } } } else { name += stream.ReadString(StringTable.MaxNameLength); } // add the key to the history keyHistory.Push(name); } // read the inner value byte[] value = null; if (stream.ReadBool()) { int bitLength; if (this.UserDataFixedSize) { bitLength = this.UserDataSizeBits; } else { bitLength = stream.ReadBits(14) * 8; } value = stream.ReadBytes(bitLength); } map[index] = new StringTableRow(name, value); } return(map); }
public void Undo() { Buffer.RemoveBack(); KeyHistory.RemoveBack(); }