using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; /// /// Summary description for Sites /// public static class Sites { public static List sites = new List(); public static SiteResource resource = new SiteResource(); private static string appurl { get { return HttpContext.Current.Server.MapPath("~"); } } private static string site_host { get { string host = HttpContext.Current.Request.Url.Host; string r = "default"; var h = sites.FirstOrDefault(q=>q.url == host); if (h != null) { r = h.folder; } return r; } } private static string site_root { get { string r = ""; r = appurl; return HttpContext.Current.Server.MapPath("~"); } } public static double MaxAge = 3600 * 24 * 365; static Sites() { JObject o=get_jsonfile(@"sites\sites-config.json"); sites = o["sites"].ToObject>(); resource = o["resource"].ToObject(); //resource.Add(new KeyValuePair("assets", "assets")); //resource.Add(new KeyValuePair("config", "config")); } private static JObject get_jsonfile(string jsonfile) { JObject o; //string appurl = HttpContext.Current.Server.MapPath("~"); string path = Path.Combine(appurl, jsonfile); o = JObject.Parse(File.ReadAllText(path)); return o; } public static string get_url(string path, string url) { string r=""; char s = Path.DirectorySeparatorChar; url = url.Replace('/', s); r = $@"{appurl}sites{s}{site_host}{s}{path}{s}{url}"; return r; } } public class Site { public string url { get; set; } public string folder { get; set; } public string connection { get; set; } public string title { get; set; } } public class SiteResource { public string assets { get; set; } public string config { get; set; } public string modules { get; set; } public string upload { get; set; } }