public ThemeReference CreateTheme(Models.ThemeBuilderTheme theme) { UserTheme t = null; ThemeReference ret = null; User currentUser = ApplicationContext.Current.User; if (currentUser != null && currentUser.Subscription != null && currentUser.Subscription.Type != SubscriptionType.Basic) { t = UserThemeSource.Current.CloneTheme(theme.CopyFrom, theme.Name, new ThemeMetadata() { FontFamily = theme.FontFamily, FontColor = theme.FontColor, AccentColor1 = theme.AccentColor1, AccentColor2 = theme.AccentColor2, AccentColor3 = theme.AccentColor3, AccentColor4 = theme.AccentColor4, BackgroundColor = theme.BackgroundColor, BackgroundImage = theme.BackgroundImage, Logo = theme.Logo }); if (t != null) { ret = CreateReferenceFromTheme(t); } } return(ret); }
private void generateColorTheme() { List <UserTheme> lstTheme = UserTheme.generateTheme(); foreach (UserTheme theme in lstTheme) { Panel _tile = new Panel(); _tile.Size = new Size(30, 30); _tile.Margin = new Padding(5, 3, 0, 0); _tile.Tag = theme.Name; _tile.BackColor = ColorTranslator.FromHtml(theme.PrimaryColor); _tile.Cursor = Cursors.Hand; _tile.Click += _tile_Click; pnlTheme.Controls.Add(_tile); } }
/// <summary> /// Returns theme reference from user theme. /// </summary> /// <param name="theme">User theme.</param> /// <param name="fileName">Theme file name.</param> /// <returns>Theme reference.</returns> private ThemeReference CreateReferenceFromTheme(UserTheme theme, string fileName = null) { User currentUser = ApplicationContext.Current.User; if (string.IsNullOrEmpty(fileName)) { fileName = System.IO.Path.GetFileName(theme.PhysicalPath); } return(new ThemeReference() { Id = theme.Id, Name = theme.Name, Url = string.Format("{0}://{1}/themes/{2}/{3}", Request.RequestUri.Scheme, Request.RequestUri.Host, currentUser.Id, fileName) }); }
/// <summary> /// Resolves the CSS contents of a given theme. /// </summary> /// <param name="id">Theme Id.</param> /// <returns>Theme CSS contents.</returns> public static string ResolveThemeContents(string id) { string ret = string.Empty; int startIndex = -1, endIndex = -1; string themeCssClassName = string.Concat(".theme-", id); UserTheme theme = UserThemeSource.Current.GetImportedThemes().Themes .Where(t => string.Compare(t.Id, id, true) == 0) .FirstOrDefault(); if (theme != null && System.IO.File.Exists(theme.PhysicalPath)) { ret = System.IO.File.ReadAllText(theme.PhysicalPath); } else if (HttpContext.Current != null) { ret = System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/Assets/css/Embed/Themes.css")); startIndex = ret.IndexOf(themeCssClassName, StringComparison.OrdinalIgnoreCase); if (startIndex >= 0) { endIndex = ret.LastIndexOf(themeCssClassName, StringComparison.OrdinalIgnoreCase); if (endIndex >= 0 && endIndex > startIndex) { endIndex = ret.IndexOf('}', endIndex); if (endIndex >= 0) { ret = ret.Substring(startIndex, endIndex - startIndex + 1); } } } } return(ret); }
public async Task <ThemeReference> UploadTheme() { UserTheme t = null; int maxSizeKb = 1024; ThemeReference ret = null; string root = string.Empty; MultipartFileData file = null; string fileName = string.Empty; string targetFileName = string.Empty; string originalPhysicalPath = string.Empty; MultipartFormDataStreamProvider provider = null; User currentUser = ApplicationContext.Current.User; if (currentUser != null && currentUser.Subscription != null && currentUser.Subscription.Type != SubscriptionType.Basic) { if (!this.Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } root = System.Web.HttpContext.Current.Server.MapPath(string.Format("~/App_Data/Themes/{0}", currentUser.Id)); if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } provider = new MultipartFormDataStreamProvider(root); await this.Request.Content.ReadAsMultipartAsync(provider); file = provider.FileData.FirstOrDefault(); if (file != null) { originalPhysicalPath = file.LocalFileName; if (File.Exists(originalPhysicalPath)) { if ((new FileInfo(originalPhysicalPath).Length / maxSizeKb) > maxSizeKb) { File.Delete(originalPhysicalPath); } else { if (file.Headers != null && file.Headers.ContentDisposition != null) { fileName = Path.GetFileNameWithoutExtension((file.Headers.ContentDisposition.FileName ?? file.Headers.ContentDisposition.Name ?? string.Empty).Trim('"', '\\', '\'').Trim()); } if (string.IsNullOrEmpty(fileName)) { fileName = string.Format("Theme {0}", System.DateTime.UtcNow.Ticks); } fileName = string.Format("{0}.css", fileName); targetFileName = Path.Combine(Path.GetDirectoryName(originalPhysicalPath), fileName); if (File.Exists(targetFileName)) { File.Delete(targetFileName); } File.Move(originalPhysicalPath, targetFileName); t = ThemeSource.CreateThemeInstance <UserTheme>(targetFileName, null, true); ret = CreateReferenceFromTheme(t, fileName); } } } } return(ret); }