Exemplo n.º 1
0
 public static List <Models.PageTemplate> GetPageTemplatesByContentId(string contentId)
 {
     return(Portal.GetPageTemplates().Where(t => t.Widgets.Exists(w => w.ContentIds.Contains(contentId))).ToList());
 }
Exemplo n.º 2
0
        public static bool Import(Models.PortalExport export, string portalId)
        {
            var idMap = new Dictionary <string, string>();

            var portal = GetPortalById(portalId);

            if (portal != null)
            {
                export.Portal.Id      = portal.Id;
                export.Portal.Name    = portal.Name; //IMPORTANT:  since we pass in the portalId that we want to import into, we need to ensure that is used, therefore, the name must match as that is how the duplicate lookup is done.  (i.e. {Id: 1, Name=Default} {Id: 2, Name=Foo}.  If we import Id:2 and its name importing is Default)
                export.Portal.Default = portal.Default;
            }
            else
            {
                throw new Exception("Portal Not found: " + portalId);
            }

            Save(export.Portal);
            portal = GetPortal(export.Portal.Name);
            SetIdMap <Models.Portal>(portal.Id, export.Portal.Id, idMap);

            if (export.Roles != null)
            {
                Logging.Logger.DebugFormat("Importing {0} roles...", export.Roles.Count);
                foreach (var role in export.Roles)
                {
                    SetIdMap <Models.Role>(role.Id, Account.ImportRole(portal.Id, role), idMap);
                }
            }
            if (export.Users != null)
            {
                Logging.Logger.DebugFormat("Importing {0} users...", export.Users.Count);
                foreach (var exportUser in export.Users)
                {
                    SetIdMap <Models.User>(exportUser.Id, Account.ImportUser(portal.Id, exportUser, idMap), idMap);
                }
            }

            if (export.SecureActivities != null)
            {
                Logging.Logger.DebugFormat("Importing {0} secure activities...", export.SecureActivities.Count);
                foreach (var exportActivity in export.SecureActivities)
                {
                    SetIdMap <Models.SecureActivity>(exportActivity.Id, Security.Import(portal.Id, exportActivity, idMap), idMap);
                }
            }

            if (export.Files != null)
            {
                Logging.Logger.DebugFormat("Importing {0} files...", export.Files.Count);

                //todo:  embed file base64???
                foreach (var file in export.Files)
                {
                    var origId = file.Id;
                    SetIdMap <Models.File>(file.Id, File.Import(portal.Id, file), idMap);
                    if (export.FileContent.ContainsKey(origId))
                    {
                        var fileName = Portal.GetFile(file.PortalId, file.Id);
                        if (System.IO.File.Exists(fileName))
                        {
                            System.IO.File.Delete(fileName);
                        }
                        export.FileContent[origId].Base64ToFile(fileName);
                    }
                }
            }

            if (export.Manifests != null)
            {
                Logging.Logger.DebugFormat("Importing {0} manifests...", export.Manifests.Count);
                foreach (var manifest in export.Manifests)
                {
                    SetIdMap <Models.WidgetManifest>(manifest.Id, Import(manifest), idMap);
                }
            }
            if (export.Localizations != null)
            {
                Logging.Logger.DebugFormat("Importing {0} localizations...", export.Localizations.Count);
                foreach (var exportLocalization in export.Localizations)
                {
                    SetIdMap <Models.Localization>(exportLocalization.Id, Localization.Import(portal.Id, exportLocalization), idMap);
                }
            }
            if (export.Templates != null)
            {
                Logging.Logger.DebugFormat("Importing {0} page templates...", export.Templates.Count);
                foreach (var exportTemplate in export.Templates)
                {
                    SetIdMap <Models.PageTemplate>(exportTemplate.Id, Import(portal.Id, exportTemplate, export.WidgetContent, idMap), idMap);
                }
            }
            if (export.LayoutTemplates != null)
            {
                Logging.Logger.DebugFormat("Importing {0} layout templates...", export.LayoutTemplates.Count);
                foreach (var exportTemplate in export.LayoutTemplates)
                {
                    SetIdMap <Models.LayoutTemplate>(exportTemplate.Id, Import(portal.Id, exportTemplate, export.WidgetContent, idMap), idMap);
                }
            }
            return(true);
        }