/// <summary> /// Update the general data: dateCreated, source. /// </summary> private static void updateDatosGen(ISACFDataContext db) { XDocument xDocumentIndex; ccfDatosGen dbDatosGen = new ccfDatosGen(); FileInfo indexFile = new FileInfo(Path.Combine(clsSettings.serviceSettings.dataDirectory.FullName, string.Format("{0}{1}{2}", xmlDestinationFolderName, Path.DirectorySeparatorChar, indexFileName))); // Load the XML document containing the CategoryIndex. xDocumentIndex = XDocument.Load(indexFile.FullName); ccfDatosGen xmlDatosGen = new ccfDatosGen(); xmlDatosGen = (from e in xDocumentIndex.Descendants("CategoryIndex") where ((string)e.Attribute("CategoryIndex")) != string.Empty select new ccfDatosGen { dateCreated = (DateTime)e.Attribute("DateCreated"), source = (string)e.Attribute("source"), }).Single(); dbDatosGen.dateCreated = xmlDatosGen.dateCreated; dbDatosGen.source = xmlDatosGen.source; if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Closed) { db.Connection.Open(); } db.ccfDatosGens.InsertOnSubmit(dbDatosGen); db.SubmitChanges(); if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Open) { db.Connection.Close(); db = null; } // Do some Cleanup. if (dbDatosGen != null) { dbDatosGen = null; } if (xDocumentIndex != null) { xDocumentIndex = null; } if (indexFile != null) { indexFile = null; } GC.Collect(); }
private static void updateCategories(ISACFDataContext db) { FileInfo indexFile = new FileInfo(Path.Combine(clsSettings.serviceSettings.dataDirectory.FullName, string.Format("{0}{1}{2}", xmlDestinationFolderName, Path.DirectorySeparatorChar, indexFileName))); XDocument xDocumentIndex; xDocumentIndex = XDocument.Load(indexFile.FullName); // Read only the Attribute name of each Category Element. var Categories = (from e in xDocumentIndex.Elements("CategoryIndex").Elements("Category") where ((string)e.Element("name")) != string.Empty select e).ToArray(); if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Closed) { db.Connection.Open(); } var CategoriesToBlock = (from e in db.ccfCategoryToBlocks select e.name).ToArray(); ccfCategory newCat = null; ccfCategoryName_es newCatNameEs = null; foreach (XElement Category in Categories) { newCat = new ccfCategory(); newCat.name = Category.Attribute("name").Value; newCat.default_type = Category.Element("default-type").Value; newCat.name_en = Category.Element("name-en").Value; newCat.desc_en = Category.Element("desc-en").Value; newCat.processForISARule = CategoriesToBlock.Contains(newCat.name); if (!string.IsNullOrEmpty(Category.Element("name-es").Value)) { newCatNameEs = new ccfCategoryName_es(); newCatNameEs.id_Category = newCat.ID; newCatNameEs.name_es = Category.Element("name-es").Value; newCatNameEs.desc_es = string.IsNullOrEmpty(Category.Element("desc-es").Value) ? DBNull.Value.ToString() : Category.Element("desc-es").Value; newCat.ccfCategoryName_es = newCatNameEs; } db.ccfCategories.InsertOnSubmit(newCat); // Do cleanup. if (newCatNameEs != null) { newCatNameEs = null; } if (newCat != null) { newCat = null; } } db.SubmitChanges(); if (db.Transaction == null & db.Connection.State == System.Data.ConnectionState.Open) { db.Connection.Close(); db = null; } // Do some Cleanup. if (indexFile != null) { indexFile = null; } if (xDocumentIndex != null) { xDocumentIndex = null; } if (Categories != null) { Categories = null; } if (CategoriesToBlock != null) { CategoriesToBlock = null; } GC.Collect(); }