private void Load(string Filename, XmlDocument Document, XmlNamespaceManager NSMgr) { IsFileImportLoadingRunning = true; //Store the filename we're using this.Filename = Filename; //Create an XML document object from the file specified Document.Load(Filename); //Find the Header node XmlNode headerNode = Document.SelectSingleNode("/ia:Message/ia:Header", NSMgr); if (headerNode == null) { headerNode = Document.CreateElement("Header", NSMgr.LookupNamespace("ia")); if (Document.DocumentElement.HasChildNodes) { Document.DocumentElement.InsertBefore(headerNode, Document.DocumentElement.FirstChild); } else { Document.DocumentElement.AppendChild(headerNode); } } this.Header = new ILR.Header(headerNode, NSMgr); //Find the LearningProvider node XmlNode learningProviderNode = Document.SelectSingleNode("/ia:Message/ia:LearningProvider", NSMgr); //Find the Learner nodes XmlNodeList learnerNodes = Document.SelectNodes("/ia:Message/ia:Learner", NSMgr); //If we have no LearningProvider node create one in the correct place if (learningProviderNode == null) { learningProviderNode = Document.CreateElement("LearningProvider", NSMgr.LookupNamespace("ia")); if (learnerNodes.Count == 0) { Document.DocumentElement.AppendChild(learningProviderNode); } else { Document.DocumentElement.InsertBefore(learningProviderNode, learnerNodes.Item(0)); } } //Create a LearningProvider instance this.LearningProvider = new ILR.LearningProvider(learningProviderNode, NSMgr); //Create Learner instances for all of the learners in the XML foreach (XmlNode node in learnerNodes) { Learner newInstance = new Learner(node, NSMgr); newInstance.IsFileImportLoadingRunning = true; newInstance.Message = this; newInstance.ResequenceAimSeqNumber(); foreach (LearningDelivery ld in newInstance.LearningDeliveryList) { ld.IsImportRunning = false; } newInstance.IsFileImportLoadingRunning = false; LearnerList.Add(newInstance); //Console.WriteLine(String.Format("Loaded {0} Learner.", LearnerList.Count)); } //Find the LearnerDestinationandProgression nodes XmlNodeList learnerDestinationandProgressionNodes = Document.SelectNodes("/ia:Message/ia:LearnerDestinationandProgression", NSMgr); //Create LearnerDestinationandProgression instances for all of the LearnerDestinationandProgressions in the XML foreach (XmlNode node in learnerDestinationandProgressionNodes) { LearnerDestinationandProgression newLDP = new LearnerDestinationandProgression(node, NSMgr); newLDP.Message = this; LearnerDestinationandProgressionList.Add(newLDP); } foreach (Learner l in LearnerList) { foreach (LearningDelivery ld in l.LearningDeliveryList) { ld.IsImportRunning = false; } l.IsFileImportLoadingRunning = false; } IsFileImportLoadingRunning = false; }
public void Import(string FilenameToLoad) { String InterlStoreFilename = this.Filename; //Instantiate a new document to hold the ILR data this.ILRFile = new XmlDocument(); //Get a namespace manager from the XML document NSMgr = new XmlNamespaceManager(ILRFile.NameTable); NSMgr.AddNamespace("ia", CurrentNameSpace); this.ILRFile.AppendChild(this.ILRFile.CreateElement("Message", NSMgr.LookupNamespace("ia"))); // Clear Old Learner and Old LearnerDestinationandProgression Records this.LearnerList.Clear(); this.LearnerDestinationandProgressionList.Clear(); Message importMessage = new Message(); System.IO.FileInfo fi = new System.IO.FileInfo(FilenameToLoad); if (fi.Name.Contains("-" + CurrentYear.ToString() + "-")) { this.Load(FilenameToLoad); //importMessage.Load(Filename); } else if (fi.Name.Contains("-" + (CurrentYear - 101).ToString() + "-")) { importMessage.LoadPreviousYearILR(FilenameToLoad); XmlNode headerNode = this.ILRFile.SelectSingleNode("/ia:Message/ia:Header", NSMgr); if (headerNode == null) { headerNode = this.ILRFile.CreateElement("Header", NSMgr.LookupNamespace("ia")); } if (this.ILRFile.DocumentElement.HasChildNodes) { this.ILRFile.DocumentElement.InsertBefore(headerNode, this.ILRFile.DocumentElement.FirstChild); } else { this.ILRFile.DocumentElement.AppendChild(headerNode); } this.Header = new ILR.Header(headerNode, NSMgr); //Find the LearningProvider node XmlNode learningProviderNode = this.ILRFile.SelectSingleNode("/ia:Message/ia:LearningProvider", NSMgr); //Find the Learner nodes XmlNodeList learnerNodes = this.ILRFile.SelectNodes("/ia:Message/ia:Learner", NSMgr); //If we have no LearningProvider node create one in the correct place if (learningProviderNode == null) { learningProviderNode = this.ILRFile.CreateElement("LearningProvider", NSMgr.LookupNamespace("ia")); if (learnerNodes.Count == 0) { this.ILRFile.DocumentElement.AppendChild(learningProviderNode); } else { this.ILRFile.DocumentElement.InsertBefore(learningProviderNode, learnerNodes.Item(0)); } } this.LearningProvider = new ILR.LearningProvider(learningProviderNode, NSMgr); this.LearningProvider.UKPRN = importMessage.LearningProvider.UKPRN; foreach (Learner learner in importMessage.LearnerList.Where(l => l.HasContinuingAims)) { try { XmlNode newNode = ILRFile.CreateElement("Learner", NSMgr.LookupNamespace("ia")); Learner newInstance = new Learner(learner, newNode, NSMgr); newInstance.Message = this; LearnerList.Add(newInstance); AppendToLastOfNodeNamed(newNode, newNode.Name); newInstance.ResequenceAimSeqNumber(); } catch (Exception) { Console.WriteLine(String.Format("Learern Ref:{0}", learner.LearnRefNumber)); } } foreach (LearnerDestinationandProgression learnerDestinationandProgression in importMessage.LearnerDestinationandProgressionList.Where(ldp => ldp.HasCurrentDPOutcomes)) { XmlNode newNode = ILRFile.CreateElement("LearnerDestinationandProgression", NSMgr.LookupNamespace("ia")); LearnerDestinationandProgression newInstance = new LearnerDestinationandProgression(learnerDestinationandProgression, newNode, NSMgr); newInstance.Message = this; LearnerDestinationandProgressionList.Add(newInstance); AppendToLastOfNodeNamed(newNode, newNode.Name); } } else { throw (new Exception("Unable to identify Year from filename. Confirm the file name matchesd the ILR Specification.")); } this.Filename = InterlStoreFilename; Save(); GC.Collect(); }
public void Import(string FilenameToLoad) { String InterlStoreFilename = this.Filename; //Instantiate a new document to hold the ILR data this.ILRFile = new XmlDocument(); //Get a namespace manager from the XML document NSMgr = new XmlNamespaceManager(ILRFile.NameTable); NSMgr.AddNamespace("ia", "http://www.theia.org.uk/ILR/2014-15/1"); this.ILRFile.AppendChild(this.ILRFile.CreateElement("Message", NSMgr.LookupNamespace("ia"))); // Clear Old Learner and Old LearnerDestinationandProgression Records this.LearnerList.Clear(); this.LearnerDestinationandProgressionList.Clear(); Message importMessage = new Message(); System.IO.FileInfo fi = new System.IO.FileInfo(FilenameToLoad); if (fi.Name.Contains("-1415-")) { this.Load(FilenameToLoad); //importMessage.Load(Filename); } else if (fi.Name.Contains("-1314-")) { importMessage.Load1314(FilenameToLoad); XmlNode headerNode = this.ILRFile.SelectSingleNode("/ia:Message/ia:Header", NSMgr); if (headerNode == null) { headerNode = this.ILRFile.CreateElement("Header", NSMgr.LookupNamespace("ia")); } if (this.ILRFile.DocumentElement.HasChildNodes) { this.ILRFile.DocumentElement.InsertBefore(headerNode, this.ILRFile.DocumentElement.FirstChild); } else { this.ILRFile.DocumentElement.AppendChild(headerNode); } this.Header = new ILR.Header(headerNode, NSMgr); //Find the LearningProvider node XmlNode learningProviderNode = this.ILRFile.SelectSingleNode("/ia:Message/ia:LearningProvider", NSMgr); //Find the Learner nodes XmlNodeList learnerNodes = this.ILRFile.SelectNodes("/ia:Message/ia:Learner", NSMgr); //If we have no LearningProvider node create one in the correct place if (learningProviderNode == null) { learningProviderNode = this.ILRFile.CreateElement("LearningProvider", NSMgr.LookupNamespace("ia")); if (learnerNodes.Count == 0) { this.ILRFile.DocumentElement.AppendChild(learningProviderNode); } else { this.ILRFile.DocumentElement.InsertBefore(learningProviderNode, learnerNodes.Item(0)); } } this.LearningProvider = new ILR.LearningProvider(learningProviderNode, NSMgr); this.LearningProvider.UKPRN = importMessage.LearningProvider.UKPRN; foreach (Learner learner in importMessage.LearnerList) { if (learner.HasContinuingAims) { XmlNode newNode = ILRFile.CreateElement("Learner", NSMgr.LookupNamespace("ia")); Learner newInstance = new Learner(learner, newNode, NSMgr); newInstance.Message = this; LearnerList.Add(newInstance); AppendToLastOfNodeNamed(newNode, newNode.Name); newInstance.ResequenceAimSeqNumber(); } } } else { throw (new Exception("Unable to identify Year from filename. Confirm the file name matchesd the ILR Specification.")); } this.Filename = InterlStoreFilename; Save(); }