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); }
//This is an overloaded method. This function will return the current rollout version number of the passed in XmlDocument, //NOT the current backend.xml file. This is used in the process of adding a new rollout. internal static int GetCurrentRolloutVersionNumber(XmlDocument doc, DTO.Enums.UserTypeEnum userType) { string userTypeName = Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType); return(int.Parse(doc.SelectSingleNode("//CurrentVersions") .Attributes.GetNamedItem(userTypeName).Value)); }
/*This method is used to roll back the backend.xml file to a previous version. * 1. It will set a the current version to the number passed in for the specified UserType. * 2. It will remove all newer versions from the document of the specified UserType. * 3. It will then save the document. */ public static void RollBackToVersionNumber(int versionToRollTo, DTO.Enums.UserTypeEnum userType) { var doc = GetXmlDoc.GetBackEndXmlDoc(DTO.Enums.BackEndOrFrontEndEnum.BackEnd); setCurrentVersionNumber(doc, versionToRollTo, userType); removeAllNewVersions(doc, versionToRollTo, userType); SaveXmlDoc.saveBackEndDoc(doc); }
//This will compare version numbers and make sure the highest one in the document is listed as //The current version for the specified UserType. private static void ensureHighestVersionNumber(XmlDocument doc, string userTypeName) { DTO.Enums.UserTypeEnum userType = (DTO.Enums.UserTypeEnum)Enum.Parse(typeof(DTO.Enums.UserTypeEnum), userTypeName); int highestVersionNumber = GetData.GetHighestVersionNumber(doc); if (highestVersionNumber > GetData.GetCurrentRolloutVersionNumber(doc, userType)) { setCurrentVersionNumber(doc, highestVersionNumber, userType); } }
//This function will return the backend.xml file loaded into a XmlDocument object. //This function will pull the latest rollout in a RolloutInfo object from the memory cache. public static RolloutInfo GetLatestRollout(DTO.Enums.UserTypeEnum userType, DTO.Enums.BackEndOrFrontEndEnum whichEnd) { try { return(Caching.PullLatestRolloutFromCache(userType, whichEnd)); } catch (Exception) { throw; } }
public Rollout(string directoryPath, string launchPath, DTO.Enums.UserTypeEnum userType) { //This will ensure that the directory doesn't use mapped drive letters but instead the //full UNC path. directoryPath = PathManager.GetUNCPath(directoryPath); this.LaunchFileName = getLaunchFileName(launchPath); this.DirectoryPath = Validator.ValidateDirectoryPath(directoryPath); this.UserType = userType; this.RollOutDirectoryPath = Validator.ValidateDirectoryPath(PathManager.GetRolloutDirectoryPath(DTO.Enums.BackEndOrFrontEndEnum.BackEnd)); this.BackEndXMLPath = this.RollOutDirectoryPath + "backend.xml"; this.VersionNumber = GetDataFromXml.GetCurrentRolloutVersionNumber(DTO.Enums.BackEndOrFrontEndEnum.BackEnd, this.UserType) + 1; }
public static void RollBackVersionNumber(int versionToRollTo, DTO.Enums.UserTypeEnum userType) { try { //This will attempt to roll back to the specified version number. UpdateXmlFile.RollBackToVersionNumber(versionToRollTo, userType); } catch (Exception) { //IF an exception is raised, it will delete the current backend.xml and then repair the back end, restoring it //to what it was before the rollback attempt. then it will throw a CouldNotRollBackException. var pathToAccess = GetDataFromXml.GetAccessPathFromCurrentConnectionString(DTO.Enums.BackEndOrFrontEndEnum.BackEnd); File.Delete(PathManager.GetBackEndXmlPath(DTO.Enums.BackEndOrFrontEndEnum.BackEnd)); var installer = new Installer(PathManager.GetRolloutDirectoryPath(DTO.Enums.BackEndOrFrontEndEnum.BackEnd), pathToAccess); installer.TryFixBrokenBackEnd(); throw new DTO.Exceptions.CouldNotRollBackException(); } }
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); }
public static RolloutInfo GetLatestRollout(DTO.Enums.UserTypeEnum userType, DTO.Enums.BackEndOrFrontEndEnum whichEnd) { return(XML.GetData.GetLatestRollout(userType, whichEnd)); }
public static int GetCurrentRolloutVersionNumber(DTO.Enums.BackEndOrFrontEndEnum whichEnd, DTO.Enums.UserTypeEnum userType) { try { return(XML.GetData.GetCurrentRolloutVersionNumber(whichEnd, userType)); } catch (Exception) { throw; } }
internal static void RollBackToVersionNumber(int versionToRollTo, DTO.Enums.UserTypeEnum userType) { XML.UpdateData.RollBackToVersionNumber(versionToRollTo, userType); }
//This is an overloaded method. This function will return the current rollout version number for the specified UserType, //from the perspective of whichever end of the application the user is calling from. public static int GetCurrentRolloutVersionNumber(DTO.Enums.BackEndOrFrontEndEnum whichEnd, DTO.Enums.UserTypeEnum userType) { string userTypeName = Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType); return(int.Parse(GetXmlDoc.GetBackEndXmlDoc(whichEnd).SelectSingleNode("//CurrentVersions") .Attributes.GetNamedItem(userTypeName).Value)); }
//This function provides the template path for the specified userType. public static string GetTemplatePath(DTO.Enums.UserTypeEnum userType) { return(GetPath.GetRolloutDirectoryPath(DTO.Enums.BackEndOrFrontEndEnum.BackEnd) + @"Front End Templates\" + Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType)); }
public static void UpdateFrontEnd(DTO.Enums.UserTypeEnum userType) { updateFrontEndXML(userType); deleteAllAccessFiles(); extractZipFile(userType); }
//This will remove all versions newer than the passed in version from the passed in XmlDocument. private static void removeAllNewVersions(XmlDocument doc, int versionToRollTo, DTO.Enums.UserTypeEnum userType) { string userTypeName = Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType); XmlNodeList nodeList = doc.SelectNodes("//Version[@value>" + versionToRollTo.ToString() + "]"); foreach (XmlNode node in nodeList) { XmlNode foundnode = node.SelectSingleNode("./" + userTypeName); if (foundnode != null) { foundnode.ParentNode.RemoveChild(foundnode); } } }
//This will set the current version number. private static void setCurrentVersionNumber(XmlDocument doc, int versionNumber, DTO.Enums.UserTypeEnum userType) { string userTypeName = Enum.GetName(typeof(DTO.Enums.UserTypeEnum), userType); doc.SelectSingleNode("//CurrentVersions").Attributes.GetNamedItem(userTypeName).Value = versionNumber.ToString(); }
private static void updateFrontEndXML(DTO.Enums.UserTypeEnum userType) { DTO.RolloutInfo rollout = GetDataFromXml.GetLatestRollout(userType, DTO.Enums.BackEndOrFrontEndEnum.FrontEnd); UpdateXmlFile.UpdateFrontEndXml(rollout); }
private static void extractZipFile(DTO.Enums.UserTypeEnum userType) { ZipFile.ExtractToDirectory(GetDataFromXml.GetLatestRollout(userType, DTO.Enums.BackEndOrFrontEndEnum.FrontEnd).ZipPath, GetInfo.GetAppDataPath() + "\\Access Files\\"); }