// Modules.cs created with MonoDevelop // User: chadk at 1:08 PMĀ 12/23/2007 // // To change standard headers go to Edit->Preferences->Coding->Standard Headers // using System; using System.Collections.Generic; using System.IO; namespace Lunar { public class Modules { private Moonbase mSourceMoonbase; private SortedList mModuleList; public int Count { get { return this.mModuleList.Count; } } public Modules(Moonbase parentMoonbase) { this.mSourceMoonbase = parentMoonbase; this.UpdateModuleList(); } // TODO: this currently ignores zlocal private void UpdateModuleList() { this.mModuleList = new SortedList(); foreach (Section section in this.mSourceMoonbase.Sections) { if (!section.IsZLocal) { foreach (FileInfo file in section.DirectoryInfo.GetFiles("DETAILS", SearchOption.AllDirectories)) { try { this.mModuleList.Add(file.Directory.Name, section.Name); } catch (System.ArgumentException ex) { if (ex.Message.Equals("element already exists")) throw new Lunar.Modules.DuplicateModuleException(file.Directory.Name, this.mModuleList[file.Directory.Name], section.Name); else throw; } } } } } public class DuplicateModuleException : ApplicationException { private string mModuleName; private string mSection1; private string mSection2; public DuplicateModuleException(string moduleName, string section1, string section2) { this.mModuleName = moduleName; this.mSection1 = section1; this.mSection2 = section2; } public override string Message { get { string errorMessage = "ERROR: Duplicate Module name detected!" + Environment.NewLine + "Name: " + this.mModuleName + Environment.NewLine; if (this.mSection1.Equals(this.mSection2)) errorMessage += "Section: " + this.mSection1; else errorMessage += "Sections: " + this.mSection1 + " and " + this.mSection2; return errorMessage; } } } } }