/// <summary>FindAopOnClass
 /// <para></para>
 /// </summary>
 public void FindAopOnClass(TypeRefCollection ClassDetail, List <AopDetail> aopDetailLst)
 {
     try
     {
         if (aopDetailLst != null && aopDetailLst.Count() > 0)
         {
             string Name           = ClassDetail.ClassFullyQualifiedName.Split(new char[] { '`' })[0];
             var    AOPClassDetail = aopDetailLst.Where(x => x.ForNameSpace == Name).FirstOrDefault();
             if (AOPClassDetail != null)
             {
                 ClassDetail.IsAOPEnabled     = true;
                 ClassDetail.AppliedAopDetail = AOPClassDetail;
             }
         }
     }
     catch (BeanException _beanEx)
     {
         _beanEx.LocationTrack(this.GetType().FullName + "EnableAOP()");
         throw _beanEx;
     }
     catch (Exception ex)
     {
         BeanException ObjBeanException = new BeanException();
         ObjBeanException.LocationTrack(this.GetType().FullName + "EnableAOP()");
         ObjBeanException.SetMessage(ex.Message);
         throw ObjBeanException;
     }
 }
 public TypeRefCollection GetMySqlDbRefType()
 {
     try
     {
         BottomhalfCore.DatabaseLayer.MySql.Code.Db db = new BottomhalfCore.DatabaseLayer.MySql.Code.Db(null);
         Type DbType = db.GetType();
         TypeRefCollection typeRefCollection = new TypeRefCollection();
         typeRefCollection.ClassName = DbType.Name;
         typeRefCollection.ClassFullyQualifiedName = DbType.FullName;
         typeRefCollection.IsFullyCreated          = true;
         typeRefCollection.AssemblyQualifiedName   = DbType.AssemblyQualifiedName;
         typeRefCollection.AssemblyName            = this.GetType().Assembly.FullName;
         return(typeRefCollection);
     }
     catch (BeanException _beanEx)
     {
         _beanEx.LocationTrack(this.GetType().FullName + "GetDbRefType()");
         throw _beanEx;
     }
     catch (Exception ex)
     {
         BeanException ObjBeanException = new BeanException();
         ObjBeanException.LocationTrack(this.GetType().FullName + "GetDbRefType()");
         ObjBeanException.SetMessage(ex.Message);
         throw ObjBeanException;
     }
 }
