/* PUBLIC */
        public List<Dictionary<string, string>> GetQueries()
        {
            List<Dictionary<string, string>> queries = new List<Dictionary<string, string>>();

            // leaves if imput values are not all correct
            if (_scheduleInterval < 0 || _dbFilePath == string.Empty || _xmlFolderPath == string.Empty) return queries;

            db_config_page pages = new db_config_page();
            // open the connection to the sqlite database
            pages.Open(_dbFilePath);

            foreach (Page page in pages.AllPages)
            {
                // get folder path
                string path = !page.XMLFolderPath.StartsWith("default") & page.XMLFolderPath != string.Empty
                                                                                                        ? page.XMLFolderPath.Trim()
                                                                                                        : _xmlFolderPath.Trim();

                List<Frame> frames = (from f in pages.GetAllFrames(page.ID)
                                             where f.ScheduleInterval == _scheduleInterval && f.IsActive == 1
                                             select f).ToList();

                foreach (Frame frame in frames)
                {
                    // add the options to the option smasher :) to get the individual strings
                    OptionItems oi = new OptionItems(frame.Options);

                    string frameTitle = frame.Title;
                    string pageTitle = page.Title;
                    string sql = oi.GetSingle("sql");           // first sql found
                    string conn = oi.GetSingle("conn");         // first conn found
                    string xmlFile = oi.GetSingle("xml_file");  // forst xml file found

                    // if any of the above strins its empty, its because the user did someting very bad
                    if (sql != string.Empty && conn != string.Empty && xmlFile != string.Empty)
                    {
                        // if the xml file contains ":\" its because its a c:\bla bla or d:\bla bla or someting like that.
                        queries.Add(BuildQueryObject(
                                                        sql,
                                                        conn,
                                                        path.EndsWith(@"\") ? path + xmlFile : path + @"\" + xmlFile,
                                                        pageTitle,
                                                        frameTitle
                                                    ));
                    }

                }
            }

            return queries;
        }
Example #2
0
    public string ListAllUserPages(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        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("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            if (userPagesId.Count > 0)
                dcp.SelectAuthenticatedObjectsFromDb(userPagesId); // list public pages and pages that user can have
            else
                dcp.SelectPublicObjectsFromDb();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> userPages = (from ap in dcp.AllPages
                                            select new JsonUserPages {Id = ap.ID, Title = ap.Title, Name = ap.Name}).ToList();

            return js.Serialize(userPages);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "List All User Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Example #3
0
    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("");
    }
Example #4
0
    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;
    }
Example #5
0
    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();
        }
    }
Example #6
0
    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();
        }
    }
Example #7
0
    public string DeletePage(string pageId, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_page dcp = null;

        try
        {
            dcp = new db_config_page(Convert.ToInt32(pageId), false);
            dcp.Open();
            dcp.Delete(Convert.ToInt32(pageId));
            return "Operation Done";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }
    }
Example #8
0
    public string ListFrames(string pageId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        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, true);
            dcp.Open();

            List<Frame> frames = dcp.GetAllFrames(id);

            List<Dictionary<string, object>> rows = frames.Select(f => new Dictionary<string, object>
                                                                    {
                                                                        {"ID", f.ID},
                                                                        {"Title", f.Title},
                                                                        {"FrameType", f.FrameType},
                                                                        {"X", f.X},
                                                                        {"Y", f.Y},
                                                                        {"Width", f.Width},
                                                                        {"Height", f.Height},
                                                                        {"IsActive", f.IsActive},
                                                                        {"Columnspan", new OptionItems(f.Options).GetSingle("columnspan")},
                                                                        {"Rowspan", new OptionItems(f.Options).GetSingle("rowspan")},
                                                                    }).ToList();

            return js.Serialize(rows);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice Frames Webservice", "List Frames", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Example #9
0
    public string ListAvailablePagesToUser(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return js.Serialize("");

        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("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> noAvailableUserPages = userPagesId.Count == 0 ? (from ap in dcp.AllPages
                                                                                 select new JsonUserPages { Id = ap.ID, Title = ap.Title, Name = ap.Name }).ToList()
                                                                            : (from nup in dcp.AllPages
                                                                                where !userPagesId.Contains(nup.ID)
                                                                                select new JsonUserPages { Id = nup.ID, Title = nup.Title, Name = nup.Name }).ToList();

            return js.Serialize(noAvailableUserPages);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice User Webservice", "List All Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Example #10
0
    /************************ Selector Box ************************/
    /// <summary>
    ///  Build page selector if ID  is negative then it will select first item
    /// </summary>
    private void BuildPageSelector(int currentPageId)
    {
        db_config_page dcp = null;

        // Clear all items
        f_pageid.Items.Clear();

        try
        {
            dcp = new db_config_page();
            dcp.Open();

            List<Page> allPages = dcp.AllPages.OrderBy(x=>x.Title).ToList();

            for (int i = 0; i < allPages.Count; i++)
            {
                f_pageid.Items.Add(new ListItem(
                                                allPages[i].Title,
                                                allPages[i].ID.ToString(CultureInfo.InvariantCulture)
                                                ));

                // Get the page position then set the selector index
                if (allPages[i].ID == currentPageId)
                    f_pageid.SelectedIndex = i;
            }
        }
        catch (Exception ex)
        {
            throw new Exception("error: building page list " + ex.Message);
        }
        finally
        {
            if (dcp != null)
                dcp.Close();
        }
    }
Example #11
0
        /// <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();
                }
            }
        }
Example #12
0
    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());
    }
Example #13
0
    /* 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();
        }
    }
Example #14
0
    /* 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();
        }
    }
Example #15
0
    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);
        }
    }
Example #16
0
    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 + "');");
        }
    }