private void RegistFolder(string folderName, ParseHandler handler) { try { string filePath = Configure.cfgPath; if (!File.Exists(Configure.cfgPath + folderName)) { filePath = Configure.cfgPathStn; } string[] files = Directory.GetFiles(filePath.Replace("file:///", "") + folderName); string fileName = ""; for (int i = 0; i < files.Length; ++i) { fileName = files[i].Substring(files[i].LastIndexOf("/")); if (fileName.Contains(".xml")) { RegistTable(folderName + files[i].Substring(files[i].LastIndexOf("/")), handler); } } } catch (IOException e) { ClientLog.Instance.LogError(e.ToString()); } }
/// <summary> /// Tries parsing <paramref name="stringValue"/> into the specified return type. /// </summary> /// <param name="defaultValue">the default value to return if parsing fails</param> /// <param name="stringValue">the string value to parse</param> /// <returns>the successfully parsed value, <paramref name="defaultValue"/> otherwise.</returns> public static T TryParse <T>(T defaultValue, string stringValue) { T result = defaultValue; if (string.IsNullOrEmpty(stringValue)) { return(defaultValue); } ParseHandler <T> parser = s_parsers[typeof(T)] as ParseHandler <T>; if (parser == null) { throw new ArgumentException(string.Format("There is no parser registered for type {0}", typeof(T).FullName)); } try { result = parser(stringValue); } catch { Trace.WriteLine(string.Format("WARN: failed converting value '{0}' to type '{1}' - returning default '{2}'", stringValue, typeof(T).FullName, result)); } return(result); }
public async Task <List <BusinessLogic.Objects.Product> > GetOrderProductListByID(int orderID) { try { List <Entities.OrderProduct> CTXOrdProdList = await _context.OrderProduct.AsNoTracking().Where(op => op.OrderId == orderID).ToListAsync(); List <BusinessLogic.Objects.Product> BLProdList = new List <BusinessLogic.Objects.Product>(); foreach (OrderProduct CTXOrdProd in CTXOrdProdList) { BLProdList.Add(ParseHandler.ContextOrderProductToLogicProduct(CTXOrdProd)); } foreach (Entities.Product CTXProduct in _context.Product) { foreach (BusinessLogic.Objects.Product BLProd in BLProdList) { if (CTXProduct.ProductTypeId == BLProd.productTypeID) { BLProd.name = CTXProduct.ProductName; } } } return(BLProdList); } catch { throw new Exception("Failed to retrieve order product information for order ID: " + orderID); } }
protected T[] ParseValues <T>(string key, ParseHandler <T> handler) where T : struct { var values = GetValue(key); return(values.Select(v => handler(v)).ToArray()); }
public async Task <List <Order> > GetListAllOrdersForStore(int storeID) { try { List <BusinessLogic.Objects.Order> BLListOrders = new List <Order>(); foreach (Entities.Orders CTXOrder in _context.Orders.AsNoTracking().Where(o => o.StoreNumber == storeID).ToHashSet()) { BLListOrders.Add(ParseHandler.ContextOrderToLogicOrder(CTXOrder)); } foreach (BusinessLogic.Objects.Order BLOrd in BLListOrders) { BLOrd.StoreLocation = await GetStoreInformation(BLOrd.StoreLocation.storeNumber); } foreach (Order BLOrdToFill in BLListOrders) { BLOrdToFill.CustomerProductList = await GetOrderProductListByID(BLOrdToFill.orderID); BLOrdToFill.Customer = await GetCustomerByID(BLOrdToFill.Customer.customerID); } return(BLListOrders); } catch { throw new Exception("Failed to retrieve order information for store number: " + storeID); } }
private SyntaxTree(SourceText text, ParseHandler handler) { Text = text; handler(this, out var root, out var diagnostics); Diagnostics = diagnostics; Root = root; }
public void FindFakeIngredientInContainerFail() { string input = "fake ingredient"; Ingredient returnedIngredient; returnedIngredient = ParseHandler.findIngredient(input, testContainer); Assert.IsNull(returnedIngredient); }
private SyntaxTree(SourceFile file, ParseHandler handler) { File = file; handler(this, out var root, out var diagnostics); Root = root; Diagnostics = diagnostics.ToImmutableArray(); }
public void ParseFractionCorrectly() { string input = "3/4"; double answer = -1; answer = ParseHandler.measurementConversion(input); Assert.AreEqual(answer, 0.75); }
public void ParseNumberAndFractionCorrectly() { string input = "4 1/4"; double answer = -1; answer = ParseHandler.measurementConversion(input); Assert.AreEqual(answer, 4.25); }
public void Test_Global_Var_Decls_002() { string src = Resources.Global_Var_Decls_002.GetString(); var result = ParseHandler.Parse(src); string a = result.ParseTree.ToStringTree(); int b = 5; }
private SyntaxTree(SourceText text, ParseHandler handler, string?filePath = null) { Text = text; handler(this, out var root, out var diagnostics); Diagnostics = new DiagnosticBag(diagnostics); FilePath = filePath; Root = root; }
private void RegistTable(string name, ParseHandler handler) { if (parseFunc.ContainsKey(name)) { ClientLog.Instance.LogError("more tables with same name!" + name); return; } parseFunc [name] = handler; }
public async Task <BusinessLogic.Objects.Customer> GetCustomerByID(int CustomerID) { try { return(ParseHandler.ContextCustomerToLogicCustomer(await _context.Customer.AsNoTracking().FirstAsync(c => c.CustomerId == CustomerID))); } catch (Exception e) { throw new Exception("Failed to retrieve customer information for customer ID: " + CustomerID + "\nException thrown: " + e.Message); } }
private SyntaxTree(SourceText text, ParseHandler handler) { this.Text = text; var parser = new Parser(this); handler(this, out var root, out var diagnostics); this.Root = root; this.Diagnostics = diagnostics; }
protected T ParseValue <T>(string key, ParseHandler <T> handler) where T : struct { var values = GetValue(key); if (values.Length.Equals(1)) { return(handler(values[0])); } throw new InvalidCastException(); }
public void FindIngredientInContainerTest() { string input = "- 1/2 cup olive oil"; Ingredient returnedIngredient; returnedIngredient = ParseHandler.findIngredient(input, testContainer); Assert.IsNotNull(returnedIngredient); Assert.IsTrue(returnedIngredient.getIsOrganic()); Assert.IsFalse(returnedIngredient.getIsProduce()); Assert.AreEqual(returnedIngredient.getName(), "olive oil"); }
/// <summary> /// Returns a <see cref="Tuple"/> with specified <paramref name="descriptor"/> /// parsed from the <paramref name="source"/> string. /// </summary> /// <param name="descriptor">The descriptor of <see cref="Tuple"/> to parse.</param> /// <param name="source">The string to parse.</param> /// <returns>A <see cref="Tuple"/> parsed from the <paramref name="source"/> string.</returns> /// <exception cref="System.InvalidOperationException"><paramref name="source"/> string /// can't be parsed to a <see cref="Tuple"/> with specified <paramref name="descriptor"/>.</exception> public static Tuple Parse(this TupleDescriptor descriptor, string source) { ArgumentValidator.EnsureArgumentNotNull(descriptor, "descriptor"); var target = Tuple.Create(descriptor); var count = target.Count; var sources = source.RevertibleSplit(Escape, Comma).ToArray(); for (int i = 0; i < count; i++) { ParseHandler.Get(descriptor[i]).Execute(sources, target, i); } return(target); }
public void InvalidInputRecipeStringParseFail() { // Arrange string input = "!@#$%^&"; IngredientType ingredType = IngredientType.Produce; RecipeIngredient theIngredient; // Act theIngredient = ParseHandler.parseRecipeLine(input, testContainer); // Assert Assert.IsNull(theIngredient); }
public void InvalidInputStringParseFail() { // Arrange string input = "!@#$%^&"; IngredientType ingredType = IngredientType.Produce; Ingredient theIngredient; // Act theIngredient = ParseHandler.parseIngredientLine(input, ingredType); // Assert Assert.IsNull(theIngredient); }
public void Test_Global_Var_Decls_001() { string src = Resources.Global_Var_Decls_001.GetString(); var result = ParseHandler.Parse(src); Assert.IsFalse(result.IsError); Assert.IsNull(result.ErrorMessage); Assert.IsNotNull(result.ParseTree); Assert.AreEqual(2, result.ParseTree.ChildCount); Assert.IsInstanceOfType(result.ParseTree.GetChild(0).Payload, typeof(CommonToken)); Assert.AreEqual("VAR_GLOBAL", ((CommonToken)result.ParseTree.GetChild(0).Payload).Text); Assert.IsInstanceOfType(result.ParseTree.GetChild(1).Payload, typeof(CommonToken)); Assert.AreEqual("END_VAR", ((CommonToken)result.ParseTree.GetChild(1).Payload).Text); }
/// <summary> /// Loads the data. /// </summary> /// <param name="path">A location from which to load the data.</param> /// <param name="handler">A method handler to which we return the data.</param> /// <param name="asResource">If set to <c>true</c> the path is assumed to be a Resource location rather than a URI.</param> public void LoadData(string path, ParseHandler handler, bool asResource = false) { m_ParseHandler = handler; if (!string.IsNullOrEmpty(path)) { if (asResource) { LoadResource(path); } else { LoadStream(path); } } }
static private ParseHandler <T> TryGetParser <T>(Type t) { MethodInfo mi; mi = t.GetMethod("Parse", new Type[] { typeof(string) }); if (mi == null) { return(null); } else { ParseHandler <T> parseHandler = (ParseHandler <T>)Delegate.CreateDelegate(typeof(ParseHandler <T>), mi); return((ParseHandler <T>)parseHandler); } }
static public T SafeCastFromString <T>(string source, T defaultValue) { if (defaultValue is string) { return((T)(object)source); } T result; try { if (typeof(T).IsEnum) { return((T)System.Enum.Parse(typeof(T), source, true)); } else { Delegate parseHandler = RetrieveHandler <T>(); TryParseHandler <T> tryParser = parseHandler as TryParseHandler <T>; if (tryParser != null) { if (tryParser(source, out result) == false) { result = defaultValue; } } else { ParseHandler <T> parser = parseHandler as ParseHandler <T>; if (parser != null) { result = parser(source); } else { result = defaultValue; } } } } catch { result = defaultValue; } return(result); }
public async Task <List <BusinessLogic.Objects.Product> > GetListStockedProductsForStoreAsync(int StoreID) { List <BusinessLogic.Objects.Product> BLProdStockList = new List <BusinessLogic.Objects.Product>(); List <InventoryProduct> CTXInventory = await _context.InventoryProduct.AsNoTracking().Where(ip => ip.StoreNumber == StoreID).ToListAsync(); foreach (Entities.Product CTXProd in _context.Product) { foreach (Entities.InventoryProduct CTXInvProd in CTXInventory) { if (CTXInvProd.ProductTypeId == CTXProd.ProductTypeId) { BLProdStockList.Add(ParseHandler.ContextProductInformationToLogicProduct(CTXProd)); } } } return(BLProdStockList); }
public void ValidRecipeStringParseSuccess() { // Arrange string input = "- 3/4 cup olive oil"; RecipeIngredient theIngredient; // Act theIngredient = ParseHandler.parseRecipeLine(input, testContainer); // Assert Assert.IsNotNull(theIngredient); Assert.IsTrue(theIngredient.getIngredient().getIsOrganic()); Assert.IsFalse(theIngredient.getIngredient().getIsProduce()); Assert.AreEqual(theIngredient.getIngredient().getName(), "olive oil"); Assert.AreEqual(theIngredient.getAmount(), 0.75m); }
public async Task <BusinessLogic.Objects.Store> GetStoreInformation(int StoreID) { try { Store CTXStore = await _context.Store.AsNoTracking().FirstAsync(s => s.StoreNumber == StoreID); return(ParseHandler.ContextStoreToLogicStore(CTXStore)); } catch (InvalidOperationException) { throw new InvalidOperationException("Unable to get a store connected to the manager's ID"); } catch (Exception e) { throw new Exception("Something went wrong in getting the store's information: " + e.Message); } }
public async Task <BusinessLogic.Objects.Manager> GetManagerInformation(int ManagerID) { try { Manager CTXMan = await _context.Manager.AsNoTracking().FirstAsync(m => m.ManagerId == ManagerID); return(ParseHandler.ContextManagerToLogicManager(CTXMan)); } catch (InvalidOperationException) { throw new InvalidOperationException("Was unable to get a manager with that ID"); } catch (Exception e) { throw new Exception("Something went wrong in getting the manager's information: " + e.Message); } }
public void ValidIngredientStringParseSuccessPantry() { // Arrange string input = "- 1 teaspoon of salt = $0.16"; IngredientType ingredType = IngredientType.Pantry; Ingredient theIngredient; // Act theIngredient = ParseHandler.parseIngredientLine(input, ingredType); // Assert Assert.IsNotNull(theIngredient); Assert.IsFalse(theIngredient.getIsOrganic()); Assert.IsFalse(theIngredient.getIsProduce()); Assert.AreEqual(theIngredient.getName(), "salt"); Assert.AreEqual(theIngredient.getCost(), 0.16m); }
public BusinessLogic.Objects.Customer GetLastCustomerWithFirstLast(string firstName, string lastName) { try { Customer CTXCust = new Customer(); //Customer CTXCustomer = await _context.Customer.Where(c => c.FirstName == firstName).LastAsync(); foreach (Customer CTXCustomer in _context.Customer.Where(c => c.FirstName == firstName && c.LastName == lastName)) { CTXCust = CTXCustomer; } return(ParseHandler.ContextCustomerToLogicCustomer(CTXCust)); } catch (InvalidOperationException e) { throw new Exception("Failed to get the new customer with first name: " + firstName + "\nand lastName: " + lastName + "\nException: " + e.Message); } }
protected void ParseFile(ParseHandler parser, string filename) { var reader = new StreamReader(filename); while (!reader.EndOfStream) { string line = reader.ReadLine(); if (string.IsNullOrEmpty(line)) continue; string[] tokens = line.Split(omitchars, StringSplitOptions.RemoveEmptyEntries); if (tokens == null || tokens[0].StartsWith("#")) continue; parser(line, tokens); } }
public HttpDataQuery(HttpRequest request) { Cmd = request.Form["act"]; Queries = new Node(); Queries["cmd"] = new Node(Cmd, NodeType.String); Queries["curtstyle"] = new Node(NodeType.String); Queries["fields"] = new Node("name", NodeType.Object); //select [pagesize] [fields] from [tables] [wheres] [orders] //select [pagesize] [fields] from [tables] where [pk] not in select [excludes] from [tables] [wheres] [orders] Queries.AddChild("select", NodeType.Object); Queries["select"]["fields"] = new Node("#name", NodeType.Array); Queries["select"]["tables"] = new Node("#name", NodeType.Array); Queries["select"]["wheres"] = new Node("#list", NodeType.Object); Queries["select"]["orders"] = new Node("#list", NodeType.Object); Queries["select"]["pagesize"] = new Node("#num", NodeType.Empty); Queries["select"]["pageskip"] = new Node("#num", NodeType.Empty); Queries["select"]["curtpage"] = new Node("#num", NodeType.Empty); Queries["select"]["pk"] = new Node("#name", NodeType.Object); Form = request.Form; Qstyle = Form["qstyle"]; Queries.SetValue(Qstyle, NodeType.String, "curtstyle"); if (string.IsNullOrEmpty(Qstyle)) { Qstyle = "select"; } if (string.IsNullOrEmpty(Cmd)) { Cmd = "normal"; } Node Root = Queries["select"]; OnParse = ParseTypes; EnumNames(null); OnParse = ParseNames; EnumNames(Root); Sql = MakeSql(); }
public IniPropertyDescription(string name, PropertyInfo property, Type itemType, ParseHandler parseHandler, int minOccurrences = 0, int maxOccurrences = 1) { _name = name; _property = property; TheParseHandler = parseHandler; _minOccurrences = minOccurrences; _maxOccurrences = maxOccurrences; _itemType = itemType; }