public string GetUserDefaultPage(string userId, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; // user db_config_page dcp = null; // page try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return js.Serialize(""); dcu = new db_config_users(auxUserId); dcu.Open(); object userOptions = dcu.Get(auxUserId).UserOptions; // if user does not exist leaves if (userOptions == null) return string.Empty; OptionItems oi = new OptionItems((string)userOptions); string pageName = oi.GetSingle("default_frontoffice_page"); // if no default page leave if (pageName == string.Empty) return string.Empty; dcp = new db_config_page(pageName); dcp.Open(); string pageTitle = dcp.Get(pageName).Title; Dictionary<string, string> defPage = new Dictionary<string, string>() {{"Name", pageName}, {"Title", pageTitle}}; return js.Serialize(defPage); } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Get Default Page ", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); try { if(dcp != null) dcp.Close(); } catch { } } return string.Empty; }
public string GetUserFavorites(string userId, string ctrl) { JavaScriptSerializer js = new JavaScriptSerializer(); string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); //if (ctrl != crlHash) return js.Serialize(""); db_config_users dcu = null; db_config_page dcp = null; try { // first validation to guarantee that user is greater than zero int auxUserId = Convert.ToInt32(userId); if (auxUserId < 0) return js.Serialize(""); dcu = new db_config_users(auxUserId); dcu.Open(); dcp = new db_config_page(); dcp.Open(); object userOptions = dcu.Get(auxUserId).UserOptions; if (userOptions == null) return js.Serialize(""); OptionItems oi = new OptionItems((string)userOptions); List<Dictionary<string, string>> favoriteList = new List<Dictionary<string, string>>(); foreach (string favoritePage in oi.GetList("favorites")) { try { string title = dcp.Get(favoritePage).Title; favoriteList.Add(new Dictionary<string, string>() { {"Name", favoritePage}, {"Title", title} }); } catch {} } return js.Serialize(favoriteList); } catch (Exception ex) { loging.Error("FrontOffice User Webservice", "Get Favorites ", ex.Message, _logRecord); } finally { if (dcu != null) dcu.Close(); try { if(dcp != null) dcp.Close(); } catch {} // needed to open a new connection (forgot to implement a page method that accepts new ) } return js.Serialize(""); }
public string GetPageTitle(string pageId, string ctrl) { string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); if (ctrl != crlHash) return string.Empty; db_config_page dcp = null; try { int id = Convert.ToInt32(pageId); dcp = new db_config_page(id, false); dcp.Open(); Page p = dcp.Get(id); return p.Title; } catch (Exception ex) { return ex.Message; } finally { if (dcp != null) dcp.Close(); } }
public string GetPageType(string pageId, string ctrl) { string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey")); if (ctrl != crlHash) return string.Empty; db_config_page dcp = null; try { int id = Convert.ToInt32(pageId); dcp = new db_config_page(id, false); dcp.Open(); Page p = dcp.Get(id); OptionItems oi = new OptionItems(p.Options); return oi.GetSingle("page_type").ToLower() == "free_draw" ? "free_draw" : "table"; } catch (Exception ex) { return ex.Message; } finally { if (dcp != null) dcp.Close(); } }
/// <summary> /// Generate header bar /// </summary> private void FillMenuBar(OptionItems foOptions) { string username = "******"; try { headerContainer.Controls.Clear(); UserLoginData user = (UserLoginData)db_config_sessions.GetUserAuthentication(); OptionItems userOi = null; db_config_master_page dcmp = new db_config_master_page(); dcmp.Open(); List<string> userFavorites = new List<string>(); // user not autenticated show just public pages if (user == null) { dcmp.SelectPublicObjectsFromDb(); } else { // user autenticated show public pages and user pages dcmp.SelectAuthenticatedObjectsFromDb(user.UserPages); userOi = new OptionItems(user.User.UserOptions); userFavorites = userOi.GetList("favorites"); // prepare username to be used in error exception. username = user.User.Name; } // set url to use when the page start SelectDefaultPage(foOptions.GetSingle("default_page"), user != null ? userOi.GetSingle("default_frontoffice_page") : ""); MenuBar mb = new MenuBar(); mb.AddHeader("Home", "frontoffice.aspx"); // just show data if is not refresh if (!IsPostBack) { mb.AddHeader("Site pages", ""); // site pages int headerId = mb.GetHeaderPosition("Site pages"); db_config_page dcp; foreach (DbConfig.MasterPage item in dcmp.AllMasterPages) { // just show pages that admin dont want to hide from you :) List<DbConfig.Page> visiblePages = (from p in dcmp.GetAllPages(item.ID) where (new OptionItems(p.Options).GetSingle("hidden_from_frontoffice").Equals("true")) == false select p).ToList(); dcp = new db_config_page(dcmp.Db, visiblePages, item.ID); if (user == null) dcp.SelectPublicObjectsFromDb(); else dcp.SelectAuthenticatedObjectsFromDb(user.UserPages); // will just add master page if it has visible pages to show, // if the master page does not have pages will not get here. if (dcp.AllPages.Count > 0) { // add master page to menu mb.AddMenuItem(headerId, item.Title, ""); int menuItemId = mb.GetMenuPosition(headerId, item.Title); // add pages to sub menus foreach (DbConfig.Page subItem in dcp.AllPages) mb.AddSubMenuItem(headerId, menuItemId, subItem.Title, "page.aspx?nm=" + subItem.Name); } dcp.Close(); } if (userFavorites.Count > 0) // favorites { mb.AddHeader("Favorites", ""); int favItemId = mb.GetHeaderPosition("Favorites"); dcp = new db_config_page(dcmp.Db, new List<DbConfig.Page>(), -1); dcp.Refresh(); foreach (string favpage in userFavorites) { if (!dcp.PageExists(favpage)) continue; DbConfig.Page p = dcp.Get(favpage); mb.AddMenuItem(favItemId, p.Title, "page.aspx?nm=" + p.Name); } dcp.Close(); } } dcmp.Close(); headerContainer.Controls.Add(mb.Get()); Generic.JavaScriptInjector("js", mb.GetLoginJavascript()); } catch (Exception ex) { throw new Exception("error: fill menu bar for user " + username + " - " + ex.Message + " ..."); } }
/// <summary> /// Transforms the list of hyperlink into a list /// of cases that will be used in javascript /// </summary> /// <param name="listHyperlinks"></param> private void BuildFilters(List<string> listHyperlinks, int thisPageId) { foreach (string link in listHyperlinks) { string[] lk = link.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (lk.Length != 4) continue; string columnName = lk[0].Trim(); string pageName = lk[1].Trim(); string masterFilterName = lk[2].Trim(); string filterCondition = lk[3].Trim(); db_config_page dcp = null; try { _columnNames.Add(columnName); /* case 'sin_req': pageIdHash = '123123123123'; filterTitleHash = '1asfa2324q23'; isCurrentPage = false filter = "sin_req = 'value'".replace('value', value.toString()); */ dcp = new db_config_page(pageName); dcp.Open(); DbConfig.Page p = dcp.Get(pageName); int pageId = p.ID; string pageHashId = Generic.GetHash(pageId.ToString(CultureInfo.InvariantCulture)); string masterFilterNameHash = Generic.GetHash(masterFilterName); string js = string.Empty; js += "case '" + columnName + "': \n"; js += " pageName = '" + pageName + "'; \n"; js += " pageIdHash = '" + pageHashId + "'; \n"; js += " filterTitle = '" + masterFilterName + "'; \n"; js += " filterTitleHash = '" + masterFilterNameHash + "'; \n"; js += " isCurrentPage = " + (pageId == thisPageId ? "true" : "false") + "; \n"; js += " \n"; js += " filter = \"" + filterCondition + "\".replace('value', value.toString()); \n"; _jsSwith.Add(js); } finally { if (dcp != null) dcp.Close(); } } }
private void Startup(string pageName) { db_config_page dcp = new db_config_page(pageName); dcp.Open(); DbConfig.Page page = dcp.Get(pageName); PageAuthentication pa = new PageAuthentication(page.ID); if (!pa.IsPageVisible()) Response.Redirect("frontoffice.aspx"); pageTitle.Text = page.Title; /*************** Options ****************/ OptionItems oi = new OptionItems(page.Options); ChangeAlignment(oi.GetSingle("page_alignment")); ChangeCss(oi.GetSingle("css")); ChangeBackground(oi.GetSingle("background-color")); RefreshPage(oi.GetSingle("refresh_page_interval")); /*************** draw frames ****************/ DrawFrames df = new DrawFrames(pageName, oi.GetSingle("page_type")); mPage.Controls.Add(df.GetFrames()); }
/* Build Xml Virtual Path */ private string BuildFileVirtualPath(string fileName) { db_config_page page = null; try { // if contains a fixed path then there is no need to add page or default path if (fileName.StartsWith("http://")) return fileName; // if the filename is not added then there is no reason to be here if (string.IsNullOrEmpty(fileName)) throw new Exception("filename is empty"); // page virtual path string pageXmlUrl = string.Empty; if (PageId != -1) { page = new db_config_page(PageId, false); page.Open(); pageXmlUrl = page.Get(PageId).XMLURL; } // webconfig virtual path string virtualFolder = Generic.GetWebConfigValue("DataVirtualFolderPath"); if (string.IsNullOrEmpty(virtualFolder)) virtualFolder = "~/data/"; if (!string.IsNullOrEmpty(pageXmlUrl) && !pageXmlUrl.StartsWith("default", StringComparison.CurrentCultureIgnoreCase)) { return pageXmlUrl.EndsWith("/") ? pageXmlUrl + fileName : pageXmlUrl + @"/" + fileName; } return virtualFolder.EndsWith("/") ? virtualFolder + fileName : virtualFolder + @"/" + fileName; } catch (Exception ex) { throw new Exception("build vistual path: " + fileName + " - " + ex.Message + " ..."); } finally { if (page != null) page.Close(); } }
/* Build Fisical Path */ private string BuildFilePath(string fileName) { db_config_page page = null; try { // if contains a fixed path then there is no need to add page or default path if (fileName.StartsWith("http://") || fileName.Contains(@":\")) return fileName; // if the filename is not added then there is no reason to be here if (string.IsNullOrEmpty(fileName)) throw new Exception("filename is empty"); // page fisical path string pageDataFolder = string.Empty; if (PageId != -1) { page = new db_config_page(PageId, false); page.Open(); pageDataFolder = page.Get(PageId).XMLFolderPath; } // webconfig fisical path string sitePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; string dataFile = Generic.GetWebConfigValue("DataFolderPath"); // if sitePath is null then WTF and if pageXmlFolder is empty well in this case you have Murphy's Law problems if (string.IsNullOrEmpty(sitePath) && (string.IsNullOrEmpty(pageDataFolder) || pageDataFolder.StartsWith("default"))) throw new Exception("no fisical path to build"); // if path is null then set to empty ele remove any space that it was added in the end sitePath = (sitePath == null) ? string.Empty : sitePath.TrimEnd(); dataFile = (dataFile == null) ? string.Empty : dataFile.TrimEnd(); if (!string.IsNullOrEmpty(pageDataFolder) && !pageDataFolder.StartsWith("default", StringComparison.CurrentCultureIgnoreCase)) { return pageDataFolder.EndsWith(@"\") ? pageDataFolder + fileName : pageDataFolder + @"\" + fileName; } return dataFile != string.Empty ? dataFile.EndsWith(@"\") // if not empty then it contains another path then the default ? dataFile + fileName : dataFile + @"\" + fileName : sitePath.EndsWith(@"\") // if empty then user whants to use default path ? sitePath + @"data\" + fileName : sitePath + @"\data\" + fileName; } catch (Exception ex) { throw new Exception("build fisical file path: " + fileName + " - " + ex.Message + " ..."); } finally { if (page != null) page.Close(); } }
private static void SavePage(int id, int masterPageID, string name, string title, string xmlFolder, string xmlUrl, string options) { try { db_config_page dcp = new db_config_page(); dcp.Open(); Page p = id >= 0 ? dcp.Get(id) : new Page(); p.IDMasterPage = masterPageID; p.Name = name; p.Title = title; p.XMLFolderPath = xmlFolder; p.XMLURL = xmlUrl; p.Options = options; if (id >= 0) dcp.Commit(); else dcp.Add(p); dcp.Close(); } catch (Exception ex) { throw new Exception("error: Save Page: " + ex.Message); } }
private void LoadPage(string id) { try { int pId = Convert.ToInt32(id); db_config_page dcp = new db_config_page(pId, false); dcp.Open(); DbConfig.Page p = dcp.Get(pId); p_id.Value = p.ID.ToString(CultureInfo.InvariantCulture); p_name.Value = p.Name; p_title.Value = p.Title; p_xml_folder.Value = p.XMLFolderPath; p_xml_url.Value = p.XMLURL; p_options.Value = p.Options; BuildPageSelector(p.IDMasterPage); SetPageTitle(p.Title); dcp.Close(); } catch (Exception ex) { Generic.JavaScriptInjector("alert('" + ex.Message + "');"); } }