public ProjectUpdatedEventArgs(ProjectState state, ModificationFile current) { State = state; Current = current; }
/// <summary> /// Allocates the files on disk for import. /// </summary> /// <param name="progress">The asynchronous progress reporter.</param> /// <returns>Returns true on successful completion.</returns> /// TODO: Allocation needs to invalidate previous allocations! /// TODO: Only allocate tables defined in the modifications runtime plugins. public bool Allocate(IProgress <ProgressEventArgs> progress = null) { Modification = null; try { var files = GetXmlFiles(SearchOption.TopDirectoryOnly); foreach (var file in files) { var xml = XDocument.Load(file.FullName); int count = xml.Root.Descendants("RuntimeModule").Count(); if (count == 1) { Modification = new ModificationFile(this, file.FullName); Report.Progress(progress, Report.Message("A modification index was allocated at " + Modification.FilePath, MessageIcon.CompleteB)); break; } } } catch (Exception exception) { Report.Progress(progress, Report.Message(MessageFormat.GetWarning(exception), MessageIcon.Error)); } try { if (Modification != null) { Modification.Read(progress); // deserialize if (Modification.Xml.FirstOrDefault().Value is RuntimeModule runtimeModule) { List <TableFile> allocated = new List <TableFile>(); foreach (var plugin in runtimeModule.Plugins) { if (plugin is AIPlugin aiPlugin) { Trace.WriteLine(string.Format("{0} has AI contributions. Plugin[Priority:{1}, Configuration:{2}, AssemblyPath:{3}]", runtimeModule.Name, aiPlugin.Priority, aiPlugin.Configuration, aiPlugin.AssemblyPath)); } else if (plugin is RegistryPlugin registryPlugin) { Trace.WriteLine(string.Format("{0} has registry contributions. Plugin[Priority:{1}, FilePath:{2}]", runtimeModule.Name, registryPlugin.Priority, registryPlugin.FilePath)); } else if (plugin is LocalizationPlugin localizationPlugin) { Trace.WriteLine(string.Format("{0} has localization contributions. Plugin[Priority:{1}, DefaultLanguage:{2}, Directory:{3}]", runtimeModule.Name, localizationPlugin.Priority, localizationPlugin.DefaultLanguage, localizationPlugin.Directory)); } else if (plugin is DatabasePlugin databasePlugin) { Trace.WriteLine(string.Format("{0} has database contributions. Plugin[Priority:{1}, FilePath:{2}, DataType:{3}, ExtraTypes:{4}]", runtimeModule.Name, databasePlugin.Priority, databasePlugin.FilePath, databasePlugin.DataType, databasePlugin.ExtraTypes)); foreach (var pattern in databasePlugin.FilePath) { string filePattern = pattern.Replace(Environment.NewLine, String.Empty).Replace("/", "\\").Trim(); //string relDirectory = Path.GetDirectoryName(filePattern); string relFile = Path.GetFileName(filePattern); string fullPath = Path.Combine(FolderPath, filePattern); string fullDirectoryPath = Path.GetDirectoryName(fullPath); if (Directory.Exists(fullDirectoryPath)) { var files = Directory.GetFiles(fullDirectoryPath, relFile); foreach (var file in files) { TableFile asset = new TableFile(this, fullPath); allocated.Add(asset); Report.Progress(progress, Report.Message("Index, allocated file: " + asset.FilePath, MessageIcon.InformationB)); } } else { Report.Progress(progress, Report.Message("Index, directory does not exist: " + fullDirectoryPath, MessageIcon.Warning)); } } } else { throw new InvalidOperationException("Unexpected runtime plugin."); } } allocated.Where(asset => Tables.Contains(asset) == false).ToList() .ForEach(asset => Tables.Add(asset)); } return(true); // COMPELTED } else { Report.Progress(progress, Report.Message("A modification index containing a RuntimeModule could not be found.", MessageIcon.Error)); return(false); } } catch (Exception exception) { Report.Progress(progress, Report.Message(MessageFormat.GetWarning(exception), MessageIcon.Error)); } throw new NotImplementedException("The 'Allocate' method is not implemented yet."); }