diff --git a/WebsitePanel/Database/QuotasSharepoint.sql b/WebsitePanel/Database/QuotasSharepoint.sql
new file mode 100644
index 00000000..d3b94426
--- /dev/null
+++ b/WebsitePanel/Database/QuotasSharepoint.sql
@@ -0,0 +1 @@
+INSERT INTO Quotas (QuotaID, GroupID, QuotaOrder, QuotaName,QuotaDescription, QuotaTypeID, ServiceQuota) VALUES (400, 20, 3, 'HostedSharePoint.UseSharedSSL' ,'Use shared SSL Root', 1, 0)
\ No newline at end of file
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Packages/Quotas.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Packages/Quotas.cs
index b1362844..0f353415 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Packages/Quotas.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer.Base/Packages/Quotas.cs
@@ -136,7 +136,8 @@ order by rg.groupOrder
public const string SHAREPOINT_SITES = "SharePoint.Sites"; // SharePoint Sites
public const string HOSTED_SHAREPOINT_SITES = "HostedSharePoint.Sites"; // Hosted SharePoint Sites
public const string HOSTED_SHAREPOINT_STORAGE_SIZE = "HostedSharePoint.MaxStorage"; // Hosted SharePoint storage size;
- public const string DNS_EDITOR = "DNS.Editor"; // DNS Editor
+ public const string HOSTED_SHAREPOINT_USESHAREDSSL = "HostedSharePoint.UseSharedSSL"; // Hosted SharePoint Use Shared SSL Root
+ public const string DNS_EDITOR = "DNS.Editor"; // DNS Editor
public const string DNS_ZONES = "DNS.Zones"; // DNS Editor
public const string DNS_PRIMARY_ZONES = "DNS.PrimaryZones"; // DNS Editor
public const string DNS_SECONDARY_ZONES = "DNS.SecondaryZones"; // DNS Editor
diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/SharePoint/HostedSharePointServerController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/SharePoint/HostedSharePointServerController.cs
index ea1011a2..8d149714 100644
--- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/SharePoint/HostedSharePointServerController.cs
+++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/SharePoint/HostedSharePointServerController.cs
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, Outercurve Foundation.
+// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -40,26 +40,26 @@ using WebsitePanel.Providers.SharePoint;
namespace WebsitePanel.EnterpriseServer.Code.SharePoint
{
- ///
- /// Exposes handful API on hosted SharePoint site collections management.
- ///
- public class HostedSharePointServerController : IImportController, IBackupController
- {
- private const int FILE_BUFFER_LENGTH = 5000000; // ~5MB
+ ///
+ /// Exposes handful API on hosted SharePoint site collections management.
+ ///
+ public class HostedSharePointServerController : IImportController, IBackupController
+ {
+ private const int FILE_BUFFER_LENGTH = 5000000; // ~5MB
- ///
- /// Gets site collections in raw form.
- ///
- /// Package to which desired site collections belong.
- /// Organization to which desired site collections belong.
- /// Filter column name.
- /// Filter value.
- /// Sort column name.
- /// Row index to start from.
- /// Maximum number of rows to retrieve.
- /// Site collections that match.
- public static SharePointSiteCollectionListPaged GetSiteCollectionsPaged(int packageId, int organizationId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
- {
+ ///
+ /// Gets site collections in raw form.
+ ///
+ /// Package to which desired site collections belong.
+ /// Organization to which desired site collections belong.
+ /// Filter column name.
+ /// Filter value.
+ /// Sort column name.
+ /// Row index to start from.
+ /// Maximum number of rows to retrieve.
+ /// Site collections that match.
+ public static SharePointSiteCollectionListPaged GetSiteCollectionsPaged(int packageId, int organizationId, string filterColumn, string filterValue, string sortColumn, int startRow, int maximumRows)
+ {
if (IsDemoMode)
{
SharePointSiteCollectionListPaged demoResult = new SharePointSiteCollectionListPaged();
@@ -68,35 +68,35 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
return demoResult;
}
- SharePointSiteCollectionListPaged paged = new SharePointSiteCollectionListPaged();
- DataSet result = PackageController.GetRawPackageItemsPaged(packageId, typeof(SharePointSiteCollection),
- true, filterColumn, filterValue, sortColumn, startRow, Int32.MaxValue);
- List items = PackageController.CreateServiceItemsList(result, 1).ConvertAll(delegate(ServiceProviderItem item) { return (SharePointSiteCollection)item; });
+ SharePointSiteCollectionListPaged paged = new SharePointSiteCollectionListPaged();
+ DataSet result = PackageController.GetRawPackageItemsPaged(packageId, typeof(SharePointSiteCollection),
+ true, filterColumn, filterValue, sortColumn, startRow, Int32.MaxValue);
+ List items = PackageController.CreateServiceItemsList(result, 1).ConvertAll(delegate(ServiceProviderItem item) { return (SharePointSiteCollection)item; });
- if (organizationId > 0)
- {
- items = items.FindAll(delegate(SharePointSiteCollection siteCollection) { return siteCollection.OrganizationId == organizationId; });
- }
- paged.TotalRowCount = items.Count;
+ if (organizationId > 0)
+ {
+ items = items.FindAll(delegate(SharePointSiteCollection siteCollection) { return siteCollection.OrganizationId == organizationId; });
+ }
+ paged.TotalRowCount = items.Count;
- if (items.Count > maximumRows)
- {
- items.RemoveRange(maximumRows, items.Count - maximumRows);
- }
+ if (items.Count > maximumRows)
+ {
+ items.RemoveRange(maximumRows, items.Count - maximumRows);
+ }
- paged.SiteCollections = items;
+ paged.SiteCollections = items;
- return paged;
- }
+ return paged;
+ }
public static List GetSiteCollections(int organizationId)
{
Organization org = OrganizationController.GetOrganization(organizationId);
-
- List items = PackageController.GetPackageItemsByType(org.PackageId, typeof(SharePointSiteCollection), false);
+
+ List items = PackageController.GetPackageItemsByType(org.PackageId, typeof(SharePointSiteCollection), false);
items.ConvertAll(delegate(ServiceProviderItem item) { return (SharePointSiteCollection)item; });
List ret = new List();
- foreach(ServiceProviderItem item in items)
+ foreach (ServiceProviderItem item in items)
{
SharePointSiteCollection siteCollection = item as SharePointSiteCollection;
if (siteCollection != null && siteCollection.OrganizationId == organizationId)
@@ -104,54 +104,54 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
ret.Add(siteCollection);
}
}
-
- return ret;
+
+ return ret;
}
- ///
- /// Gets list of supported languages by this installation of SharePoint.
- ///
- /// List of supported languages
- public static int[] GetSupportedLanguages(int packageId)
- {
+ ///
+ /// Gets list of supported languages by this installation of SharePoint.
+ ///
+ /// List of supported languages
+ public static int[] GetSupportedLanguages(int packageId)
+ {
if (IsDemoMode)
{
- return new int[] {1033};
+ return new int[] { 1033 };
}
- // Log operation.
- TaskManager.StartTask("HOSTEDSHAREPOINT", "GET_LANGUAGES");
+ // Log operation.
+ TaskManager.StartTask("HOSTEDSHAREPOINT", "GET_LANGUAGES");
- int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedSharePoint);
- if (serviceId == 0)
- {
- return new int[]{};
- }
+ int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedSharePoint);
+ if (serviceId == 0)
+ {
+ return new int[] { };
+ }
- try
- {
- // Create site collection on server.
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
- return hostedSharePointServer.GetSupportedLanguages();
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
+ try
+ {
+ // Create site collection on server.
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
+ return hostedSharePointServer.GetSupportedLanguages();
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ TaskManager.CompleteTask();
+ }
+ }
- ///
- /// Gets list of SharePoint site collections that belong to the package.
- ///
- /// Package that owns site collections.
- /// A value which shows whether nested spaces must be searched as well.
- /// List of found site collections.
- public static List GetSiteCollections(int packageId, bool recursive)
- {
+ ///
+ /// Gets list of SharePoint site collections that belong to the package.
+ ///
+ /// Package that owns site collections.
+ /// A value which shows whether nested spaces must be searched as well.
+ /// List of found site collections.
+ public static List GetSiteCollections(int packageId, bool recursive)
+ {
if (IsDemoMode)
{
List demoResult = new List();
@@ -183,592 +183,626 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
}
- List items = PackageController.GetPackageItemsByType(packageId, typeof(SharePointSiteCollection), recursive);
- return items.ConvertAll(delegate(ServiceProviderItem item) { return (SharePointSiteCollection)item; });
- }
+ List items = PackageController.GetPackageItemsByType(packageId, typeof(SharePointSiteCollection), recursive);
+ return items.ConvertAll(delegate(ServiceProviderItem item) { return (SharePointSiteCollection)item; });
+ }
- ///
- /// Gets SharePoint site collection with given id.
- ///
- /// Site collection id within metabase.
- /// Site collection or null in case no such item exist.
- public static SharePointSiteCollection GetSiteCollection(int itemId)
- {
+ ///
+ /// Gets SharePoint site collection with given id.
+ ///
+ /// Site collection id within metabase.
+ /// Site collection or null in case no such item exist.
+ public static SharePointSiteCollection GetSiteCollection(int itemId)
+ {
if (IsDemoMode)
{
- return GetSiteCollections(1, false)[itemId-1];
+ return GetSiteCollections(1, false)[itemId - 1];
}
- SharePointSiteCollection item = PackageController.GetPackageItem(itemId) as SharePointSiteCollection;
- return item;
- }
+ SharePointSiteCollection item = PackageController.GetPackageItem(itemId) as SharePointSiteCollection;
+ return item;
+ }
- ///
- /// Adds SharePoint site collection.
- ///
- /// Site collection description.
- /// Created site collection id within metabase.
- public static int AddSiteCollection(SharePointSiteCollection item)
- {
- string domainName = item.Name;
- // Check account.
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0)
- {
- return accountCheck;
- }
+ ///
+ /// Adds SharePoint site collection.
+ ///
+ /// Site collection description.
+ /// Created site collection id within metabase.
+ public static int AddSiteCollection(SharePointSiteCollection item)
+ {
- // Check package.
- int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0)
- {
- return packageCheck;
- }
+ // Check account.
+ int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
+ if (accountCheck < 0)
+ {
+ return accountCheck;
+ }
- // Check quota.
- OrganizationStatistics orgStats = OrganizationController.GetOrganizationStatistics(item.OrganizationId);
- //QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_SITES);
+ // Check package.
+ int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive);
+ if (packageCheck < 0)
+ {
+ return packageCheck;
+ }
- if (orgStats.AllocatedSharePointSiteCollections > -1
- && orgStats.CreatedSharePointSiteCollections >= orgStats.AllocatedSharePointSiteCollections)
- {
- return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT;
- }
+ // Check quota.
+ OrganizationStatistics orgStats = OrganizationController.GetOrganizationStatistics(item.OrganizationId);
+ //QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_SITES);
- // Check if stats resource is available
- int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.HostedSharePoint);
- if (serviceId == 0)
- {
- return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE;
- }
- StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(serviceId);
- Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]);
- 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 (orgStats.AllocatedSharePointSiteCollections > -1
+ && orgStats.CreatedSharePointSiteCollections >= orgStats.AllocatedSharePointSiteCollections)
+ {
+ return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT;
+ }
- Organization org = OrganizationController.GetOrganization(item.OrganizationId);
+ // Check if stats resource is available
+ int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.HostedSharePoint);
+ if (serviceId == 0)
+ {
+ return BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE;
+ }
+
+ StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(serviceId);
+ QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.HOSTED_SHAREPOINT_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.SharePointSiteCollection, 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.MaxSharePointStorage, (int)item.MaxSiteStorage);
- item.WarningStorage = item.MaxSiteStorage == -1 ? -1 : Math.Min((int)item.WarningStorage, 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(SharePointSiteCollection)) != null)
- {
- return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS;
- }
-
- // Log operation.
- TaskManager.StartTask("HOSTEDSHAREPOINT", "ADD_SITE_COLLECTION", item.Name);
+ if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSiteCollection)) != null)
+ {
+ return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS;
+ }
+
+ // Log operation.
+ TaskManager.StartTask("HOSTEDSHAREPOINT", "ADD_SITE_COLLECTION", item.Name);
+
+ try
+ {
+ // Create site collection on server.
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
- try
- {
- // Create site collection on server.
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
-
hostedSharePointServer.CreateSiteCollection(item);
- // Make record in metabase.
- item.ServiceId = serviceId;
- int itemId = PackageController.AddPackageItem(item);
- int dnsServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Dns);
- if (dnsServiceId > 0)
- {
- DomainInfo domain = ServerController.GetDomain(domainName);
- if (domain != null)
- {
- string website = domain.WebSiteName;
-
- if (!String.IsNullOrEmpty(domain.WebSiteName))
+ // Make record in metabase.
+ item.ServiceId = serviceId;
+ int itemId = PackageController.AddPackageItem(item);
+
+ hostedSharePointServer.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));
+
+ DomainInfo domain = ServerController.GetDomain(domainName);
+ if (domain != null)
+ {
+ string website = siteName;
+
+ DnsRecord[] records = ServerController.GetDnsZoneRecords(domain.DomainId);
+ foreach (DnsRecord record in records)
{
- DnsRecord[] records = ServerController.GetDnsZoneRecords(domain.DomainId);
- foreach (DnsRecord record in records)
+ if (record.RecordType.Equals(DnsRecordType.A) && (record.RecordName == hostName))
{
- if (record.RecordType.Equals(DnsRecordType.A) && String.IsNullOrEmpty(record.RecordName))
- {
- ServerController.DeleteDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, record.RecordData);
- break;
- }
- }
-
- }
- ServerController.AddDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"], 0);
- }
- }
-
- TaskManager.ItemId = itemId;
- return itemId;
- }
- catch(Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
-
- ///
- /// Deletes SharePoint site collection with given id.
- ///
- /// Site collection id within metabase.
- /// ?
- public static int DeleteSiteCollection(int itemId)
- {
- // Check account.
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0)
- {
- return accountCheck;
- }
-
- // Load original meta item
- SharePointSiteCollection origItem = (SharePointSiteCollection) PackageController.GetPackageItem(itemId);
- if (origItem == null)
- {
- return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND;
- }
-
- // Get service settings.
- StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(origItem.ServiceId);
- Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]);
- string domainName = origItem.Name.Replace(String.Format("{0}://", rootWebApplicationUri.Scheme), String.Empty);
-
- // Log operation.
- TaskManager.StartTask("HOSTEDSHAREPOINT", "DELETE_SITE", origItem.Name);
- TaskManager.ItemId = itemId;
-
- try
- {
- // Delete site collection on server.
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
- hostedSharePointServer.DeleteSiteCollection(origItem.Url);
- // Delete record in metabase.
- PackageController.DeletePackageItem(origItem.Id);
-
- int dnsServiceId = PackageController.GetPackageServiceId(origItem.PackageId, ResourceGroups.Dns);
- if (dnsServiceId > 0)
- {
- DomainInfo domain = ServerController.GetDomain(domainName);
- if (domain != null)
- {
- ServerController.DeleteDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"]);
- ServerController.DeleteDnsZoneRecord(domain.DomainId, "www", DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"]);
-
- if (!String.IsNullOrEmpty(domain.WebSiteName))
- {
- DnsRecord[] records = ServerController.GetDnsZoneRecords(domain.DomainId);
- foreach (DnsRecord record in records)
- {
- if (record.RecordType.Equals(DnsRecordType.A) && record.RecordName.Equals("www", StringComparison.CurrentCultureIgnoreCase))
- {
- ServerController.AddDnsZoneRecord(domain.DomainId, String.Empty, DnsRecordType.A,
- record.RecordData, 0);
- break;
- }
+ ServerController.DeleteDnsZoneRecord(domain.DomainId, hostName, DnsRecordType.A, record.RecordData);
+ break;
}
}
- }
- }
+ ServerController.AddDnsZoneRecord(domain.DomainId, hostName, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"], 0);
+ }
+ }
+ TaskManager.ItemId = itemId;
+ return itemId;
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ TaskManager.CompleteTask();
+ }
+ }
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
+ ///
+ /// Deletes SharePoint site collection with given id.
+ ///
+ /// Site collection id within metabase.
+ /// ?
+ public static int DeleteSiteCollection(int itemId)
+ {
+ // Check account.
+ int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
+ if (accountCheck < 0)
+ {
+ return accountCheck;
+ }
- ///
- /// Deletes SharePoint site collections which belong to organization.
- ///
- /// Site collection id within metabase.
- public static void DeleteSiteCollections(int organizationId)
- {
- Organization org = OrganizationController.GetOrganization(organizationId);
- SharePointSiteCollectionListPaged existentSiteCollections = GetSiteCollectionsPaged(org.PackageId, org.Id, String.Empty, String.Empty, String.Empty, 0, Int32.MaxValue);
- foreach (SharePointSiteCollection existentSiteCollection in existentSiteCollections.SiteCollections)
- {
- DeleteSiteCollection(existentSiteCollection.Id);
- }
- }
+ // Load original meta item
+ SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
+ if (origItem == null)
+ {
+ return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND;
+ }
- ///
- /// Backups SharePoint site collection.
- ///
- /// Site collection id within metabase.
- /// Backed up site collection file name.
- /// A value which shows whether back up must be archived.
- /// A value which shows whether created back up must be downloaded.
- /// Local folder to store downloaded backup.
- /// Created backup file name.
- public static string BackupSiteCollection(int itemId, string fileName, bool zipBackup, bool download, string folderName)
- {
- // Check account.
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0)
- {
- return null;
- }
+ // Get service settings.
+ StringDictionary hostedSharePointSettings = ServerController.GetServiceSettings(origItem.ServiceId);
+ Uri rootWebApplicationUri = new Uri(hostedSharePointSettings["RootWebApplicationUri"]);
+ string siteName = origItem.Name.Replace(String.Format("{0}://", rootWebApplicationUri.Scheme), String.Empty);
- // Load original meta item
- SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
- if (origItem == null)
- {
- return null;
- }
+ // Log operation.
+ TaskManager.StartTask("HOSTEDSHAREPOINT", "DELETE_SITE", origItem.Name);
+ TaskManager.ItemId = itemId;
- // Log operation.
- TaskManager.StartTask("HOSTEDSHAREPOINT", "BACKUP_SITE_COLLECTION", origItem.Name);
- TaskManager.ItemId = itemId;
+ try
+ {
+ // Delete site collection on server.
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
+ hostedSharePointServer.DeleteSiteCollection(origItem);
+ // Delete record in metabase.
+ PackageController.DeletePackageItem(origItem.Id);
- try
- {
- // Create site collection on server.
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
- string backFile = hostedSharePointServer.BackupSiteCollection(origItem.Name, fileName, zipBackup);
+ int dnsServiceId = PackageController.GetPackageServiceId(origItem.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));
- if (!download)
- {
- // Copy backup files to space folder.
- string relFolderName = FilesController.CorrectRelativePath(folderName);
- if (!relFolderName.EndsWith("\\"))
- {
- relFolderName = relFolderName + "\\";
- }
+ DomainInfo domain = ServerController.GetDomain(domainName);
+ if (domain != null)
+ {
+ ServerController.DeleteDnsZoneRecord(domain.DomainId, hostName, DnsRecordType.A, hostedSharePointSettings["RootWebApplicationIpAddress"]);
+ }
+ }
- // Create backup folder if not exists
- if (!FilesController.DirectoryExists(origItem.PackageId, relFolderName))
- {
- FilesController.CreateFolder(origItem.PackageId, relFolderName);
- }
+ return 0;
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ TaskManager.CompleteTask();
+ }
+ }
- string packageFile = relFolderName + Path.GetFileName(backFile);
+ ///
+ /// Deletes SharePoint site collections which belong to organization.
+ ///
+ /// Site collection id within metabase.
+ public static void DeleteSiteCollections(int organizationId)
+ {
+ Organization org = OrganizationController.GetOrganization(organizationId);
+ SharePointSiteCollectionListPaged existentSiteCollections = GetSiteCollectionsPaged(org.PackageId, org.Id, String.Empty, String.Empty, String.Empty, 0, Int32.MaxValue);
+ foreach (SharePointSiteCollection existentSiteCollection in existentSiteCollections.SiteCollections)
+ {
+ DeleteSiteCollection(existentSiteCollection.Id);
+ }
+ }
- // Delete destination file if exists
- if (FilesController.FileExists(origItem.PackageId, packageFile))
- {
- FilesController.DeleteFiles(origItem.PackageId, new string[] { packageFile });
- }
+ ///
+ /// Backups SharePoint site collection.
+ ///
+ /// Site collection id within metabase.
+ /// Backed up site collection file name.
+ /// A value which shows whether back up must be archived.
+ /// A value which shows whether created back up must be downloaded.
+ /// Local folder to store downloaded backup.
+ /// Created backup file name.
+ public static string BackupSiteCollection(int itemId, string fileName, bool zipBackup, bool download, string folderName)
+ {
+ // Check account.
+ int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
+ if (accountCheck < 0)
+ {
+ return null;
+ }
- byte[] buffer = null;
+ // Load original meta item
+ SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
+ if (origItem == null)
+ {
+ return null;
+ }
- int offset = 0;
- do
- {
- // Read remote content.
- buffer = hostedSharePointServer.GetTempFileBinaryChunk(backFile, offset, FILE_BUFFER_LENGTH);
+ // Log operation.
+ TaskManager.StartTask("HOSTEDSHAREPOINT", "BACKUP_SITE_COLLECTION", origItem.Name);
+ TaskManager.ItemId = itemId;
- // Write remote content.
- FilesController.AppendFileBinaryChunk(origItem.PackageId, packageFile, buffer);
+ try
+ {
+ // Create site collection on server.
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
+ string backFile = hostedSharePointServer.BackupSiteCollection(origItem.Name, fileName, zipBackup);
- offset += FILE_BUFFER_LENGTH;
- }
- while (buffer.Length == FILE_BUFFER_LENGTH);
- }
+ if (!download)
+ {
+ // Copy backup files to space folder.
+ string relFolderName = FilesController.CorrectRelativePath(folderName);
+ if (!relFolderName.EndsWith("\\"))
+ {
+ relFolderName = relFolderName + "\\";
+ }
- return backFile;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
+ // Create backup folder if not exists
+ if (!FilesController.DirectoryExists(origItem.PackageId, relFolderName))
+ {
+ FilesController.CreateFolder(origItem.PackageId, relFolderName);
+ }
- ///
- /// Restores SharePoint site collection.
- ///
- /// Site collection id within metabase.
- ///
- ///
- ///
- public static int RestoreSiteCollection(int itemId, string uploadedFile, string packageFile)
- {
- // Check account.
- int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
- if (accountCheck < 0)
- {
- return accountCheck;
- }
+ string packageFile = relFolderName + Path.GetFileName(backFile);
- // Load original meta item.
- SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
- if (origItem == null)
- {
- return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND;
- }
+ // Delete destination file if exists
+ if (FilesController.FileExists(origItem.PackageId, packageFile))
+ {
+ FilesController.DeleteFiles(origItem.PackageId, new string[] { packageFile });
+ }
- // Check package.
- int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);
- if (packageCheck < 0)
- {
- return packageCheck;
- }
+ byte[] buffer = null;
- // Log operation.
- TaskManager.StartTask("HOSTEDSHAREPOINT", "BACKUP_SITE_COLLECTION", origItem.Name);
- TaskManager.ItemId = itemId;
+ int offset = 0;
+ do
+ {
+ // Read remote content.
+ buffer = hostedSharePointServer.GetTempFileBinaryChunk(backFile, offset, FILE_BUFFER_LENGTH);
- try
- {
- // Create site collection on server.
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
+ // Write remote content.
+ FilesController.AppendFileBinaryChunk(origItem.PackageId, packageFile, buffer);
- string backupFile = null;
- if (!String.IsNullOrEmpty(packageFile))
- {
- // Copy package files to the remote SharePoint Server.
- string path = null;
- byte[] buffer = null;
+ offset += FILE_BUFFER_LENGTH;
+ }
+ while (buffer.Length == FILE_BUFFER_LENGTH);
+ }
- int offset = 0;
- do
- {
- // Read package file.
- buffer = FilesController.GetFileBinaryChunk(origItem.PackageId, packageFile, offset, FILE_BUFFER_LENGTH);
+ return backFile;
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ TaskManager.CompleteTask();
+ }
+ }
- // Write remote backup file
- string tempPath = hostedSharePointServer.AppendTempFileBinaryChunk(Path.GetFileName(packageFile), path, buffer);
- if (path == null)
- {
- path = tempPath;
- backupFile = path;
- }
+ ///
+ /// Restores SharePoint site collection.
+ ///
+ /// Site collection id within metabase.
+ ///
+ ///
+ ///
+ public static int RestoreSiteCollection(int itemId, string uploadedFile, string packageFile)
+ {
+ // Check account.
+ int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
+ if (accountCheck < 0)
+ {
+ return accountCheck;
+ }
- offset += FILE_BUFFER_LENGTH;
- }
- while (buffer.Length == FILE_BUFFER_LENGTH);
- }
- else if (!String.IsNullOrEmpty(uploadedFile))
- {
- // Upladed files.
- backupFile = uploadedFile;
- }
+ // Load original meta item.
+ SharePointSiteCollection origItem = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
+ if (origItem == null)
+ {
+ return BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND;
+ }
- // Restore.
- if (!String.IsNullOrEmpty(backupFile))
- {
- hostedSharePointServer.RestoreSiteCollection(origItem, backupFile);
- }
+ // Check package.
+ int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive);
+ if (packageCheck < 0)
+ {
+ return packageCheck;
+ }
- return 0;
- }
- catch (Exception ex)
- {
- throw TaskManager.WriteError(ex);
- }
- finally
- {
- TaskManager.CompleteTask();
- }
- }
+ // Log operation.
+ TaskManager.StartTask("HOSTEDSHAREPOINT", "BACKUP_SITE_COLLECTION", origItem.Name);
+ TaskManager.ItemId = itemId;
- ///
- /// Gets binary data chunk of specified size from specified offset.
- ///
- /// Item id to obtain realted service id.
- /// Path to file to get bunary data chunk from.
- /// Offset from which to start data reading.
- /// Binary data chunk length.
- /// Binary data chunk read from file.
- public static byte[] GetBackupBinaryChunk(int itemId, string path, int offset, int length)
- {
- // Load original meta item.
- SharePointSiteCollection item = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
- if (item == null)
- {
- return null;
- }
+ try
+ {
+ // Create site collection on server.
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(origItem.ServiceId);
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(item.ServiceId);
- return hostedSharePointServer.GetTempFileBinaryChunk(path, offset, length);
- }
+ string backupFile = null;
+ if (!String.IsNullOrEmpty(packageFile))
+ {
+ // Copy package files to the remote SharePoint Server.
+ string path = null;
+ byte[] buffer = null;
- ///
- /// Appends supplied binary data chunk to file.
- ///
- /// Item id to obtain realted service id.
- /// Non existent file name to append to.
- /// Full path to existent file to append to.
- /// Binary data chunk to append to.
- /// Path to file that was appended with chunk.
- public static string AppendBackupBinaryChunk(int itemId, string fileName, string path, byte[] chunk)
- {
- // Load original meta item.
- SharePointSiteCollection item = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
- if (item == null)
- {
- return null;
- }
+ int offset = 0;
+ do
+ {
+ // Read package file.
+ buffer = FilesController.GetFileBinaryChunk(origItem.PackageId, packageFile, offset, FILE_BUFFER_LENGTH);
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(item.ServiceId);
- return hostedSharePointServer.AppendTempFileBinaryChunk(fileName, path, chunk);
- }
+ // Write remote backup file
+ string tempPath = hostedSharePointServer.AppendTempFileBinaryChunk(Path.GetFileName(packageFile), path, buffer);
+ if (path == null)
+ {
+ path = tempPath;
+ backupFile = path;
+ }
+
+ offset += FILE_BUFFER_LENGTH;
+ }
+ while (buffer.Length == FILE_BUFFER_LENGTH);
+ }
+ else if (!String.IsNullOrEmpty(uploadedFile))
+ {
+ // Upladed files.
+ backupFile = uploadedFile;
+ }
+
+ // Restore.
+ if (!String.IsNullOrEmpty(backupFile))
+ {
+ hostedSharePointServer.RestoreSiteCollection(origItem, backupFile);
+ }
+
+ return 0;
+ }
+ catch (Exception ex)
+ {
+ throw TaskManager.WriteError(ex);
+ }
+ finally
+ {
+ TaskManager.CompleteTask();
+ }
+ }
+
+ ///
+ /// Gets binary data chunk of specified size from specified offset.
+ ///
+ /// Item id to obtain realted service id.
+ /// Path to file to get bunary data chunk from.
+ /// Offset from which to start data reading.
+ /// Binary data chunk length.
+ /// Binary data chunk read from file.
+ public static byte[] GetBackupBinaryChunk(int itemId, string path, int offset, int length)
+ {
+ // Load original meta item.
+ SharePointSiteCollection item = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
+ if (item == null)
+ {
+ return null;
+ }
+
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(item.ServiceId);
+ return hostedSharePointServer.GetTempFileBinaryChunk(path, offset, length);
+ }
+
+ ///
+ /// Appends supplied binary data chunk to file.
+ ///
+ /// Item id to obtain realted service id.
+ /// Non existent file name to append to.
+ /// Full path to existent file to append to.
+ /// Binary data chunk to append to.
+ /// Path to file that was appended with chunk.
+ public static string AppendBackupBinaryChunk(int itemId, string fileName, string path, byte[] chunk)
+ {
+ // Load original meta item.
+ SharePointSiteCollection item = (SharePointSiteCollection)PackageController.GetPackageItem(itemId);
+ if (item == null)
+ {
+ return null;
+ }
+
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(item.ServiceId);
+ return hostedSharePointServer.AppendTempFileBinaryChunk(fileName, path, chunk);
+ }
+
+ ///
+ /// Initializes a new hosted SharePoint server proxy.
+ ///
+ /// Hosted SharePoint service id.
+ /// Hosted SharePoint server proxy.
+ private static HostedSharePointServer GetHostedSharePointServer(int serviceId)
+ {
- ///
- /// Initializes a new hosted SharePoint server proxy.
- ///
- /// Hosted SharePoint service id.
- /// Hosted SharePoint server proxy.
- private static HostedSharePointServer GetHostedSharePointServer(int serviceId)
- {
-
HostedSharePointServer sps = new HostedSharePointServer();
- ServiceProviderProxy.Init(sps, serviceId);
- return sps;
- }
+ ServiceProviderProxy.Init(sps, serviceId);
+ return sps;
+ }
- ///
- /// Gets list of importable items.
- ///
- /// Package that owns importable items.
- /// Item type id.
- /// Item type.
- /// Item resource group.
- /// List of importable item names.
- public List GetImportableItems(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group)
- {
- List items = new List();
+ ///
+ /// Gets list of importable items.
+ ///
+ /// Package that owns importable items.
+ /// Item type id.
+ /// Item type.
+ /// Item resource group.
+ /// List of importable item names.
+ public List GetImportableItems(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group)
+ {
+ List items = new List();
- // Get service id
- int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
- if (serviceId == 0)
- {
- return items;
- }
+ // Get service id
+ int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
+ if (serviceId == 0)
+ {
+ return items;
+ }
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
- if (itemType == typeof(SharePointSiteCollection))
- {
- foreach (SharePointSiteCollection siteCollection in hostedSharePointServer.GetSiteCollections())
- {
- items.Add(siteCollection.Url);
- }
- }
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
+ if (itemType == typeof(SharePointSiteCollection))
+ {
+ foreach (SharePointSiteCollection siteCollection in hostedSharePointServer.GetSiteCollections())
+ {
+ items.Add(siteCollection.Url);
+ }
+ }
- return items;
- }
+ return items;
+ }
- ///
- /// Imports selected item into metabase.
- ///
- /// Package to which items must be imported.
- /// Item type id.
- /// Item type.
- /// Item resource group.
- /// Item name to import.
- public void ImportItem(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group, string itemName)
- {
- // Get service id
- int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
- if (serviceId == 0)
- {
- return;
- }
+ ///
+ /// Imports selected item into metabase.
+ ///
+ /// Package to which items must be imported.
+ /// Item type id.
+ /// Item type.
+ /// Item resource group.
+ /// Item name to import.
+ public void ImportItem(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group, string itemName)
+ {
+ // Get service id
+ int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName);
+ if (serviceId == 0)
+ {
+ return;
+ }
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
- if (itemType == typeof(SharePointSiteCollection))
- {
- SharePointSiteCollection siteCollection = hostedSharePointServer.GetSiteCollection(itemName);
- PackageController.AddPackageItem(siteCollection);
- }
- }
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
+ if (itemType == typeof(SharePointSiteCollection))
+ {
+ SharePointSiteCollection siteCollection = hostedSharePointServer.GetSiteCollection(itemName);
+ PackageController.AddPackageItem(siteCollection);
+ }
+ }
- ///
- /// Backups service item by serializing it into supplied writer.
- ///
- /// Temporary directory path.
- /// Xml wirter used to store backuped service provider items.
- /// Service provider item to be backed up..
- /// Service provider resource group.
- /// Resulting code.
- public int BackupItem(string tempFolder, XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
- {
- SharePointSiteCollection siteCollection = item as SharePointSiteCollection;
- if (siteCollection != null)
- {
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(siteCollection.ServiceId);
- SharePointSiteCollection loadedSiteCollection = hostedSharePointServer.GetSiteCollection(siteCollection.Url);
- // Update item
- siteCollection.Url = loadedSiteCollection.Url;
- siteCollection.OwnerLogin = loadedSiteCollection.OwnerLogin;
- siteCollection.OwnerName = loadedSiteCollection.OwnerName;
- siteCollection.OwnerEmail = loadedSiteCollection.OwnerEmail;
- siteCollection.LocaleId = loadedSiteCollection.LocaleId;
- siteCollection.Title = loadedSiteCollection.Title;
- siteCollection.Description = loadedSiteCollection.Description;
- // Serialize it.
- XmlSerializer serializer = new XmlSerializer(typeof(SharePointSiteCollection));
- serializer.Serialize(writer, siteCollection);
+ ///
+ /// Backups service item by serializing it into supplied writer.
+ ///
+ /// Temporary directory path.
+ /// Xml wirter used to store backuped service provider items.
+ /// Service provider item to be backed up..
+ /// Service provider resource group.
+ /// Resulting code.
+ public int BackupItem(string tempFolder, XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group)
+ {
+ SharePointSiteCollection siteCollection = item as SharePointSiteCollection;
+ if (siteCollection != null)
+ {
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(siteCollection.ServiceId);
+ SharePointSiteCollection loadedSiteCollection = hostedSharePointServer.GetSiteCollection(siteCollection.Url);
+ // Update item
+ siteCollection.Url = loadedSiteCollection.Url;
+ siteCollection.OwnerLogin = loadedSiteCollection.OwnerLogin;
+ siteCollection.OwnerName = loadedSiteCollection.OwnerName;
+ siteCollection.OwnerEmail = loadedSiteCollection.OwnerEmail;
+ siteCollection.LocaleId = loadedSiteCollection.LocaleId;
+ siteCollection.Title = loadedSiteCollection.Title;
+ siteCollection.Description = loadedSiteCollection.Description;
+ // Serialize it.
+ XmlSerializer serializer = new XmlSerializer(typeof(SharePointSiteCollection));
+ serializer.Serialize(writer, siteCollection);
- }
- return 0;
- }
+ }
+ return 0;
+ }
- ///
- /// Restore backed up previously service provider item.
- ///
- /// Temporary directory path.
- /// Serialized service provider item.
- /// Service provider item id.
- /// Service provider item type.
- /// Service provider item name.
- /// Service provider item package.
- /// Service provider item service id.
- /// Service provider item resource group.
- /// Resulting code.
- public int RestoreItem(string tempFolder, XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group)
- {
- if (itemType == typeof(SharePointSiteCollection))
- {
- HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
- // Deserialize item.
- XmlSerializer serializer = new XmlSerializer(typeof(SharePointSiteCollection));
- SharePointSiteCollection siteCollection = (SharePointSiteCollection)serializer.Deserialize(new XmlNodeReader(itemNode.SelectSingleNode("SharePointSiteCollection")));
- siteCollection.PackageId = packageId;
- siteCollection.ServiceId = serviceId;
+ ///
+ /// Restore backed up previously service provider item.
+ ///
+ /// Temporary directory path.
+ /// Serialized service provider item.
+ /// Service provider item id.
+ /// Service provider item type.
+ /// Service provider item name.
+ /// Service provider item package.
+ /// Service provider item service id.
+ /// Service provider item resource group.
+ /// Resulting code.
+ public int RestoreItem(string tempFolder, XmlNode itemNode, int itemId, Type itemType, string itemName, int packageId, int serviceId, ResourceGroupInfo group)
+ {
+ if (itemType == typeof(SharePointSiteCollection))
+ {
+ HostedSharePointServer hostedSharePointServer = GetHostedSharePointServer(serviceId);
+ // Deserialize item.
+ XmlSerializer serializer = new XmlSerializer(typeof(SharePointSiteCollection));
+ SharePointSiteCollection siteCollection = (SharePointSiteCollection)serializer.Deserialize(new XmlNodeReader(itemNode.SelectSingleNode("SharePointSiteCollection")));
+ siteCollection.PackageId = packageId;
+ siteCollection.ServiceId = serviceId;
- // Create site collection if needed.
- if (hostedSharePointServer.GetSiteCollection(siteCollection.Url) == null)
- {
- hostedSharePointServer.CreateSiteCollection(siteCollection);
- }
+ // Create site collection if needed.
+ if (hostedSharePointServer.GetSiteCollection(siteCollection.Url) == null)
+ {
+ hostedSharePointServer.CreateSiteCollection(siteCollection);
+ }
+
+ // Add metabase record if needed.
+ SharePointSiteCollection metaSiteCollection = (SharePointSiteCollection)PackageController.GetPackageItemByName(packageId, itemName, typeof(SharePointSiteCollection));
+ if (metaSiteCollection == null)
+ {
+ PackageController.AddPackageItem(siteCollection);
+ }
+ }
+
+ return 0;
+ }
- // Add metabase record if needed.
- SharePointSiteCollection metaSiteCollection = (SharePointSiteCollection)PackageController.GetPackageItemByName(packageId, itemName, typeof(SharePointSiteCollection));
- if (metaSiteCollection == null)
- {
- PackageController.AddPackageItem(siteCollection);
- }
- }
- return 0;
- }
-
-
private static int GetHostedSharePointServiceId(int packageId)
{
return PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedSharePoint);
}
-
+
private static List GetOrganizationSharePointSiteCollections(int orgId)
{
Organization org = OrganizationController.GetOrganization(orgId);
@@ -776,18 +810,18 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
SharePointSiteCollectionListPaged siteCollections = GetSiteCollectionsPaged(org.PackageId, org.Id, String.Empty, String.Empty, String.Empty, 0, Int32.MaxValue);
return siteCollections.SiteCollections;
}
-
+
private static int RecalculateStorageMaxSize(int size, int packageId)
- {
+ {
PackageContext cntx = PackageController.GetPackageContext(packageId);
- QuotaValueInfo quota = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE];
+ QuotaValueInfo quota = cntx.Quotas[Quotas.HOSTED_SHAREPOINT_STORAGE_SIZE];
if (quota.QuotaAllocatedValue == -1)
{
if (size == -1)//Unlimited
return -1;
else
- return size;
+ return size;
}
else
{
@@ -795,7 +829,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
return quota.QuotaAllocatedValue;
return Math.Min(size, quota.QuotaAllocatedValue);
- }
+ }
}
private static int RecalculateMaxSize(int parentSize, int realSize)
@@ -815,8 +849,8 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
return Math.Min(parentSize, realSize);
}
-
-
+
+
public static int SetStorageSettings(int itemId, int maxStorage, int warningStorage, bool applyToSiteCollections)
{
// check account
@@ -831,15 +865,15 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
{
Organization org = (Organization)PackageController.GetPackageItem(itemId);
if (org == null)
- return 0;
+ return 0;
// set limits
int realMaxSizeValue = RecalculateStorageMaxSize(maxStorage, org.PackageId);
org.MaxSharePointStorage = realMaxSizeValue;
- org.WarningSharePointStorage = realMaxSizeValue == -1 ? -1 : Math.Min(warningStorage, realMaxSizeValue);
-
+ org.WarningSharePointStorage = realMaxSizeValue == -1 ? -1 : Math.Min(warningStorage, realMaxSizeValue);
+
// save organization
UpdateOrganization(org);
@@ -851,9 +885,9 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
List currentOrgSiteCollection =
GetOrganizationSharePointSiteCollections(org.Id);
-
-
- foreach( SharePointSiteCollection siteCollection in currentOrgSiteCollection)
+
+
+ foreach (SharePointSiteCollection siteCollection in currentOrgSiteCollection)
{
try
{
@@ -861,17 +895,17 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
sc.MaxSiteStorage = realMaxSizeValue;
sc.WarningStorage = realMaxSizeValue == -1 ? -1 : warningStorage;
PackageController.UpdatePackageItem(sc);
-
+
hostedSharePointServer.UpdateQuotas(siteCollection.PhysicalAddress, realMaxSizeValue,
warningStorage);
}
- catch(Exception ex)
+ catch (Exception ex)
{
TaskManager.WriteError(ex);
}
- }
+ }
}
-
+
return 0;
}
catch (Exception ex)
@@ -894,14 +928,14 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
{
errorCode = accountCheck;
return null;
- }
+ }
// place log record
TaskManager.StartTask("HOSTED_SHAREPOINT", "CALCULATE_DISK_SPACE");
TaskManager.ItemId = itemId;
try
{
- Organization org = (Organization) PackageController.GetPackageItem(itemId);
+ Organization org = (Organization)PackageController.GetPackageItem(itemId);
if (org == null)
return null;
@@ -917,7 +951,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
{
urls.Add(siteCollection.PhysicalAddress);
}
- if (urls.Count > 0)
+ if (urls.Count > 0)
retDiskSpace = hostedSharePointServer.CalculateSiteCollectionsDiskSpace(urls.ToArray());
else
{
@@ -927,7 +961,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
retDiskSpace[0].Url = string.Empty;
}
}
- catch(Exception ex)
+ catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
@@ -935,10 +969,10 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
{
TaskManager.CompleteTask();
}
- return retDiskSpace;
+ return retDiskSpace;
}
- private static void UpdateOrganization(Organization organization)
+ private static void UpdateOrganization(Organization organization)
{
PackageController.UpdatePackageItem(organization);
}
@@ -949,7 +983,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
TaskManager.StartTask("HOSTED_SHAREPOINT", "UPDATE_QUOTA");
try
{
- Organization org = (Organization) PackageController.GetPackageItem(itemId);
+ Organization org = (Organization)PackageController.GetPackageItem(itemId);
if (org == null)
return;
@@ -960,7 +994,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
SharePointSiteCollection sc = GetSiteCollection(siteCollectionId);
int maxSize = RecalculateMaxSize(org.MaxSharePointStorage, maxStorage);
- int warningSize = warningStorage;
+ int warningSize = warningStorage;
sc.MaxSiteStorage = maxSize;
@@ -970,7 +1004,7 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
hostedSharePointServer.UpdateQuotas(sc.PhysicalAddress, maxSize,
warningStorage);
}
- catch(Exception ex)
+ catch (Exception ex)
{
throw TaskManager.WriteError(ex);
}
@@ -989,5 +1023,5 @@ namespace WebsitePanel.EnterpriseServer.Code.SharePoint
return (SecurityContext.CheckAccount(DemandAccount.NotDemo) < 0);
}
}
- }
+ }
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationUser.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationUser.cs
index 228bf436..687c96cf 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationUser.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/HostedSolution/OrganizationUser.cs
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, Outercurve Foundation.
+// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -30,15 +30,15 @@ using System;
namespace WebsitePanel.Providers.HostedSolution
{
-
-
+
+
public class OrganizationUser
{
private int accountId;
private int itemId;
private int packageId;
- private string primaryEmailAddress;
+ private string primaryEmailAddress;
private string accountPassword;
private string samAccountName;
private string displayName;
@@ -65,18 +65,23 @@ namespace WebsitePanel.Providers.HostedSolution
private string domainUserName;
private bool disabled;
+ private bool locked;
+ private bool isOCSUser;
+ private bool isBlackBerryUser;
+ private bool isLyncUser;
+
ExchangeAccountType accountType;
private OrganizationUser manager;
private Guid crmUserId;
-
+
public Guid CrmUserId
{
get { return crmUserId; }
set { crmUserId = value; }
}
-
+
public string DomainUserName
{
@@ -98,10 +103,10 @@ namespace WebsitePanel.Providers.HostedSolution
public bool Disabled
{
- get { return disabled;}
- set { disabled = value;}
+ get { return disabled; }
+ set { disabled = value; }
}
-
+
public string FirstName
{
get { return firstName; }
@@ -258,17 +263,40 @@ namespace WebsitePanel.Providers.HostedSolution
set { primaryEmailAddress = value; }
}
-
+
public string AccountPassword
{
get { return accountPassword; }
set { accountPassword = value; }
}
- public string ExternalEmail { get; set; }
+ public string ExternalEmail { get; set; }
public string DistinguishedName { get; set; }
- public bool Locked { get; set; }
+ public bool Locked
+ {
+ get { return locked; }
+ set { locked = value; }
+ }
+
+ public bool IsOCSUser
+ {
+ get { return isOCSUser; }
+ set { isOCSUser = value; }
+ }
+
+ public bool IsLyncUser
+ {
+ get { return isLyncUser; }
+ set { isLyncUser = value; }
+ }
+
+ public bool IsBlackBerryUser
+ {
+ get { return isBlackBerryUser; }
+ set { isBlackBerryUser = value; }
+ }
+
}
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/IHostedSharePointServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/IHostedSharePointServer.cs
index 219e0301..16b4822e 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/IHostedSharePointServer.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/IHostedSharePointServer.cs
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, Outercurve Foundation.
+// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -30,89 +30,91 @@ using System;
namespace WebsitePanel.Providers.SharePoint
{
- ///
- /// Exposes functionality for share point server provider hosted in conjunction with organization management provider and
- /// exchange server.
- ///
- public interface IHostedSharePointServer
- {
- ///
- /// When implemented gets root web application uri.
- ///
- Uri RootWebApplicationUri
- {
- get;
- }
+ ///
+ /// Exposes functionality for share point server provider hosted in conjunction with organization management provider and
+ /// exchange server.
+ ///
+ public interface IHostedSharePointServer
+ {
+ ///
+ /// When implemented gets root web application uri.
+ ///
+ Uri RootWebApplicationUri
+ {
+ get;
+ }
- ///
- /// When implemented gets list of supported languages by this installation of SharePoint.
- ///
- /// List of supported languages
- int[] GetSupportedLanguages();
+ ///
+ /// When implemented gets list of supported languages by this installation of SharePoint.
+ ///
+ /// List of supported languages
+ int[] GetSupportedLanguages();
- ///
- /// When implemented gets list of SharePoint collections within root web application.
- ///
- /// List of SharePoint collections within root web application.
- SharePointSiteCollection[] GetSiteCollections();
+ ///
+ /// When implemented gets list of SharePoint collections within root web application.
+ ///
+ /// List of SharePoint collections within root web application.
+ SharePointSiteCollection[] GetSiteCollections();
- ///
- /// When implemented gets SharePoint collection within root web application with given name.
- ///
- /// Url that uniquely identifies site collection to be loaded.
- /// SharePoint collection within root web application with given name.
- SharePointSiteCollection GetSiteCollection(string url);
+ ///
+ /// When implemented gets SharePoint collection within root web application with given name.
+ ///
+ /// Url that uniquely identifies site collection to be loaded.
+ /// SharePoint collection within root web application with given name.
+ SharePointSiteCollection GetSiteCollection(string url);
- ///
- /// When implemented creates site collection within predefined root web application.
- ///
- /// Information about site coolection to be created.
- void CreateSiteCollection(SharePointSiteCollection siteCollection);
-
- ///
- /// When implemented deletes site collection under given url.
- ///
- /// Url that uniquely identifies site collection to be deleted.
- void DeleteSiteCollection(string url);
+ ///
+ /// When implemented creates site collection within predefined root web application.
+ ///
+ /// Information about site coolection to be created.
+ void CreateSiteCollection(SharePointSiteCollection siteCollection);
- ///
- /// When implemeneted backups site collection under give url.
- ///
- /// Url that uniquely identifies site collection to be deleted.
- /// Resulting backup file name.
- /// A value which shows whether created backup must be archived.
- /// Created backup full path.
- string BackupSiteCollection(string url, string filename, bool zip);
+ ///
+ /// When implemented deletes site collection under given url.
+ ///
+ /// Url that uniquely identifies site collection to be deleted.
+ void DeleteSiteCollection(SharePointSiteCollection siteCollection);
- ///
- /// When implemented restores site collection under given url from backup.
- ///
- /// Site collection to be restored.
- /// Backup file name to restore from.
- void RestoreSiteCollection(SharePointSiteCollection siteCollection, string filename);
+ ///
+ /// When implemeneted backups site collection under give url.
+ ///
+ /// Url that uniquely identifies site collection to be deleted.
+ /// Resulting backup file name.
+ /// A value which shows whether created backup must be archived.
+ /// Created backup full path.
+ string BackupSiteCollection(string url, string filename, bool zip);
+
+ ///
+ /// When implemented restores site collection under given url from backup.
+ ///
+ /// Site collection to be restored.
+ /// Backup file name to restore from.
+ void RestoreSiteCollection(SharePointSiteCollection siteCollection, string filename);
+
+ ///
+ /// When implemented gets binary data chunk of specified size from specified offset.
+ ///
+ /// Path to file to get bunary data chunk from.
+ /// Offset from which to start data reading.
+ /// Binary data chunk length.
+ /// Binary data chunk read from file.
+ byte[] GetTempFileBinaryChunk(string path, int offset, int length);
+
+ ///
+ /// When implemented appends supplied binary data chunk to file.
+ ///
+ /// Non existent file name to append to.
+ /// Full path to existent file to append to.
+ /// Binary data chunk to append to.
+ /// Path to file that was appended with chunk.
+ string AppendTempFileBinaryChunk(string fileName, string path, byte[] chunk);
- ///
- /// When implemented gets binary data chunk of specified size from specified offset.
- ///
- /// Path to file to get bunary data chunk from.
- /// Offset from which to start data reading.
- /// Binary data chunk length.
- /// Binary data chunk read from file.
- byte[] GetTempFileBinaryChunk(string path, int offset, int length);
-
- ///
- /// When implemented appends supplied binary data chunk to file.
- ///
- /// Non existent file name to append to.
- /// Full path to existent file to append to.
- /// Binary data chunk to append to.
- /// Path to file that was appended with chunk.
- string AppendTempFileBinaryChunk(string fileName, string path, byte[] chunk);
-
void UpdateQuotas(string url, long maxStorage, long warningStorage);
- SharePointSiteDiskSpace[] CalculateSiteCollectionsDiskSpace(string[] urls);
+ SharePointSiteDiskSpace[] CalculateSiteCollectionsDiskSpace(string[] urls);
- long GetSiteCollectionSize(string url);
- }
+ long GetSiteCollectionSize(string url);
+
+ void SetPeoplePickerOu(string site, string ou);
+ }
}
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/SharePointSiteCollection.cs b/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/SharePointSiteCollection.cs
index 77133bf8..120863c3 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/SharePointSiteCollection.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.Base/SharePoint/SharePointSiteCollection.cs
@@ -51,6 +51,9 @@ namespace WebsitePanel.Providers.SharePoint
private long diskspace;
private long maxSiteStorage;
private long warningStorage;
+ private string rootWebApplicationInteralIpAddress;
+ private string rootWebApplicationFQDN;
+
[Persistent]
@@ -178,6 +181,39 @@ namespace WebsitePanel.Providers.SharePoint
}
}
+ ///
+ /// Gets or sets the internal ip address
+ ///
+ [Persistent]
+ public string RootWebApplicationInteralIpAddress
+ {
+ get
+ {
+ return this.rootWebApplicationInteralIpAddress;
+ }
+ set
+ {
+ this.rootWebApplicationInteralIpAddress = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the internal ip address
+ ///
+ [Persistent]
+ public string RootWebApplicationFQDN
+ {
+ get
+ {
+ return this.rootWebApplicationFQDN;
+ }
+ set
+ {
+ this.rootWebApplicationFQDN = value;
+ }
+ }
+
+
///
/// Gets or sets locale id of the site collection to be created.
///
diff --git a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/HostedSharePointServer.cs b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/HostedSharePointServer.cs
index a162f2fa..3639da0b 100644
--- a/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/HostedSharePointServer.cs
+++ b/WebsitePanel/Sources/WebsitePanel.Providers.HostedSolution/HostedSharePointServer.cs
@@ -1,4 +1,4 @@
-// Copyright (c) 2012, Outercurve Foundation.
+// Copyright (c) 2011, Outercurve Foundation.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
@@ -36,14 +36,14 @@ using Microsoft.Win32;
namespace WebsitePanel.Providers.HostedSolution
{
- ///
- /// Provides hosted SharePoint server functionality implementation.
- ///
- public class HostedSharePointServer : HostingServiceProviderBase, IHostedSharePointServer
- {
- private delegate TReturn SharePointAction(HostedSharePointServerImpl impl);
+ ///
+ /// Provides hosted SharePoint server functionality implementation.
+ ///
+ public class HostedSharePointServer : HostingServiceProviderBase, IHostedSharePointServer
+ {
+ private delegate TReturn SharePointAction(HostedSharePointServerImpl impl);
- protected string Wss3RegistryKey;
+ protected string Wss3RegistryKey;
protected string Wss3Registry32Key;
protected string LanguagePacksPath;
@@ -54,301 +54,301 @@ namespace WebsitePanel.Providers.HostedSolution
this.LanguagePacksPath = @"%commonprogramfiles%\microsoft shared\Web Server Extensions\12\HCCab\";
}
- ///
- /// Gets root web application uri.
- ///
- public Uri RootWebApplicationUri
- {
- get
- {
- return new Uri(ProviderSettings["RootWebApplicationUri"]);
- }
- }
+ ///
+ /// Gets root web application uri.
+ ///
+ public Uri RootWebApplicationUri
+ {
+ get
+ {
+ return new Uri(ProviderSettings["RootWebApplicationUri"]);
+ }
+ }
public string BackupTemporaryFolder
- {
- get
- {
+ {
+ get
+ {
return ProviderSettings["BackupTemporaryFolder"];
- }
- }
+ }
+ }
- ///
- /// Gets list of supported languages by this installation of SharePoint.
- ///
- /// List of supported languages
- public int[] GetSupportedLanguages()
- {
- HostedSharePointServerImpl impl = new HostedSharePointServerImpl();
- return impl.GetSupportedLanguages(LanguagePacksPath);
- }
+ ///
+ /// Gets list of supported languages by this installation of SharePoint.
+ ///
+ /// List of supported languages
+ public int[] GetSupportedLanguages()
+ {
+ HostedSharePointServerImpl impl = new HostedSharePointServerImpl();
+ return impl.GetSupportedLanguages(LanguagePacksPath);
+ }
- ///
- /// Gets list of SharePoint collections within root web application.
- ///
- /// List of SharePoint collections within root web application.
- public SharePointSiteCollection[] GetSiteCollections()
- {
- return
- ExecuteSharePointAction(delegate(HostedSharePointServerImpl impl)
- {
- return impl.GetSiteCollections(RootWebApplicationUri);
- });
- }
+ ///
+ /// Gets list of SharePoint collections within root web application.
+ ///
+ /// List of SharePoint collections within root web application.
+ public SharePointSiteCollection[] GetSiteCollections()
+ {
+ return
+ ExecuteSharePointAction(delegate(HostedSharePointServerImpl impl)
+ {
+ return impl.GetSiteCollections(RootWebApplicationUri);
+ });
+ }
- ///
- /// Gets SharePoint collection within root web application with given name.
- ///
- /// Url that uniquely identifies site collection to be loaded.
- /// SharePoint collection within root web application with given name.
- public SharePointSiteCollection GetSiteCollection(string url)
- {
- return
- ExecuteSharePointAction(delegate(HostedSharePointServerImpl impl)
- {
- return impl.GetSiteCollection(RootWebApplicationUri, url);
- });
- }
+ ///
+ /// Gets SharePoint collection within root web application with given name.
+ ///
+ /// Url that uniquely identifies site collection to be loaded.
+ /// SharePoint collection within root web application with given name.
+ public SharePointSiteCollection GetSiteCollection(string url)
+ {
+ return
+ ExecuteSharePointAction(delegate(HostedSharePointServerImpl impl)
+ {
+ return impl.GetSiteCollection(RootWebApplicationUri, url);
+ });
+ }
- ///
- /// Creates site collection within predefined root web application.
- ///
- /// Information about site coolection to be created.
- public void CreateSiteCollection(SharePointSiteCollection siteCollection)
- {
- ExecuteSharePointAction