public CachedTypes(CachedTypesReadyHandler typesReadyHandler = null) { StartCacheTask(typesReadyHandler); }
protected void StartCacheTask(CachedTypesReadyHandler typesReadyHandler) { new Task(() => { lock (_cacheLock) { _cacheReady = false; } try { PluginManager.ReceiveOutput("Caching of project types for CSV editor has begun. " + "Some functionality will not be available until this is complete"); // Save all the entity screens and _entities = ObjectFinder.Self.GlueProject.Entities; _screens = ObjectFinder.Self.GlueProject.Screens; // Go through all the code in the project and generate a list of enums and classes var items = ProjectManager.ProjectBase.Where(x => x.Name == "Compile"); string baseDirectory = ProjectManager.ProjectBase.Directory; _parsedPrjectClasses = new List<ParsedClass>(); _parsedProjectEnums = new List<ParsedEnum>(); foreach (var item in items) { var file = new ParsedFile(baseDirectory + item.Include); foreach (var ns in file.Namespaces) { _parsedProjectEnums.AddRange(ns.Enums); _parsedPrjectClasses.AddRange(ns.Classes); } } // Get a list of all enums via reflection _assemblyEnums = AppDomain.CurrentDomain .GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => x.IsEnum) .ToList(); _assemblyClasses = AppDomain.CurrentDomain .GetAssemblies() .SelectMany(x => x.GetTypes()) .Where(x => !x.IsEnum) .ToList(); } catch (Exception ex) { PluginManager.ReceiveOutput( string.Concat( "Exception occurred while caching project types: ", ex.GetType(), ":", ex.Message)); return; } lock (_cacheLock) { _cacheReady = true; } PluginManager.ReceiveOutput("Caching of project types completed"); // Run the CachedTypesHandler delegate if (typesReadyHandler != null) typesReadyHandler(); }).Start(); }