Пример #1
0
        /// <summary>
        /// Load info for a portal template
        /// </summary>
        /// <param name="templatePath">Full path to the portal template</param>
        /// <param name="cultureCode">the culture code if any for the localization of the portal template</param>
        /// <returns>A portal template</returns>
        public PortalTemplateInfo GetPortalTemplate(string templatePath, string cultureCode)
        {
            var template = new PortalTemplateInfo(templatePath, cultureCode);

            if(!string.IsNullOrEmpty(cultureCode) && template.CultureCode != cultureCode)
            {
                return null;
            }

            return template;
        }
Пример #2
0
        /// <summary>
        /// Creates the portal.
        /// </summary>
        /// <param name="portalName">Name of the portal.</param>
        /// <param name="adminUser">The obj admin user.</param>
        /// <param name="description">The description.</param>
        /// <param name="keyWords">The key words.</param>
        /// <param name="template"> </param>
        /// <param name="homeDirectory">The home directory.</param>
        /// <param name="portalAlias">The portal alias.</param>
        /// <param name="serverPath">The server path.</param>
        /// <param name="childPath">The child path.</param>
        /// <param name="isChildPortal">if set to <c>true</c> means the portal is child portal.</param>
        /// <returns>Portal id.</returns>
        public int CreatePortal(string portalName, UserInfo adminUser, string description, string keyWords, PortalTemplateInfo template, 
                                string homeDirectory, string portalAlias, string serverPath, string childPath, bool isChildPortal)
        {
            string message = Null.NullString;
            int administratorId = Null.NullInteger;

            //Attempt to create a new portal
            int portalId = CreatePortal(portalName, homeDirectory);

            string templatePath, templateFile;
            PrepareLocalizedPortalTemplate(template, out templatePath, out templateFile);
            string mergedTemplatePath = Path.Combine(templatePath, templateFile);

            if (portalId != -1)
            {
                if (String.IsNullOrEmpty(homeDirectory))
                {
                    homeDirectory = "Portals/" + portalId;
                }
                string mappedHomeDirectory = String.Format(Globals.ApplicationMapPath + "\\" + homeDirectory + "\\").Replace("/", "\\");
                message += CreateProfileDefinitions(portalId, mergedTemplatePath);
                if (message == Null.NullString)
                {
                    //add administrator
                    try
                    {
                        adminUser.PortalID = portalId;
                        UserCreateStatus createStatus = UserController.CreateUser(ref adminUser);
                        if (createStatus == UserCreateStatus.Success)
                        {
                            administratorId = adminUser.UserID;
                            //reload the UserInfo as when it was first created, it had no portal id and therefore
                            //used host profile definitions
                            adminUser = UserController.GetUserById(adminUser.PortalID, adminUser.UserID);
                        }
                        else
                        {
                            message += UserController.GetUserCreateStatus(createStatus);
                        }
                    }
                    catch (Exception Exc)
                    {
                        Logger.Error(Exc);
                        message += Localization.GetString("CreateAdminUser.Error") + Exc.Message + Exc.StackTrace;
                    }
                }
                else
                {
                    throw new Exception(message);
                }
                if (String.IsNullOrEmpty(message) && administratorId > 0)
                {
                    try
                    {
                        //the upload directory may already exist if this is a new DB working with a previously installed application
                        if (Directory.Exists(mappedHomeDirectory))
                        {
                            Globals.DeleteFolderRecursive(mappedHomeDirectory);
                        }
                    }
                    catch (Exception Exc)
                    {
                        Logger.Error(Exc);
                        message += Localization.GetString("DeleteUploadFolder.Error") + Exc.Message + Exc.StackTrace;
                    }

                    //Set up Child Portal
                    if (message == Null.NullString)
                    {
                        if (isChildPortal)
                        {
                            message = CreateChildPortalFolder(childPath);
                        }
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                    if (message == Null.NullString)
                    {
                        try
                        {
                            //create the upload directory for the new portal
                            Directory.CreateDirectory(mappedHomeDirectory);
                            //ensure that the Templates folder exists
                            string templateFolder = String.Format("{0}Templates", mappedHomeDirectory);
                            if (!Directory.Exists(templateFolder))
                            {
                                Directory.CreateDirectory(templateFolder);
                            }

                            //ensure that the Users folder exists
                            string usersFolder = String.Format("{0}Users", mappedHomeDirectory);
                            if (!Directory.Exists(usersFolder))
                            {
                                Directory.CreateDirectory(usersFolder);
                            }

                            //copy the default page template
                            CopyPageTemplate("Default.page.template", mappedHomeDirectory);

                            // process zip resource file if present
                            if (File.Exists(template.ResourceFilePath))
                            {
                                ProcessResourceFileExplicit(mappedHomeDirectory, template.ResourceFilePath);
                            }

							//copy getting started css into portal's folder.
							var hostGettingStartedFile = string.Format("{0}GettingStarted.css", Globals.HostMapPath);
							if (File.Exists(hostGettingStartedFile))
							{
								var portalFile = mappedHomeDirectory + "GettingStarted.css";
								if (!File.Exists(portalFile))
								{
									File.Copy(hostGettingStartedFile, portalFile);
								}
							}
                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);
                            message += Localization.GetString("ChildPortal.Error") + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                    if (message == Null.NullString)
                    {
                        try
                        {
                            FolderMappingController.Instance.AddDefaultFolderTypes(portalId);
                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);
                            message += Localization.GetString("DefaultFolderMappings.Error") + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception(message);
                    }

                    LocaleCollection newPortalLocales = null;
                    if (message == Null.NullString)
                    {
                        try
                        {
                            ParseTemplate(portalId, templatePath, templateFile, administratorId, PortalTemplateModuleAction.Replace, true, out newPortalLocales);
                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);
                            message += Localization.GetString("PortalTemplate.Error") + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                    if (message == Null.NullString)
                    {
                        var portal = GetPortal(portalId);
						portal.Description = description;
						portal.KeyWords = keyWords;
						portal.UserTabId = TabController.GetTabByTabPath(portal.PortalID, "//UserProfile", portal.CultureCode);
                        if (portal.UserTabId == -1)
                        {
                            portal.UserTabId = TabController.GetTabByTabPath(portal.PortalID, "//ActivityFeed", portal.CultureCode);
                        }
                        portal.SearchTabId = TabController.GetTabByTabPath(portal.PortalID, "//SearchResults", portal.CultureCode);
						UpdatePortalInfo(portal);
						adminUser.Profile.PreferredLocale = portal.DefaultLanguage;
						var portalSettings = new PortalSettings(portal);
						adminUser.Profile.PreferredTimeZone = portalSettings.TimeZone;
						UserController.UpdateUser(portal.PortalID, adminUser);
                        DesktopModuleController.AddDesktopModulesToPortal(portalId);
                        AddPortalAlias(portalId, portalAlias);

                        if (newPortalLocales != null)
                        {
                            foreach (Locale newPortalLocale in newPortalLocales.AllValues)
                            {
                                Localization.AddLanguageToPortal(portalId, newPortalLocale.LanguageId, false);
                            }
                        }

                        try
                        {
                            RelationshipController.Instance.CreateDefaultRelationshipsForPortal(portalId);
                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);                            
                        }

                        //add profanity list to new portal
                        try
                        {
                            const string listName = "ProfanityFilter";
                            var listController = new ListController();
                            var entry = new ListEntryInfo();
                            entry.PortalID = portalId;
                            entry.SystemList = false;
                            entry.ListName = listName + "-" + portalId;
                            listController.AddListEntry(entry);

                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);
                        }

                        //add banned password list to new portal
                        try
                        {
                            const string listName = "BannedPasswords";
                            var listController = new ListController();
                            var entry = new ListEntryInfo();
                            entry.PortalID = portalId;
                            entry.SystemList = false;
                            entry.ListName = listName + "-" + portalId;
                            listController.AddListEntry(entry);

                        }
                        catch (Exception Exc)
                        {
                            Logger.Error(Exc);
                        }

                        // Add default workflows
                        try
                        {
                            ContentWorkflowController.Instance.CreateDefaultWorkflows(portalId);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex);
                        }

                        ServicesRoutingManager.ReRegisterServiceRoutesWhileSiteIsRunning();

                        try
                        {
                            var objEventLogInfo = new LogInfo();
                            objEventLogInfo.BypassBuffering = true;
                            objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("Install Portal:", portalName));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("FirstName:", adminUser.FirstName));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("LastName:", adminUser.LastName));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("Username:"******"Email:", adminUser.Email));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("Description:", description));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("Keywords:", keyWords));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("Template:", template.TemplateFilePath));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("TemplateCulture:", template.CultureCode));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("HomeDirectory:", homeDirectory));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("PortalAlias:", portalAlias));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("ServerPath:", serverPath));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("ChildPath:", childPath));
                            objEventLogInfo.LogProperties.Add(new LogDetailInfo("IsChildPortal:", isChildPortal.ToString()));
                            var eventLog = new EventLogController();
                            eventLog.AddLog(objEventLogInfo);
                        }
                        catch (Exception exc)
                        {
                            Logger.Error(exc);
                        }
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                }
                else
                {
                    DeletePortalInfo(portalId);
                    portalId = -1;
                    throw new Exception(message);
                }
            }
            else
            {
                message += Localization.GetString("CreatePortal.Error");
                throw new Exception(message);
            }
            return portalId;
        }
