/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="product"></param> /// <param name="mb"></param> /// <param name="delivery"></param> /// <param name="part"></param> /// <param name="name"></param> /// <param name="spliter"></param> /// <returns></returns> public static string GetValue(Session session, IProduct product, IMB mb, Delivery delivery, IPart part, string name, char spliter) { int index = name.IndexOf(spliter); if (index < 1) { throw new Exception("wrong method name : " + name); } string objName = name.Substring(0, index).ToUpper(); string objMethod = name.Substring(index + 1).Trim(); if (objName == "PRODUCTINFO") { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "ProductInfo" }); } return product.ProductInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == "MODELINFO") { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } return product.ModelObj.Attributes .Where(x => x.Name == objMethod) .Select(y => y.Value).FirstOrDefault(); } if (objName == "FAMILYINFO") { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } string family = product.Family; IList<FamilyInfoDef> familyInfoList = familyRep.GetExistFamilyInfo(new FamilyInfoDef { family = family, name = objMethod }); if (familyInfoList == null || familyInfoList.Count == 0) { throw new FisException("CHK1036", new List<string> { family, objMethod }); } return familyInfoList[0].value; } if (objName == "PRODUCT") { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } string value = (string)product.GetProperty(objMethod); if (string.IsNullOrEmpty(value)) { throw new FisException("not exists property name:" + name); } return value; } if (objName == "PCB") { if (mb == null) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } string value = (string)mb.GetProperty(objMethod); if (string.IsNullOrEmpty(value)) { throw new FisException("not exists property name:" + name); } return value; } if (objName == "PCBINFO") { if (mb == null) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } return mb.MBInfos .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == "DELIVERY") { if (delivery == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } string value = (string)delivery.GetProperty(objMethod); if (string.IsNullOrEmpty(value)) { throw new FisException("not exists property name:" + name); } return value; } if (objName == "DELIVERYINFO") { if (delivery == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } return delivery.DeliveryInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == "PART") { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Part" }); } string value = (string)part.GetProperty(objMethod); if (string.IsNullOrEmpty(value)) { throw new FisException("not exists property name:" + name); } return value; } if (objName == "PARTINFO") { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Part" }); } return part.Attributes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } throw new Exception("not support resolve name:" + name); }
/// <summary> /// /// </summary> /// <param name="session"></param> /// <param name="product"></param> /// <param name="mb"></param> /// <param name="delivery"></param> /// <param name="part"></param> /// <param name="name"></param> /// <param name="spliter"></param> /// <returns></returns> public static string GetValue(Session session, IProduct product, IMB mb, Delivery delivery, IPart part, string name, char spliter) { int index = name.IndexOf(spliter); if (index < 1) { throw new Exception("wrong method name : " + name); } string objName = name.Substring(0, index).ToUpper(); string objMethod = name.Substring(index + 1).Trim(); if (objName == GlobalConstName.ResolveValue.PRODUCTINFO) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } return product.ProductInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == GlobalConstName.ResolveValue.PRODUCTATTR) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } if (product.ProductAttributes == null || !product.ProductAttributes.Any(x => x.AttributeName == objMethod)) { throw new FisException("CHK1036", new List<string> { product.ProId, name }); } return product.ProductAttributes .Where(x => x.AttributeName == objMethod) .Select(y => y.AttributeValue).FirstOrDefault().Trim(); } if (objName == GlobalConstName.ResolveValue.MODEL) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } if (product.ModelObj == null) { throw new FisException("CQCHK0006", new List<string> { "Product.ModelObj" }); } object value = product.ModelObj.GetProperty(objMethod); if (value == null) { return null; } return value.ToString().Trim(); } if (objName == GlobalConstName.ResolveValue.MODELINFO) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } if (product.ModelObj == null) { throw new FisException("CQCHK0006", new List<string> { "Product.ModelObj" }); } return product.ModelObj.Attributes .Where(x => x.Name == objMethod) .Select(y => y.Value).FirstOrDefault(); } if (objName == GlobalConstName.ResolveValue.FAMILYINFO) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } string family = product.Family; //IFamilyRepository familyRep = RepositoryFactory.GetInstance().GetRepository<IFamilyRepository>(); IList<FamilyInfoDef> familyInfoList = familyRep.GetExistFamilyInfo(new FamilyInfoDef { family = family, name = objMethod }); if (familyInfoList == null || familyInfoList.Count == 0) { throw new FisException("CHK1036", new List<string> { family, objMethod }); } return familyInfoList[0].value; } if (objName == GlobalConstName.ResolveValue.PRODUCT) { if (product == null) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } object value = product.GetProperty(objMethod); if (value==null) { throw new FisException("not exists property name:" + name); } return value.ToString(); } #region disable for ICI HTC case //if (objName == GlobalConstName.ResolveValue.IMGOSVER) //{ // if (product == null) // { // throw new FisException("CQCHK0006", new List<string> { "Product" }); // } // if (product.ModelObj == null || // string.IsNullOrEmpty(product.ModelObj.OSCode) || // product.ModelObj.LastEffectiveOSVer == null) // { // throw new FisException("CQCHK0006", new List<string> { "No setup ImgOSVer" }); // } // object value = product.ModelObj.LastEffectiveOSVer.GetField(objMethod); // if (value == null) // { // throw new FisException("not exists field name:" + name); // } // return value.ToString().Trim(); //} #endregion if (objName == GlobalConstName.ResolveValue.PCB) { if (mb == null) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } object value = mb.GetProperty(objMethod); if (value == null) { throw new FisException("not exists property name:" + name); } return value.ToString(); } if (objName == GlobalConstName.ResolveValue.PCBINFO) { if (mb == null) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } return mb.MBInfos .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == GlobalConstName.ResolveValue.DELIVERY) { if (delivery == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } object value = delivery.GetProperty(objMethod); if (value == null) { throw new FisException("not exists property name:" + name); } return value.ToString(); } if (objName == GlobalConstName.ResolveValue.DELIVERYINFO) { if (delivery == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } return delivery.DeliveryInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == GlobalConstName.ResolveValue.PART) { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } object value = part.GetProperty(objMethod); if (value==null) { throw new FisException("not exists property name:" + name); } return value.ToString(); } if (objName == GlobalConstName.ResolveValue.PARTINFO) { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } return part.Attributes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (objName == GlobalConstName.ResolveValue.SESSION) { if (session == null) { throw new FisException("CQCHK0006", new List<string> { "Session" }); } object value = session.GetValue(objMethod); if (value == null) { throw new FisException("not exists session key name:" + name); } return value.ToString().Trim(); } if (objName == GlobalConstName.ResolveValue.DATETIME) { DateTime now = DateTime.Now; return now.ToString(objMethod); } if (objName == GlobalConstName.ResolveValue.CONSTANT) { return objMethod; } throw new Exception("not support resolve name:" + name); }
/// <summary> /// /// </summary> /// <param name="part"></param> /// <param name="name"></param> /// <param name="objName"></param> /// <param name="fieldName"></param> /// <returns></returns> public static string ResolvePart(IPart part,string name, string objName, string fieldName) { if (string.Compare(objName, GlobalConstName.ResolveValue.PART,true)==0) { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Par" }); } object value = part.GetProperty(fieldName); if (value == null) { //throw new FisException("not exists property name:" + name); return null; } return value.ToString(); } if (string.Compare(objName , GlobalConstName.ResolveValue.PARTINFO,true)==0) { if (part == null) { throw new FisException("CQCHK0006", new List<string> { "Par" }); } if (part.Attributes == null || !part.Attributes.Any(x => x.InfoType == fieldName)) { //throw new FisException("CHK1036", new List<string> { part.PN, name }); return null; } return part.Attributes .Where(x => x.InfoType == fieldName) .Select(y => y.InfoValue).FirstOrDefault(); } throw new Exception("not support resolve name:" + name); //return null; }
/// <summary> /// PartPropertyExp与PnExp的匹配方法实现 /// e.g. /// PN(1,8)=CODE(2,9);PN(10,10)=CODE(15,15) /// PN=CODE /// PN=CODE(1,6) /// e.g. /// GCode(1,8)=CODE(2,9); /// GCode(10,10)=CODE(15,15); /// GCode=CODE /// </summary> /// <param name="input">匹配目标</param> /// <param name="pattern">匹配规则表达式</param> /// <returns>匹配结果</returns> public static bool IsMatch(string input, IPart part, string pattern) { if (string.IsNullOrEmpty(pattern)) { return true; } string[] patternSections = pattern.Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries); foreach (var section in patternSections) { string[] pair = section.Split(new char[] {'='}); if ((pair.Length != 2) || string.IsNullOrEmpty(pair[0]) || string.IsNullOrEmpty(pair[1])) { string msg = string.Format("Invalid match rule : {0}", pattern); var e = new Exception(msg); throw e; } var leftDef = pair[0]; var rightDef = pair[1]; string[] leftItem = leftDef.Split(new char[] {'(', ',', ')'}, StringSplitOptions.RemoveEmptyEntries); string[] rightItem = rightDef.Split(new char[] {'(', ',', ')'}, StringSplitOptions.RemoveEmptyEntries); string leftValue = string.Empty; string rightValue = string.Empty; int begin; int end; if ((leftItem.Length == 1)) { leftValue = part.GetProperty(leftItem[0]); } else if ((leftItem.Length == 3) && int.TryParse(leftItem[1], out begin) && int.TryParse(leftItem[2], out end) && begin <= end) { string property = part.GetProperty(leftItem[0]); if (property == null || property.Length < end) { return false; } leftValue = property.Substring(begin - 1, end - begin + 1); } else { string msg = string.Format("Invalid match rule : {0}", pattern); var e = new Exception(msg); throw e; } if ((rightItem.Length == 1) && rightItem[0].Equals("CODE")) { rightValue = input; } else if ((rightItem.Length == 3) && rightItem[0].Equals("CODE") && int.TryParse(rightItem[1], out begin) && int.TryParse(rightItem[2], out end) && begin <= end ) { if (input.Length < end) { return false; } rightValue = input.Substring(begin - 1, end - begin + 1); } else { string msg = string.Format("Invalid match rule : {0}", pattern); var e = new Exception(msg); throw e; } if (leftValue.Equals(rightValue) == false) { return false; } } return true; }
private static string getValueInner(Session session, IProduct product, IMB mb, Delivery delivery, IPart part, string name, char spliter, bool isThrowError) { int index = name.IndexOf(spliter); if (index < 1) { throw new Exception("wrong method name : " + name); } string objName = name.Substring(0, index); string objMethod = name.Substring(index + 1).Trim(); if (string.Compare(objName, GlobalConstName.ResolveValue.PRODUCTINFO, true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } if (product.ProductInfoes == null || !product.ProductInfoes.Any(x => x.InfoType == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { product.ProId, name }); } else { return null; } } return product.ProductInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PRODUCTATTR, true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } if (product.ProductAttributes == null || !product.ProductAttributes.Any(x => x.AttributeName == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { product.ProId, name }); } else { return null; } } return product.ProductAttributes .Where(x => x.AttributeName == objMethod) .Select(y => y.AttributeValue).FirstOrDefault().Trim(); } if (string.Compare(objName, GlobalConstName.ResolveValue.MODEL,true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } if (product.ModelObj == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product.ModelObj" }); } else { return null; } } object value = product.ModelObj.GetProperty(objMethod); if (value == null) { var model = product.ModelObj; value = model.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { product.Model, name }); } else { return null; } } } return value.ToString(); } if (string.Compare(objName, GlobalConstName.ResolveValue.MODELINFO, true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } var model = product.ModelObj; if (model == null) { throw new FisException("CQCHK0006", new List<string> { "Product.ModelObj" }); } string value = model.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { product.Model, name }); } else { return null; } } return value; } if (string.Compare(objName, GlobalConstName.ResolveValue.FAMILYINFO, true) == 0 || string.Compare(objMethod, GlobalConstName.ResolveValue.FAMILY, true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } var family = product.FamilyObj; if (family == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Family" }); } else { return null; } } object value = family.GetProperty(objMethod); if (value == null) { value = family.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { family.FamilyName, objMethod }); } else { return null; } } } return value.ToString(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PRODUCT, true) == 0) { if (product == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Product" }); } else { return null; } } object value = product.GetProperty(objMethod); if (value == null) { value = product.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("not exists property name:" + name); } else { return null; } } } return value.ToString(); } #region IMGOSVER for HTC //if (string.Compare(objName, GlobalConstName.ResolveValue.IMGOSVER, true) == 0) //{ // if (product == null) // { // if (isThrowError) // { // throw new FisException("CQCHK0006", new List<string> { "Product" }); // } // else // { // return null; // } // } // if (product.ModelObj == null || // string.IsNullOrEmpty(product.ModelObj.OSCode) || // product.ModelObj.LastEffectiveOSVer == null) // { // if (isThrowError) // { // throw new FisException("CQCHK0006", new List<string> { "No setup ImgOSVer" }); // } // else // { // return null; // } // } // object value = product.ModelObj.LastEffectiveOSVer.GetField(objMethod); // if (value == null) // { // if (isThrowError) // { // throw new FisException("not exists field name:" + name); // } // else // { // return null; // } // } // return value.ToString().Trim(); //} #endregion if (string.Compare(objName, GlobalConstName.ResolveValue.PCB, true) == 0) { if (mb == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } else { return null; } } object value = mb.GetProperty(objMethod); if (value == null) { value = mb.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("not exists property name:" + name); } else { return null; } } } return value.ToString(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PCBINFO, true) == 0) { if (mb == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } else { return null; } } if (mb.MBInfos == null || !mb.MBInfos.Any(x => x.InfoType == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { mb.Sn, name }); } else { return null; } } return mb.MBInfos .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PCBATTR, true) == 0) { if (mb == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "PCB" }); } else { return null; } } if (mb.PCBAttributes == null || !mb.PCBAttributes.Any(x => x.AttributeName == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { mb.Sn, name }); } else { return null; } } return mb.PCBAttributes .Where(x => x.AttributeName == objMethod) .Select(y => y.AttributeValue).FirstOrDefault().Trim(); } if (string.Compare(objName, GlobalConstName.ResolveValue.DELIVERY, true) == 0) { if (delivery == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } else { return null; } } object value = delivery.GetProperty(objMethod); if (value == null) { value = delivery.GetExtendedProperty(objMethod); if (value == null) { if (isThrowError) { throw new FisException("not exists property name:" + name); } else { return null; } } } return value.ToString(); } if (string.Compare(objName, GlobalConstName.ResolveValue.DELIVERYINFO, true) == 0) { if (delivery == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Delivery" }); } else { return null; } } if (delivery.DeliveryInfoes == null || !delivery.DeliveryInfoes.Any(x => x.InfoType == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { delivery.DeliveryNo, name }); } else { return null; } } return delivery.DeliveryInfoes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PART, true) == 0) { if (part == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Part" }); } else { return null; } } object value = part.GetProperty(objMethod); if (value == null) { value = part.GetAttribute(objMethod); if (value == null) { if (isThrowError) { throw new FisException("not exists property name:" + name); } else { return null; } } } return value.ToString(); } if (string.Compare(objName, GlobalConstName.ResolveValue.PARTINFO, true) == 0) { if (part == null) { if (isThrowError) { throw new FisException("CQCHK0006", new List<string> { "Part" }); } else { return null; } } if (part.Attributes == null || !part.Attributes.Any(x => x.InfoType == objMethod)) { if (isThrowError) { throw new FisException("CHK1036", new List<string> { part.PN, name }); } else { return null; } } return part.Attributes .Where(x => x.InfoType == objMethod) .Select(y => y.InfoValue).FirstOrDefault(); } if (string.Compare(objName, GlobalConstName.ResolveValue.SESSION, true) == 0) { if (session == null) { throw new FisException("CQCHK0006", new List<string> { "Session" }); } object value = session.GetValue(objMethod); if (value == null) { if (isThrowError) { throw new FisException("not exists session key name:" + name); } else { return null; } } return value.ToString().Trim(); } if (string.Compare(objName, GlobalConstName.ResolveValue.DATETIME, true) == 0) { DateTime now = DateTime.Now; return now.ToString(objMethod); } if (string.Compare(objName, GlobalConstName.ResolveValue.CONSTANT, true) == 0) { return objMethod; } throw new Exception("not support resolve name:" + name); }