using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; namespace InABox.Core { public delegate void ImportNotificationEvent(object sender, string message); public delegate void ImportLogEvent(object sender, string message); public delegate bool ImportPreProcessEvent(object sender, Dictionary values); public delegate bool ImportPostProcessEvent(object sender, object entity, Dictionary values); public delegate void ImportSaveEvent(object sender, object entity); public delegate CoreTable ImportLoadEvent(object sender, Type type, String[] fields, String ID); public interface IImporter { string[] Properties { get; } /// /// Represents the fields in the header of the imported file, and therefore what fields can map from. /// These should be populated by . /// string[] Fields { get; } bool HasHeader { get; set; } int HeaderRow { get; set; } /// /// While represents the fields that this importer recognises, represents how the properties of /// the imported object are populated, so while there may be a one to one mapping from , this does not have to be the case. /// /// /// These mappings must be initialised to get any data from . /// List Mappings { get; } IEnumerable Log { get; } event ImportNotificationEvent OnNotify; event ImportLogEvent OnError; event ImportLogEvent OnLog; event ImportPreProcessEvent BeforeProcess; event ImportPostProcessEvent AfterProcess; event ImportSaveEvent OnSave; event ImportLoadEvent OnLoad; bool Open(Stream stream); void Close(); /// /// Import the data from the stream specified when was called, using to for each line. /// /// /// This method must be called after and . /// /// One should also have set and . /// /// The number of items imported. int Import(); /// /// Move to the next line in the import. /// /// /// While not all importers will need to do anything with this method, it must be called before . /// /// if there is still data to be read. bool MoveNext(); /// /// Read the header of the file, populating . /// /// /// This is called regardless of whether is . /// /// if the header was read successfully. bool ReadHeader(); /// /// Read the values of a line. /// /// /// The keys of the results are those present in . /// /// /// A dictionary of values, where the keys are given by . /// Dictionary ReadLine(); } }