Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new portal.
        /// </summary>
        /// <param name="PortalName">Name of the portal to be created</param>
        /// <param name="FirstName">Portal Administrator's first name</param>
        /// <param name="LastName">Portal Administrator's last name</param>
        /// <param name="Username">Portal Administrator's username</param>
        /// <param name="Password">Portal Administrator's password</param>
        /// <param name="Email">Portal Administrator's email</param>
        /// <param name="Description">Description for the new portal</param>
        /// <param name="KeyWords">KeyWords for the new portal</param>
        /// <param name="TemplatePath">Path where the templates are stored</param>
        /// <param name="TemplateFile">Template file</param>
        /// <param name="PortalAlias">Portal Alias String</param>
        /// <param name="ServerPath">The Path to the root of the Application</param>
        /// <param name="ChildPath">The Path to the Child Portal Folder</param>
        /// <param name="IsChildPortal">True if this is a child portal</param>
        /// <returns>PortalId of the new portal if there are no errors, -1 otherwise.</returns>
        /// <remarks>
        /// After the selected portal template is parsed the admin template ("admin.template") will be
        /// also processed. The admin template should only contain the "Admin" menu since it's the same
        /// on all portals. The selected portal template can contain a <settings/> node to specify portal
        /// properties and a <roles/> node to define the roles that will be created on the portal by default.
        /// </remarks>
        /// <history>
        /// 	[cnurse]	11/08/2004	created (most of this code was moved from SignUp.ascx.vb)
        /// </history>
        public int CreatePortal( string PortalName, string FirstName, string LastName, string Username, string Password, string Email, string Description, string KeyWords, string TemplatePath, string TemplateFile, string HomeDirectory, string PortalAlias, string ServerPath, string ChildPath, bool IsChildPortal )
        {
            FolderController objFolderController = new FolderController();
            string strMessage = Null.NullString;
            int AdministratorId = Null.NullInteger;
            UserInfo objAdminUser = new UserInfo();

            //Attempt to create a new portal
            int intPortalId = CreatePortal( PortalName, HomeDirectory );

            if( intPortalId != -1 )
            {
                if( HomeDirectory == "" )
                {
                    HomeDirectory = "Portals/" + intPortalId.ToString();
                }
                string MappedHomeDirectory = objFolderController.GetMappedDirectory( Globals.ApplicationPath + "/" + HomeDirectory + "/" );

                strMessage += CreateProfileDefinitions( intPortalId, TemplatePath, TemplateFile );
                if( strMessage == Null.NullString )
                {
                    // add administrator
                    try
                    {
                        objAdminUser.PortalID = intPortalId;
                        objAdminUser.FirstName = FirstName;
                        objAdminUser.LastName = LastName;
                        objAdminUser.Username = Username;
                        objAdminUser.DisplayName = FirstName + " " + LastName;
                        objAdminUser.Membership.Password = Password;
                        objAdminUser.Email = Email;
                        objAdminUser.IsSuperUser = false;
                        objAdminUser.Membership.Approved = true;

                        objAdminUser.Profile.FirstName = FirstName;
                        objAdminUser.Profile.LastName = LastName;

                        UserCreateStatus createStatus = UserController.CreateUser( ref objAdminUser );

                        if( createStatus == UserCreateStatus.Success )
                        {
                            AdministratorId = objAdminUser.UserID;
                        }
                        else
                        {
                            strMessage += UserController.GetUserCreateStatus( createStatus );
                        }
                    }
                    catch( Exception Exc )
                    {
                        strMessage += Localization.GetString( "CreateAdminUser.Error" ) + Exc.Message + Exc.StackTrace;
                    }
                }
                else
                {
                    throw new Exception( strMessage );
                }

                if( strMessage == "" & 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 )
                    {
                        strMessage += Localization.GetString( "DeleteUploadFolder.Error" ) + Exc.Message + Exc.StackTrace;
                    }

                    //Set up Child Portal
                    if( strMessage == Null.NullString )
                    {
                        try
                        {
                            if( IsChildPortal )
                            {
                                // create the subdirectory for the new portal
                                if( !( Directory.Exists( ChildPath ) ) )
                                {
                                    Directory.CreateDirectory( ChildPath );
                                }

                                // create the subhost default.aspx file
                                if( !( File.Exists( ChildPath + "\\" + Globals.glbDefaultPage ) ) )
                                {
                                    File.Copy( Globals.HostMapPath + "subhost.aspx", ChildPath + "\\" + Globals.glbDefaultPage );
                                }
                            }
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "ChildPortal.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        try
                        {
                            // create the upload directory for the new portal
                            Directory.CreateDirectory( MappedHomeDirectory );

                            // copy the default stylesheet to the upload directory
                            File.Copy( Globals.HostMapPath + "portal.css", MappedHomeDirectory + "portal.css" );

                            // process zip resource file if present
                            ProcessResourceFile( MappedHomeDirectory, TemplatePath + TemplateFile );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "ChildPortal.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        // parse portal template
                        try
                        {
                            ParseTemplate( intPortalId, TemplatePath, TemplateFile, AdministratorId, PortalTemplateModuleAction.Replace, true );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "PortalTemplate.Error" ) + Exc.Message + Exc.StackTrace;
                        }

                        // parse admin template
                        try
                        {
                            ParseTemplate( intPortalId, TemplatePath, "admin.template", AdministratorId, PortalTemplateModuleAction.Replace, true );
                        }
                        catch( Exception Exc )
                        {
                            strMessage += Localization.GetString( "AdminTemplate.Error" ) + Exc.Message + Exc.StackTrace;
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }

                    if( strMessage == Null.NullString )
                    {
                        // update portal setup
                        PortalInfo objportal = GetPortal( intPortalId );

                        // update portal info
                        objportal.Description = Description;
                        objportal.KeyWords = KeyWords;
                        UpdatePortalInfo( objportal.PortalID, objportal.PortalName, objportal.LogoFile, objportal.FooterText, objportal.ExpiryDate, objportal.UserRegistration, objportal.BannerAdvertising, objportal.Currency, objportal.AdministratorId, objportal.HostFee, objportal.HostSpace, objportal.PageQuota, objportal.UserQuota, objportal.PaymentProcessor, objportal.ProcessorUserId, objportal.ProcessorPassword, objportal.Description, objportal.KeyWords, objportal.BackgroundFile, objportal.SiteLogHistory, objportal.SplashTabId, objportal.HomeTabId, objportal.LoginTabId, objportal.UserTabId, objportal.DefaultLanguage, objportal.TimeZoneOffset, objportal.HomeDirectory );

                        //Update Administrators Locale/TimeZone
                        objAdminUser.Profile.PreferredLocale = objportal.DefaultLanguage;
                        objAdminUser.Profile.TimeZone = objportal.TimeZoneOffset;

                        //Save Admin User
                        UserController.UpdateUser( objportal.PortalID, objAdminUser );

                        //clear portal alias cache
                        DataCache.ClearHostCache( true );

                        // clear roles cache
                        DataCache.RemoveCache( "GetRoles" );

                        //Create Portal Alias
                        AddPortalAlias( intPortalId, PortalAlias );

                        // log installation event
                        try
                        {
                            LogInfo objEventLogInfo = new LogInfo();
                            objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                            objEventLogInfo.LogTypeKey = EventLogController.EventLogType.HOST_ALERT.ToString();
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Install Portal:", PortalName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "FirstName:", FirstName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "LastName:", LastName ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Username:"******"Email:", Email ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Description:", Description ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "Keywords:", KeyWords ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "TemplatePath:", TemplatePath ) );
                            objEventLogInfo.LogProperties.Add( new LogDetailInfo( "TemplateFile:", TemplateFile ) );
                            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() ) );
                            EventLogController objEventLog = new EventLogController();
                            objEventLog.AddLog( objEventLogInfo );
                        }
                        catch( Exception ex )
                        {
                            // error
                        }
                    }
                    else
                    {
                        throw new Exception( strMessage );
                    }
                }
                else // clean up
                {
                    DeletePortalInfo( intPortalId );
                    intPortalId = -1;
                    throw new Exception( strMessage );
                }
            }
            else
            {
                strMessage += Localization.GetString( "CreatePortal.Error" );
                throw new Exception( strMessage );
            }

            return intPortalId;
        }