public CodeManager() { Author[] author = new Author[1]; string[] description = new string[1]; CodeRepresentative selfRepresentative = new CodeRepresentative(); author[0] = new Author("Maciej 'Expro' Grabowski", "*****@*****.**"); description[0] = "Dynamic code manager, extends application features with modules and plugins."; managerDetails = new CodeDetails(Environment.GetCommandLineArgs()[0], typeof(CodeManager).FullName); managerDetails.Authors = author; managerDetails.Descriptions = description; managerDetails.IsModule = true; managerDetails.IsShared = true; managerDetails.Version = new CodeVersion(1, 0, 0); managerDetails.Name = "Code Manager"; selfRepresentative.Details = managerDetails; selfRepresentative.Instance = this; selfRepresentative.Provider = this; selfRepresentative.State = CodeState.Created; modulePermissions = new PermissionSet(PermissionState.Unrestricted); addinPermissions = new PermissionSet(PermissionState.Unrestricted); addinPermissions.AddPermission(new UIPermission(PermissionState.Unrestricted)); addinPermissions.AddPermission(new IsolatedStorageFilePermission(PermissionState.Unrestricted)); SeparateModules = false; binaries = ";"; memoryManagement = MemoryMode.FastestInitialization; codes = new SortedSet<CodeDetails>(); shared = new SortedSet<CodeDetails>(); modules = new SortedSet<CodeDetails>(); addins = new SortedSet<CodeDetails>(); controllable = new SortedSet<CodeDetails>(); conditions = new SortedSet<string>(); resolver = new SortedDictionary<string, CodeDetails>(); representatives = new SortedDictionary<CodeDetails, CodeRepresentative>(); domains = new SortedDictionary<CodeDetails, AppDomain>(); files = new SortedSet<string>(); modulesLock = new SemaphoreSlim(2); resolver.Add(typeof(CodeManager).FullName, managerDetails); domains.Add(managerDetails, AppDomain.CurrentDomain); representatives.Add(managerDetails, selfRepresentative); codes.Add(managerDetails); shared.Add(managerDetails); modules.Add(managerDetails); }
private CodeDetails RetriveDetails(Type type) { Contract.Requires(type != null); Contract.Ensures(Contract.Result<CodeDetails>() != null); CodeDetails result = new CodeDetails(path, type.FullName); object[] attributes = type.GetCustomAttributes(true); Type[] allInterfaces = type.GetInterfaces(); ISet<Author> authors = new HashSet<Author>(); ISet<string> description = new HashSet<string>(); ISet<string> interfaces = new HashSet<string>(); if (typeof(IControllableCode).IsAssignableFrom(type)) result.IsControllable = true; if (typeof(SharedCode).IsAssignableFrom(type)) result.IsShared = true; if (typeof(MarshalByRefObject).IsAssignableFrom(type)) result.IsShared = true; foreach (object attribute in attributes) { if (attribute is NameAttribute) result.Name = (attribute as NameAttribute).Value; if (attribute is DescriptionAttribute) description.Add((attribute as DescriptionAttribute).Text); if (attribute is AuthorAttribute) { var authorAttribute = (AuthorAttribute)attribute; authors.Add(new Author(authorAttribute.Name, authorAttribute.Email)); } if (attribute is VersionAttribute) { var versionAttribute = (VersionAttribute)attribute; result.Version = new CodeVersion(versionAttribute.Major, versionAttribute.Minor, versionAttribute.Build); } if (attribute is ModuleAttribute) { result.IsModule = true; result.ModuleCondition = (attribute as ModuleAttribute).Condition; } } foreach (Type iface in allInterfaces) interfaces.Add(iface.FullName); var authorsArray = new Author[authors.Count]; authors.CopyTo(authorsArray, 0); result.Authors = authorsArray; var descriptionArray = new string[description.Count]; description.CopyTo(descriptionArray, 0); result.Descriptions = descriptionArray; var interfacesArray = new string[interfaces.Count]; interfaces.CopyTo(interfacesArray, 0); result.Interfaces = interfacesArray; return result; }