public HtmlGenericControl GenerateJsFileTag(string relToRootPath, string templateBaseUrl, Dictionary <string, string> attributes = null, bool useUrlAsIs = false) { HtmlGenericControl tag = new HtmlGenericControl(); tag.TagName = "script"; var url = relToRootPath; if (!useUrlAsIs) { url = URIHelper.ConvertToAbsUrl(LoadFileServiceUrl) + URIHelper.ConvertToAbsUrl(relToRootPath); } //url = URIHelper.ConvertToAbsUrl(LoadFileServiceUrl) + URIHelper.ConvertToAbsUrl(relToRootPath) + "&templateBaseUrl=" + templateBaseUrl; if (!url.Contains("?")) { url = url.Replace("&", "?"); } tag.Attributes.Add("src", url); tag.Attributes.Add("type", "text/javascript"); tag = AddAttributesToTag(tag, attributes); return(tag); }
public HtmlLink GenerateCssFileTag(string relToRootPath, string templateBaseUrl, Dictionary <string, string> attributes = null, bool useUrlAsIs = false) { HtmlLink tag = new HtmlLink(); var url = relToRootPath; if (!useUrlAsIs) { url = URIHelper.ConvertToAbsUrl(LoadFileServiceUrl) + URIHelper.ConvertToAbsUrl(relToRootPath); } //url = URIHelper.ConvertToAbsUrl(LoadFileServiceUrl) + URIHelper.ConvertToAbsUrl(relToRootPath) + "&templateBaseUrl=" + templateBaseUrl; if (!url.Contains("?")) { url = url.Replace("&", "?"); } tag.Href = url; tag.Attributes.Add("type", "text/css"); tag.Attributes.Add("rel", "stylesheet"); tag = AddAttributesToTag(tag, attributes); return(tag); }
public static void WriteRss(Rss rss, Stream stream) { XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteStartElement("channel"); writer.WriteElementString("title", rss.Title); writer.WriteElementString("link", URIHelper.ConvertToAbsUrl(rss.Link)); writer.WriteElementString("description", rss.Description); writer.WriteElementString("copyright", rss.Copyright); writer.WriteElementString("ttl", rss.TTL); foreach (RssItem item in rss.Items) { WriteRssItem(item, writer); } writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); stream.Close(); }
public string CalculatedVirtualPath() { var parents = GetAllParentMediaDetails(this.LanguageID).Reverse(); var virtualPath = ""; foreach (var parent in parents) { if (parent is RootPage || parent is Website) { continue; } virtualPath = StringHelper.CreateSlug(parent.LinkTitle) + "/" + virtualPath; } if (virtualPath == "") { virtualPath = "~/"; } virtualPath = URIHelper.ConvertAbsUrlToTilda(virtualPath); return(virtualPath); }
public static string ReadUrl(string url, bool enableCaching = false, long cacheDurationInSeconds = 86400) { if (url == null) { return(""); } var absUrl = URIHelper.ConvertToAbsUrl(url).ToLower(); var data = ""; string absPath = URIHelper.ConvertToAbsPath(URIHelper.ConvertAbsUrlToTilda(url)); using (FileStream fs = File.Open(absPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { data = sr.ReadToEnd(); } if (enableCaching) { ContextHelper.SaveToCache(absUrl, data, DateTime.Now.AddSeconds(cacheDurationInSeconds)); } return(data); }
public static FileInfo GetFileInfoFromUrl(string url) { var invalid = Path.GetInvalidPathChars().ToList(); foreach (var c in invalid) { if (url.Contains(c)) { url = url.Replace(c.ToString(), "_"); } } url = url.Replace("?", "_"); url = url.Replace(":", "-"); var absPath = ""; if (new FileInfo(url).Extension == "") { if (!url.EndsWith("/")) { url = url + "/"; } absPath = URIHelper.ConvertToAbsPath($"{baseDir}{url.ToLower()}{htmlFileName}"); } else { absPath = URIHelper.ConvertToAbsPath($"{baseDir}{url.ToLower()}"); } var fileInfo = new FileInfo(absPath); return(fileInfo); }
public static string GetUrlToDetailsPage(string absListPageUrl, Tag item) { if (!absListPageUrl.EndsWith("/")) { absListPageUrl = absListPageUrl + "/"; } return(URIHelper.ConvertToAbsUrl(absListPageUrl) + item.SefTitle); }
public static void AddToList(string url) { url = URIHelper.ConvertToAbsUrl(url); if (list.Contains(url)) { return; } list.Add(url); }
public static bool IsSame(string url1, string url2) { url1 = URIHelper.ConvertToAbsUrl(url1); url2 = URIHelper.ConvertToAbsUrl(url2); if (Prepair(url1) == Prepair(url2)) { return(true); } return(false); }
public static string GetParentPath(string url, int levelsUp) { var segments = GetParentPathList(url, levelsUp); var path = String.Join("/", segments); if (!path.EndsWith("/")) { path += "/"; } path = URIHelper.ConvertAbsUrlToTilda(path); return(path); }
public string GetMobileTemplate() { if (string.IsNullOrEmpty(this.MobileTemplate)) { return(this.PathToFile); } if (File.Exists(URIHelper.ConvertToAbsPath(this.MobileTemplate))) { return(this.MobileTemplate); } return(this.PathToFile); }
public Return Validate() { var returnOnj = BaseMapper.GenerateReturn(); MediaTypeHandler = MediaTypeHandler.Trim(); if (!File.Exists(URIHelper.ConvertToAbsPath(URIHelper.ConvertAbsUrlToTilda(MediaTypeHandler)))) { var ex = new Exception("Media Type MediaTypeHandler is invalid", new Exception("File (" + MediaTypeHandler + ") does not exist")); returnOnj.Error = ErrorHelper.CreateError(ex); } return(returnOnj); }
public Dictionary <string, object> GetFieldValuePairs() { var dictionary = new Dictionary <string, object>(); if (MediaType.ShowInSiteTree) { dictionary["FriendlyUrl"] = AbsoluteUrl; } dictionary["PermaUrl"] = URIHelper.ConvertToAbsUrl(PermaLink); dictionary["PermaApiUrl"] = dictionary["PermaUrl"] + "&format=json"; var children = new List <Dictionary <string, object> >(); foreach (MediaDetail mediaDetail in ChildMediaDetails.Where(i => i.ShowInMenu)) { children.Add(mediaDetail.GetFieldValuePairs()); } dictionary["Children"] = children; foreach (var field in Fields) { var fieldAssociations = field.GetPublishedFieldAssociations(); if (!fieldAssociations.Any()) { dictionary[field.FieldCode] = field.FieldValue; } else { var fieldDoctionary = new List <Dictionary <string, object> >(); foreach (var association in fieldAssociations) { var mediaDetail = association.MediaDetail; fieldDoctionary.Add(mediaDetail.GetFieldValuePairs()); } dictionary[field.FieldCode] = fieldDoctionary; } } return(dictionary); }
public static EmailLog GetEmailLogFromMailMessage(MailMessage mailObj) { EmailLog obj = new EmailLog(); obj.SenderName = mailObj.Sender.DisplayName; obj.SenderEmailAddress = mailObj.Sender.Address; obj.ToEmailAddresses = EmailHelper.GetMailAddressesAsString(mailObj.To); obj.FromEmailAddress = mailObj.From.Address; obj.Message = mailObj.Body; obj.Subject = mailObj.Subject; obj.VisitorIP = HttpContext.Current.Request.UserHostAddress; obj.RequestUrl = URIHelper.GetCurrentVirtualPath(true); obj.DateCreated = DateTime.Now; obj.DateLastModified = DateTime.Now; return(obj); }
public static Return ClearAllCache() { if (string.IsNullOrEmpty(baseDir)) { return(new Return()); } //FileCacheHelper.DeleteGenerateNav(); //FileCacheHelper.DeleteSettings(); //FileCacheHelper.DeleteHTMLCache(); var directoryInfo = new DirectoryInfo(URIHelper.ConvertToAbsPath(baseDir)); var subDirectories = directoryInfo.GetDirectories(); var allFiles = directoryInfo.GetFiles(); foreach (var file in allFiles) { try { File.Delete(file.FullName); } catch (Exception ex) { ErrorHelper.LogException(ex); } } foreach (var directory in subDirectories) { try { Directory.Delete(directory.FullName, true); } catch (Exception ex) { ErrorHelper.LogException(ex); } } ContextHelper.ClearAllMemoryCache(); return(new Return()); }
private static void WriteRssItem(RssItem rssItem, XmlTextWriter writer) { writer.WriteStartElement("item"); writer.WriteElementString("title", rssItem.Title); writer.WriteElementString("link", URIHelper.ConvertToAbsUrl(rssItem.Link)); string shortDesc = StringHelper.StripHtmlTags(rssItem.Description); if (shortDesc.Length > 255) { shortDesc = shortDesc.Substring(0, 255) + " ..."; } writer.WriteElementString("description", shortDesc); writer.WriteElementString("author", rssItem.Author); writer.WriteElementString("pubDate", rssItem.PubDate); writer.WriteElementString("updated", rssItem.Updated); writer.WriteEndElement(); }
public static string GetCurrentVirtualPath(bool asAbsPath = false, bool includeQueryString = false) { string virtualPath = HttpContext.Current.Request.Path; if (virtualPath.StartsWith("~/" + HttpContext.Current.Request.Url.Host)) { virtualPath = virtualPath.Replace("~/" + HttpContext.Current.Request.Url.Host, "~"); } if (HttpContext.Current.Request.ApplicationPath != "/") { virtualPath = virtualPath.ToLower().Replace(HttpContext.Current.Request.ApplicationPath.ToLower(), ""); } if (virtualPath.ToLower().Contains("~/default.aspx")) { virtualPath = "~/"; } virtualPath = URIHelper.ConvertAbsUrlToTilda(virtualPath); if (asAbsPath) { virtualPath = ConvertToAbsUrl(virtualPath); } if (virtualPath == "") { virtualPath = "~/"; } /*var details = MediaDetailsMapper.GetByVirtualPath(virtualPath, false); * * if (details == null) * { * if (!virtualPath.Contains(FrameworkSettings.RootMediaDetail.VirtualPath)) * virtualPath = virtualPath.Replace("~/", FrameworkSettings.RootMediaDetail.VirtualPath); * }*/ return(virtualPath); }
public static bool StartsWithLanguage(string url) { IEnumerable <Language> languages = LanguagesMapper.GetAllActive(); url = ConvertAbsUrlToTilda(url); foreach (Language language in languages) { string url2 = URIHelper.ConvertAbsUrlToTilda(GetBaseUrlWithLanguage(language)); if (url2.EndsWith("/")) { url2 = url2.Remove(url2.Length - 1); } if (url.StartsWith(url2)) { return(true); } } return(false); }
public static string ParseData(string data, object obj, bool compileRazor = true) { //return data; if (obj == null) { return(""); } data = data.Trim(); if (data.StartsWith("@") && data.EndsWith("}")) { data = RunOrCompileRazorCode(data, data, obj, compileRazor); } var matches = Regex.Matches(data, openToken + "[a-zA-Z0-9-.&=<>/\\;(\n|\r|\r\n)\"#?']+" + closeToken); foreach (var item in matches) { var tag = item.ToString(); var tagValue = ""; var propertyName = tag.Replace("{", "").Replace("}", ""); var queryStringParams = ""; if (propertyName.Contains("?")) { var segments = propertyName.Split('?').ToList(); propertyName = segments[0]; segments.RemoveAt(0); queryStringParams = string.Join("", segments); } var nestedProperties = StringHelper.SplitByString(propertyName, "."); if (nestedProperties.Length > 0) { if (obj == null) { continue; } object tempNestedProperty = obj; var propertyloopIndex = 0; foreach (var nestedProperty in nestedProperties) { PropertyInfo tempPropertyInfo = null; MethodInfo tempMethodInfo = null; var matchParams = Regex.Matches(nestedProperty, "([a-zA-Z0-9-_]+)"); var methodParamsMatches = new List <string>(); for (int i = 0; i < matchParams.Count; i++) { var val = matchParams[i].ToString(); if (val != "quot") { methodParamsMatches.Add(val); } } if (nestedProperty.Contains("(") && !nestedProperty.Contains(".")) { try { tempMethodInfo = tempNestedProperty.GetType().GetMethod(methodParamsMatches[0]); } catch (Exception ex) { ErrorHelper.LogException(ex); } } else { var prop = nestedProperty; var queryParamsSplit = nestedProperty.Split('?'); if (queryParamsSplit.Count() > 1) { prop = queryParamsSplit.ElementAt(0); } if (tempNestedProperty is JObject) { var val = (tempNestedProperty as JObject).GetValue(prop); if (val is JArray) { tempNestedProperty = String.Join(",", val as JArray); } else { if (val != null) { tempNestedProperty = val.ToString(); } } } else { tempPropertyInfo = tempNestedProperty.GetType().GetProperty(prop); } } if (tempPropertyInfo != null || tempMethodInfo != null) { if (tempPropertyInfo != null) { tempNestedProperty = tempPropertyInfo.GetValue(tempNestedProperty, null); } else if (tempMethodInfo != null) { var objParams = new object[methodParamsMatches.Count - 1]; var parametersInfo = tempMethodInfo.GetParameters(); for (var i = 0; i < methodParamsMatches.Count - 1; i++) { if (parametersInfo.Count() > i) { objParams[i] = Convert.ChangeType(methodParamsMatches[i + 1], parametersInfo[i].ParameterType); } } tempNestedProperty = tempMethodInfo.Invoke(tempNestedProperty, objParams.Where(i => i != null)?.ToArray()); } if (tempNestedProperty != null) { var hasEnumerable = tempNestedProperty.GetType().ToString().Contains("Enumerable") || tempNestedProperty.GetType().ToString().Contains("Collection"); long tmpIndex = 0; if (nestedProperties.Count() > propertyloopIndex + 1) { if (hasEnumerable) { if (long.TryParse(nestedProperties[propertyloopIndex + 1], out tmpIndex)) { var count = 0; foreach (var nestedItem in tempNestedProperty as IEnumerable <object> ) { if (count == tmpIndex) { tempNestedProperty = nestedItem; break; } count++; } continue; } else { var count = 0; var returnValue = ""; var tempPropertiesString = ""; var tmp = nestedProperties.ToList(); tmp.RemoveAt(propertyloopIndex); var newPropertyString = string.Join(".", tmp); foreach (var nestedItem in (dynamic)tempNestedProperty) { var tmpReturn = ParseData("{" + newPropertyString + "}", nestedItem); returnValue += ParseData(tmpReturn, nestedItem); /*var tmpReturn = ParseData("{" + nestedProperties[propertyloopIndex + 1] + "}", nestedItem); * returnValue += ParseData(tmpReturn, nestedItem); * count++;*/ } tagValue = returnValue; } } } else { if (nestedProperties.Length < propertyloopIndex + 1) { return(ParseData("{" + nestedProperties[propertyloopIndex + 1] + "}", tempNestedProperty)); } else if (tempNestedProperty is string) { if (tempMethodInfo != null) { tagValue = tempNestedProperty.ToString(); } //return ParseData("{" + nestedProperties[propertyloopIndex + 1] + "}", tempNestedProperty); } } } } else { var splitEq = nestedProperty.ToString().Split('='); if (splitEq.Count() > 1) { tempPropertyInfo = tempNestedProperty.GetType().GetProperty(splitEq[0]); if (tempPropertyInfo != null) { var returnVal = tempPropertyInfo.GetValue(tempNestedProperty, null); if (splitEq[1].Replace("\"", "") == returnVal.ToString()) { var tmp = nestedProperties.ToList(); tmp.RemoveAt(propertyloopIndex); var newPropertyString = string.Join(".", tmp); tempNestedProperty = ParseData("{" + newPropertyString + "}", tempNestedProperty); } else { tempNestedProperty = ""; } } } } propertyloopIndex++; } if (tempNestedProperty is DateTime) { tagValue = data.Replace(item.ToString(), StringHelper.FormatOnlyDate((DateTime)tempNestedProperty)); } if (tempNestedProperty is string || tempNestedProperty is bool || tempNestedProperty is long) { var val = tempNestedProperty.ToString(); var queryStringSplit = item.ToString().Replace(OpenToken, "").Replace(CloseToken, "").Split('?'); if (queryStringSplit.Count() > 1) { var nv = HttpUtility.ParseQueryString(queryStringSplit.ElementAt(1)); foreach (string key in nv) { var value = nv[key]; val = val.Replace(OpenToken + key + CloseToken, value); } } tagValue = data.Replace(item.ToString(), val); } } if (tagValue.StartsWith("~/")) { tagValue = URIHelper.ConvertToAbsUrl(tagValue); } if (!string.IsNullOrEmpty(tagValue)) { data = RunOrCompileRazorCode(tag, tagValue, obj, compileRazor); } } data = RunOrCompileRazorCode(data, data, obj, compileRazor); return(data); }
public static MasterPage GetByPathToFile(string pathToFile) { pathToFile = URIHelper.ConvertAbsUrlToTilda(pathToFile).ToLower(); return(GetDataModel().MasterPages.FirstOrDefault(item => item.PathToFile.ToLower() == pathToFile)); }
public string GetCacheKey(RenderVersion renderVersion) { var path = (renderVersion.ToString() + URIHelper.GetCurrentVirtualPath().Replace("~", "")).ToLower(); return(path); }