예제 #1
0
        public void Load(out IList <string> errors)
        {
            errors = new List <string>();

            foreach (var type in _businessAssembly.GetTypes())
            {
                var bc = BusinessClassInfo.Create(type, ref errors);
                if (bc != null)
                {
                    this.BusinessClasses.Add(bc);
                }
            }
        }
예제 #2
0
        public static BusinessClassInfo Create(Type businessClassType, ref IList <string> errors)
        {
            var attr = businessClassType.GetCustomAttributes().FirstOrDefault(i => i.TypeId.ToString().EndsWith("BusinessClassAttribute"));

            if (attr == null)
            {
                return(null);
            }

            int errorCount = errors.Count;

            var bc = new BusinessClassInfo();

            bc.Name = businessClassType.Name.Substring(0, businessClassType.Name.LastIndexOf("Business"));

            if (!businessClassType.IsPublic)
            {
                errors.Add(string.Format("'{0}.{1}' -> Business classes must be 'public'",
                                         businessClassType.Namespace, businessClassType.Name));
            }

            if (businessClassType.IsAbstract)
            {
                errors.Add(string.Format("'{0}.{1}' -> Business classes cannot be 'abstract'",
                                         businessClassType.Namespace, businessClassType.Name));
            }

            if (!businessClassType.Name.EndsWith("Business"))
            {
                errors.Add(string.Format("'{0}.{1}' -> Business classes must end with 'Business' suffix ({1}Business)",
                                         businessClassType.Namespace, businessClassType.Name));
            }

            bc.ServiceContractAttribute = businessClassType.GetCustomAttributes <ServiceContractAttribute>().FirstOrDefault();
            bc.ServiceBehaviorAttribute = businessClassType.GetCustomAttributes <ServiceBehaviorAttribute>().FirstOrDefault();

            foreach (var method in businessClassType.GetMethods() /* Only 'public' methods are returned */)
            {
                var bm = BusinessMethodInfo.Create(method, ref errors);
                if (bm != null)
                {
                    // Check that the business method name is unique (for WCF layer)...

                    bool   bOverridedName      = false;
                    string bmWsdlOperationName = bm.Method.Name;

                    if (bm.OperationContractAttribute != null && !string.IsNullOrEmpty(bm.OperationContractAttribute.Name))
                    {
                        bOverridedName      = true;
                        bmWsdlOperationName = bm.OperationContractAttribute.Name;
                    }

                    var tmpBm = bc.BusinessMethods.FirstOrDefault(i => i.Method.Name == bmWsdlOperationName);
                    if (tmpBm != null)
                    {
                        if (bOverridedName)
                        {
                            errors.Add(string.Format("[OperationContract(Name = \"{2}\")] '{0}::{1}()' -> Business method names must be unique (another method has the same name of this OperationContract Name)",
                                                     businessClassType.Name, bm.Method.Name, bm.OperationContractAttribute.Name));
                        }
                        else
                        {
                            errors.Add(string.Format("'{0}::{1}()' -> Business method names must be unique (another method has the same name)",
                                                     businessClassType.Name, bm.Method.Name));
                        }
                    }
                    else
                    {
                        tmpBm = bc.BusinessMethods.Where(i1 => i1.OperationContractAttribute != null)
                                .Where(i2 => !string.IsNullOrEmpty(i2.OperationContractAttribute.Name))
                                .FirstOrDefault(i3 => i3.OperationContractAttribute.Name == bmWsdlOperationName);

                        if (tmpBm != null)
                        {
                            if (bOverridedName)
                            {
                                errors.Add(string.Format("[OperationContract(Name = \"{2}\")] '{0}::{1}()' -> Business method names must be unique (another method has the same OperationContract Name)",
                                                         businessClassType.Name, bm.Method.Name, bm.OperationContractAttribute.Name));
                            }
                            else
                            {
                                errors.Add(string.Format("'{0}::{1}()' -> Business method names must be unique (another method has the name of this OperationContract Name)",
                                                         businessClassType.Name, bm.Method.Name));
                            }
                        }
                    }

                    bc.BusinessMethods.Add(bm);
                }
            }

            return((errorCount == errors.Count) ? bc : null);
        }