internal static KitsuneWebsiteCollection CreateDefaultWebsite(string projectId, string projectName, string developerEmail, string clientId) { try { if (_kitsuneServer == null) { InitializeConnection(); } var userCollection = _kitsuneDatabase.GetCollection <UserModel>(KitsuneUserCollectionName); var websiteCollection = _kitsuneDatabase.GetCollection <KitsuneWebsiteCollection>(KitsuneWebsiteCollectionName); UserModel userDetails = userCollection.Find(x => x.UserName.Equals(developerEmail)).Limit(1).FirstOrDefault(); #region GENERATE WEBSITETAG AND WEBSITEURL bool?isSSLEnabled = null; // Removes all special characters if (projectName.ToLower().Trim().StartsWith("http://")) { isSSLEnabled = false; } string websiteTag = projectName.Replace("http://", "", StringComparison.InvariantCultureIgnoreCase) .Replace("https://", "", StringComparison.InvariantCultureIgnoreCase) .Replace("www.", "", StringComparison.InvariantCultureIgnoreCase); websiteTag = Regex.Replace(websiteTag, @"[^0-9a-zA-Z]+", "").ToUpper(); websiteTag = $"{websiteTag}DEFAULT"; //If the same name website tag exist use {projectname_developerfirstname_01} var existingWebsites = websiteCollection.Find(x => x.WebsiteTag == websiteTag).Count(); if (existingWebsites > 0) { Random random = new Random(); websiteTag = websiteTag + random.Next(100, 999); } var basePlugin = BasePluginConfigGenerator.GetBasePlugin(clientId); //update clientId if the id is not present clientId = basePlugin.GetClientId(); string websiteDomain = websiteTag.ToUpper() + basePlugin.GetSubDomain(); #endregion //Create new customer KitsuneWebsiteCollection customerDetails = CreateNewWebsite(projectId, websiteTag, developerEmail, userDetails.PhoneNumber, developerEmail, websiteDomain, userDetails._id, clientId, isSSLEnabled: isSSLEnabled); return(customerDetails); } catch (Exception ex) { throw ex; } }
public static void CreateAndUpdateDemoScreenShot(string projectId) { //Get Project Details //Create absolute Url of demo //Call screenshot API //Update KitsuneProject Collection with new Screenshot if (string.IsNullOrEmpty(projectId)) { throw new ArgumentNullException(nameof(projectId)); } try { if (_kitsuneServer == null) { InitializeConnection(); } #region INITIALISE var kitsuneProjectCollection = _kitsuneDatabase.GetCollection <KitsuneProject>(KitsuneProjectsCollectionName); var defaultProjectCollection = _kitsuneDatabase.GetCollection <KitsuneWebsiteCollection>(KitsuneWebsiteCollectionName); #endregion #region CREATE DEMO URI KitsuneWebsiteCollection websiteCollection = defaultProjectCollection.Find(x => x.ProjectId.Equals(projectId)).FirstOrDefault(); Uri uri = Helpers.GetDemoUri(websiteCollection._id); #endregion #region CALL SCREENSHOT API var screenShotUrl = APIHelper.TakeScreenShotForDemoWebsite(projectId, uri); #endregion #region UPDATE SCREENSHOT URL IN DB var updateDefination = Builders <KitsuneProject> .Update.Set(x => x.ScreenShotUrl, screenShotUrl); kitsuneProjectCollection.UpdateOne(x => x.ProjectId.Equals(projectId), updateDefination); #endregion } catch (Exception ex) { //LOG: Error with ProjectId } }
/// <summary> /// Kitsune website creation with default website user /// </summary> /// <param name="projectId"></param> /// <param name="websiteTag"></param> /// <param name="customerMail"></param> /// <param name="customerPhoneNumber"></param> /// <param name="developerEmail"></param> /// <param name="websiteUrl"></param> /// <param name="developerId"></param> /// <returns></returns> internal static KitsuneWebsiteCollection CreateNewWebsite(string projectId, string websiteTag, string customerMail, string customerPhoneNumber, string developerEmail, string websiteUrl, string developerId, string clientId, string customerName = null, string domain = null, string customWebsiteId = null, bool?isSSLEnabled = true) { try { if (_kitsuneServer == null) { InitializeConnection(); } var kitsuneWebsiteCollection = _kitsuneDatabase.GetCollection <KitsuneWebsiteCollection>(KitsuneWebsiteCollectionName); var websiteDNSCollection = _kitsuneDatabase.GetCollection <WebsiteDNSInfo>(KitsuneWebsiteDNSInfoCollectionName); var userCollection = _kitsuneDatabase.GetCollection <KitsuneWebsiteUserCollection>(KitsuneWebsiteUserCollectionName); DateTime datetime = DateTime.Now; ObjectId websiteId = ObjectId.GenerateNewId(); //if the custom website id is present and is valid objectid then assign it if (!string.IsNullOrEmpty(customWebsiteId)) { if (!ObjectId.TryParse(customWebsiteId, out websiteId)) { websiteId = ObjectId.GenerateNewId(); } } #region GENERATE USERNAME AND PASSWORD PasswordGenerator passwordGenerator = new PasswordGenerator(); var password = passwordGenerator.GeneratePassword(true, true, true, 7); var userName = passwordGenerator.GenerateUserName(websiteTag); if (String.IsNullOrEmpty(password)) { throw new Exception($"Error generating password"); } if (String.IsNullOrEmpty(userName)) { throw new Exception($"Error generating userName"); } #endregion #region VERIFY IF WEBSITETAG ALREADY PRESENT OR NOT var count = kitsuneWebsiteCollection.Count(x => x.WebsiteTag.Equals(websiteTag) && x.ClientId == clientId); if (count > 0) { throw new Exception("Unable to get the KitsuneTag"); ////String kitsuneTag = kitsuneUrl.Split('.').First(); //if (string.IsNullOrEmpty(websiteTag)) // throw new Exception("Unable to get the KitsuneTag"); //Random random = new Random(); //var basePlugin = BasePluginConfigGenerator.GetBasePlugin(clientId); //kitsuneUrl = kitsuneTag + random.Next(100, 999) + basePlugin.GetSubDomain(); } #endregion #region CREATE NEW WEBSITE IN WEBSITECOLLECTION (WITH SUBDOMAIN AS WEBSITEURL) KitsuneWebsiteCollection websiteObject = new KitsuneWebsiteCollection { _id = websiteId.ToString(), UpdatedOn = datetime, CreatedOn = datetime, DeveloperId = developerId, WebsiteTag = websiteTag, ProjectId = projectId, IsArchived = false, IsActive = false, WebsiteUrl = websiteUrl, ClientId = clientId }; kitsuneWebsiteCollection.InsertOne(websiteObject); #endregion #region CREATE NEW RECORD IN WEBSITEDNSCOLLECTION (FOR SUBDOMAIN AS ACTIVE STATUS AND ALSO FOR REQUESTED DOMAIN IF PROVIDED WITH PENDING STATUS) var websiteDNSObj = new WebsiteDNSInfo { CreatedOn = datetime, DNSStatus = DNSStatus.Active, DomainName = websiteUrl.ToUpper(), IsSSLEnabled = isSSLEnabled ?? true, RootPath = websiteUrl.ToUpper(), WebsiteId = websiteObject._id }; websiteDNSCollection.InsertOne(websiteDNSObj); if (!string.IsNullOrEmpty(domain)) { websiteDNSObj = new WebsiteDNSInfo { CreatedOn = datetime, DNSStatus = DNSStatus.Pending, DomainName = domain.ToUpper(), IsSSLEnabled = isSSLEnabled ?? false, //default is false for custom domain RootPath = domain.ToUpper(), WebsiteId = websiteObject._id }; websiteDNSCollection.InsertOne(websiteDNSObj); } #endregion #region CREATE NEW WEBISITE USER FOR THE ABOVE CREATED WEBSITE (WITH OWNER ACCESSTYPE) var websiteUser = new KitsuneWebsiteUserCollection { DeveloperId = developerId, WebsiteId = websiteObject._id, AccessType = KitsuneWebsiteAccessType.Owner, UserName = websiteTag, CreatedOn = DateTime.UtcNow, IsActive = true, Password = password, Contact = new ContactDetails { Email = customerMail, PhoneNumber = customerPhoneNumber, FullName = customerName ?? websiteTag }, }; userCollection.InsertOne(websiteUser); #endregion return(websiteObject); } catch (Exception ex) { throw ex; } }