private static string compareConnectionStrings(ref XmlDocument doc, DTO.RolloutInfo rollout) { var connNode = doc.SelectSingleNode("//ConnectionInfo"); string connString = ""; if (connNode != null && !string.IsNullOrEmpty(rollout.Connection.ConnectionString) && rollout.Connection.DateSet != null) { try { string currentString = connNode.Attributes.GetNamedItem("ConnectionString").Value; DateTime currentStringDate = DateTime.Parse(connNode.Attributes.GetNamedItem("ConnectionDateSet").Value); if (DateTime.Compare(currentStringDate, rollout.Connection.DateSet.Value) < 0 || String.IsNullOrEmpty(currentString)) { connString = connNode.Attributes.GetNamedItem("ConnectionString").Value = rollout.Connection.ConnectionString; connNode.Attributes.GetNamedItem("ConnectionDateSet").Value = rollout.Connection.DateSet.ToString(); } else { connString = currentString; } } catch (Exception) { connString = connNode.Attributes.GetNamedItem("ConnectionString").Value = rollout.Connection.ConnectionString; connNode.Attributes.GetNamedItem("ConnectionDateSet").Value = rollout.Connection.DateSet.ToString(); } } else { connString = ""; } return(connString); }
private void reconstructBackEndFromRolloutsFolder(object sender, DoWorkEventArgs e) { //1. Create back end xml file to be updated. CreateXmlFile.CreateBackEndXmlFileInRolloutDirectory(); var directory = new DirectoryInfo(this.RollOutDirectory + "Rollouts\\"); var fileCount = directory.EnumerateFiles("FE-*.zip").Count(); int progressPercentage = Convert.ToInt32(((double)1 / (fileCount + 1)) * 100); (sender as BackgroundWorker).ReportProgress(progressPercentage, e.Argument); int progress = 1; //2. Loop through the zipped files in the rollouts folder foreach (var file in directory.EnumerateFiles("FE-*.zip")) { //For each file, read the file into a ZipArchive object ZipArchive zipfile = ZipFile.OpenRead(file.FullName); //Find the only .xml file in the zip file and extract it to the reconstruction path. zipfile.Entries.FirstOrDefault(p => p.Name.Contains(".xml")).ExtractToFile(this.ReconstructionPath, true); //Release the object reference in memory to the zip file. zipfile.Dispose(); //Create a rolloutInfo file (which is plain object with only properties and not methods) out of //the newly extracted xml file. DTO.RolloutInfo rollout = GetDataFromXml.GetReconstructedInfo(this.ReconstructionPath); //Add a rollout record with the info in the rollout record. UpdateXmlFile.AddRolloutRecord(rollout); progressPercentage = Convert.ToInt32(((double)++progress / fileCount) * 100); (sender as BackgroundWorker).ReportProgress(progressPercentage, "Reconstructed " + file.Name); } }
private static void addLatestRolloutToCache(ObjectCache cache, DTO.Enums.UserTypeEnum userType, DTO.Enums.BackEndOrFrontEndEnum whichEnd) { CacheItemPolicy policy = new CacheItemPolicy() { SlidingExpiration = TimeSpan.FromSeconds(10) }; var rollout = new DTO.RolloutInfo(); rollout.UserType = userType; var doc = GetXmlDoc.GetBackEndXmlDoc(DTO.Enums.BackEndOrFrontEndEnum.FrontEnd); string currentVersion = doc.SelectSingleNode("//CurrentVersions").Attributes.GetNamedItem(rollout.UserTypeName).Value; rollout.Connection.ConnectionString = GetData.GetCurrentConnectionString(whichEnd); rollout.Connection.DateSet = DateTime.Parse(doc.SelectSingleNode("//ConnectionInfo").Attributes.GetNamedItem("ConnectionDateSet").Value); rollout.DateTimeStamp = rollout.Connection.DateSet.Value; XmlNode rolloutNode = doc.SelectSingleNode("//Version[@value='" + currentVersion + "']/" + Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType)); try { string launchFile = rolloutNode.Attributes.GetNamedItem("LaunchFile").Value; rollout.LaunchFile = launchFile; string zipPath = rolloutNode.Attributes.GetNamedItem("FullZipPath").Value; rollout.ZipPath = zipPath; } catch (NullReferenceException) { throw new DTO.Exceptions.CouldNotFindValueException(); } rollout.RolloutVersionString = currentVersion; cache.Set("LatestRollout", rollout, policy); }
public static bool CompareUserInfo(DTO.User user) { try { DTO.RolloutInfo currentRollout = GetDataFromXml.GetFrontEndSettings(); if (user.UserType != currentRollout.UserType) { return(true); } if (currentRollout.RolloutVersionNumber != GetDataFromXml.GetCurrentRolloutVersionNumber(DTO.Enums.BackEndOrFrontEndEnum.FrontEnd, user.UserType)) { return(true); } } catch (DTO.Exceptions.CouldNotFindValueException) { throw; } //This exception is raised when the front end has yet to be set up (i.e. first launch after install). catch (DTO.Exceptions.FrontEndNeedsUpdateException) { return(true); } return(false); }
//This is an important method for the FrontEnd. A DTO.RolloutInfo object is passed in and then this will //update the frontend.xml file for the user with that info. public static void UpdateFrontEndXml(DTO.RolloutInfo rollout) { var doc = GetXmlDoc.GetFrontEndXmlDoc(); doc.SelectSingleNode("//LaunchFile").InnerText = rollout.LaunchFile; doc.SelectSingleNode("//CurrentUserType").InnerText = rollout.UserTypeName; doc.SelectSingleNode("//CurrentVersion").InnerText = rollout.RolloutVersionString; doc.SelectSingleNode("//CurrentZipPath").InnerText = rollout.ZipPath; SaveXmlDoc.saveFrontEndDoc(doc); }
//This will set the necessary rollout node attributes with the neccesary info from the RolloutInfo object //Passed into it. private static XmlNode setRolloutAttributes(XmlDocument doc, XmlNode node, DTO.RolloutInfo rollout) { XmlAttribute datestamp = doc.CreateAttribute("DateTimeStamp"); datestamp.Value = rollout.DateTimeStamp.ToString(); XmlAttribute zipPath = doc.CreateAttribute("FullZipPath"); zipPath.Value = rollout.ZipPath; XmlAttribute launch = doc.CreateAttribute("LaunchFile"); launch.Value = rollout.LaunchFile; node.Attributes.Append(launch); node.Attributes.Append(datestamp); node.Attributes.Append(zipPath); return(node); }
//This is a main function in the Back End tool. It takes a RolloutInfo object and with that info, //it creates a new rollout record. public static void AddRolloutRecord(DTO.RolloutInfo rollout) { var doc = GetXmlDoc.GetBackEndXmlDoc(DTO.Enums.BackEndOrFrontEndEnum.BackEnd); //Compare current connection string and date and resolve for latest string string latestConnectionString = compareConnectionStrings(ref doc, rollout); XmlNode versionNode = doc.SelectSingleNode("//Version[@value='" + rollout.RolloutVersionString + "']"); //Check to see if a node for the current version exists if (versionNode != null) { //If a node for the current version exists, then check if a rollout node exists for the specified userType XmlNode rolloutNode = versionNode.SelectSingleNode("./" + rollout.UserTypeName); if (rolloutNode != null) { //If a rollout node exists for the userType, then modify the values with the most up-to-date info. rolloutNode = setRolloutAttributes(doc, rolloutNode, rollout); } else { //If a rollout node does NOT exist for the userType, then create one. versionNode.AppendChild(createRolloutNode(doc, rollout)); } } //If a version node for the current version number does NOT exist, then create one with attributes set else { XmlNode rolloutsNode = doc.SelectSingleNode("//BackEnd/RollOuts"); XmlElement newVersionNode = doc.CreateElement("Version"); newVersionNode.SetAttribute("value", rollout.RolloutVersionString); newVersionNode.AppendChild(createRolloutNode(doc, rollout)); rolloutsNode.AppendChild(newVersionNode); } //Compare current version number with highest listed version number. If current is less than highest, update current. ensureHighestVersionNumber(doc, rollout.UserTypeName); ensureLatestRolloutDate(doc, rollout.DateTimeStamp); //Create backup rollout document within zip folder XmlNode newRolloutNode = doc.SelectSingleNode("//Version[@value='" + rollout.RolloutVersionString + "']").SelectSingleNode("./" + rollout.UserTypeName); CreateXmlDoc.createBackupRolloutDocument(newRolloutNode, rollout.RolloutVersionNumber, latestConnectionString); SaveXmlDoc.saveBackEndDoc(doc); }
internal static DTO.RolloutInfo PullLatestRolloutFromCache(DTO.Enums.UserTypeEnum userType, DTO.Enums.BackEndOrFrontEndEnum whichEnd) { ObjectCache cache = MemoryCache.Default; TryAgain: DTO.RolloutInfo rollout = cache["LatestRollout"] as DTO.RolloutInfo; try { if (rollout == null) { addLatestRolloutToCache(cache, userType, whichEnd); goto TryAgain; } } catch (Exception) { throw; } return(rollout); }
private void reconstructBackEndFromRolloutsFolder() { //1. Create back end xml file to be updated. CreateXmlFile.CreateBackEndXmlFileInRolloutDirectory(); var directory = new DirectoryInfo(this.RollOutDirectory + "Rollouts\\"); //2. Loop through the zipped files in the rollouts folder foreach (var file in directory.EnumerateFiles("FE-*.zip")) { //For each file, read the file into a ZipArchive object ZipArchive zipfile = ZipFile.OpenRead(file.FullName); //Find the only .xml file in the zip file and extract it to the reconstruction path. zipfile.Entries.FirstOrDefault(p => p.Name.Contains(".xml")).ExtractToFile(this.ReconstructionPath, true); //Release the object reference in memory to the zip file. zipfile.Dispose(); //Create a rolloutInfo file (which is plain object with only properties and not methods) out of //the newly extracted xml file. DTO.RolloutInfo rollout = GetDataFromXml.GetReconstructedInfo(this.ReconstructionPath); //Add a rollout record with the info in the rollout record. UpdateXmlFile.AddRolloutRecord(rollout); } }
//This creates and returns a rollout node after setting rollout attributes. private static XmlNode createRolloutNode(XmlDocument doc, DTO.RolloutInfo rollout) { XmlElement newNode = doc.CreateElement(rollout.UserTypeName); return(setRolloutAttributes(doc, newNode, rollout)); }
private static void updateFrontEndXML(DTO.Enums.UserTypeEnum userType) { DTO.RolloutInfo rollout = GetDataFromXml.GetLatestRollout(userType, DTO.Enums.BackEndOrFrontEndEnum.FrontEnd); UpdateXmlFile.UpdateFrontEndXml(rollout); }
internal static void AddRolloutRecord(DTO.RolloutInfo rollout) { XML.UpdateData.AddRolloutRecord(rollout); }