/// <summary> /// Read the custom redirects from the dynamic data store, and /// stores them in the CustomRedirect property /// </summary> protected void LoadCustomRedirects() { DataStoreHandler dynamicHandler = new DataStoreHandler(); _customRedirects = new CustomRedirectCollection(); foreach (CustomRedirect redirect in dynamicHandler.GetCustomRedirects(false)) _customRedirects.Add(redirect); }
/// <summary> /// Read the custom redirects from the dynamic data store, and /// stores them in the CustomRedirect property /// </summary> protected void LoadCustomRedirects() { _customRedirects = new CustomRedirectCollection(); foreach (var redirect in RedirectsService.GetAll()) { _customRedirects.Add(redirect); } }
/// <summary> /// Save a collection of redirects, and call method to raise an event in order to clear cache on all servers. /// </summary> /// <param name="redirects"></param> public void SaveCustomRedirects(CustomRedirectCollection redirects) { DataStoreHandler dynamicHandler = new DataStoreHandler(); foreach (CustomRedirect redirect in redirects) { // Add redirect dynamicHandler.SaveCustomRedirect(redirect); } DataStoreEventHandlerHook.DataStoreUpdated(); }
/// <summary> /// Read the custom redirects from the dynamic data store, and /// stores them in the CustomRedirect property /// </summary> protected void LoadCustomRedirects() { var dynamicHandler = new DataStoreHandler(); _customRedirects = new CustomRedirectCollection(); foreach (var redirect in dynamicHandler.GetCustomRedirects(false)) { _customRedirects.Add(redirect); } }
/// <summary> /// Save a collection of redirects, and call method to raise an event in order to clear cache on all servers. /// </summary> /// <param name="redirects"></param> public void SaveCustomRedirects(CustomRedirectCollection redirects) { var dynamicHandler = new DataStoreHandler(); foreach (CustomRedirect redirect in redirects) { // Add redirect dynamicHandler.SaveCustomRedirect(redirect); } DataStoreEventHandlerHook.DataStoreUpdated(); }
/// <summary> /// Save a collection of redirects, and call method to raise an event in order to clear cache on all servers. /// </summary> /// <param name="redirects"></param> public void SaveCustomRedirects(CustomRedirectCollection redirects) { var dynamicHandler = new DataStoreHandler(); foreach (CustomRedirect redirect in redirects) { // Add redirect dynamicHandler.SaveCustomRedirect(redirect); } ClearCache(); }
/// <summary> /// Read the custom redirects from the dynamic data store, and /// stores them in the CustomRedirect property /// </summary> protected void LoadCustomRedirects() { _customRedirects = new CustomRedirectCollection(); foreach (var redirect in RedirectsService.GetAll()) { try { _customRedirects.Add(redirect); } catch (Exception ex) { Logger.Error(string.Format("An error occurred while loading redirect OldUrl = {0}", redirect.OldUrl), ex); CustomRedirectHandlerException = ex.ToString(); } } }
/// <summary> /// Parses the xml file and reads all redirects. /// </summary> /// <returns>A collection of CustomRedirect objects</returns> public CustomRedirectCollection Load() { const string urlpath = "/redirects/urls/url"; var redirects = new CustomRedirectCollection(); // Parse all url nodes var nodes = _customRedirectsXmlFile.SelectNodes(urlpath); foreach (XmlNode node in nodes) { // Each url new url can have several old values // we need to create a redirect object for each pair var newNode = node.SelectSingleNode(Newurl); var oldNodes = node.SelectNodes(Oldurl); foreach (XmlNode oldNode in oldNodes) { var skipWildCardAppend = false; var skipWildCardAttr = oldNode.Attributes[Skipwildcard]; if (skipWildCardAttr != null) { // If value parsing fails, it will be false by default. We do // not really care to check if it fails, as we cannot do anything // about it (throwing an exception is not a good idea here) bool.TryParse(skipWildCardAttr.Value, out skipWildCardAppend); } var redirectType = Data.RedirectType.Permanent; var redirectTypeAttr = oldNode.Attributes[RedirectType]; if (redirectTypeAttr != null) { Enum.TryParse(redirectTypeAttr.Value, out redirectType); } // Create new custom redirect nodes var redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend, redirectType); redirects.Add(redirect); } } return(redirects); }
/// <summary> /// Parses the xml file and reads all redirects. /// </summary> /// <returns>A collection of CustomRedirect objects</returns> public CustomRedirectCollection Load() { const string URLPATH = "/redirects/urls/url"; const string NEWURL = "new"; const string OLDURL = "old"; const string SKIPWILDCARD = "onWildCardMatchSkipAppend"; CustomRedirectCollection redirects = new CustomRedirectCollection(); // Parse all url nodes XmlNodeList nodes = _customRedirectsXmlFile.SelectNodes(URLPATH); foreach (XmlNode node in nodes) { // Each url new url can have several old values // we need to create a redirect object for each pair XmlNode newNode = node.SelectSingleNode(NEWURL); XmlNodeList oldNodes = node.SelectNodes(OLDURL); foreach (XmlNode oldNode in oldNodes) { bool skipWildCardAppend = false; XmlAttribute skipWildCardAttr = oldNode.Attributes[SKIPWILDCARD]; if (skipWildCardAttr != null) { // If value parsing fails, it will be false by default. We do // not really care to check if it fails, as we cannot do anything // about it (throwing an exception is not a good idea here) bool.TryParse(skipWildCardAttr.Value, out skipWildCardAppend); } // Create new custom redirect nodes CustomRedirect redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend); redirects.Add(redirect); } } return(redirects); }
/// <summary> /// Parses the xml file and reads all redirects. /// </summary> /// <returns>A collection of CustomRedirect objects</returns> public CustomRedirectCollection Load() { const string URLPATH = "/redirects/urls/url"; const string NEWURL = "new"; const string OLDURL = "old"; const string SKIPWILDCARD = "onWildCardMatchSkipAppend"; CustomRedirectCollection redirects = new CustomRedirectCollection(); // Parse all url nodes XmlNodeList nodes = _customRedirectsXmlFile.SelectNodes(URLPATH); foreach (XmlNode node in nodes) { // Each url new url can have several old values // we need to create a redirect object for each pair XmlNode newNode = node.SelectSingleNode(NEWURL); XmlNodeList oldNodes = node.SelectNodes(OLDURL); foreach (XmlNode oldNode in oldNodes) { bool skipWildCardAppend = false; XmlAttribute skipWildCardAttr = oldNode.Attributes[SKIPWILDCARD]; if (skipWildCardAttr != null) { // If value parsing fails, it will be false by default. We do // not really care to check if it fails, as we cannot do anything // about it (throwing an exception is not a good idea here) bool.TryParse(skipWildCardAttr.Value, out skipWildCardAppend); } // Create new custom redirect nodes CustomRedirect redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend); redirects.Add(redirect); } } return redirects; }
public FileUploadJsonResult ImportDeleted(HttpPostedFileBase txtFile) { CheckAccess(); var redirects = new CustomRedirectCollection(); using (var streamReader = new StreamReader(txtFile.InputStream)) { while (streamReader.Peek() >= 0) { var url = streamReader.ReadLine(); if (!string.IsNullOrEmpty(url)) { redirects.Add(new CustomRedirect { OldUrl = url, State = (int)DataStoreHandler.State.Deleted, }); } } } string message; if (redirects.Count != 0) { CustomRedirectHandler.Current.SaveCustomRedirects(redirects); message = string.Format(LocalizationService.Current.GetString("/gadget/redirects/importdeletedsuccess"), redirects.Count); } else { message = LocalizationService.Current.GetString("/gadget/redirects/importnone"); } return new FileUploadJsonResult { Data = new { message = message } }; }