예제 #3
0
        /// <summary>DiscoverClassFiles
        /// <para></para>
        /// </summary>
        public Dictionary <string, TypeRefCollection> DiscoverClassFiles()
        {
            List <AopDetail> aopDetailLst;
            IManageTypeCollection <ManageTypeCollection>      manageTypeCollection;
            ILoasTypeDetail <LoadTypeDetail>                  loasTypeDetail;
            Dictionary <string, TypeRefCollection>            ClassTypeCollection  = null;
            Dictionary <string, List <InterfaceClassLinker> > interfaceClassLinker = null;

            try
            {
                aopDetailLst = null;
                //assemblyList = AppDomain.CurrentDomain.GetAssemblies().ToList<Assembly>();
                assemblyList         = LoadAssemblies();
                manageTypeCollection = new ManageTypeCollection();
                loasTypeDetail       = new LoadTypeDetail(assemblyList);
                ClassTypeCollection  = loasTypeDetail.BuildClassInformation(aopDetailLst);
                ICircularDependencyCheck _iCircularDependencyCheck = new CircularDependencyCheck(assemblyList);
                if (_iCircularDependencyCheck.LoadTypeForDependencyCheck() && ClassTypeCollection != null && ClassTypeCollection.Count() > 0)
                {
                    interfaceClassLinker = manageTypeCollection.MapInterfaceToClasses(ClassTypeCollection, aopDetailLst);
                    if (interfaceClassLinker != null)
                    {
                        container.SetInterfaceClassLinker(interfaceClassLinker);
                    }
                    manageTypeCollection.ManageConstructor(ClassTypeCollection);
                    if (container.MSSqlState)
                    {
                        TypeRefCollection ObjTypeRefCollection = manageTypeCollection.GetDbRefType();
                        ClassTypeCollection.Add("BottomhalfCore.DatabaseLayer.MsSql.Code.Db".ToLower(), ObjTypeRefCollection);
                        ClassTypeCollection.Add("BottomhalfCore.DatabaseLayer.Common.Code.IDb".ToLower(), ObjTypeRefCollection);
                    }
                    else if (container.MYSqlState)
                    {
                        TypeRefCollection ObjTypeRefCollection = manageTypeCollection.GetMySqlDbRefType();
                        ClassTypeCollection.Add("BottomhalfCore.DatabaseLayer.MySql.Code.Db".ToLower(), ObjTypeRefCollection);
                        ClassTypeCollection.Add("BottomhalfCore.DatabaseLayer.Common.Code.IDb".ToLower(), ObjTypeRefCollection);
                    }
                }
                return(ClassTypeCollection);
            }
            catch (BeanException _beanEx)
            {
                ClassTypeCollection  = null;
                interfaceClassLinker = null;
                assemblyList         = null;
                _beanEx.LocationTrack(this.GetType().FullName + "DiscoverClassFiles()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "DiscoverClassFiles()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }
예제 #4
0
        /// <summary>GetClassTypeCollection
        /// <para></para>
        /// </summary>
        private Dictionary <string, TypeRefCollection> GetClassTypeCollection(Type[] ActiveTypeCollection, List <AopDetail> aopDetailLst)
        {
            List <DocCollector> docCollectorlst = null;
            string            KeyName           = string.Empty;
            TypeRefCollection typeRefCollection = null;
            Dictionary <string, TypeRefCollection> ClassTypeCollection = new Dictionary <string, TypeRefCollection>();

            try
            {
                foreach (Type type in ActiveTypeCollection.ToList <Type>())
                {
                    if (type.Namespace != null && type.FullName.IndexOf("<") == -1 && type.FullName.IndexOf("<>") == -1 && !type.IsInterface && !type.IsAbstract)
                    {
                        typeRefCollection = new TypeRefCollection();
                        //FileName = ClassName.Replace(".cs", "").Trim();
                        //type = assemblyList.Where(x => x.FullName.Split(',')[0].ToLower() == asmName.ToLower())
                        //                   .SelectMany(a => a.GetTypes())
                        //                   .Where(i => i.Name.ToLower() == FileName.ToLower())
                        //                   .FirstOrDefault();

                        if (type != null)
                        {
                            /*---------------------- Reading and storing constructor detail of each class type. ---------------------------------
                             * /                                                                                                                    /
                             * / In this section it will iterate each classtype. Based on classtype this section will find all the constructor and  /
                             * / their parameter and also their detail. It will be used at the time of object creation and constructor selection.   /
                             * /                                                                                                                    /
                             * /                                                                                                                   */

                            DocCollector Docs = this.manageCodeDocuments.GenerateDocumentation(type);
                            if (Docs != null)
                            {
                                if (docCollectorlst == null)
                                {
                                    docCollectorlst = new List <DocCollector>();
                                }
                                docCollectorlst.Add(Docs);
                            }


                            /*-------------------------------------------- End Constructor reading --------------------------------------------- */



                            /*---------------------- Reading and storing constructor detail of each class type. ---------------------------------
                             * /                                                                                                                    /
                             * / In this section it will iterate each classtype. Based on classtype this section will find all the constructor and  /
                             * / their parameter and also their detail. It will be used at the time of object creation and constructor selection.   /
                             * /                                                                                                                    /
                             * /                                                                                                                   */

                            IFindClassAssets <FindConstructors> findClassAssets = new FindConstructors();
                            var CtorParam = findClassAssets.InspectMethods(type);
                            if (CtorParam != null && CtorParam.Count > 0)
                            {
                                typeRefCollection.Constructors = CtorParam;
                            }

                            /*-------------------------------------------- End Constructor reading --------------------------------------------- */



                            /*------------------------------ Reading and storing Class level annotation -----------------------------------------/
                             * /                                                                                                                    /
                             * / In this section it will iterate each classtype. Based on classtype this section will find all the constructor and  /
                             * / their parameter and also their detail. It will be used at the time of object creation and constructor selection.   /
                             * /                                                                                                                    /
                             * /                                                                                                                    /
                             * / ------------------------------------------------------------------------------------------------------------------ */

                            IFindClassAssets <FindAnnotations> findAnnotations = new FindAnnotations();
                            var ClassAnnotations = findAnnotations.InspectAnnotations(type, typeRefCollection);
                            if (ClassAnnotations != null)
                            {
                                if (ClassAnnotations.annotationDefination != null && ClassAnnotations.annotationDefination.Count > 0)
                                {
                                    typeRefCollection.AnnotationNames = ClassAnnotations.annotationDefination;
                                }
                                aopDetailLst = ClassAnnotations.aopDetailLst;
                            }

                            /*-------------------------------------------- End Constructor reading --------------------------------------------- */



                            /*---------------------- Reading and storing attributes detail of each class type. ---------------------------------
                             * /                                                                                                                    /
                             * / In this section it will iterate each classtype. Based on classtype this section will find all the constructor and  /
                             * / their parameter and also their detail. It will be used at the time of object creation and constructor selection.   /
                             * /                                                                                                                   */

                            IFindClassAssets <FindAttributes> findAttributes = new FindAttributes();
                            var TypeAttr = findAttributes.InspectAttributes(type);
                            if (TypeAttr != null && TypeAttr.Count > 0)
                            {
                                typeRefCollection.FieldAttributesCollection = TypeAttr;
                            }

                            /*                                                                                                                   /
                             * /                                                                                                                    /
                             * / ------------------------------------------------------------------------------------------------------------------ */

                            var AllBases = this.typeLoadingHelper.GetDeepBaseTypes(type, this.assemblyList);
                            if (AllBases != null)
                            {
                                typeRefCollection.BaseTypeHirarchy = AllBases;
                            }
                            //typeRefCollection.ClassType = type;
                            typeRefCollection.AssemblyQualifiedName       = type.AssemblyQualifiedName;
                            typeRefCollection.IsContainsGenericParameters = type.ContainsGenericParameters;
                            typeRefCollection.IsInterface             = type.IsInterface;
                            typeRefCollection.IsClass                 = type.IsClass;
                            typeRefCollection.ClassName               = type.Name;
                            typeRefCollection.ClassFullyQualifiedName = type.FullName;
                            typeRefCollection.AssemblyName            = type.Assembly.GetName().Name;
                            typeRefCollection.IsFullyCreated          = true;
                            if (type.Name.IndexOf("`") != -1)
                            {
                                KeyName = type.Name.Split('`')[0];
                            }
                            else
                            {
                                KeyName = type.Name;
                            }
                            ClassTypeCollection.Add(type.FullName.ToLower(), typeRefCollection);
                        }
                    }
                }

                return(ClassTypeCollection);
            }
            catch (BeanException _beanEx)
            {
                _beanEx.LocationTrack(this.GetType().FullName + "GetClassTypeCollection()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "GetClassTypeCollection()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }
 public ClassAnnotationDetail InspectAnnotations(Type CurrentType, TypeRefCollection refCollection)
 {
     throw new NotImplementedException();
 }
예제 #6
0
        /// <summary>InspectClassAnnotation
        /// <para></para>
        /// </summary>
        public ClassAnnotationDetail InspectAnnotations(Type CurrentType, TypeRefCollection refCollection)
        {
            ClassAnnotationDetail classAnnotationDetail;
            List <AopDetail>      aopDetailLst = null;
            Boolean DocumentGenerationFlag     = false;
            List <AnnotationDefination> ObjAnnotationDefinationList = new List <AnnotationDefination>();
            AnnotationDefination        ObjAnnotationDefination     = null;

            try
            {
                classAnnotationDetail = new ClassAnnotationDetail();
                foreach (var Annotate in CurrentType.CustomAttributes)
                {
                    if (Annotate.AttributeType.Name == Constants.Scoped)
                    {
                        refCollection.IsScoped = true;
                    }
                    else if (Annotate.AttributeType.Name == Constants.SingleTon)
                    {
                        refCollection.IsSingleTon = true;
                    }
                    else if (Annotate.AttributeType.Name == Constants.Transient)
                    {
                        refCollection.IsTransient = true;
                    }
                    else if (Annotate.AttributeType.Name == "GenerateDoc")
                    {
                        DocumentGenerationFlag = true;
                    }
                    else
                    {
                        ObjAnnotationDefinationList.Add(new AnnotationDefination {
                            AnnotationName = Annotate.AttributeType.Name
                        });
                        if (Annotate.AttributeType.FullName.IndexOf("BottomhalfCore.Annotations") != -1)
                        {
                            if (Annotate.AttributeType.Name == "NoCheck")
                            {
                                container.AddNoCheckClass(CurrentType.FullName.ToLower());
                            }

                            if (IsAopApplied(Annotate.AttributeType.Name))
                            {
                                string ReturnType       = Annotate.ConstructorArguments[0].Value.ToString();
                                string NameSpace        = Annotate.ConstructorArguments[1].Value.ToString();
                                string MethodExpression = Annotate.ConstructorArguments[2].Value.ToString();
                                string Arguments        = Annotate.ConstructorArguments[3].Value.ToString();
                                if (!string.IsNullOrEmpty(ReturnType) && !string.IsNullOrEmpty(NameSpace) && !string.IsNullOrEmpty(MethodExpression) && !string.IsNullOrEmpty(Arguments))
                                {
                                    AopDetail ObjAopDetail = new AopDetail();
                                    ObjAopDetail.AOPType                  = Annotate.AttributeType.Name;
                                    ObjAopDetail.ForArgumentType          = Arguments;
                                    ObjAopDetail.ForNameSpace             = NameSpace;
                                    ObjAopDetail.ForWhichReturnType       = ReturnType;
                                    ObjAopDetail.MethodExpression         = MethodExpression;
                                    ObjAopDetail.AspectClassName          = CurrentType.Name;
                                    ObjAopDetail.AspectFullyQualifiedName = CurrentType.Namespace;
                                    aopDetailLst.Add(ObjAopDetail);
                                }
                            }
                            else
                            {
                                if (ObjAnnotationDefination == null)
                                {
                                    ObjAnnotationDefination = new AnnotationDefination();
                                }
                                ObjAnnotationDefination.AnnotationName = Annotate.AttributeType.Name;
                                foreach (var CtorArgs in Annotate.ConstructorArguments)
                                {
                                    if (CtorArgs.Value != null)
                                    {
                                        ObjAnnotationDefination.Value.Add(CtorArgs.Value);
                                        ObjAnnotationDefination.AppliedOn = "class";
                                        if (Annotate.AttributeType.Name == "Auth")
                                        {
                                            if (ObjAnnotationDefination.Value.Count > 0)
                                            {
                                                string TokenName = ObjAnnotationDefination.Value.FirstOrDefault();
                                                if (!string.IsNullOrEmpty(TokenName))
                                                {
                                                    container.SetTokenName(TokenName);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                classAnnotationDetail.annotationDefination = ObjAnnotationDefinationList;
                classAnnotationDetail.aopDetailLst         = aopDetailLst;
                classAnnotationDetail.IsCodeDocRequired    = DocumentGenerationFlag;
                return(classAnnotationDetail);
            }
            catch (BeanException _beanEx)
            {
                _beanEx.LocationTrack(this.GetType().FullName + "InspectClassAnnotation()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "InspectClassAnnotation()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }
        /// <summary>ManageConstructor
        /// <para></para>
        /// </summary>
        public void ManageConstructor(Dictionary <string, TypeRefCollection> ClassTypeCollection)
        {
            try
            {
                string Element = null;
                ParameterNameCollection ParamCollectionName = null;
                int               typeindex = 0, CtorIndex = 0, paramindex = 0;
                List <string>     Properties = null;
                TypeRefCollection TypeRef    = null;
                ParameterDetail   ObjParameterDetail = null;
                Boolean           RemoveFlag = false;
                Dictionary <string, List <InterfaceClassLinker> > interfaceClassLinker = container.GetInterfaceClassLinker();
                INameSpaceHandler nameSpaceHandler = new NameSpaceHandler();
                while (typeindex < ClassTypeCollection.Count)
                {
                    TypeRef = ClassTypeCollection.ElementAt(typeindex).Value;

                    //--------------------------------- Managing attribute  ---------------------------------------------------
                    if (TypeRef.FieldAttributesCollection != null && TypeRef.FieldAttributesCollection.Count > 0)
                    {
                        int fieldindex = 0;
                        Properties = new List <string>();
                        while (fieldindex < TypeRef.FieldAttributesCollection.Count)
                        {
                            var FieldName = TypeRef.FieldAttributesCollection[fieldindex].FieldName;
                            if (FieldName != null && FieldName.IndexOf('`') != -1)
                            {
                                Element = null;
                                Element = FieldName.Substring(0, FieldName.IndexOf("[["));
                                var NewObj = interfaceClassLinker.Where(x => x.Key == Element).FirstOrDefault().Value;
                                if (NewObj != null && NewObj.Count > 0)
                                {
                                    if (TypeRef.FieldAttributesCollection[fieldindex].IsInterface)
                                    {
                                        List <string> SplittedCollection = ConvertNameSpaceToList(FieldName);

                                        /// <summary>
                                        /// Handle and manage class or types namespace
                                        /// </summary>
                                        SplittedCollection = nameSpaceHandler.ResolveNamespace(SplittedCollection);
                                        if (SplittedCollection.Count == 2)
                                        {
                                            int removeindex = 0;
                                            while (removeindex < SplittedCollection.Count)
                                            {
                                                if (SplittedCollection[removeindex].IndexOf("`") != 1)
                                                {
                                                    SplittedCollection.RemoveAt(removeindex);
                                                }
                                                removeindex++;
                                            }
                                        }
                                        else
                                        {
                                            SplittedCollection[0] = NewObj.FirstOrDefault().FullName; //ParamCollectionName.Name;
                                        }

                                        if (SplittedCollection.Count == 1)
                                        {
                                            TypeRef.FieldAttributesCollection[fieldindex].FieldName   = SplittedCollection[0];
                                            TypeRef.FieldAttributesCollection[fieldindex].GenericList = null;
                                            Properties.Add(SplittedCollection[0]);
                                        }
                                        else
                                        {
                                            TypeRef.FieldAttributesCollection[fieldindex].FieldName   = null;
                                            TypeRef.FieldAttributesCollection[fieldindex].GenericList = SplittedCollection;
                                            Properties.AddRange(SplittedCollection);
                                        }
                                    }
                                }
                            }
                            fieldindex++;
                        }
                    }

                    //-------------------------------------------- Managing controller -------------------------------------------
                    if (TypeRef != null && TypeRef.Constructors.Count > 0)
                    {
                        CtorIndex = 0;
                        while (CtorIndex < TypeRef.Constructors.Count)
                        {
                            ObjParameterDetail = TypeRef.Constructors.ElementAt(CtorIndex).Value;
                            if (ObjParameterDetail != null && ObjParameterDetail.Parameters.Count > 0)
                            {
                                paramindex = 0;
                                while (paramindex < ObjParameterDetail.Parameters.Count)
                                {
                                    RemoveFlag          = false;
                                    ParamCollectionName = ObjParameterDetail.Parameters.ElementAt(paramindex);
                                    //------------->  Converting generic collection types -----------------------------
                                    if (ParamCollectionName.Name.IndexOf("`") != -1)
                                    {
                                        if ((ParamCollectionName.Name.Split(new char[] { '`' })[0]).IndexOf("System.Collections") == -1)
                                        {
                                            if (ParamCollectionName.Name.IndexOf("[[") != -1)
                                            {
                                                Element = ParamCollectionName.Name.Split(new string[] { "[[" }, StringSplitOptions.RemoveEmptyEntries)[0];
                                            }
                                            else
                                            {
                                                Element = ParamCollectionName.Name;
                                            }
                                            if (Element.IndexOf("`1") != -1)
                                            {
                                                if (ParamCollectionName.Name.IndexOf("[[") != -1)
                                                {
                                                    Element = ParamCollectionName.Name.Split(new string[] { "[[" }, StringSplitOptions.RemoveEmptyEntries)[1];
                                                }
                                                else
                                                {
                                                    Element = ParamCollectionName.Name;
                                                }
                                                ParamCollectionName.Name = Element.Split(new[] { ',' })[0];
                                                RemoveFlag = true;
                                            }
                                            else
                                            {
                                                var NewObj = interfaceClassLinker.Where(x => x.Key == Element).FirstOrDefault().Value;
                                                if (NewObj != null)
                                                {
                                                    RemoveFlag = true;
                                                    ParamCollectionName.Name = NewObj.FirstOrDefault().FullName;
                                                }
                                            }
                                            ObjParameterDetail.Parameters[paramindex++] = ParamCollectionName;
                                        }
                                        else
                                        {
                                            RemoveFlag = true;
                                            Element    = GetImplementedName(ParamCollectionName.Name);
                                            ObjParameterDetail.Parameters[paramindex++] = ParamCollectionName;
                                        }
                                    }
                                    if (!RemoveFlag)
                                    {
                                        paramindex++;
                                    }
                                }
                            }
                            CtorIndex++;
                        }
                    }
                    typeindex++;
                }
            }
            catch (BeanException _beanEx)
            {
                _beanEx.LocationTrack(this.GetType().FullName + "ManageConstructor()");
                throw _beanEx;
            }
            catch (Exception ex)
            {
                BeanException ObjBeanException = new BeanException();
                ObjBeanException.LocationTrack(this.GetType().FullName + "ManageConstructor()");
                ObjBeanException.SetMessage(ex.Message);
                throw ObjBeanException;
            }
        }