/// <summary> /// Replaces previous extracted references to Tridion items in the template. /// </summary> /// <param name="newReferences"></param> public override void PerformSubstituteReferences(string[] newReferences) { RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content); handler.Initialize(); List <string> references = handler.GetImportReferences(); List <string> dwReferences = new List <string>(); int count = newReferences.Length - references.Count; for (int i = 0; i < count; i++) { dwReferences.Add(newReferences[i]); } _dwHandler.PerformSubstituteReferences(dwReferences.ToArray()); if (handler.Config.ImportSettings.ReplaceRelativePaths) { foreach (string path in references) { if (!path.StartsWith("tcm:") && !path.StartsWith("/webdav/")) { Content = Content.Replace(path, GetRelativeImportPath(path)); } } } }
/// <summary> /// Extarcts the references to Tridion items from the template content. It is allowed to have values in the result that are not valid Tridion references. /// </summary> /// <returns></returns> public override string[] PerformExtractReferences() { TemplatingLogger log = TemplatingLogger.GetLogger(this.GetType()); string[] dwReferences = _dwHandler.PerformExtractReferences(); RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content); handler.Initialize(); List <string> imports = handler.GetImportReferences(); List <string> references = dwReferences.ToList(); foreach (string path in imports) { if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/")) { references.Add(GetRelativeImportPath(path)); } else { if (path.StartsWith("/webdav/")) { string[] pathParts = path.Split('/'); string[] webDavParts = WebDavUrl.Split('/'); if (pathParts[2] != webDavParts[2]) { pathParts[2] = webDavParts[2]; } references.Add(String.Join("/", pathParts)); } else if (TcmUri.IsValid(path)) { TcmUri uri = new TcmUri(path); if (uri.PublicationId != TemplateId.PublicationId) { uri = new TcmUri(uri.ItemId, uri.ItemType, TemplateId.PublicationId); } references.Add(uri.ToString()); } } } return(references.ToArray()); }
/// <summary> /// Extarcts the references to Tridion items from the template content. It is allowed to have values in the result that are not valid Tridion references. /// </summary> /// <returns></returns> public override string[] PerformExtractReferences() { TemplatingLogger log = TemplatingLogger.GetLogger(this.GetType()); string[] dwReferences = _dwHandler.PerformExtractReferences(); RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content); handler.Initialize(); List<string> imports = handler.GetImportReferences(); List<string> references = dwReferences.ToList(); foreach (string path in imports) { if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/")) { references.Add(GetRelativeImportPath(path)); } else { if (path.StartsWith("/webdav/")) { string[] pathParts = path.Split('/'); string[] webDavParts = WebDavUrl.Split('/'); if (pathParts[2] != webDavParts[2]) { pathParts[2] = webDavParts[2]; } references.Add(String.Join("/", pathParts)); } else if (TcmUri.IsValid(path)) { TcmUri uri = new TcmUri(path); if (uri.PublicationId != TemplateId.PublicationId) { uri = new TcmUri(uri.ItemId, uri.ItemType, TemplateId.PublicationId); } references.Add(uri.ToString()); } } } return references.ToArray(); }
/// <summary> /// Replaces previous extracted references to Tridion items in the template. /// </summary> /// <param name="newReferences"></param> public override void PerformSubstituteReferences(string[] newReferences) { RazorHandler handler = new RazorHandler(TemplateId.ToString(), WebDavUrl, Content); handler.Initialize(); List<string> references = handler.GetImportReferences(); List<string> dwReferences = new List<string>(); int count = newReferences.Length - references.Count; for (int i = 0; i < count; i++) { dwReferences.Add(newReferences[i]); } _dwHandler.PerformSubstituteReferences(dwReferences.ToArray()); if (handler.Config.ImportSettings.ReplaceRelativePaths) { foreach (string path in references) { if (!path.StartsWith("tcm:") && !path.StartsWith("/webdav/")) { Content = Content.Replace(path, GetRelativeImportPath(path)); } } } }