コード例 #1
0
        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;
        }
コード例 #2
0
 public PortalTemplateRepository()
 {
     db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
 }
コード例 #3
0
 private static void AlterModuleSettingsPage(rb_Portals portal,
     rb_Pages pages, IDictionary<int, int> pageList, IDictionary<Guid, string> desktopSources)
 {
     var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
     var modules = db.rb_Modules.Where(m => m.rb_Pages.PageID == pages.PageID).ToList();
     AlterModuleSettingsAux(modules, portal, pageList, desktopSources);
 }
コード例 #4
0
        private static void AlterModuleSettingsAux(
            IEnumerable<rb_Modules> modules, rb_Portals portal, IDictionary<int, int> pageList, IDictionary<Guid, string> desktopSources)
        {
            var p = new Page();
            var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            foreach (var module in modules)
            {
                var portalModuleName = string.Concat(
                    Path.ApplicationRoot, "/", desktopSources[module.rb_ModuleDefinition.GeneralModDefID]);
                if (!portalModuleName.Contains("/Areas/") && !portalModuleName.StartsWith("Areas/"))
                {
                    var portalModule = (PortalModuleControl)p.LoadControl(portalModuleName);
                    foreach (var key in
                        portalModule.BaseSettings.Keys.Cast<string>().Where(
                            key =>
                            key.Equals("TARGETURL") ||
                            portalModule.BaseSettings[key] is PageListDataType))
                    {
                        try
                        {
                            var setting = module.rb_ModuleSettings.First(s => s.SettingName.Equals(key));
                            var oldPageId =
                                Regex.Match(setting.SettingValue, "(/\\d+/)|(^\\d+$)", RegexOptions.IgnoreCase).Value.
                                    Replace("/", string.Empty);
                            var newPageId = portal.rb_Pages[pageList[Convert.ToInt16(oldPageId)]].PageID;
                            setting.SettingValue = setting.SettingValue.Replace(oldPageId, newPageId.ToString());
                        }
                        catch (Exception e)
                        {
                            ErrorHandler.Publish(
                                LogLevel.Error,
                                string.Format(
                                    "There was an error on modifying the module settings for moduleID= {0} and setting= {1}",
                                    module.ModuleID,
                                    key),
                                e);
                        }
                    }
                }
            }

            try
            {
                db.SubmitChanges(ConflictMode.FailOnFirstConflict);
            }
            catch (Exception e)
            {
                ErrorHandler.Publish(LogLevel.Error, "There was an error on modifying the module settings", e);
            }
        }
コード例 #5
0
        /// <summary>
        /// Alters the module definitions.
        /// </summary>
        /// <param name="portalId">
        /// The portal id.
        /// </param>
        /// <param name="moduleDefinitions">
        /// The module definitions.
        /// </param>
        private static void AlterModuleDefinitions(int portalId, Dictionary<Guid, rb_ModuleDefinition> moduleDefinitions)
        {
            var db = new PortalTemplateDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            var keys = moduleDefinitions.Keys.ToList();
            try {
                foreach (var key in keys) {
                    rb_ModuleDefinition oldDef;
                    moduleDefinitions.TryGetValue(key, out oldDef);
                    var def = db.rb_ModuleDefinitions
                        .Where(d => d.PortalID == oldDef.PortalID && d.GeneralModDefID == key && d.ModuleDefID == oldDef.ModuleDefID) /*ModuleDefID is already updated so must match*/
                        .OrderByDescending(d => d.ModuleDefID)
                        .First(); /*to avoid possible duplicates, Last() is not supported*/

                    def.PortalID = portalId;
                }

                db.SubmitChanges(ConflictMode.FailOnFirstConflict);
            } catch (Exception e) {
                ErrorHandler.Publish(LogLevel.Error, "There was an error on modifying the module definitions", e);
            }
        }
コード例 #6
0
        /// <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;
        }
コード例 #7
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;
        }