/// <summary> /// /// </summary> /// <param name="packages"></param> public static void Load(List <JsonPackage> packages) { try { foreach (var pkg in GetAllPublishedPackages().ToList()) { //System.Diagnostics.Debug.WriteLine(string.Format("{0}|{1}|{2}|{3}", pkg.Id, pkg.Version, pkg.IsLatestVersion, pkg.IconUrl)); var jp = new JsonPackage { Id = pkg.Id, PackageType = pkg.PackageType, Authors = string.IsNullOrEmpty(pkg.Authors) ? "unknown" : pkg.Authors, Description = pkg.Description.Length > 140 ? string.Format("{0}...", pkg.Description.Substring(0, 140)) : pkg.Description, DownloadCount = pkg.DownloadCount, LastUpdated = pkg.LastUpdated.ToString(Utils.GetDefaultCulture().DateTimeFormat.ShortDatePattern), Title = pkg.Title, OnlineVersion = pkg.Version, Website = pkg.ProjectUrl, Tags = pkg.Tags, IconUrl = pkg.IconUrl, Location = "G" }; // for themes or widgets, get screenshot instead of icon // also get screenshot if icon is missing for package if (pkg.Screenshots != null && pkg.Screenshots.Count > 0) { if ((pkg.PackageType == Constants.Theme || pkg.PackageType == Constants.Widget) || string.IsNullOrEmpty(pkg.IconUrl)) { jp.IconUrl = pkg.Screenshots[0].ScreenshotUri; } } // if both icon and screenshot missing, get default image for package type if (string.IsNullOrEmpty(jp.IconUrl)) { jp.IconUrl = DefaultThumbnail(pkg.PackageType); } if (!string.IsNullOrEmpty(jp.IconUrl) && !jp.IconUrl.StartsWith("http:")) { jp.IconUrl = Constants.GalleryUrl + jp.IconUrl; } if (!string.IsNullOrWhiteSpace(pkg.GalleryDetailsUrl)) { jp.PackageUrl = PackageUrl(pkg.PackageType, pkg.Id); } //System.Diagnostics.Debug.WriteLine(string.Format("{0}|{1}|{2}|{3}", jp.Id, jp.OnlineVersion, jp.PackageType, jp.IconUrl)); packages.Add(jp); } } catch (Exception ex) { Utils.Log("BlogEngine.Core.Packaging.Load", ex); } }
public static string GetOneEmployee(EmployeeEntity employee) { EmployeeEntity emp = new EmployeeEntity(); EmployeeRequest employeeRequest = new EmployeeRequest(); var conn = new SQLiteConnection(ConnectionString); SQLiteDataReader sqlite_datareader; SQLiteCommand sqlite_cmd; sqlite_cmd = conn.CreateCommand(); sqlite_cmd.CommandText = "SELECT * FROM employee where employeeid = '" + employee.Id + "'"; sqlite_datareader = sqlite_cmd.ExecuteReader(); while (sqlite_datareader.Read()) { emp.FirstName = sqlite_datareader.GetString(0); emp.Id = sqlite_datareader.GetString(1); } conn.Close(); employeeRequest.Employee = emp; JsonPackage package = new JsonPackage(); //package.Content = employeeRequest; string jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
/// <summary> /// Write theme manifest to xml file /// </summary> /// <param name="id">id</param> /// <param name="description">description</param> /// <param name="authors">authors</param> /// <param name="url">project url</param> /// <returns></returns> public static JsonPackage WriteThemeManifest(string id, string description = "", string authors = "", string url = "", string version = "", string iconUrl = "") { if (string.IsNullOrEmpty(authors)) { authors = "Unknown"; } var jp = new JsonPackage { Id = id, Description = description, Authors = authors, Website = url }; var themeUrl = string.Format("{0}themes/{1}/theme.xml", Utils.ApplicationRelativeWebRoot, id); var themePath = HttpContext.Current.Server.MapPath(themeUrl); try { var textWriter = new XmlTextWriter(themePath, null) { Formatting = Formatting.Indented, Indentation = 4 }; textWriter.WriteStartDocument(); textWriter.WriteStartElement("metadata"); textWriter.WriteElementString("id", id); textWriter.WriteElementString("description", description); textWriter.WriteElementString("authors", authors); textWriter.WriteElementString("website", url); textWriter.WriteElementString("version", version); #region Thumbnail var thumbnail = Utils.ApplicationRelativeWebRoot + "pics/Theme.png"; var customPng = string.Format("{0}themes/{1}/theme.png", Utils.ApplicationRelativeWebRoot, id); if (File.Exists(HttpContext.Current.Server.MapPath(customPng))) { thumbnail = customPng; } if (!string.IsNullOrEmpty(iconUrl)) { thumbnail = iconUrl; } textWriter.WriteElementString("iconurl", thumbnail); jp.IconUrl = thumbnail; #endregion textWriter.WriteEndDocument(); textWriter.Close(); } catch (Exception ex) { Utils.Log("Packaging.FileSystem.WriteThemeManifest", ex); return(null); } return(jp); }
static string DefaultIconUrl(JsonPackage pkg) { var validImages = new List <string> { "screenshot.jpg", "screenshot.png", "theme.jpg", "theme.png" }; var pkgDir = pkg.PackageType == "Widget" ? "widgets" : "themes"; foreach (var img in validImages) { var url = string.Format("{0}{1}/{2}/{3}", Utils.ApplicationRelativeWebRoot, pkgDir, pkg.Id, img); var path = HttpContext.Current.Server.MapPath(url); if (File.Exists(path)) { return(url); } } if (pkg.PackageType == "Widget") { return(Utils.ApplicationRelativeWebRoot + "pics/Widget.png"); } return(Utils.ApplicationRelativeWebRoot + "pics/Theme.png"); }
static JsonPackage GetPackageManifest(string id, string pkgType) { var jp = new JsonPackage { Id = id, PackageType = pkgType }; var pkgUrl = pkgType == "Theme" ? string.Format("{0}themes/{1}/theme.xml", Utils.ApplicationRelativeWebRoot, id) : string.Format("{0}widgets/{1}/widget.xml", Utils.ApplicationRelativeWebRoot, id); var pkgPath = HttpContext.Current.Server.MapPath(pkgUrl); try { if (File.Exists(pkgPath)) { using (var textReader = new XmlTextReader(pkgPath)) { textReader.Read(); while (textReader.Read()) { textReader.MoveToElement(); if (textReader.Name == "description") { jp.Description = textReader.ReadString(); } if (textReader.Name == "authors") { jp.Authors = textReader.ReadString(); } if (textReader.Name == "website") { jp.Website = textReader.ReadString(); } if (textReader.Name == "version") { jp.LocalVersion = textReader.ReadString(); } if (textReader.Name == "iconurl") { jp.IconUrl = textReader.ReadString(); } } textReader.Close(); } return(jp); } } catch (Exception ex) { Utils.Log("Packaging.FileSystem.GetPackageManifest", ex); } return(null); }
static string DefaultIconUrl(JsonPackage pkg) { var url = string.Format("{0}themes/{1}/theme.png", Utils.ApplicationRelativeWebRoot, pkg.Id); var path = HttpContext.Current.Server.MapPath(url); return(File.Exists(path) ? url : Utils.ApplicationRelativeWebRoot + "pics/Theme.png"); }
/// <summary> /// Json package representing current selected theme /// </summary> /// <param name="themeId">Theme id</param> /// <returns>Json package</returns> public static JsonPackage GetCurrentTheme(string themeId) { // first try to pull theme metadata from manifest file var jp = FileSystem.GetThemeManifest(themeId); if (jp != null) { if (string.IsNullOrEmpty(jp.IconUrl)) { jp.IconUrl = DefaultIconUrl(jp); } return(jp); } // if no manifest file, check themes in online gallery // and if found create manifest file using package info var srs = new PackagingSource { FeedUrl = _feedUrl }; var gPkg = GetPublishedPackages(srs).ToList().Where(p => p.Id == themeId).FirstOrDefault(); if (gPkg != null) { if (gPkg.Screenshots != null && gPkg.Screenshots.Count > 0) { gPkg.IconUrl = string.Format("http://dnbegallery.org{0}", gPkg.Screenshots[0].ScreenshotUri); } jp = FileSystem.WriteThemeManifest(gPkg.Id, gPkg.Description, gPkg.Authors, gPkg.ProjectUrl, gPkg.Version, gPkg.IconUrl); if (jp != null) { return(jp); } } // generate default blank manifest if both methods failed var jpw = FileSystem.WriteThemeManifest(themeId); if (jpw != null) { jp = jpw; } // return default values if theme folder read only if (jp == null) { jp = new JsonPackage { Id = themeId, Authors = "Unknown", IconUrl = Utils.ApplicationRelativeWebRoot + "pics/Theme.png" } } ; return(jp); }
/// <summary> /// get theme manifest from xml file /// </summary> /// <param name="id"></param> /// <returns></returns> public static JsonPackage GetThemeManifest(string id) { var jp = new JsonPackage { Id = id }; var themeUrl = string.Format("{0}themes/{1}/theme.xml", Utils.ApplicationRelativeWebRoot, id); var themePath = HttpContext.Current.Server.MapPath(themeUrl); try { if (File.Exists(themePath)) { var textReader = new XmlTextReader(themePath); textReader.Read(); while (textReader.Read()) { textReader.MoveToElement(); if (textReader.Name == "description") { jp.Description = textReader.ReadString(); } if (textReader.Name == "authors") { jp.Authors = textReader.ReadString(); } if (textReader.Name == "website") { jp.Website = textReader.ReadString(); } if (textReader.Name == "version") { jp.Version = textReader.ReadString(); } if (textReader.Name == "iconurl") { jp.IconUrl = textReader.ReadString(); } } return(jp); } } catch (Exception ex) { Utils.Log("Packaging.FileSystem.GetThemeManifest", ex); } return(null); }
public async Task <JsonPackage <SiteConfig> > GetConfigAsync() { JsonPackage <SiteConfig> siteConfig = new JsonPackage <SiteConfig>(); try { siteConfig = await httpClient.GetJsonAsync <JsonPackage <SiteConfig> >("api/SiteConfig/Get"); } catch (Exception ex) { siteConfig.Success = false; siteConfig.Message = ex.Message; } return(siteConfig); }
public String Create(List <BacklogItemEntity> items) { BacklogEntity backlogEntity = new BacklogEntity(); BacklogRequest backlogRequest = new BacklogRequest(); JsonPackage package = new JsonPackage(); backlogEntity.items = items; backlogRequest.backlogEntity = backlogEntity; package.Type = "CreateRequest"; package.ForwardTo = "BacklogController"; package.Content = backlogRequest; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
public string Remove(String id) { EmployeeEntity employee = new EmployeeEntity(); employee.setId(id); JsonPackage package = new JsonPackage(); EmployeeRequest emp = new EmployeeRequest(); emp.Employee = employee; package.Type = "RemoveRequest"; package.ForwardTo = "EmployeeController"; package.Content = emp; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
public String Add(string name, string password) { EmployeeEntity employee = new EmployeeEntity(); employee.SetValues(name, password); JsonPackage package = new JsonPackage(); EmployeeRequest emp = new EmployeeRequest(); emp.Employee = employee; package.ForwardTo = "EmployeeController"; package.Type = "AddRequest"; package.Content = emp; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
public string AssignToTeam(string id, string AssginedToTeam) { SprintRequest sprintRequest = new SprintRequest(); SprintEntity sprint = new SprintEntity(); sprint.Id = id; sprint.AssignedToTeam = AssginedToTeam; sprintRequest.sprint = sprint; JsonPackage package = new JsonPackage(); package.Type = "AssignToTeamRequest"; package.ForwardTo = "SprintController"; package.Content = sprintRequest; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
public String Add(String name, String task) { SprintRequest sprintRequest = new SprintRequest(); SprintEntity sprint = new SprintEntity(); sprint.SetValues(name, task); sprintRequest.sprint = sprint; JsonPackage package = new JsonPackage(); package.Type = "AddRequest"; package.ForwardTo = "SprintController"; package.Content = sprintRequest; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
public string CheckPassword(string id, string password) { EmployeeEntity employee = new EmployeeEntity(); employee.setId(id); employee.Password = password; JsonPackage package = new JsonPackage(); EmployeeRequest emp = new EmployeeRequest(); emp.Employee = employee; package.Type = "CheckPassword"; package.ForwardTo = "EmployeeController"; package.Content = emp; String jsonpackage = JsonConvert.SerializeObject(package); return(jsonpackage); }
/// <summary> /// Installed packages /// </summary> /// <param name="pkgType">Package type</param> /// <returns>List of installed packages</returns> public static List <JsonPackage> InstalledPackages(string pkgType) { var installedThemes = new Dictionary <string, JsonPackage>(); var path = HttpContext.Current.Server.MapPath(string.Format("{0}themes/", Utils.ApplicationRelativeWebRoot)); // read themes directory foreach (var d in Directory.GetDirectories(path)) { var index = d.LastIndexOf(Path.DirectorySeparatorChar) + 1; var themeId = d.Substring(index); // first try to pull theme metadata from manifest file var p = FileSystem.GetThemeManifest(themeId); if (p == null) { p = new JsonPackage(); p.Id = themeId; } if (p.Id != BlogSettings.Instance.Theme && p.Id != BlogSettings.Instance.MobileTheme && p.Id != "RazorHost") { if (string.IsNullOrEmpty(p.IconUrl)) { p.IconUrl = DefaultIconUrl(p); } installedThemes.Add(p.Id, p); } } // add package metadata from online repository var srs = new PackagingSource { FeedUrl = _feedUrl }; try { var pkgList = GetPublishedPackages(srs); foreach (var pkg in pkgList.ToList()) { if (pkg.PackageType != pkgType || !pkg.IsLatestVersion) { continue; } if (installedThemes.ContainsKey(pkg.Id)) { installedThemes[pkg.Id].Title = pkg.Title; installedThemes[pkg.Id].Description = pkg.Description; installedThemes[pkg.Id].Tags = pkg.Tags; installedThemes[pkg.Id].Authors = pkg.Authors; installedThemes[pkg.Id].Website = pkg.ProjectUrl; installedThemes[pkg.Id].LastUpdated = pkg.LastUpdated.ToString("dd MMM yyyy"); installedThemes[pkg.Id].Version = pkg.Version; if (pkg.PackageType == "Theme" && pkg.Screenshots != null && pkg.Screenshots.Count > 0) { installedThemes[pkg.Id].IconUrl = string.Format("http://dnbegallery.org{0}", pkg.Screenshots[0].ScreenshotUri); } } } // return combined result return(installedThemes.Select(t => t.Value).ToList()); } catch (Exception) { // no connection - return local return(installedThemes.Select(t => t.Value).ToList()); } }