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; } }
/// <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; } }
/// <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; } }
/// <summary>BuildClassInformation /// <para></para> /// </summary> public Dictionary <string, TypeRefCollection> BuildClassInformation(List <AopDetail> aopDetailLst) { Assembly asm = null; int AssemblyIndex = 0; Dictionary <string, TypeRefCollection> ClassTypeCollection = new Dictionary <string, TypeRefCollection>(); try { while (AssemblyIndex < assemblyList.Count) { asm = assemblyList[AssemblyIndex]; // this.container.WriteToFile(asm.FullName); Type[] TypeCollection = asm.GetTypes().Where(x => !x.IsEnum && !x.IsInterface && !x.IsAbstract).ToArray <Type>(); if (TypeCollection.Length > 0) { //this.container.WriteToFile(TypeCollection.Select(x => x.Name).ToList<string>()); var CollectionTypes = GetClassTypeCollection(TypeCollection, aopDetailLst); foreach (var item in CollectionTypes) { if (!ClassTypeCollection.ContainsKey(item.Key)) { ClassTypeCollection.Add(item.Key, item.Value); } } } AssemblyIndex++; } //Type Weaving = typeof(WeavProxy<>); //SpringClassInfo.Add(Weaving); //var SpringCollectionTypes = GetClassTypeCollection(SpringClassInfo.ToArray<Type>()); //foreach (var item in SpringCollectionTypes) //{ // if (!ClassTypeCollection.ContainsKey(item.Key)) // ClassTypeCollection.Add(item.Key, item.Value); //} AddWeaving(); return(ClassTypeCollection); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "BuildClassInformation()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "BuildClassInformation()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
public void DiscoverPath() { string ProjectDirctory = string.Empty; try { string CurrentBinDirectory = null; if (AppDomain.CurrentDomain.BaseDirectory != null) { CurrentBinDirectory = AppDomain.CurrentDomain.BaseDirectory; if (CurrentBinDirectory.IndexOf("bin") != -1) { var DirectoryPart = Regex.Split(CurrentBinDirectory, "bin"); if (DirectoryPart.Count() == 2) { ProjectDirctory = DirectoryPart[0]; CurrentBinDirectory = Path.Combine(ProjectDirctory, "bin"); } else { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "DiscoverPath()"); ObjBeanException.SetMessage("Not able to find current bin directory"); throw ObjBeanException; } } else if (Directory.Exists(Path.Combine(CurrentBinDirectory, "bin"))) { ProjectDirctory = CurrentBinDirectory; CurrentBinDirectory = Path.Combine(CurrentBinDirectory, "bin"); } } else { CurrentBinDirectory = this.GetType().Assembly.Location; ProjectDirctory = CurrentBinDirectory.Replace("\\Bottomhalf.dll", ""); ProjectDirctory = CurrentBinDirectory; } container.SetProjectPath(ProjectDirctory, CurrentBinDirectory); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "DiscoverPath()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "DiscoverPath()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>GenerateDocumentation /// <para></para> /// </summary> public DocCollector GenerateDocumentation(Type CurrentType) { DocCollector ObjDocCollector = null; MethodDefination ObjMethodDefination = null; List <MethodDefination> ObjMethodDefinationlst = new List <MethodDefination>(); List <string> TypeCollections = null; try { TypeCollections = new List <string>(); foreach (var method in ((System.Reflection.TypeInfo)CurrentType).DeclaredMethods) { IEnumerable <Attribute> Attributes = method.GetCustomAttributes(); foreach (Attribute attr in Attributes) { if (attr.GetType().Name == "Doc") { ObjMethodDefination = new MethodDefination(); ObjMethodDefination.MethodName = method.Name; ObjMethodDefination.Summary = ((BottomhalfCore.Annotations.Doc)attr).Summary; ObjMethodDefinationlst.Add(ObjMethodDefination); } } } if (ObjMethodDefinationlst.Count() > 0) { ObjDocCollector = new DocCollector(); ObjDocCollector.ClassName = CurrentType.FullName; ObjDocCollector.ObjMethodDefination = ObjMethodDefinationlst; } return(ObjDocCollector); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "GenerateDocumentation()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "GenerateDocumentation()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>BuildParameter /// <para></para> /// </summary> private ParameterNameCollection BuildParameter(Type GenericClassType, ref List <string> GenericParameterTypeName) { ParameterNameCollection ObjGenericTypeDefination = null; try { if (GenericClassType.GenericTypeArguments.Count() > 0) { ObjGenericTypeDefination = new ParameterNameCollection(); ObjGenericTypeDefination.Name = GenericClassType.Name; foreach (Type InnerType in GenericClassType.GenericTypeArguments) { if (ObjGenericTypeDefination.ParameterStructurInfo == null) { ObjGenericTypeDefination.ParameterStructurInfo = new List <ParameterNameCollection>(); } var InnerTypeDefination = BuildParameter(InnerType, ref GenericParameterTypeName); ObjGenericTypeDefination.ParameterStructurInfo.Add(InnerTypeDefination); } } else { ObjGenericTypeDefination = new ParameterNameCollection(); ObjGenericTypeDefination.Name = GenericClassType.Name; if (GenericParameterTypeName.Where(x => x == GenericClassType.Name).FirstOrDefault() == null) { GenericParameterTypeName.Add(GenericClassType.Name); } } return(ObjGenericTypeDefination); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "BuildParameter()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "BuildParameter()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
public ConfigDetail LoadConfigurationDetail() { try { ConfigDetail ObjConfigDetail = new ConfigDetail(); string Key = null; string CSName = ""; //int CSCounter = ConfigurationManager.ConnectionStrings.Count; //if (CSCounter > 0) //{ // ObjConfigDetail.ConnectionStringCollection = new ConcurrentDictionary<string, string>(); // while (CSCounter != 0) // { // CSName = ConfigurationManager.ConnectionStrings[CSCounter - 1].ConnectionString; // Key = ConfigurationManager.ConnectionStrings[CSCounter - 1].Name; // if (!string.IsNullOrEmpty(CSName) && Key != "LocalSqlServer") // ObjConfigDetail.ConnectionStringCollection.Add(Key, CSName); // CSCounter--; // } //} //string[] KeyArrays = ConfigurationManager.AppSettings.AllKeys; //if (KeyArrays.Count() > 0) //{ // ObjConfigDetail.AppSettingCollection = new ConcurrentDictionary<string, string>(); // foreach (string key in KeyArrays) // ObjConfigDetail.AppSettingCollection.Add(key, ConfigurationManager.AppSettings[key]); //} return(ObjConfigDetail); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "LoadConfigurationDetail()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "LoadConfigurationDetail()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>SetUpContextEnvironment /// <para></para> /// </summary> private void SetUpContextEnvironment() { ILoadAsmTypes<LoadAsmTypes> loadAsmTypes; IOrganizeContainer organizeContainer = null; IDictionary<string, TypeRefCollection> beansType = null; ConcurrentDictionary<string, GraphContainerModal> containerCollection = null; List<DocCollector> docCollectorlst = null; try { loadAsmTypes = new LoadAsmTypes(); organizeContainer = new OrganizeContainer(); //var ProjectNames = container.GetProjectName(); beansType = loadAsmTypes.DiscoverClassFiles(); container.ContainerStatus(true); containerCollection = organizeContainer.ReOrganizeContainer(beansType); if (containerCollection != null && containerCollection.Count() > 0) { container.SetGraphContainerModalCollection(containerCollection); if (DocumentGenerationFlag && docCollectorlst != null && docCollectorlst.Count() > 0) container.SetProjectDocumentation(docCollectorlst); } else { BeanException ObjBeanException = new BeanException(); ObjBeanException.SetMessage("Not able to create Container context."); throw ObjBeanException; } } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "SetUpContextEnvironment()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "SetUpContextEnvironment()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>ResolverClassType Constructor /// <para></para> /// </summary> public ResolverClassType() { List<AopDetail> aopDetailLst; IFileCollector fileCollector = null; try { container = Container.GetInstance(); WhiteList = new List<string>(); aopDetailLst = new List<AopDetail>(); string CurrentProjectDirectory = this.container.GetProjectPath(); #region FILECOLLECTOR /// <summary>FileCollector read files /// <para></para> /// </summary> fileCollector = new FileCollector(); if (string.IsNullOrEmpty(CurrentProjectDirectory)) fileCollector.DiscoverPath(); //if (container.ProjectNamesIsNotEmpty()) // fileCollector.ReadCoreProjectFile(); #endregion SetUpContextEnvironment(); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "ResolverClassType()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "ResolverClassType()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>MapInterfaceToClasses /// <para></para> /// </summary> public Dictionary <string, List <InterfaceClassLinker> > MapInterfaceToClasses(Dictionary <string, TypeRefCollection> TypeCollection, List <AopDetail> aopDetailLst) { IManageAopDetail <ManageAopDetail> manageAopDetail; Dictionary <string, List <InterfaceClassLinker> > InterfaceClassMapper = new Dictionary <string, List <InterfaceClassLinker> >(); List <InterfaceClassLinker> interfaceClassLinkerList = null; InterfaceClassLinker interfaceClassLinker = null; try { if (TypeCollection != null && TypeCollection.Count > 0) { foreach (var TypeRef in TypeCollection) { manageAopDetail = new ManageAopDetail(); manageAopDetail.FindAopOnClass(TypeRef.Value, aopDetailLst); interfaceClassLinkerList = new List <InterfaceClassLinker>(); foreach (var Base in TypeRef.Value.BaseTypeHirarchy) { interfaceClassLinker = new InterfaceClassLinker(); interfaceClassLinker.FullName = TypeRef.Value.ClassFullyQualifiedName; interfaceClassLinker.Name = TypeRef.Value.ClassName; var ExistingObject = InterfaceClassMapper.Where(x => x.Key == Base.TypeFullName).FirstOrDefault(); if (ExistingObject.Key == null || ExistingObject.Value == null) { ExistingObject = InterfaceClassMapper.Where(x => x.Key == Base.TypeName).FirstOrDefault(); } if (ExistingObject.Key != null && ExistingObject.Value != null) { interfaceClassLinkerList = ExistingObject.Value; var ObjReferenced = interfaceClassLinkerList.Where(x => x.FullName == interfaceClassLinker.FullName || x.Name == interfaceClassLinker.Name).FirstOrDefault(); if (ObjReferenced == null) { interfaceClassLinkerList.Add(interfaceClassLinker); if (Base.TypeFullName != null) { InterfaceClassMapper[Base.TypeFullName] = interfaceClassLinkerList; } else { InterfaceClassMapper[Base.TypeName] = interfaceClassLinkerList; } } } else { interfaceClassLinkerList.Add(interfaceClassLinker); if (Base.TypeFullName != null) { InterfaceClassMapper.Add(Base.TypeFullName, interfaceClassLinkerList); } else { InterfaceClassMapper.Add(Base.TypeName, interfaceClassLinkerList); } } } } } return(InterfaceClassMapper); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "MapInterfaceToClasses()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "MapInterfaceToClasses()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <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 Dictionary <string, List <APIManagerModal> > GetAPIs() { try { string Name = null; Assembly asm = null; List <Assembly> Assemblies = new List <Assembly>(); string Bindir = container.GetProjectBinPath(); Dictionary <string, int> LoadedAssemblyNames = new Dictionary <string, int>(); var AsmFilesArr = Directory.GetFiles(Bindir, "*.dll", SearchOption.AllDirectories); var AsmExeFiles = Directory.GetFiles(Bindir, "*.exe", SearchOption.AllDirectories); List <string> AsmFiles = AsmFilesArr.Union(AsmExeFiles).ToList <string>(); string ProjectAssemblyName = Assembly.GetEntryAssembly().GetName().Name + ".dll"; LoadedAssemblyNames.Add(ProjectAssemblyName, 0); string InnerAsm = null; string FoundAsmPath = null; Type type = null; ConstructorInfo Ctor = null; ParameterInfo Param = null; int ParamIndex = 0; int CtorIndex = 0; int TypeIndex = 0; int Index = 0; while (Index < LoadedAssemblyNames.Count()) { FoundAsmPath = AsmFiles.Where(x => x.Contains(LoadedAssemblyNames.ElementAt(Index).Key)).FirstOrDefault(); if (FoundAsmPath != null && LoadedAssemblyNames.ElementAt(Index).Value == 0 && LoadedAssemblyNames.ElementAt(Index).Key != this.container.FrameWorkName + ".dll") { asm = null; if (Assemblies.Where(x => x.GetName().Name == Name).FirstOrDefault() == null) { asm = Assembly.LoadFrom(FoundAsmPath); Assemblies.Add(asm); IEnumerable <Type> Types = asm.ExportedTypes; TypeIndex = 0; while (TypeIndex < Types.Count()) { type = Types.ElementAt(TypeIndex); if (!type.IsInterface) { ReadAttributeAndParameters(type); IEnumerable <ConstructorInfo> Ctors = type.GetConstructors(); CtorIndex = 0; while (CtorIndex < Ctors.Count()) { Ctor = Ctors.ElementAt(CtorIndex); IEnumerable <ParameterInfo> Parameters = Ctor.GetParameters(); ParamIndex = 0; while (ParamIndex < Parameters.Count()) { Param = Parameters.ElementAt(ParamIndex); InnerAsm = Param.ParameterType.Assembly.GetName().Name + ".dll"; if (LoadedAssemblyNames.Where(x => x.Key == InnerAsm).FirstOrDefault().Key == null && InnerAsm != this.container.FrameWorkName + ".dll" && InnerAsm.ToLower().IndexOf("microsoft.") == -1 && InnerAsm.ToLower().IndexOf("system.") == -1) { LoadedAssemblyNames.Add(InnerAsm, 0); } ParamIndex++; } CtorIndex++; } } TypeIndex++; } } } LoadedAssemblyNames[LoadedAssemblyNames.ElementAt(Index).Key] = 1; Index++; } Assemblies = null; return(aPIManager); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "LoadAssemblies()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "LoadAssemblies()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>GetDeepBaseTypes /// <para></para> /// </summary> public List <ImplementedHirarchy> GetDeepBaseTypes(Type CurrentType, List <Assembly> assemblyList) { List <ImplementedHirarchy> ObjImplementedHirarchyList = new List <ImplementedHirarchy>(); ImplementedHirarchy ObjImplementedHirarchy = null; Type NewBaseType = CurrentType; NewBaseType = NewBaseType.BaseType; int Index = 0; try { Type FilteredType = null; var ImplementedInterfaceTypes = CurrentType.GetInterfaces(); if (ImplementedInterfaceTypes != null && ImplementedInterfaceTypes.Count() > 0) { foreach (Type ParentInterface in ImplementedInterfaceTypes) { FilteredType = null; ObjImplementedHirarchy = new ImplementedHirarchy(); try { FilteredType = assemblyList.SelectMany(a => a.GetTypes()).Where(x => x.Name == ParentInterface.Name).FirstOrDefault(); } catch (Exception) { FilteredType = null; } if (FilteredType != null) { ObjImplementedHirarchy.TypeName = FilteredType.Name; ObjImplementedHirarchy.TypeFullName = FilteredType.FullName; if (FilteredType.IsInterface) { ObjImplementedHirarchy.ImplementedType = "interface"; } else if (FilteredType.IsAbstract) { ObjImplementedHirarchy.ImplementedType = "abstract"; } else { ObjImplementedHirarchy.ImplementedType = "class"; } ObjImplementedHirarchy.IndexOrder = ++Index; ObjImplementedHirarchyList.Add(ObjImplementedHirarchy); } } } return(ObjImplementedHirarchyList); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "GetDeepBaseTypes()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "GetDeepBaseTypes()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <summary>LoadAssemblies /// <para></para> /// </summary> private List <Assembly> LoadAssemblies() { try { string Name = null; Assembly asm = null; List <Assembly> Assemblies = new List <Assembly>(); Bindir = container.GetProjectBinPath(); Dictionary <string, int> LoadedAssemblyNames = new Dictionary <string, int>(); var AsmFilesArr = Directory.GetFiles(Bindir, "*.dll", SearchOption.AllDirectories); var AsmExeFiles = Directory.GetFiles(Bindir, "*.exe", SearchOption.AllDirectories); List <string> AsmFiles = AsmFilesArr.Union(AsmExeFiles).ToList <string>(); string ProjectAssemblyName = Assembly.GetEntryAssembly().GetName().Name + ".dll"; LoadedAssemblyNames.Add(ProjectAssemblyName, 0); string InnerAsm = null; string FoundAsmPath = null; Type type = null; ConstructorInfo Ctor = null; ParameterInfo Param = null; int ParamIndex = 0; int CtorIndex = 0; int TypeIndex = 0; int Index = 0; while (Index < LoadedAssemblyNames.Count()) { FoundAsmPath = AsmFiles.Where(x => x.Contains(LoadedAssemblyNames.ElementAt(Index).Key)).FirstOrDefault(); if (FoundAsmPath != null && LoadedAssemblyNames.ElementAt(Index).Value == 0 && LoadedAssemblyNames.ElementAt(Index).Key != this.container.FrameWorkName + ".dll") { asm = null; if (Assemblies.Where(x => x.GetName().Name == Name).FirstOrDefault() == null) { asm = Assembly.LoadFrom(FoundAsmPath); Assemblies.Add(asm); IEnumerable <Type> Types = asm.ExportedTypes; TypeIndex = 0; while (TypeIndex < Types.Count()) { type = Types.ElementAt(TypeIndex); if (!type.IsInterface) { //ReadAttributeAndParameters(type); IEnumerable <ConstructorInfo> Ctors = type.GetConstructors(); CtorIndex = 0; while (CtorIndex < Ctors.Count()) { Ctor = Ctors.ElementAt(CtorIndex); IEnumerable <ParameterInfo> Parameters = Ctor.GetParameters(); ParamIndex = 0; while (ParamIndex < Parameters.Count()) { Param = Parameters.ElementAt(ParamIndex); InnerAsm = Param.ParameterType.Assembly.GetName().Name + ".dll"; if (LoadedAssemblyNames.Where(x => x.Key == InnerAsm).FirstOrDefault().Key == null && InnerAsm != this.container.FrameWorkName + ".dll" && InnerAsm.ToLower().IndexOf("microsoft.") == -1 && InnerAsm.ToLower().IndexOf("system.") == -1) { LoadedAssemblyNames.Add(InnerAsm, 0); } ParamIndex++; } CtorIndex++; } } TypeIndex++; } } } LoadedAssemblyNames[LoadedAssemblyNames.ElementAt(Index).Key] = 1; Index++; } #region DEADCODE //foreach (var dir in Files) //{ // foreach (string dll in AsmFiles) // { // Name = dll.Substring(dll.LastIndexOf(@"\"), dll.Length - dll.LastIndexOf(@"\")).Replace(@"\", "").Replace(".dll", ""); // if (dir == Name && Name == dir && Name != this.container.FrameWorkName) // { // asm = null; // if (Assemblies.Where(x => x.GetName().Name == Name).FirstOrDefault() == null) // { // asm = Assembly.LoadFrom(dll); // Assemblies.Add(asm); // } // break; // } // } // if (AsmExeFiles.Count() > 0) // { // foreach (string ExeFile in AsmExeFiles) // { // Name = ExeFile.Substring(ExeFile.LastIndexOf(@"\"), ExeFile.Length - ExeFile.LastIndexOf(@"\")).Replace(@"\", "").Replace(".exe", ""); // if (dir == Name && Name == dir && Name != this.container.FrameWorkName) // { // asm = null; // if (Assemblies.Where(x => x.GetName().Name == Name).FirstOrDefault() == null) // { // asm = Assembly.LoadFile(ExeFile); // Assemblies.Add(asm); // } // break; // } // } // } //} #endregion return(Assemblies); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "LoadAssemblies()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "LoadAssemblies()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }
/// <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>InspectAttributes /// <para></para> /// </summary> public List <BottomhalfModel.FieldAttributes> InspectAttributes(Type CurrentType) { List <BottomhalfModel.FieldAttributes> ObjFieldAttributesCollection = new List <BottomhalfModel.FieldAttributes>(); IEnumerable <Attribute> FAttributes = null; BottomhalfModel.FieldAttributes ObjFieldAttributes = null; try { var Fields = CurrentType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance); if (Fields.Count() > 0) { foreach (var field in Fields) { FAttributes = field.GetCustomAttributes(); foreach (var Attr in FAttributes) { if (Attr != null) { if (Attr.GetType().FullName.IndexOf("BottomhalfCore.Annotations") != -1) { if (ObjFieldAttributesCollection.Where(x => x.DeclaredName == field.Name).FirstOrDefault() == null) { ObjFieldAttributes = new BottomhalfModel.FieldAttributes(); ObjFieldAttributes.Attributes.Add(Attr.GetType().Name); ObjFieldAttributes.FieldName = field.FieldType.FullName; ObjFieldAttributes.Name = field.FieldType.Name; ObjFieldAttributes.DeclaredName = field.Name; ObjFieldAttributes.IsGenericType = field.FieldType.IsGenericType; ObjFieldAttributes.IsField = true; if (field.FieldType.IsInterface) { ObjFieldAttributes.IsInterface = true; } else { ObjFieldAttributes.IsInterface = false; } ObjFieldAttributesCollection.Add(ObjFieldAttributes); } } } } } } var Properties = CurrentType.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); if (Properties.Count() > 0) { foreach (var property in Properties) { FAttributes = property.GetCustomAttributes(); foreach (var Attr in FAttributes) { if (Attr != null) { if (Attr.GetType().FullName.IndexOf("BottomhalfCore.Annotations") != -1) { if (ObjFieldAttributesCollection.Where(x => x.DeclaredName == property.Name).FirstOrDefault() == null) { ObjFieldAttributes = new BottomhalfModel.FieldAttributes(); ObjFieldAttributes.Attributes.Add(Attr.GetType().Name); ObjFieldAttributes.FieldName = property.PropertyType.FullName; ObjFieldAttributes.Name = property.PropertyType.Name; ObjFieldAttributes.DeclaredName = property.Name; ObjFieldAttributes.IsGenericType = property.PropertyType.IsGenericType; ObjFieldAttributes.IsField = false; if (property.PropertyType.IsInterface) { ObjFieldAttributes.IsInterface = true; } else { ObjFieldAttributes.IsInterface = false; } ObjFieldAttributesCollection.Add(ObjFieldAttributes); } } } } } } return(ObjFieldAttributesCollection); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "InspectAttributes()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "InspectAttributes()"); 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; } }
/// <summary>InspectConstructor /// <para></para> /// </summary> public Dictionary <int, ParameterDetail> InspectMethods(Type CurrentType) { ParameterInfo[] parameters = null; ParameterDetail ObjParameterDetail = null; AnnotationDefination ObjAnnotationDefination = null; Dictionary <int, ParameterDetail> CtorParams = new Dictionary <int, ParameterDetail>(); List <string> TypeCollections = null; ParameterNameCollection ObjParameterNameCollection = null; List <string> GenericParameterTypeName = new List <string>(); try { int index = 0; TypeCollections = new List <string>(); foreach (var ctor in CurrentType.GetConstructors()) { ObjParameterDetail = new ParameterDetail(); parameters = ctor.GetParameters(); foreach (var param in parameters) { var NewType = param.ParameterType; String FullNameSpace = NewType.AssemblyQualifiedName; if (FullNameSpace != null) { if (FullNameSpace != null) { ObjParameterNameCollection = new ParameterNameCollection(); ObjParameterDetail.WrapperFullDescription = ""; if (FullNameSpace.IndexOf("`") != -1) { ObjParameterNameCollection.Name = FullNameSpace; } else { ObjParameterNameCollection.Name = FullNameSpace.Split(new char[] { ',' })[0]; } ObjParameterNameCollection.ArgumentName = param.Name; ObjParameterDetail.Parameters.Add(ObjParameterNameCollection); } else { throw new ApplicationException("Unable to resolve constructor paramter for class: " + NewType.Name); } } else if (NewType.AssemblyQualifiedName == null) { if (NewType.IsGenericType) { if (NewType.AssemblyQualifiedName == null) { if (NewType.GenericTypeArguments.Count() > 0) { ObjParameterNameCollection = BuildParameter(NewType, ref GenericParameterTypeName); } if (ObjParameterNameCollection != null) { TypeCollections.Add(ObjParameterNameCollection.Name); } } } else { ObjParameterNameCollection = BuildParameter(NewType, ref GenericParameterTypeName); if (ObjParameterNameCollection != null) { TypeCollections.Add(ObjParameterNameCollection.Name); } } ObjParameterDetail.WrapperFullDescription = ""; if (ObjParameterNameCollection == null) { ObjParameterNameCollection = new ParameterNameCollection { Name = NewType.Name } } ; ObjParameterDetail.Parameters.Add(ObjParameterNameCollection); } } IEnumerable <Attribute> CtorAttributes = ctor.GetCustomAttributes(); foreach (var attr in CtorAttributes) { ObjAnnotationDefination = new AnnotationDefination(); ObjAnnotationDefination.AnnotationName = attr.GetType().Name; ObjAnnotationDefination.AppliedOn = "ctor"; if (ObjAnnotationDefination.AnnotationName == "Enabled") { ObjAnnotationDefination.OrderNo = ((BottomhalfCore.Annotations.Enabled)attr).Order; } if (ObjAnnotationDefination.AnnotationName == "File") { ObjAnnotationDefination.Filename = ((BottomhalfCore.Annotations.File)attr).Filename; } if (ObjParameterDetail.AnnotationDetail == null) { ObjParameterDetail.AnnotationDetail = new List <AnnotationDefination>(); } ObjParameterDetail.AnnotationDetail.Add(ObjAnnotationDefination); } if ((ObjParameterDetail.AnnotationDetail != null && ObjParameterDetail.AnnotationDetail.Count > 0) || ObjParameterDetail.Parameters.Count > 0) { CtorParams.Add(++index, ObjParameterDetail); } } if (TypeCollections.Count() > 0) { ObjParameterDetail.IsGeneric = true; if (GenericParameterTypeName.Count() > 0) { ObjParameterDetail.GenericParameterTypeName = GenericParameterTypeName; } else { GenericParameterTypeName = null; } } return(CtorParams); } catch (BeanException _beanEx) { _beanEx.LocationTrack(this.GetType().FullName + "InspectConstructor()"); throw _beanEx; } catch (Exception ex) { BeanException ObjBeanException = new BeanException(); ObjBeanException.LocationTrack(this.GetType().FullName + "InspectConstructor()"); ObjBeanException.SetMessage(ex.Message); throw ObjBeanException; } }