public int CopyPage(int id, string name)
        {
            var ok = -1;
            var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            var desktopSources = this.iptRepository.GetDesktopSources();

            var translate = new Translate { DesktopSources = desktopSources, PTDataContext = db };
            IList < rb_Pages > pagelist = (from p in db.rb_Pages where p.PageID == id select p).ToList<rb_Pages>();
            var page = (pagelist.Count == 0) ? null: translate.TranslateRb_PagesIntoPagesDTO(pagelist[0]);
            if (page != null)
            {
                this.ModulesNotInserted = new Dictionary<int, string>();
                translate.ContentModules = new Dictionary<int, string>();
                translate.ModuleDefinitionsDeserialized = new Dictionary<Guid, rb_ModuleDefinition>();

                page.Modules.RemoveAll(m=> m.ShowEveryWhere == true);
                var newpage = translate.TranslatePagesDTOIntoRb_Pages(page);
                newpage.PageName = name;

                db.rb_Pages.InsertOnSubmit(newpage);
                db.SubmitChanges(ConflictMode.FailOnFirstConflict);

                IList < rb_Portals > portallist = (from p in db.rb_Portals where p.PortalID == newpage.PortalID select p).ToList<rb_Portals>();
                var portal = portallist[0];
                translate.PageList = new Dictionary<int, int> { { newpage.PageID, 0 } };

                this.SaveModuleContentPage(newpage, desktopSources, translate.ContentModules);
                AlterModuleSettingsPage(portal, newpage, translate.PageList, desktopSources);
                AlterModuleDefinitions(portal.PortalID, translate.ModuleDefinitionsDeserialized);
                ok = newpage.PageID;
            }

            return ok;
        }
        public PortalsDTO GetPortal(int portalID)
        {
            Translate _translate = new Translate();
            IList<rb_Portals> list=(from p in db.rb_Portals where p.PortalID == portalID select p).ToList<rb_Portals>();
            _translate.DesktopSources = this.GetDesktopSources();

            return list.Count == 0 ? null : _translate.TranslateRb_PortalsIntoPortalDTO(list[0]);
        }
 public HtmlTextDTO GetHtmlTextDTO(int moduleId)
 {
     Translate _translate = new Translate();
     IList<rb_HtmlText> list = (from h in db.rb_HtmlTexts where h.ModuleID == moduleId select h).ToList<rb_HtmlText>();
     return list.Count == 0 ? null : _translate.TranslateRb_HtmlTextIntoHtmlTextDTO(list[0]);
 }
