/// <summary> Checks and sets disk quotas values.</summary> /// <param name="organization"> The organization.</param> /// <param name="collection"> The site collection.</param> private void SetStorageQuotas(Organization organization, SharePointEnterpriseSiteCollection collection) { var quotaValue = organization.MaxSharePointEnterpriseStorage; if (quotaValue != -1) { var spaceResrved = GetReservedDiskStorageSpace(); if (spaceResrved > quotaValue) { quotaValue = 0; } else { quotaValue -= spaceResrved; } if (collection != null) { quotaValue += (int)collection.MaxSiteStorage; } } maxStorage.ParentQuotaValue = quotaValue; maxStorage.QuotaValue = quotaValue; editMaxStorage.ParentQuotaValue = quotaValue; warningStorage.ParentQuotaValue = quotaValue; warningStorage.QuotaValue = quotaValue; editWarningStorage.ParentQuotaValue = quotaValue; btnUpdate.Enabled = quotaValue != 0; }
private void SaveItem() { if (!Page.IsValid) { return; } if (this.SiteCollectionId == 0) { if (this.userSelector.GetAccount() == null) { localMessageBox.ShowWarningMessage("HOSTEDSHAREPOINT_NO_USERS"); return; } // new item try { item = new SharePointEnterpriseSiteCollection(); if (!UseSharedSLL(PanelSecurity.PackageId)) { SharePointEnterpriseSiteCollectionListPaged existentSiteCollections = ES.Services.HostedSharePointServersEnt.Enterprise_GetSiteCollectionsPaged(PanelSecurity.PackageId, this.OrganizationId, "ItemName", String.Format("%{0}", this.domain.DomainName), String.Empty, 0, Int32.MaxValue); foreach (SharePointEnterpriseSiteCollection existentSiteCollection in existentSiteCollections.SiteCollections) { Uri existentSiteCollectionUri = new Uri(existentSiteCollection.Name); if (existentSiteCollection.Name == String.Format("{0}://{1}", existentSiteCollectionUri.Scheme, this.txtHostName.Text.ToLower() + "." + this.domain.DomainName)) { localMessageBox.ShowWarningMessage("HOSTEDSHAREPOINT_DOMAIN_IN_USE"); return; } } item.Name = this.txtHostName.Text.ToLower() + "." + this.domain.DomainName; } else item.Name = string.Empty; // get form data item.OrganizationId = this.OrganizationId; item.Id = this.SiteCollectionId; item.PackageId = PanelSecurity.PackageId; item.LocaleId = Int32.Parse(this.ddlLocaleID.SelectedValue); item.OwnerLogin = this.userSelector.GetSAMAccountName(); item.OwnerEmail = this.userSelector.GetPrimaryEmailAddress(); item.OwnerName = this.userSelector.GetDisplayName(); item.Title = txtTitle.Text; item.Description = txtDescription.Text; item.MaxSiteStorage = maxStorage.QuotaValue; item.WarningStorage = warningStorage.QuotaValue; int result = ES.Services.HostedSharePointServersEnt.Enterprise_AddSiteCollection(item); if (result < 0) { localMessageBox.ShowResultMessage(result); return; } } catch (Exception ex) { localMessageBox.ShowErrorMessage("HOSTEDSHAREPOINT_ADD_SITECOLLECTION", ex); return; } } else { ES.Services.HostedSharePointServersEnt.Enterprise_UpdateQuota(PanelRequest.ItemID, SiteCollectionId, editMaxStorage.QuotaValue, editWarningStorage.QuotaValue); } // return RedirectToSiteCollectionsList(); }
/// <summary> /// Adds SharePoint site collection. /// </summary> /// <param name="item">Site collection description.</param> /// <returns>Created site collection id within metabase.</returns> public static int AddSiteCollection(SharePointEnterpriseSiteCollection item) { // Check account. int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return accountCheck; } // Check package. int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return packageCheck; } // Check quota. OrganizationStatistics orgStats = OrganizationController.GetOrganizationStatisticsByOrganization(item.OrganizationId); //QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_SITES); if (orgStats.AllocatedSharePointEnterpriseSiteCollections > -1 && orgStats.CreatedSharePointEnterpriseSiteCollections >= orgStats.AllocatedSharePointEnterpriseSiteCollections) { return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT; } // Check if stats resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharepointEnterpriseServer); if (serviceId == 0) { return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE; } StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(serviceId); QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_ENTERPRISE_USESHAREDSSL); Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]); Organization org = OrganizationController.GetOrganization(item.OrganizationId); string siteName = item.Name; if (quota.QuotaAllocatedValue == 1) { string sslRoot = hostedSharePointSettings["SharedSSLRoot"]; string defaultDomain = org.DefaultDomain; string hostNameBase = string.Empty; string[] tmp = defaultDomain.Split('.'); if (tmp.Length == 2) { hostNameBase = tmp[0]; } else { if (tmp.Length > 2) { hostNameBase = tmp[0] + tmp[1]; } } int counter = 0; item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, hostNameBase + "-" + counter.ToString() + "." + sslRoot); siteName = String.Format("{0}", hostNameBase + "-" + counter.ToString() + "." + sslRoot); while (DataProvider.CheckServiceItemExists(serviceId, item.Name, "WebsitePanel.Providers.SharePoint.SharePointEnterpriseSiteCollection, WebsitePanel.Providers.Base")) { counter++; item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, hostNameBase + "-" + counter.ToString() + "." + sslRoot); siteName = String.Format("{0}", hostNameBase + "-" + counter.ToString() + "." + sslRoot); } } else item.Name = String.Format("{0}://{1}", rootWebApplicationUri.Scheme, item.Name); if (rootWebApplicationUri.Port > 0 && rootWebApplicationUri.Port != 80 && rootWebApplicationUri.Port != 443) { item.PhysicalAddress = String.Format("{0}:{1}", item.Name, rootWebApplicationUri.Port); } else { item.PhysicalAddress = item.Name; } if (Utils.ParseBool(hostedSharePointSettings["LocalHostFile"], false)) { item.RootWebApplicationInteralIpAddress = hostedSharePointSettings["RootWebApplicationInteralIpAddress"]; item.RootWebApplicationFQDN = item.Name.Replace(rootWebApplicationUri.Scheme + "://", ""); } item.MaxSiteStorage = RecalculateMaxSize(org.MaxSharePointEnterpriseStorage, (int)item.MaxSiteStorage); item.WarningStorage = item.MaxSiteStorage == -1 ? -1 : Math.Min((int)item.WarningStorage, item.MaxSiteStorage); // Check package item with given name already exists. if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointEnterpriseSiteCollection)) != null) { return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS; } // Log operation. TaskManager.StartTask("HOSTED_SHAREPOINT_ENTERPRISE", "ADD_SITE_COLLECTION", item.Name); try { // Create site collection on server. HostedSharePointServerEnt hostedSharePointServer = GetHostedSharePointServer(serviceId); hostedSharePointServer.Enterprise_CreateSiteCollection(item); // Make record in metabase. item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); hostedSharePointServer.Enterprise_SetPeoplePickerOu(item.Name, org.DistinguishedName); int dnsServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Dns); if (dnsServiceId > 0) { string[] tmpStr = siteName.Split('.'); string hostName = tmpStr[0]; string domainName = siteName.Substring(hostName.Length + 1, siteName.Length - (hostName.Length + 1)); List<GlobalDnsRecord> dnsRecords = ServerController.GetDnsRecordsByService(serviceId); List<DnsRecord> resourceRecords = DnsServerController.BuildDnsResourceRecords(dnsRecords, hostName, domainName, ""); DNSServer dns = new DNSServer(); ServiceProviderProxy.Init(dns, dnsServiceId); // add new resource records dns.AddZoneRecords(domainName, resourceRecords.ToArray()); } TaskManager.ItemId = itemId; return itemId; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public int Enterprise_AddSiteCollection(SharePointEnterpriseSiteCollection item) { return HostedSharePointServerEntController.AddSiteCollection(item); }
/// <summary>Restores site collection under given url from backup.</summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">Site collection to be restored.</param> /// <param name="filename">Backup file name to restore from.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> public void RestoreSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection, string filename) { string url = siteCollection.Url; try { string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port); HostedSolutionLog.LogStart("RestoreSiteCollection"); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); HostedSolutionLog.DebugInfo("backupFilePath: {0}", filename); Runspace runspace = null; try { string tempPath = Path.GetTempPath(); string expandedFile = filename; if (Path.GetExtension(filename).ToLower() == ".zip") { expandedFile = FileUtils.UnzipFiles(filename, tempPath)[0]; // Delete zip archive. FileUtils.DeleteFile(filename); } runspace = OpenRunspace(); DeleteSiteCollection(runspace, siteCollectionUrl, false); var command = new Command("Restore-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); command.Parameters.Add("Path", filename); ExecuteShellCommand(runspace, command); command = new Command("Set-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); command.Parameters.Add("OwnerAlias", siteCollection.OwnerLogin); ExecuteShellCommand(runspace, command); command = new Command("Set-SPUser"); command.Parameters.Add("Identity", siteCollection.OwnerLogin); command.Parameters.Add("Email", siteCollection.OwnerEmail); command.Parameters.Add("DisplayName", siteCollection.Name); ExecuteShellCommand(runspace, command); FileUtils.DeleteFile(expandedFile); } finally { CloseRunspace(runspace); HostedSolutionLog.LogEnd("RestoreSiteCollection"); } } catch (Exception ex) { throw new InvalidOperationException("Failed to restore site collection.", ex); } }
/// <remarks/> public void Enterprise_AddSiteCollectionAsync(SharePointEnterpriseSiteCollection item) { this.Enterprise_AddSiteCollectionAsync(item, null); }
/// <remarks/> public System.IAsyncResult BeginEnterprise_RestoreSiteCollection(SharePointEnterpriseSiteCollection siteCollection, string filename, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("Enterprise_RestoreSiteCollection", new object[] { siteCollection, filename}, callback, asyncState); }
/// <summary> Creates site collection within predefined root web application.</summary> /// <param name="runspace"> The runspace.</param> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">Information about site coolection to be created.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> private void CreateCollection(Runspace runspace, Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection) { string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); try { SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri); rootWebApplication.Sites.Add(siteCollectionUrl, siteCollection.Title, siteCollection.Description, (uint) siteCollection.LocaleId, String.Empty, siteCollection.OwnerLogin, siteCollection.OwnerName, siteCollection.OwnerEmail, null, null, null, true); rootWebApplication.Update(); } catch (Exception) { DeleteSiteCollection(runspace, siteCollectionUrl, true); throw; } try { GrantAccess(runspace, rootWebApplicationUri); var command = new Command("Set-SPSite"); command.Parameters.Add("Identity", siteCollectionUrl); if (siteCollection.MaxSiteStorage != -1) { command.Parameters.Add("MaxSize", siteCollection.MaxSiteStorage*1024*1024); } if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1) { command.Parameters.Add("WarningSize", Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage)*1024*1024); } ExecuteShellCommand(runspace, command); } catch (Exception) { DeleteQuotaTemplate(siteCollection.Title); DeleteSiteCollection(runspace, siteCollectionUrl, true); throw; } AddHostsRecord(siteCollection); }
/// <remarks/> public void Enterprise_DeleteSiteCollectionAsync(SharePointEnterpriseSiteCollection siteCollection) { this.Enterprise_DeleteSiteCollectionAsync(siteCollection, null); }
public void Enterprise_RestoreSiteCollection(SharePointEnterpriseSiteCollection siteCollection, string filename) { this.Invoke("Enterprise_RestoreSiteCollection", new object[] { siteCollection, filename}); }
/// <remarks/> public System.IAsyncResult BeginEnterprise_DeleteSiteCollection(SharePointEnterpriseSiteCollection siteCollection, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("Enterprise_DeleteSiteCollection", new object[] { siteCollection}, callback, asyncState); }
public void Enterprise_DeleteSiteCollection(SharePointEnterpriseSiteCollection siteCollection) { this.Invoke("Enterprise_DeleteSiteCollection", new object[] { siteCollection}); }
/// <remarks/> public void Enterprise_AddSiteCollectionAsync(SharePointEnterpriseSiteCollection item, object userState) { if ((this.Enterprise_AddSiteCollectionOperationCompleted == null)) { this.Enterprise_AddSiteCollectionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnEnterprise_AddSiteCollectionOperationCompleted); } this.InvokeAsync("Enterprise_AddSiteCollection", new object[] { item}, this.Enterprise_AddSiteCollectionOperationCompleted, userState); }
private void BindItem() { try { if (!IsPostBack) { if (!this.IsDnsServiceAvailable()) { localMessageBox.ShowWarningMessage("HOSTEDSHAREPOINT_NO_DNS"); } // load item if required if (this.SiteCollectionId > 0) { // existing item item = ES.Services.HostedSharePointServersEnt.Enterprise_GetSiteCollection(this.SiteCollectionId); if (item != null) { // save package info ViewState["PackageId"] = item.PackageId; } else RedirectToBrowsePage(); } else { // new item ViewState["PackageId"] = PanelSecurity.PackageId; if (UseSharedSLL(PanelSecurity.PackageId)) { rowUrl.Visible = false; valRequireHostName.Enabled = false; valRequireCorrectHostName.Enabled = false; } } //this.gvUsers.DataBind(); List<CultureInfo> cultures = new List<CultureInfo>(); foreach (int localeId in ES.Services.HostedSharePointServersEnt.Enterprise_GetSupportedLanguages(PanelSecurity.PackageId)) { cultures.Add(new CultureInfo(localeId, false)); } this.ddlLocaleID.DataSource = cultures; this.ddlLocaleID.DataBind(); } if (!IsPostBack) { // bind item to controls if (item != null) { // bind item to controls lnkUrl.Text = item.PhysicalAddress; lnkUrl.NavigateUrl = item.PhysicalAddress; litSiteCollectionOwner.Text = String.Format("{0} ({1})", item.OwnerName, item.OwnerEmail); litLocaleID.Text = new CultureInfo(item.LocaleId, false).DisplayName; litTitle.Text = item.Title; litDescription.Text = item.Description; editWarningStorage.QuotaValue = (int)item.WarningStorage; editMaxStorage.QuotaValue = (int)item.MaxSiteStorage; } Organization org = ES.Services.Organizations.GetOrganization(OrganizationId); if (org != null) { SetStorageQuotas(org, item); } } //OrganizationDomainName[] domains = ES.Services.Organizations.GetOrganizationDomains(PanelRequest.ItemID); //DomainInfo[] domains = ES.Services.Servers.GetMyDomains(PanelSecurity.PackageId); EnterpriseServer.DomainInfo[] domains = ES.Services.Servers.GetDomains(PanelSecurity.PackageId); if (domains.Length == 0) { localMessageBox.ShowWarningMessage("HOSTEDSHAREPOINT_NO_DOMAINS"); DisableFormControls(this, btnCancel); return; } //if (this.gvUsers.Rows.Count == 0) //{ // localMessageBox.ShowWarningMessage("HOSTEDSHAREPOINT_NO_USERS"); // DisableFormControls(this, btnCancel); // return; //} } catch { localMessageBox.ShowWarningMessage("INIT_SERVICE_ITEM_FORM"); DisableFormControls(this, btnCancel); return; } }
/// <remarks/> public void Enterprise_RestoreSiteCollectionAsync(SharePointEnterpriseSiteCollection siteCollection, string filename) { this.Enterprise_RestoreSiteCollectionAsync(siteCollection, filename, null); }
/// <summary> Creates site collection within predefined root web application.</summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">Information about site coolection to be created.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> public void CreateSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection) { HostedSolutionLog.LogStart("CreateSiteCollection"); WindowsImpersonationContext wic = null; Runspace runspace = null; try { wic = WindowsIdentity.GetCurrent().Impersonate(); runspace = OpenRunspace(); CreateCollection(runspace, rootWebApplicationUri, siteCollection); } finally { CloseRunspace(runspace); HostedSolutionLog.LogEnd("CreateSiteCollection"); if (wic != null) { wic.Undo(); } } }
/// <remarks/> public void Enterprise_RestoreSiteCollectionAsync(SharePointEnterpriseSiteCollection siteCollection, string filename, object userState) { if ((this.Enterprise_RestoreSiteCollectionOperationCompleted == null)) { this.Enterprise_RestoreSiteCollectionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnEnterprise_RestoreSiteCollectionOperationCompleted); } this.InvokeAsync("Enterprise_RestoreSiteCollection", new object[] { siteCollection, filename}, this.Enterprise_RestoreSiteCollectionOperationCompleted, userState); }
/// <summary>Deletes site collection under given url.</summary> /// <param name="rootWebApplicationUri">Root web application uri.</param> /// <param name="siteCollection">The site collection to be deleted.</param> /// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception> public void DeleteSiteCollection(Uri rootWebApplicationUri, SharePointEnterpriseSiteCollection siteCollection) { HostedSolutionLog.LogStart("DeleteSiteCollection"); Runspace runspace = null; try { string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port); HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl); runspace = OpenRunspace(); DeleteSiteCollection(runspace, siteCollectionUrl, false); RemoveHostsRecord(siteCollection); } catch (Exception ex) { throw new InvalidOperationException("Failed to delete site collection.", ex); } finally { CloseRunspace(runspace); HostedSolutionLog.LogEnd("DeleteSiteCollection"); } }
/// <summary> /// Gets list of SharePoint site collections that belong to the package. /// </summary> /// <param name="packageId">Package that owns site collections.</param> /// <param name="recursive">A value which shows whether nested spaces must be searched as well.</param> /// <returns>List of found site collections.</returns> public static List<SharePointEnterpriseSiteCollection> GetSiteCollections(int packageId, bool recursive) { if (IsDemoMode) { List<SharePointEnterpriseSiteCollection> demoResult = new List<SharePointEnterpriseSiteCollection>(); SharePointEnterpriseSiteCollection siteCollection1 = new SharePointEnterpriseSiteCollection(); siteCollection1.Id = 1; siteCollection1.OrganizationId = 1; siteCollection1.LocaleId = 1033; siteCollection1.Name = "http://john.fabrikam.com"; siteCollection1.OwnerEmail = "*****@*****.**"; siteCollection1.OwnerLogin = "******"; siteCollection1.OwnerName = "John Smith"; siteCollection1.PhysicalAddress = "http://john.fabrikam.com"; siteCollection1.Title = "John Smith's Team Site"; siteCollection1.Url = "http://john.fabrikam.com"; demoResult.Add(siteCollection1); SharePointEnterpriseSiteCollection siteCollection2 = new SharePointEnterpriseSiteCollection(); siteCollection2.Id = 2; siteCollection1.OrganizationId = 1; siteCollection2.LocaleId = 1033; siteCollection2.Name = "http://mark.contoso.com"; siteCollection2.OwnerEmail = "*****@*****.**"; siteCollection2.OwnerLogin = "******"; siteCollection2.OwnerName = "Mark Jonsons"; siteCollection2.PhysicalAddress = "http://mark.contoso.com"; siteCollection2.Title = "Mark Jonsons' Blog"; siteCollection2.Url = "http://mark.contoso.com"; demoResult.Add(siteCollection2); return demoResult; } List<ServiceProviderItem> items = PackageController.GetPackageItemsByType(packageId, typeof(SharePointEnterpriseSiteCollection), recursive); return items.ConvertAll<SharePointEnterpriseSiteCollection>(delegate(ServiceProviderItem item) { return (SharePointEnterpriseSiteCollection)item; }); }
/// <summary>Removes record from hosts file.</summary> /// <param name="siteCollection">The site collection object.</param> private void RemoveHostsRecord(SharePointEnterpriseSiteCollection siteCollection) { try { if (siteCollection.RootWebApplicationInteralIpAddress != string.Empty) { string dirPath = FileUtils.EvaluateSystemVariables(@"%windir%\system32\drivers\etc"); string path = dirPath + "\\hosts"; if (FileUtils.FileExists(path)) { string content = FileUtils.GetFileTextContent(path); content = content.Replace("\r\n", "\n").Replace("\n\r", "\n"); string[] contentArr = content.Split(new[] {'\n'}); string outPut = string.Empty; foreach (string s in contentArr) { if (s != string.Empty) { string hostName = string.Empty; if (s[0] != '#') { bool bSeperator = false; foreach (char c in s) { if ((c != ' ') & (c != '\t')) { if (bSeperator) { hostName += c; } } else { bSeperator = true; } } if (hostName.ToLower() != siteCollection.RootWebApplicationFQDN.ToLower()) { outPut += s + "\r\n"; } } else { outPut += s + "\r\n"; } } } FileUtils.UpdateFileTextContent(path, outPut); } } } catch (Exception ex) { HostedSolutionLog.LogError(ex); } }
public int Enterprise_AddSiteCollection(SharePointEnterpriseSiteCollection item) { object[] results = this.Invoke("Enterprise_AddSiteCollection", new object[] { item}); return ((int)(results[0])); }