Example #1
0
        public Site CreateNewSite(string name, string description, string email, string siteHost, Theme theme)
        {
            if (theme == null)
            throw new NullReferenceException("a default theme is mandatory to create a new site");

             // Site
             Site site = new Site
             {
            Name = name,
            Description = description,
            AllowRegistration = false,
            EnableCaptchaForComments = false,
            AllowPasswordRetrieval = true,
            DefaultCulture = "en-US",
            TimeZone = 0,
            Email = string.IsNullOrEmpty(email) ? "*****@*****.**" : email,
            MaxPostsPerPage = 10,
            MaxCommentsPerPage = 50,
            MaxLinksInComments = 3,
            MaxSyndicationFeeds = 10,
            AllowComments = true,
            AllowCommentsOnlyForRegisteredUsers = false,
            SortCommentsFromOlderToNewest = true,
            FeedUseSummary = true,
            ShowAvatars = true,
            Theme = theme,
            CreatedDate = DateTime.Now.ToUniversalTime()
             };

             // Site Host
             SiteHost host = new SiteHost
             {
            HostName = siteHost,
            IsDefault = true,
            Site = site,
            CreatedDate = DateTime.Now.ToUniversalTime()
             };

             site.Hosts.Add(host);

             //// Site Host for Control Panel
             //SiteHost cpHost = new SiteHost
             //{
             //   HostName = "admin." + siteHost,
             //   IsDefault = false,
             //   Site = site,
             //   CreatedDate = DateTime.Now.ToUniversalTime()
             //};

             //site.Hosts.Add(cpHost);

             SeoSettings seo = new SeoSettings
             {
            Site = site,
            PostTitleFormat = "%post_title% | %blog_title%",
            PageTitleFormat = "%page_title% | %blog_title%",
            CategoryTitleFormat = "%category_title% | %blog_title%",
            TagTitleFormat = "%tag% | %blog_title%",
            SearchTitleFormat = "%search% | %blog_title%",
            ArchiveTitleFormat = "%date% | %blog_title%",
            Page404TitleFormat = "Nothing found for %request_words%",
            DescriptionFormat = "%description%",
            UseCategoriesForMeta = true,
            GenerateKeywordsForPost = true,
            UseNoIndexForArchives = true,
            UseNoIndexForCategories = true,
            UseNoIndexForTags = false,
            GenerateDescriptions = true,
            CapitalizeCategoryTitles = true,
            RewriteTitles = true,
            HomeDescription = "",
            HomeKeywords = "",
            HomeTitle = ""
             };
             //site.SeoSettings = seo;

             //using (INHTransactionScope tx = new NHTransactionScope())
             //{
            log.Debug("SiteService.CreateNewSite: Saving new site...");

            // Save the new site
            SaveSite(site);

            // this is ...odd, but if I comment the following 3 lines I get an error
            // from NH: Could not perform Save for Site ---> NHibernate.PropertyValueException: not-null property references a null or transient valueArashi.Core.Domain.SeoSettings.Site
            site.SeoSettings = seo;
            SaveSeoSettings(seo);
            SaveSite(site);

            log.Debug("SiteService.CreateNewSite: Site saved...");

            log.Debug("SiteService.CreateNewSite: Creating default roles...");

            // create default roles
            userService.CreateDefaultRoles(site);

            //tx.VoteCommit();
            log.Debug("SiteService.CreateNewSite: Transaction commit");
             //}

             log.Debug("SiteService.CreateNewSite: Creating Site folder structure - Start");

             // Create SiteData folder structure
             string siteDataRoot = HttpContext.Current.Server.MapPath(site.SiteDataPath);
             log.Debug("Install.CreateSite: siteDataRoot = " + siteDataRoot);

             DirectoryInfo di = new DirectoryInfo(siteDataRoot);

             // Check if the parent folder is writable
             if (di.Parent != null && !fileService.CheckIfDirectoryIsWritable(di.Parent.FullName))
            throw new IOException(string.Format("Unable to create the site because the directory {0} is not writable.", siteDataRoot));

             string siteDataPhysicalDirectory = siteDataRoot; //Path.Combine(siteDataRoot, site.SiteId.ToString());

             fileService.CreateDirectory(siteDataPhysicalDirectory);
             //CreateDirectory(Path.Combine(siteDataPhysicalDirectory, "UserFiles"));
             fileService.CreateDirectory(Path.Combine(siteDataPhysicalDirectory, "index"));

             log.Debug("SiteService.CreateNewSite: Creating Site folder structure - End");

             return site;
        }
Example #2
0
        public void SaveSiteHost(SiteHost siteHost)
        {
            //using (INHTransactionScope tx = new NHTransactionScope())
             //{
            // Clear query cache first
            //session.SessionFactory.EvictQueries("Sites");
            Repository<Site>.ClearSecondLevelCache();
            Repository<SiteHost>.Save(siteHost);

             //   tx.VoteCommit();
             //}
        }
Example #3
0
        public void SaveSiteHost(SiteHost siteHost, string newHostName, bool isDefault)
        {
            //using (INHTransactionScope tx = new NHTransactionScope())
             //{
            // Clear query cache first
            //session.SessionFactory.EvictQueries("Sites");
            Repository<Site>.ClearSecondLevelCache();

            SiteHost oldDefaultHost = GetDefaultSiteHost(siteHost.Site);

            // if the updated host is set as default, check if it is different fromn the default sitehost,
            // in that case swap the default host
            if (isDefault && oldDefaultHost != null && oldDefaultHost != siteHost)
            {
               oldDefaultHost.IsDefault = false;
               Repository<SiteHost>.Save(oldDefaultHost);
            }

            // Save host
            siteHost.HostName = newHostName;
            siteHost.IsDefault = isDefault;
            Repository<SiteHost>.Save(siteHost);

             //   tx.VoteCommit();
             //}
        }
Example #4
0
        public void DeleteSiteHost(SiteHost siteHost)
        {
            // If is the last host don't delete it
             if (siteHost.Site.Hosts.Count == 1)
             {
            log.WarnFormat("SiteService.DeleteSiteHost: Can't delete the host {0} because is the only one for the site", siteHost.HostName);
            return;
             }

             //using (INHTransactionScope tx = new NHTransactionScope())
             //{
            bool wasDefault = siteHost.IsDefault;

            Site site = siteHost.Site;
            site.Hosts.Remove(siteHost);
            Repository<SiteHost>.Delete(siteHost);
            Repository<Site>.Save(site);

            // if the deleted host was the default, then set as default a new one
            if (wasDefault)
            {
               SiteHost newDefaultSiteHost = site.Hosts[0];
               newDefaultSiteHost.IsDefault = true;
               Repository<SiteHost>.Save(newDefaultSiteHost);
            }

             //   tx.VoteCommit();
             //}
        }