Пример #4
0
        /// <summary>
        /// Deserializes the portal.
        /// </summary>
        /// <param name="file">
        /// The file.
        /// </param>
        /// <param name="portalName">
        /// Name of the portal.
        /// </param>
        /// <param name="portalAlias">
        /// The portal alias.
        /// </param>
        /// <param name="portalPath">
        /// The portal path.
        /// </param>
        /// <param name="portalId">
        /// The portal id.
        /// </param>
        /// <returns>
        /// The deserialize portal.
        /// </returns>
        public bool DeserializePortal(
            string file, string portalName, string portalAlias, string portalPath, string filePath, out int portalId)
        {
            var result = true;

            try {
                PortalsDTO portal;
                if (file.EndsWith("AppleSeedTemplates"))
                {
                    using (var ms = new MemoryStream()) {
                        using (ZipFile zip = ZipFile.Read(GetPhysicalPackageTemplatesPath(filePath) + "\\" + file)) {
                            if (zip.Count == 1)
                            {
                                ms.Position = 0;
                                string   name = file.Replace(".AppleSeedTemplates", ".XML");
                                ZipEntry e    = zip[name];
                                e.Extract(ms);

                                //FileStream s = new FileStream(GetPhysicalPackageTemplatesPath("") + "\\" + name, FileMode.Create);
                                //int pos = int.Parse(ms.Position.ToString());
                                //s.Write(ms.GetBuffer(), 0, pos);
                                //s.Close();

                                ms.Position = 0;

                                var xs = new XmlSerializer(typeof(PortalsDTO));
                                portal = (PortalsDTO)xs.Deserialize(ms);

                                ms.Close();
                            }
                            else
                            {
                                portal = null;
                            }
                        }
                        // the application can now access the MemoryStream here
                    }
                }
                else
                {
                    var fs = new FileStream(GetPhysicalPackageTemplatesPath(filePath) + "\\" + file, FileMode.Open);
                    var xs = new XmlSerializer(typeof(PortalsDTO));
                    portal = (PortalsDTO)xs.Deserialize(fs);
                    fs.Close();
                }

                var db             = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                var desktopSources = this.iptRepository.GetDesktopSources();

                var translate = new Translate {
                    DesktopSources = desktopSources, PTDataContext = db
                };
                var _portal = translate.TranslatePortalDTOIntoRb_Portals(portal);
                this.ModulesNotInserted = translate.ModulesNotInserted;

                _portal.PortalName  = portalName;
                _portal.PortalPath  = portalPath;
                _portal.PortalAlias = portalAlias;

                db.rb_Portals.InsertOnSubmit(_portal);

                db.SubmitChanges(ConflictMode.FailOnFirstConflict);
                portalId = _portal.PortalID;
                this.SaveModuleContent(_portal, desktopSources, translate.ContentModules);
                AlterModuleSettings(_portal, translate.PageList, desktopSources);
                AlterModuleDefinitions(_portal.PortalID, translate.ModuleDefinitionsDeserialized);
            } catch (Exception ex) {
                result   = false;
                portalId = -1;
                ErrorHandler.Publish(LogLevel.Error, "There was an error on creating the portal", ex);
            }

            return(result);
        }
        /// <summary>
        /// Saves the HTML text.
        /// </summary>
        /// <param name="moduleId">
        /// The module id.
        /// </param>
        /// <param name="html">
        /// The HTML.
        /// </param>
        /// <returns>
        /// The save html text.
        /// </returns>
        public bool SaveHtmlText(int moduleId, HtmlTextDTO html)
        {
            var result = true;
            try {
                var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                var translate = new Translate();
                var htmlText = translate.TranslateHtmlTextDTOIntoRb_HtmlText(html);
                htmlText.ModuleID = moduleId;
                var htmlst = translate.TranslateHtmlTextDTOIntoRb_HtmlText_st(html);
                htmlst.ModuleID = moduleId;
                db.rb_HtmlTexts.InsertOnSubmit(htmlText);
                db.rb_HtmlText_sts.InsertOnSubmit(htmlst);
                db.SubmitChanges(ConflictMode.FailOnFirstConflict);
            } catch (Exception ex) {
                result = false;
                ErrorHandler.Publish(LogLevel.Error, "There was an error saving the content modules", ex);
            }

            return result;
        }
        /// <summary>
        /// Deserializes the portal.
        /// </summary>
        /// <param name="file">
        /// The file.
        /// </param>
        /// <param name="portalName">
        /// Name of the portal.
        /// </param>
        /// <param name="portalAlias">
        /// The portal alias.
        /// </param>
        /// <param name="portalPath">
        /// The portal path.
        /// </param>
        /// <param name="portalId">
        /// The portal id.
        /// </param>
        /// <returns>
        /// The deserialize portal.
        /// </returns>
        public bool DeserializePortal(
            string file, string portalName, string portalAlias, string portalPath, string filePath, out int portalId)
        {
            var result = true;
            try {
                PortalsDTO portal;
                if (file.EndsWith("AppleSeedTemplates")) {
                    using (var ms = new MemoryStream()) {
                        using (ZipFile zip = ZipFile.Read(GetPhysicalPackageTemplatesPath(filePath) + "\\" + file)) {
                            if (zip.Count == 1) {
                                ms.Position = 0;
                                string name = file.Replace(".AppleSeedTemplates", ".XML");
                                ZipEntry e = zip[name];
                                e.Extract(ms);

                                //FileStream s = new FileStream(GetPhysicalPackageTemplatesPath("") + "\\" + name, FileMode.Create);
                                //int pos = int.Parse(ms.Position.ToString());
                                //s.Write(ms.GetBuffer(), 0, pos);
                                //s.Close();

                                ms.Position = 0;

                                var xs = new XmlSerializer(typeof(PortalsDTO));
                                portal = (PortalsDTO)xs.Deserialize(ms);

                                ms.Close();

                            } else {
                                portal = null;
                            }

                        }
                        // the application can now access the MemoryStream here
                    }

                } else {
                    var fs = new FileStream(GetPhysicalPackageTemplatesPath(filePath) + "\\" + file, FileMode.Open);
                    var xs = new XmlSerializer(typeof(PortalsDTO));
                    portal = (PortalsDTO)xs.Deserialize(fs);
                    fs.Close();
                }

                var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                var desktopSources = this.iptRepository.GetDesktopSources();

                var translate = new Translate { DesktopSources = desktopSources, PTDataContext = db };
                var _portal = translate.TranslatePortalDTOIntoRb_Portals(portal);
                this.ModulesNotInserted = translate.ModulesNotInserted;

                _portal.PortalName = portalName;
                _portal.PortalPath = portalPath;
                _portal.PortalAlias = portalAlias;

                db.rb_Portals.InsertOnSubmit(_portal);

                db.SubmitChanges(ConflictMode.FailOnFirstConflict);
                portalId = _portal.PortalID;
                this.SaveModuleContent(_portal, desktopSources, translate.ContentModules);
                AlterModuleSettings(_portal, translate.PageList, desktopSources);
                AlterModuleDefinitions(_portal.PortalID, translate.ModuleDefinitionsDeserialized);

            } catch (Exception ex) {
                result = false;
                portalId = -1;
                ErrorHandler.Publish(LogLevel.Error, "There was an error on creating the portal", ex);
            }

            return result;
        }