PageRenderTime 108ms CodeModel.GetById 30ms RepoModel.GetById 4ms app.codeStats 0ms

/settings/CompletedCache.cs

https://github.com/moscrif/ide
C# | 366 lines | 243 code | 65 blank | 58 comment | 74 complexity | bdf2df7a86624a0a9ab1abd6daa131ad MD5 | raw file
  1. using System;
  2. using System.Linq;
  3. using System.Xml;
  4. using System.Xml.Serialization;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using Moscrif.IDE.Iface.Entities;
  8. using Moscrif.IDE.Completion;
  9. using Moscrif.IDE.Controls.SqlLite;
  10. using Mono.Data.Sqlite;
  11. using Moscrif.IDE.Tool;
  12. namespace Moscrif.IDE.Option
  13. {
  14. public class CompletedCache
  15. {
  16. [XmlIgnore]
  17. public string FilePath
  18. {
  19. get {
  20. return System.IO.Path.Combine(MainClass.Paths.ConfingDir, "completedcache");
  21. }
  22. }
  23. public CompletedCache()
  24. {
  25. //if (ListKeywords == null) ListKeywords = new List<string>();
  26. ListDataKeywords = new List<CompletionData>();
  27. ListDataTypes = new List<CompletionData>();
  28. ListDataProperties = new List<CompletionData>();
  29. ListDataMembers = new List<CompletionData>();
  30. ListDataEvents = new List<CompletionData>();
  31. }
  32. /*public CompletedCache(string filePath)
  33. {
  34. FilePath = filePath;
  35. if (ListKeywords == null) ListKeywords = new List<string>();
  36. }*/
  37. public void SaveCompletedCache()
  38. {
  39. /*using (FileStream fs = new FileStream(FilePath, FileMode.Create)) {
  40. XmlSerializer serializer = new XmlSerializer(typeof(CompletedCache));
  41. serializer.Serialize(fs, this);
  42. }*/
  43. }
  44. static public CompletedCache OpenCompletedCache(string filePath)
  45. {
  46. /*if (System.IO.File.Exists(filePath)) {
  47. try {
  48. using (FileStream fs = File.OpenRead(filePath)) {
  49. XmlSerializer serializer = new XmlSerializer(typeof(CompletedCache));
  50. CompletedCache s = (CompletedCache)serializer.Deserialize(fs);
  51. return s;
  52. }
  53. } catch {//(Exception ex) {
  54. return new CompletedCache();
  55. }
  56. } else {
  57. return new CompletedCache();
  58. }
  59. */
  60. return new CompletedCache();
  61. }
  62. public void GetCompletedData()
  63. {
  64. ListDataKeywords=new List<CompletionData>();
  65. ListDataTypes =new List<CompletionData>();
  66. ListDataMembers =new List<CompletionData>();
  67. ListDataProperties =new List<CompletionData>();
  68. ListDataEvents =new List<CompletionData>();
  69. AllCompletionRepeat=new CompletionDataList();
  70. AllCompletionOnlyOne =new CompletionDataList();
  71. NewCompletion =new CompletionDataList();
  72. DotCompletion =new CompletionDataList();
  73. if(!System.IO.File.Exists(FilePath)){
  74. Tool.Logger.Error("CodeCompletion file not exist!",null);
  75. return;
  76. }
  77. SqlLiteDal sqlLiteDal = new SqlLiteDal(FilePath);
  78. SqliteConnection dbcon = (SqliteConnection)sqlLiteDal.GetConnect();//GetConnect();
  79. if (dbcon == null){
  80. return;
  81. }
  82. SqliteCommand dbcmd = dbcon.CreateCommand();
  83. string sql = "SELECT * FROM completed;";
  84. dbcmd.CommandText = sql;
  85. SqliteDataReader reader = null;
  86. try {
  87. reader = dbcmd.ExecuteReader();
  88. int numberCollumns = reader.FieldCount;
  89. if (numberCollumns <5)return;
  90. while (reader.Read()) {
  91. CompletionData cd;
  92. string name = reader.GetValue(1).ToString();
  93. string signature= reader.GetValue(2).ToString();
  94. int type= reader.GetInt32(3);
  95. string parent= reader.GetValue(4).ToString();
  96. string summary = "";
  97. string returnType = "";
  98. if(numberCollumns >=6)
  99. summary= reader.GetValue(5).ToString();
  100. if(numberCollumns >=7)
  101. returnType= reader.GetValue(6).ToString();
  102. cd = new CompletionData(name,null,signature,name,1,parent,returnType);
  103. cd.Signature =signature;
  104. if(!string.IsNullOrEmpty(summary)){
  105. cd.Description = cd.Description + Environment.NewLine+ summary;//+Environment.NewLine;
  106. }
  107. if(type == (int)CompletionDataTyp.keywords){
  108. ListDataKeywords.Add(cd);
  109. } else if(type == (int)CompletionDataTyp.members){
  110. ListDataMembers.Add(cd);
  111. } else if(type == (int)CompletionDataTyp.types){
  112. ListDataTypes.Add(cd);
  113. } else if(type == (int)CompletionDataTyp.properties){
  114. ListDataProperties.Add(cd);
  115. } else if(type == (int)CompletionDataTyp.events){
  116. ListDataEvents.Add(cd);
  117. }
  118. }
  119. } catch (Exception ex) {
  120. Console.WriteLine(ex.Message);
  121. Tool.Logger.Error("ERROR LOADING COMPLETED CACHE");
  122. Tool.Logger.Error(ex.Message);
  123. //MessageDialogs ms = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Error", ex.Message, MessageType.Error);
  124. //ms.ShowDialog();
  125. } finally {
  126. if (reader != null) reader.Close();
  127. reader = null;
  128. dbcmd.Dispose();
  129. dbcmd = null;
  130. dbcon.Close();
  131. dbcon = null;
  132. }
  133. AllCompletionRepeat=GetCompletionData(CompletionTyp.allType,false );
  134. AllCompletionOnlyOne =GetCompletionData(CompletionTyp.allType,true );
  135. NewCompletion =GetCompletionData(CompletionTyp.newType,true );
  136. DotCompletion =GetCompletionData(CompletionTyp.dotType,true );
  137. IncludeCompletion =GetCompletionData(CompletionTyp.includeType,true );
  138. }
  139. /* [XmlArrayAttribute("keywords")]
  140. [XmlArrayItem("keyword")]
  141. public List<string> ListKeywords;
  142. [XmlArrayAttribute("types")]
  143. [XmlArrayItem("type")]
  144. public List<string> ListTypes;
  145. [XmlArrayAttribute("members")]
  146. [XmlArrayItem("member")]
  147. public List<string> ListMembers;
  148. */
  149. [XmlIgnore]
  150. public List<CompletionData> ListDataKeywords;
  151. [XmlIgnore]
  152. public List<CompletionData> ListDataTypes;
  153. [XmlIgnore]
  154. public List<CompletionData> ListDataMembers;
  155. [XmlIgnore]
  156. public List<CompletionData> ListDataProperties;
  157. [XmlIgnore]
  158. public List<CompletionData> ListDataEvents;
  159. [XmlIgnore]
  160. public CompletionDataList AllCompletionOnlyOne;
  161. [XmlIgnore]
  162. public CompletionDataList AllCompletionRepeat;
  163. [XmlIgnore]
  164. public CompletionDataList NewCompletion;
  165. [XmlIgnore]
  166. public CompletionDataList DotCompletion;
  167. [XmlIgnore]
  168. public CompletionDataList IncludeCompletion;
  169. private CompletionDataList GetCompletionData(CompletionTyp completiontype, bool onlyOne ){
  170. CompletionDataList listComplete = new CompletionDataList();
  171. if(completiontype == CompletionTyp.includeType){
  172. listComplete.Add(new CompletionData("lib",null,"lib","lib://"));
  173. listComplete.Add(new CompletionData("app",null,"app","app://"));
  174. return listComplete;
  175. }
  176. if(MainClass.CompletedCache.ListDataKeywords != null){
  177. foreach (CompletionData cd in MainClass.CompletedCache.ListDataKeywords) {
  178. if ( cd != null ){
  179. CompletionData cdParent =listComplete.Find(cd.DisplayText);
  180. if ((cdParent== null) || (!onlyOne)) {
  181. if (completiontype != CompletionTyp.newType){
  182. cdParent =cd.Clone();
  183. cdParent.OverloadedData.Add(cd.Clone());
  184. listComplete.Add(cdParent);
  185. }
  186. } else {
  187. if(!cdParent.Description.Contains(cd.Description)){
  188. cdParent.IsOverloaded = true;
  189. cdParent.OverloadedData.Add(cd.Clone());
  190. cdParent.Description =cdParent.Description+Environment.NewLine+Environment.NewLine+ cd.Description;
  191. }
  192. }
  193. }
  194. }
  195. }
  196. //Types (from doc T:)
  197. //i = 0;
  198. if(MainClass.CompletedCache.ListDataTypes != null){
  199. foreach (CompletionData cd in MainClass.CompletedCache.ListDataTypes) {
  200. if ( cd != null ){
  201. CompletionData cdParent =listComplete.Find(cd.DisplayText);
  202. if ((cdParent== null) || (!onlyOne)){
  203. if (completiontype != CompletionTyp.dotType){
  204. cdParent =cd.Clone();
  205. cdParent.OverloadedData.Add(cd.Clone());
  206. listComplete.Add(cdParent);
  207. }
  208. } else {
  209. if(!cdParent.Description.Contains(cd.Description)){
  210. cdParent.IsOverloaded = true;
  211. cdParent.OverloadedData.Add(cd.Clone());
  212. cdParent.Description =cdParent.Description+Environment.NewLine+Environment.NewLine+ cd.Description;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. // M P E
  219. //Member (from doc M: )
  220. //i = 0;
  221. if(MainClass.CompletedCache.ListDataMembers != null){
  222. foreach (CompletionData cd in MainClass.CompletedCache.ListDataMembers) {
  223. if ( cd != null ){
  224. //if (cd.DisplayText==baseWord)
  225. // i++;
  226. CompletionData cdParent =listComplete.Find(cd.DisplayText);
  227. if ((cdParent== null) || (!onlyOne)){
  228. if (completiontype != CompletionTyp.newType){
  229. cdParent =cd.Clone();
  230. cdParent.OverloadedData.Add(cd.Clone());
  231. listComplete.Add(cdParent);
  232. }
  233. } else {
  234. if(!cdParent.Description.Contains(cd.Description)){
  235. cdParent.IsOverloaded = true;
  236. cdParent.OverloadedData.Add(cd.Clone());
  237. cdParent.Description =cdParent.Description+Environment.NewLine+Environment.NewLine+ cd.Description;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. //Member (from doc P:)
  244. //i = 0;
  245. if(MainClass.CompletedCache.ListDataProperties != null){
  246. foreach (CompletionData cd in MainClass.CompletedCache.ListDataProperties) {
  247. if ( cd != null ){
  248. //if (cd.DisplayText==baseWord)
  249. // i++;
  250. //if(!onlyOne)
  251. // if(cd.DisplayText=="width")
  252. // Console.WriteLine("1");
  253. CompletionData cdParent =listComplete.Find(cd.DisplayText);
  254. if ((cdParent== null) || (!onlyOne)){
  255. if (completiontype != CompletionTyp.newType){
  256. cdParent =cd.Clone();
  257. cdParent.OverloadedData.Add(cd.Clone());
  258. listComplete.Add(cdParent);
  259. }
  260. }else {
  261. if(!cdParent.Description.Contains(cd.Description)){
  262. cdParent.IsOverloaded = true;
  263. cdParent.OverloadedData.Add(cd.Clone());
  264. cdParent.Description =cdParent.Description+Environment.NewLine+Environment.NewLine+cd.Description;
  265. }
  266. }
  267. }
  268. }
  269. }
  270. //Member (from doc E:)
  271. //i = 0;
  272. if(MainClass.CompletedCache.ListDataEvents != null){
  273. foreach (CompletionData cd in MainClass.CompletedCache.ListDataEvents) {
  274. if ( cd != null ){
  275. //if (cd.DisplayText==baseWord)
  276. // i++;
  277. CompletionData cdParent =listComplete.Find(cd.DisplayText);
  278. if ((cdParent== null) || (!onlyOne)){
  279. if (completiontype != CompletionTyp.newType){
  280. cdParent =cd.Clone();
  281. cdParent.OverloadedData.Add(cd.Clone());
  282. listComplete.Add(cdParent);
  283. }
  284. }else {
  285. if(!cdParent.Description.Contains(cd.Description)){
  286. cdParent.IsOverloaded = true;
  287. cdParent.OverloadedData.Add(cd.Clone());
  288. cdParent.Description =cdParent.Description+Environment.NewLine+ Environment.NewLine +cd.Description;
  289. }
  290. }
  291. }
  292. }
  293. }
  294. return listComplete;
  295. }
  296. }
  297. }