public CommandLineParser() { var properties = typeof(T).GetProperties(); foreach (var propertyInfo in properties) { var positionalAttribute = propertyInfo.GetCustomAttribute <PositionalParameterAttribute>(); if (positionalAttribute != null) { // NOTE: kind of cheating and we should have some kind of interface - I don't want to do 2 ReadInput. var item = new ArgumentItem(propertyInfo, positionalAttribute.ToParameterAttribute()); positionalArguments.Add(item); } else { var item = new ArgumentItem(propertyInfo, propertyInfo.GetCustomAttribute <ParameterAttribute>()); if (item.GetAlias() != 0) { aliases.Add(item.GetAlias(), item); } if (!string.IsNullOrEmpty(item.GetAction())) { actions.Add(item.GetAction(), item); } explicitArguments.Add(item); } } }
private void ViewDetail(ArgumentItem item) { this.NavigationService.Navigate(new BtyArgumentPage() { AlarmTemporaryDID = item.Name }); }
/// <summary> /// Create a new Failed message instance /// </summary> /// <param name="kind"></param> /// <param name="handler"></param> /// <param name="msg"></param> public FailedMessage(FailedEventType kind, string handler, EventMessage msg) { if (msg == null) { throw new ArgumentNullException("msg"); } Id = Guid.NewGuid().ToString(); Kind = kind; Handler = handler; ReferenceId = msg.Data.Id; Data = new ArgumentItem(msg.Id, new ArgumentItem.ArgumentValuePair("message", msg)); OccurredOn = DateTime.UtcNow; RetryTimes = 0; }
public IPagedList <ArgumentItem> GetPagedArgumentData1(int?processDID, int pageNo, int pageSize) { List <ArgumentItem> lst = new List <ArgumentItem>(); string path = "C:\\Users\\junxi\\Desktop\\bat"; DirectoryInfo theFolder = new DirectoryInfo(path); DirectoryInfo[] dirInfo = theFolder.GetDirectories(); foreach (DirectoryInfo NextFolder in dirInfo) { //if(NextFolder.ToString() == Name) //{ XmlDocument doc = new XmlDocument(); //string strName = path + "\\" + NextFolder.ToString() + "\\batteryParameters.xml"; doc.Load("C:\\Users\\junxi\\Desktop\\bat\\333993\\batteryParameters.xml"); //doc.Load(strName); XmlElement rootElem = doc.DocumentElement; //根节点 XmlNodeList oList = rootElem.ChildNodes; //二级节点 XmlNode oCurrentNode; for (int i = 0; i < oList.Count; i++) { oCurrentNode = oList[i]; if (oCurrentNode.HasChildNodes) { for (int j = 0; j < oCurrentNode.ChildNodes.Count; j++) //三级节点 { if (oCurrentNode.ChildNodes[j].Name != "#comment" && oCurrentNode.ChildNodes[j].Name != "#text") { ArgumentItem info = new ArgumentItem(); info.Name = oCurrentNode.ChildNodes[j].Name; info.Argument = oCurrentNode.ChildNodes[j].InnerText; lst.Add(info); } } } } //} } IQueryable <ArgumentItem> superset = lst.AsQueryable(); return(new PagedList <ArgumentItem>(superset, pageNo, pageSize)); }
public void TestArgumentValuePair() { var subArg = new ArgumentItem("456123"); var arg = new ArgumentItem("1", new ArgumentItem.ArgumentValuePair("EnrollNumber", "1"), new ArgumentItem.ArgumentValuePair("FingerIndex", 100), new ArgumentItem.ArgumentValuePair("ActionResult", 1), new ArgumentItem.ArgumentValuePair("TemplateLength", 520), new ArgumentItem.ArgumentValuePair("SubItem", subArg)); Assert.IsTrue(arg["EnrollNumber"] == "1"); Assert.IsTrue(arg["FingerIndex"] == "100"); Assert.IsTrue(arg["ActionResult"] == "1"); Assert.IsTrue(arg["TemplateLength"] == "520"); var newSubArg = JsonConvert.DeserializeObject <ArgumentItem>(arg["SubItem"]); Assert.IsTrue(newSubArg.Id == "456123"); }
public IPagedList <ArgumentItem> GetPagedArgumentData(int?processDID, int pageNo, int pageSize) { List <ArgumentItem> lst = new List <ArgumentItem>(); string path = "C:\\Users\\junxi\\Desktop\\bat"; DirectoryInfo theFolder = new DirectoryInfo(path); DirectoryInfo[] dirInfo = theFolder.GetDirectories(); foreach (DirectoryInfo NextFolder in dirInfo) { ArgumentItem info = new ArgumentItem(); info.Name = NextFolder.ToString(); lst.Add(info); } IQueryable <ArgumentItem> superset = lst.AsQueryable(); return(new PagedList <ArgumentItem>(superset, pageNo, pageSize)); }
public Switch(String strParse, ref int StartLocation) { while (String.IsNullOrWhiteSpace(strParse.ElementAt(StartLocation).ToString())) { StartLocation++; } var sLoc = StartLocation; var retrieved = SwitchPreceders. FirstOrDefault((s) => !(sLoc + s.Length > strParse.Length) && strParse.Substring(sLoc, s.Length) .Equals(s, StringComparison.OrdinalIgnoreCase)); if (retrieved == null) { throw new ArgumentException("Passed String " + strParse + " Does not have a switch preceder at position " + StartLocation); } var NextSpace = strParse.IndexOfAny(new char[] { ' ', '\t', '/', ':' }, sLoc + 1); if (NextSpace == -1) { NextSpace = strParse.Length; } //if(((NextSpace-sLoc)-sLoc+1) <= 0) throw new ArgumentException("Error Parsing Switch"); _SwitchValue = strParse.Substring(sLoc + 1, NextSpace - sLoc - 1); sLoc += retrieved.Length; //we don't want the switch itself. //now we need to determine where the Switch ends. colon or space seems reasonable. If a colon, the next entity will be an argument. StartLocation = NextSpace; //if the char at NextSpace is a Colon... if (NextSpace < strParse.Length && strParse.ElementAt(NextSpace) == ':') { //interpret as an argument NextSpace++; _Argument = new ArgumentItem(strParse, ref NextSpace); } StartLocation = NextSpace; }
public Switch(String strParse, ref int StartLocation) { while (String.IsNullOrWhiteSpace(strParse.ElementAt(StartLocation).ToString())) StartLocation++; var sLoc = StartLocation; var retrieved = SwitchPreceders. FirstOrDefault((s) => !(sLoc + s.Length > strParse.Length) && strParse.Substring(sLoc, s.Length) .Equals(s, StringComparison.OrdinalIgnoreCase)); if (retrieved == null) { throw new ArgumentException("Passed String " + strParse + " Does not have a switch preceder at position " + StartLocation); } var NextSpace = strParse.IndexOfAny(new char[] {' ', '\t', '/', ':'}, sLoc + 1); //if(((NextSpace-sLoc)-sLoc+1) <= 0) throw new ArgumentException("Error Parsing Switch"); _SwitchValue = strParse.Substring(sLoc + 1, NextSpace - sLoc - 1); sLoc += retrieved.Length; //we don't want the switch itself. //now we need to determine where the Switch ends. colon or space seems reasonable. If a colon, the next entity will be an argument. StartLocation = NextSpace; //if the char at NextSpace is a Colon... if (strParse.ElementAt(NextSpace) == ':') { //interpret as an argument NextSpace++; _Argument = new ArgumentItem(strParse, ref NextSpace); } StartLocation = NextSpace; }
private void ReadInput(T newItem, ArgumentItem argumentItem, string[] args, ref int i, bool isPositional = false) { if (argumentItem.PropertyInfo.PropertyType == typeof(bool)) { argumentItem.PropertyInfo.SetValue(newItem, true); } else if (typeof(IList).IsAssignableFrom(argumentItem.PropertyInfo.PropertyType) && argumentItem.PropertyInfo.PropertyType.IsGenericType) { var listType = typeof(List <>); var listItemType = argumentItem.PropertyInfo.PropertyType.GenericTypeArguments[0]; var constructedListType = listType.MakeGenericType(listItemType); var list = (IList)Activator.CreateInstance(constructedListType); if (list == null) { throw new NullReferenceException($"The property of type list hasn't been initialized. See {newItem.GetType().Name}.{argumentItem.PropertyInfo.Name}'"); } var increment = isPositional ? 0 : 1; for (; i + increment < args.Length; i++) { var input = args[i + increment]; if (input.StartsWith('-')) { break; } list.Add(ConvertValue(input, listItemType, argumentItem.GetConverter())); } argumentItem.PropertyInfo.SetValue(newItem, list); } else if (argumentItem.PropertyInfo.PropertyType.IsArray) { var listItemType = argumentItem.PropertyInfo.PropertyType.GetElementType(); if (listItemType == null) { throw new Exception("Since we check the array type, this shouldn't happen.'"); } var listType = typeof(List <>).MakeGenericType(listItemType); var list = (IList)Activator.CreateInstance(listType); var increment = isPositional ? 0 : 1; for (; i + increment < args.Length; i++) { var input = args[i + increment]; if (input.StartsWith('-')) { break; } list.Add(ConvertValue(input, listItemType, argumentItem.GetConverter())); } var array = Array.CreateInstance(listItemType, list.Count); list.CopyTo(array, 0); argumentItem.PropertyInfo.SetValue(newItem, array); } else if (argumentItem.PropertyInfo.PropertyType.IsEnum) { if (Enum.TryParse(argumentItem.PropertyInfo.PropertyType, ReadParameter(args, ref i, argumentItem.GetAction(), isPositional), true, out var result)) { argumentItem.PropertyInfo.SetValue(newItem, result); } else { throw new CommandArgumentException($"Error parsing the enum for property {argumentItem.PropertyInfo.Name}."); } } else if (argumentItem.PropertyInfo.PropertyType == typeof(FileInfo)) { argumentItem.PropertyInfo.SetValue(newItem, new FileInfo(ReadParameter(args, ref i, argumentItem.GetAction(), isPositional))); } else if (argumentItem.PropertyInfo.PropertyType == typeof(DirectoryInfo)) { argumentItem.PropertyInfo.SetValue(newItem, new DirectoryInfo(ReadParameter(args, ref i, argumentItem.GetAction(), isPositional))); } else { argumentItem.PropertyInfo.SetValue(newItem, ConvertValue(ReadParameter(args, ref i, argumentItem.GetAction(), isPositional), argumentItem.PropertyInfo.PropertyType, argumentItem.GetConverter())); } }