示例#1
0
        public static Models.PortalExport ExportTemplates(string portalId, bool includeFileContent, Models.PortalExport export = null)
        {
            export = export != null ? export : GetPortalExport(portalId);
            if (export.Roles == null)
            {
                export.Roles = Account.GetRoles(portalId);    //we need mapping of roles!
            }
            if (export.SecureActivities == null)
            {
                export.SecureActivities = Security.GetSecureActivities();    //we need mapping of roles!
            }
            export.Manifests = GetWidgetManifests();
            export.Files     = File.Get(portalId); //todo:  somehow export file?!?!
            export.Templates = GetPageTemplates(portalId);

            export.LayoutTemplates = GetLayoutTemplates(portalId);

            //grab all widgets that have a content provider and create dictionary of <WidgetId, ContentJson>
            //TODO:  guard against no widgets with content???!?
            var allWidgets = new List <Models.Widget>();

            allWidgets.AddRange(export.Templates.SelectMany(w => w.Widgets).Where(w => w.Manifest.GetContentProvider() != null));
            allWidgets.AddRange(export.LayoutTemplates.SelectMany(w => w.Widgets).Where(w => w.Manifest.GetContentProvider() != null));
            allWidgets           = allWidgets.Distinct(w => w.Id).ToList(); //since content can be shared between widgets, we only want to store it once!
            export.WidgetContent = allWidgets.ToDictionary(w => w.Id, wc => wc.GetContentJson());

            if (includeFileContent)
            {
                export.FileContent = new Dictionary <string, string>();
                foreach (var file in export.Files)
                {
                    export.FileContent[file.Id] = Portal.GetFile(portalId, file.Id).GetFileBase64();
                }
            }
            return(export);
        }
示例#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);
        }