private static SPSite CreateSite(SPWebApplication webApp, SPSiteSubscription siteSubscription, string webTemplate, string title, string description, string ownerName, string ownerEmail, string quota, string secondaryContactName, string secondaryContactEmail, bool useHostHeaderAsSiteName, uint nLCID, Uri uri, string ownerLogin, string secondaryContactLogin, SPContentDatabase database)
        {
            if (database != null && database.MaximumSiteCount <= database.CurrentSiteCount)
            {
                throw new SPException("The maximum site count for the specified database has been exceeded.  Increase the maximum site count or specify another database.");
            }

            Logger.Write("PROGRESS: Creating site collection...");
            SPSite site = null;

            if (database != null)
            {
                site = database.Sites.Add(siteSubscription, uri.OriginalString, title, description, nLCID, webTemplate, ownerLogin,
                                          ownerName, ownerEmail, secondaryContactLogin, secondaryContactName, secondaryContactEmail,
                                          useHostHeaderAsSiteName);
            }
            else
            {
                site = webApp.Sites.Add(siteSubscription, uri.OriginalString, title, description, nLCID, webTemplate, ownerLogin,
                                        ownerName, ownerEmail, secondaryContactLogin, secondaryContactName, secondaryContactEmail,
                                        useHostHeaderAsSiteName);
            }
            Logger.Write("PROGRESS: Site collection successfully created.");

            if (!string.IsNullOrEmpty(quota))
            {
                Logger.Write("PROGRESS: Associating quota template with site collection...");
                using (SPSiteAdministration administration = new SPSiteAdministration(site.Url))
                {
                    SPFarm       farm       = SPFarm.Local;
                    SPWebService webService = farm.Services.GetValue <SPWebService>("");

                    SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates;
                    administration.Quota = quotaColl[quota];
                }
            }
            if (!string.IsNullOrEmpty(webTemplate))
            {
                Logger.Write("PROGRESS: Creating default security groups...");
                using (SPWeb web = site.RootWeb)
                {
                    web.CreateDefaultAssociatedGroups(ownerLogin, secondaryContactLogin, string.Empty);
                }
            }

            return(site);
        }