Пример #3
0
 /// <summary>
 /// Processess a template file for the new portal.
 /// </summary>
 /// <param name="portalId">PortalId of the new portal</param>
 /// <param name="template">The template</param>
 /// <param name="administratorId">UserId for the portal administrator. This is used to assign roles to this user</param>
 /// <param name="mergeTabs">Flag to determine whether Module content is merged.</param>
 /// <param name="isNewPortal">Flag to determine is the template is applied to an existing portal or a new one.</param>
 /// <remarks>
 /// The roles and settings nodes will only be processed on the portal template file.
 /// </remarks>
 public void ParseTemplate(int portalId, PortalTemplateInfo template, int administratorId, PortalTemplateModuleAction mergeTabs, bool isNewPortal)
 {
     string templatePath, templateFile;
     PrepareLocalizedPortalTemplate(template, out templatePath, out templateFile);
     
     ParseTemplate(portalId, templatePath, templateFile, administratorId, mergeTabs, isNewPortal);
 }
Пример #4
0
		private void PrepareLocalizedPortalTemplate(PortalTemplateInfo template, out string templatePath, out string templateFile)
		{
			if (string.IsNullOrEmpty(template.LanguageFilePath))
			{
				//no language to merge
				templatePath = Path.GetDirectoryName(template.TemplateFilePath) + @"\";
				templateFile = Path.GetFileName(template.TemplateFilePath);
				return;
			}

			templatePath = Path.Combine(TestableGlobals.Instance.HostMapPath, "MergedTemplate");
			Directory.CreateDirectory(templatePath);

			var buffer = new StringBuilder(File.ReadAllText(template.TemplateFilePath));

			XDocument languageDoc;
			using (var reader = PortalTemplateIO.Instance.OpenTextReader(template.LanguageFilePath))
			{
				languageDoc = XDocument.Load(reader);
			}

			var localizedData = languageDoc.Descendants("data");

			foreach (var item in localizedData)
			{
				var nameAttribute = item.Attribute("name");
				if (nameAttribute != null)
				{
					string name = nameAttribute.Value;
					var valueElement = item.Descendants("value").FirstOrDefault();
					if (valueElement != null)
					{
						string value = valueElement.Value;

						buffer = buffer.Replace(string.Format("[{0}]", name), value);
					}
				}
			}

			templateFile = string.Format("Merged-{0}-{1}", template.CultureCode, Path.GetFileName(template.TemplateFilePath));

			File.WriteAllText(Path.Combine(templatePath, templateFile), buffer.ToString());
		}