PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/DeveloperBranches/Ken/Previous/AssemblyProvider.Web/Entities/Assembly.cs

#
C# | 336 lines | 291 code | 45 blank | 0 comment | 15 complexity | 10e3999c212a5fbfc201427d3d29737f MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using AbstraX.ServerInterfaces;
  6. using AbstraX;
  7. using System.ComponentModel.DataAnnotations;
  8. using System.ServiceModel.DomainServices.Server;
  9. using Reflection = System.Reflection;
  10. using E = System.Linq.Expressions;
  11. using System.Linq.Expressions;
  12. using System.Runtime.Serialization;
  13. using MvvmTreeView;
  14. using AbstraX.XPathBuilder;
  15. using System.Diagnostics;
  16. using AbstraX.Templates;
  17. using AbstraX.AssemblyInterfaces;
  18. using AbstraX.TypeMappings;
  19. using AbstraX.Contracts;
  20. namespace AssemblyProvider.Web.Entities
  21. {
  22. [DataContract, NodeImage("AssemblyProvider.Web.Images.Assembly.png"), DebuggerDisplay("{ DebugInfo }"), ClientCodeGeneration(typeof(AbstraXClientInterfaceGenerator))]
  23. public class Assembly : IElement, IAssembly
  24. {
  25. private string assemblyFile;
  26. private AssembliesRoot parent;
  27. private Reflection.Assembly assembly;
  28. private string queryWhereProperty;
  29. private object queryWhereValue;
  30. public Assembly()
  31. {
  32. }
  33. public Assembly(Reflection.Assembly assembly, string file, AssembliesRoot parent)
  34. {
  35. this.assembly = assembly;
  36. this.assemblyFile = file;
  37. this.parent = parent;
  38. }
  39. public Assembly(Reflection.Assembly assembly, AssembliesRoot parent)
  40. {
  41. this.assembly = assembly;
  42. this.parent = parent;
  43. }
  44. [DataMember]
  45. public float ChildOrdinal
  46. {
  47. get
  48. {
  49. return 0;
  50. }
  51. }
  52. [DataMember]
  53. public string DebugInfo
  54. {
  55. get
  56. {
  57. return this.Name + ID;
  58. }
  59. }
  60. [DataMember, Key]
  61. public string ID
  62. {
  63. get
  64. {
  65. if (assemblyFile != null)
  66. {
  67. return this.MakeID("AssemblyFile='" + this.assemblyFile + "'");
  68. }
  69. else
  70. {
  71. return this.MakeID("Assembly='" + this.assembly.FullName + "'");
  72. }
  73. }
  74. }
  75. [DataMember]
  76. public string FolderKeyPair { get; set; }
  77. [DataMember]
  78. public string ParentID
  79. {
  80. get
  81. {
  82. return parent.ID;
  83. }
  84. }
  85. [DataMember]
  86. public IEnumerable<IAttribute> Attributes
  87. {
  88. get { throw new NotImplementedException(); }
  89. }
  90. [Association("Assembly_Types", "ID", "ParentID")]
  91. public List<AssemblyType> Types
  92. {
  93. get
  94. {
  95. var types = new List<AssemblyType>();
  96. try
  97. {
  98. if (queryWhereProperty != null && queryWhereProperty == "Type")
  99. {
  100. var type = assembly.GetType((string)queryWhereValue);
  101. Debug.Assert(type != null);
  102. types.Add(new AssemblyType(type, this));
  103. }
  104. else
  105. {
  106. foreach (System.Type type in assembly.GetTypes().Where(t => t.IsPublic))
  107. {
  108. types.Add(new AssemblyType(type, this));
  109. }
  110. }
  111. }
  112. catch
  113. {
  114. }
  115. return types;
  116. }
  117. }
  118. [DataMember]
  119. public IEnumerable<IElement> ChildElements
  120. {
  121. get
  122. {
  123. var elements = this.Types.AsQueryable().Cast<IElement>().Select(e => e);
  124. return elements;
  125. }
  126. }
  127. [DataMember]
  128. public IEnumerable<IOperation> Operations
  129. {
  130. get
  131. {
  132. return null;
  133. }
  134. }
  135. [Include, Association("Parent_BaseType", "ID", "ParentID"), ClientCodeGeneration(typeof(AbstraXClientInterfaceGenerator))]
  136. public BaseType DataType
  137. {
  138. get
  139. {
  140. return null;
  141. }
  142. }
  143. [DataMember]
  144. public string Description
  145. {
  146. get
  147. {
  148. return string.Empty;
  149. }
  150. }
  151. [DataMember]
  152. public string Documentation
  153. {
  154. get
  155. {
  156. return string.Empty;
  157. }
  158. }
  159. [DataMember]
  160. public string ImageURL
  161. {
  162. get
  163. {
  164. return string.Empty;
  165. }
  166. }
  167. [DataMember]
  168. public string Name
  169. {
  170. get
  171. {
  172. return assembly.FullName;
  173. }
  174. }
  175. public IBase Parent
  176. {
  177. get
  178. {
  179. return parent;
  180. }
  181. }
  182. [DataMember]
  183. public bool IsContainer
  184. {
  185. get
  186. {
  187. return true;
  188. }
  189. }
  190. public void ExecuteWhere(string property, object value)
  191. {
  192. if (value is XPathAxisElement && (property == "ID" || property == "ParentID"))
  193. {
  194. var predicate = ((XPathAxisElement)value).Predicates.First();
  195. queryWhereProperty = predicate.Left;
  196. queryWhereValue = predicate.Right;
  197. }
  198. else
  199. {
  200. Debugger.Break();
  201. queryWhereProperty = property;
  202. queryWhereValue = value;
  203. }
  204. }
  205. public void ExecuteWhere(Expression expression)
  206. {
  207. throw new NotImplementedException();
  208. }
  209. public void ExecuteWhere(XPathAxisElement element)
  210. {
  211. var predicate = element.Predicates.First();
  212. queryWhereProperty = predicate.Left;
  213. queryWhereValue = predicate.Right;
  214. }
  215. public void ClearPredicates()
  216. {
  217. queryWhereProperty = null;
  218. queryWhereValue = null;
  219. }
  220. public IRoot Root
  221. {
  222. get
  223. {
  224. IBase baseObject = this;
  225. while (baseObject != null)
  226. {
  227. baseObject = baseObject.Parent;
  228. if (baseObject is IRoot)
  229. {
  230. return (IRoot)baseObject;
  231. }
  232. }
  233. return null;
  234. }
  235. }
  236. [DataMember]
  237. public DefinitionKind Kind
  238. {
  239. get
  240. {
  241. return DefinitionKind.NotApplicable;
  242. }
  243. }
  244. [DataMember]
  245. public bool HasChildren
  246. {
  247. get
  248. {
  249. return assembly.GetTypes().Any();
  250. }
  251. }
  252. IEnumerable<IAssemblyType> IAssembly.Types
  253. {
  254. get
  255. {
  256. foreach (var type in this.Types)
  257. {
  258. yield return type;
  259. }
  260. }
  261. }
  262. [DataMember, Include, Association("Parent_Facet", "ID", "ParentID")]
  263. public Facet[] Facets
  264. {
  265. get
  266. {
  267. return null;
  268. }
  269. }
  270. [Exclude]
  271. public ContainerType AllowableContainerTypes
  272. {
  273. get { throw new NotImplementedException(); }
  274. }
  275. [Exclude]
  276. public ConstructType AllowableConstructTypes
  277. {
  278. get { throw new NotImplementedException(); }
  279. }
  280. [Exclude]
  281. public ContainerType DefaultContainerType
  282. {
  283. get { throw new NotImplementedException(); }
  284. }
  285. [Exclude]
  286. public ConstructType DefaultConstructType
  287. {
  288. get { throw new NotImplementedException(); }
  289. }
  290. }
  291. }