Inheritance: Persistente
Ejemplo n.º 1
0
    protected void Save_Click(object sender, EventArgs e)
    {
        RawHtml row = new RawHtml();
        row = pgserv.GetRawHtmlById(RawHtmlId);

        row.Value = edit.Text;
        row.Dirty = true;
        pgserv.SaveRawHtml(row, "");
    }
Ejemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            string idPageElement = Request.QueryString["idpel"];
            iditemamm = Convert.ToInt32(Request.QueryString["iditem"]);
            PageServices pgserv = new PageServices();

            PageElementDTO pel = new PageElementDTO();
            pel = pgserv.GetPageelementByPageelementID(Convert.ToInt32(idPageElement));

            RawHtml row = new RawHtml();
            row = pgserv.GetRawHtmlById(pel.Rawhtmlid);
            edit.Text = row.Value;
            RawHtmlId = row.Rawhtmlid;
        }
    }
Ejemplo n.º 3
0
        public void SaveRawHtml(RawHtml Row, string Folder)
        {
            using (ISession session = HibernateHelper.GetSession().OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    try {
                        if (Folder.StartsWith(@"\") == true) {
                            Folder = Folder.Remove(0, 1);
                        }
                        string SavePath = ConfigurationSettings.AppSettings["ServerPath"];
                        string FolderToSave = Path.Combine(SavePath, Folder);
                        HibernateHelper.Persist(Row, session);

                        if (Row.IsPersisted) {
                            string contrawfile = Path.Combine(FolderToSave, Row.Rawhtmlid + "_RawHtml.htm");

                            string htmlDocument = Row.Value;
                            FileStream fs = File.OpenWrite(contrawfile);
                            StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
                            writer.Write(htmlDocument);
                            writer.Close();
                            WebSiteThumbnail.SaveImage(contrawfile, FolderToSave);
                            //cancello il file temporaneo html
                            File.Delete(contrawfile);
                        }
                        transaction.Commit();

                    } catch (Exception ex) {
                        transaction.Rollback();
                        throw ex;
                    } finally {
                        session.Flush();
                        session.Close();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public PageDTO SavePage(PageDTO pagedto)
        {
            using (ISession session = HibernateHelper.GetSession().OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    try {
                        Page page = new Page();

                        Mapper.CreateMap<PageDTO, Page>();
                        Mapper.CreateMap<PageElementDTO, PageElement>();
                        Mapper.CreateMap<ElementDTO, Element>();
                        //Mappo la PageDTO in Page
                        page = Mapper.Map<PageDTO, Page>(pagedto);

                        Regex punt = new Regex(@"[\t\r\n\e\a._%+-/]");

                        page.Title = punt.Replace(page.Title.Replace("&nbsp;", "").Trim().Replace(" ", "_"), "_");

                        if (page.Publictitle != null && page.Contentid > 0 && page.Position > 0) {

                            page.Publictitle = EditorServices.ReplaceCharacters(page.Publictitle);

                            if (page.IsNew) {

                                // Salvo la Nuova pagina
                                HibernateHelper.Persist(page, session);

                                if (page.PageelementsList.Count == 0) {
                                    //Creo Le Page Elements in base alla struttura
                                    //Ricavo la lista degli elementi della struttura per generare i PageElement
                                    List<Element> structList = new List<Element>();
                                    structList = HibernateHelper.SelectCommand<Element>(session, " STRUCTUREID =" + page.Structureid);

                                    ISet<PageElement> PaElements = new HashedSet<PageElement>();
                                    foreach (Element el in structList) {

                                        PageElement PaElement = new PageElement();
                                        PaElement.Element = el;
                                        PaElement.Elementid = el.Elementid;
                                        PaElement.Page = page;
                                        PaElement.Pageid = page.Pageid;
                                        PaElement.Valore = EditorServices.ReplaceCharacters(el.Description);
                                        PaElement.IsNew = true;

                                        if (el.Elementtypeid == (int)ElementTypeEnum.RawHtml) {
                                            //solo RawHtml
                                            RawHtml raw = new RawHtml();
                                            raw.Value = EditorServices.ReplaceCharacters(el.Description);
                                            raw.IsNew = true;
                                            HibernateHelper.Persist(raw, session);
                                            PaElement.Rawhtmlid = raw.Rawhtmlid;
                                        }
                                        HibernateHelper.Persist(PaElement, session);
                                        PaElements.Add(PaElement);
                                    }
                                    page.PageElements = PaElements;
                                    PaElements = page.PageElements;
                                }

                                // Setto il padre  al pageid se è zero
                                if (page.Parentpageid == 0) {
                                    page.Parentpageid = page.Pageid;
                                } else {
                                    page.Parentpageid = page.Parentpageid;
                                }
                                // Setto skinID a null se è zero
                                if (page.Skinid == 0) {
                                    page.Skinid = null;
                                }
                                page.Dirty = true;
                                HibernateHelper.Persist(page, session);
                            } else
                                if (page.Dirty) {
                                    //Update della Pagina Esistente
                                    HibernateHelper.Persist(page, session);

                                    //Foreach delle pageelements
                                    foreach (PageElement el in page.PageelementsList) {
                                        el.Pageid = page.Pageid;
                                        if (el.Deleted) {
                                            page.PageElements.Remove(el);
                                            HibernateHelper.Persist(el, session);
                                        } else {
                                            el.Valore = EditorServices.ReplaceCharacters(el.Valore);
                                            HibernateHelper.Persist(el, session);
                                        }
                                    }
                                }
                        }
                        //Rimappo l'oggetto da restituire
                        Mapper.CreateMap<Page, PageDTO>();
                        Mapper.CreateMap<PageElement, PageElementDTO>();
                        Mapper.CreateMap<Element, ElementDTO>();
                        //Mappo la PageDTO in Page
                        pagedto = Mapper.Map<Page, PageDTO>(page);

                        transaction.Commit();

                    } catch (Exception ex) {
                        transaction.Rollback();
                        throw ex;
                    } finally {
                        session.Flush();
                        session.Close();
                    }
                }
            }
            //Setto lo stato del content a non allineato
            ContentServices contSvc = new ContentServices();
            contSvc.SetStateContent(pagedto.Contentid, (int)ContentStateEnum.NonAllineato);

            return pagedto;
        }
Ejemplo n.º 5
0
        public RawHtml GetRawHtmlById(int Rawhtmlid)
        {
            using (ISession session = HibernateHelper.GetSession().OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    try {
                        RawHtml pel = new RawHtml();
                        pel = HibernateHelper.SelectIstance<RawHtml>(session, new string[] { "Rawhtmlid" }, new object[] { Rawhtmlid }, new Operators[] { Operators.Eq });

                        return pel;

                    } catch (Exception ex) {
                        throw ex;
                    } finally {
                        session.Flush();
                        session.Close();
                    }
                }

            }
        }
Ejemplo n.º 6
0
        public PageDTO ClonePage(PageDTO pagedto, int idItemAmm, string FolderToSave)
        {
            using (ISession session = HibernateHelper.GetSession().OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    try {
                        Page page = new Page();

                        Mapper.CreateMap<PageDTO, Page>();
                        Mapper.CreateMap<PageElementDTO, PageElement>();
                        //Mappo la PageDTO in Page
                        page = Mapper.Map<PageDTO, Page>(pagedto);

                        //Tengo in memoria il pageid da clonare
                        int pageId = page.Pageid;

                        //Salvo la nuova Pagina
                        HibernateHelper.Persist(page, session);

                        //Ricavo i PageElements del padre
                        List<PageElement> CloneElements = HibernateHelper.SelectCommand<PageElement>(session, new string[] { "Pageid" }, new object[] { pageId }, new Operators[] { Operators.Eq });

                        //Ciclo  sui CloneElements
                        ISet<PageElement> ChildElements = new HashedSet<PageElement>();
                        foreach (PageElement el in CloneElements) {

                            PageElement child = new PageElement();
                            child.IsNew = true;
                            child.Page = page;
                            child.Pageid = page.Pageid;
                            child.Valore = EditorServices.ReplaceCharacters(el.Valore);
                            child.Filename = el.Filename;
                            child.Element = el.Element;
                            child.Elementid = el.Elementid;
                            if (el.Element.ElementType.Elementtypeid == (int)ElementTypeEnum.RawHtml) {

                                //Get RawHtml Clone
                                RawHtml cloneraw = new RawHtml();
                                cloneraw = HibernateHelper.SelectIstance<RawHtml>(session, new string[] { "Rawhtmlid" }, new object[] { el.Rawhtmlid }, new Operators[] { Operators.Eq });

                                RawHtml childraw = new RawHtml();
                                childraw.IsNew = true;
                                childraw.Value = EditorServices.ReplaceCharacters(cloneraw.Value);
                                SaveRawHtml(childraw, FolderToSave);
                                child.Rawhtmlid = childraw.Rawhtmlid;

                            }

                            HibernateHelper.Persist(child, session);
                            ChildElements.Add(child);
                        }

                        page.PageElements = ChildElements;
                        ChildElements = page.PageElements;

                        // Setto il padre  al pageid se è zero
                        if (page.Parentpageid == 0) {
                            page.Parentpageid = page.Pageid;
                        } else {
                            page.Parentpageid = page.Parentpageid;
                        }
                        // Setto skinID a null se è zero
                        if (page.Skinid == 0) {
                            page.Skinid = null;
                        }
                        page.Dirty = true;
                        HibernateHelper.Persist(page, session);

                        //Rimappo l'oggetto da restituire
                        Mapper.CreateMap<Page, PageDTO>();
                        Mapper.CreateMap<PageElement, PageElementDTO>();
                        Mapper.CreateMap<Element, ElementDTO>();
                        //Mappo la PageDTO in Page
                        pagedto = Mapper.Map<Page, PageDTO>(page);

                        transaction.Commit();

                    } catch (Exception ex) {
                        transaction.Rollback();
                        throw ex;
                    } finally {
                        session.Flush();
                        session.Close();
                    }
                }
            }

            //Setto lo stato del content a non allineato
            ContentServices contSvc = new ContentServices();
            contSvc.SetStateContent(pagedto.Contentid, (int)ContentStateEnum.NonAllineato);

            return pagedto;
        }