コード例 #1
0
ファイル: ResolveValue.cs プロジェクト: wra222/testgit
        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);
        }