Updated Hosted Sharepoing Provider (Foundation 2010):

A) Powershell support added within the provider
B) Now returns the actual deployed language packs
C) The PeoplePicker points to the organization OU and shows only the users from
the tentant organization. A requirement when used with Exchange 2010 SP2
Addressbook Policies
D) Shared SSL root added to use wild card certificates as part of hosting plan.
When enabled the host name is generated.
E) Search fix: Provisioning of localhost file where the server component is
active. This system expected to be the search server. Within the local hostfile
the sites are listed with their local ip address so the search server can resolve
the site and crawl through their data.

This component needs to be compiled with .NET 2.0 together with Provers.Base,
OS.Windows2003, OS.Windows2008, Server.Utils, and Server components.

Out standing is to update the build and deployment package for a dedicated
 deployment packaged so this component is using .NET 2.0, all other should be
 using .NET 4.0. This will eliminate the configuration circus that was required
 to get the .NET 4.0 version of this component working previously.
This commit is contained in:
robvde 2012-07-01 08:24:49 +04:00
parent 38592df9e6
commit a0d9e59db2
25 changed files with 3174 additions and 2256 deletions

View file

@ -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
{
/// <summary>
/// Provides hosted SharePoint server functionality implementation.
/// </summary>
public class HostedSharePointServer : HostingServiceProviderBase, IHostedSharePointServer
{
private delegate TReturn SharePointAction<TReturn>(HostedSharePointServerImpl impl);
/// <summary>
/// Provides hosted SharePoint server functionality implementation.
/// </summary>
public class HostedSharePointServer : HostingServiceProviderBase, IHostedSharePointServer
{
private delegate TReturn SharePointAction<TReturn>(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\";
}
/// <summary>
/// Gets root web application uri.
/// </summary>
public Uri RootWebApplicationUri
{
get
{
return new Uri(ProviderSettings["RootWebApplicationUri"]);
}
}
/// <summary>
/// Gets root web application uri.
/// </summary>
public Uri RootWebApplicationUri
{
get
{
return new Uri(ProviderSettings["RootWebApplicationUri"]);
}
}
public string BackupTemporaryFolder
{
get
{
{
get
{
return ProviderSettings["BackupTemporaryFolder"];
}
}
}
}
/// <summary>
/// Gets list of supported languages by this installation of SharePoint.
/// </summary>
/// <returns>List of supported languages</returns>
public int[] GetSupportedLanguages()
{
HostedSharePointServerImpl impl = new HostedSharePointServerImpl();
return impl.GetSupportedLanguages(LanguagePacksPath);
}
/// <summary>
/// Gets list of supported languages by this installation of SharePoint.
/// </summary>
/// <returns>List of supported languages</returns>
public int[] GetSupportedLanguages()
{
HostedSharePointServerImpl impl = new HostedSharePointServerImpl();
return impl.GetSupportedLanguages(LanguagePacksPath);
}
/// <summary>
/// Gets list of SharePoint collections within root web application.
/// </summary>
/// <returns>List of SharePoint collections within root web application.</returns>
public SharePointSiteCollection[] GetSiteCollections()
{
return
ExecuteSharePointAction<SharePointSiteCollection[]>(delegate(HostedSharePointServerImpl impl)
{
return impl.GetSiteCollections(RootWebApplicationUri);
});
}
/// <summary>
/// Gets list of SharePoint collections within root web application.
/// </summary>
/// <returns>List of SharePoint collections within root web application.</returns>
public SharePointSiteCollection[] GetSiteCollections()
{
return
ExecuteSharePointAction<SharePointSiteCollection[]>(delegate(HostedSharePointServerImpl impl)
{
return impl.GetSiteCollections(RootWebApplicationUri);
});
}
/// <summary>
/// Gets SharePoint collection within root web application with given name.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be loaded.</param>
/// <returns>SharePoint collection within root web application with given name.</returns>
public SharePointSiteCollection GetSiteCollection(string url)
{
return
ExecuteSharePointAction<SharePointSiteCollection>(delegate(HostedSharePointServerImpl impl)
{
return impl.GetSiteCollection(RootWebApplicationUri, url);
});
}
/// <summary>
/// Gets SharePoint collection within root web application with given name.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be loaded.</param>
/// <returns>SharePoint collection within root web application with given name.</returns>
public SharePointSiteCollection GetSiteCollection(string url)
{
return
ExecuteSharePointAction<SharePointSiteCollection>(delegate(HostedSharePointServerImpl impl)
{
return impl.GetSiteCollection(RootWebApplicationUri, url);
});
}
/// <summary>
/// Creates site collection within predefined root web application.
/// </summary>
/// <param name="siteCollection">Information about site coolection to be created.</param>
public void CreateSiteCollection(SharePointSiteCollection siteCollection)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.CreateSiteCollection(RootWebApplicationUri, siteCollection);
return null;
});
}
/// <summary>
/// Creates site collection within predefined root web application.
/// </summary>
/// <param name="siteCollection">Information about site coolection to be created.</param>
public void CreateSiteCollection(SharePointSiteCollection siteCollection)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.CreateSiteCollection(RootWebApplicationUri, siteCollection);
return null;
});
}
/// <summary>
/// Deletes site collection under given url.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
public void DeleteSiteCollection(string url)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.DeleteSiteCollection(RootWebApplicationUri, url);
return null;
});
}
/// <summary>
/// Deletes site collection under given url.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
public void DeleteSiteCollection(SharePointSiteCollection siteCollection)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.DeleteSiteCollection(RootWebApplicationUri, siteCollection);
return null;
});
}
/// <summary>
/// Backups site collection under give url.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
/// <param name="filename">Resulting backup file name.</param>
/// <param name="zip">A value which shows whether created backup must be archived.</param>
/// <returns>Created backup full path.</returns>
public string BackupSiteCollection(string url, string filename, bool zip)
{
return ExecuteSharePointAction<string>(delegate(HostedSharePointServerImpl impl)
{
return impl.BackupSiteCollection(RootWebApplicationUri, url, filename, zip, BackupTemporaryFolder);
});
}
/// <summary>
/// Backups site collection under give url.
/// </summary>
/// <param name="url">Url that uniquely identifies site collection to be deleted.</param>
/// <param name="filename">Resulting backup file name.</param>
/// <param name="zip">A value which shows whether created backup must be archived.</param>
/// <returns>Created backup full path.</returns>
public string BackupSiteCollection(string url, string filename, bool zip)
{
return ExecuteSharePointAction<string>(delegate(HostedSharePointServerImpl impl)
{
return impl.BackupSiteCollection(RootWebApplicationUri, url, filename, zip, BackupTemporaryFolder);
});
}
/// <summary>
/// Restores site collection under given url from backup.
/// </summary>
/// <param name="siteCollection">Site collection to be restored.</param>
/// <param name="filename">Backup file name to restore from.</param>
public void RestoreSiteCollection(SharePointSiteCollection siteCollection, string filename)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.RestoreSiteCollection(RootWebApplicationUri, siteCollection, filename);
return null;
});
}
/// <summary>
/// Gets binary data chunk of specified size from specified offset.
/// </summary>
/// <param name="path">Path to file to get bunary data chunk from.</param>
/// <param name="offset">Offset from which to start data reading.</param>
/// <param name="length">Binary data chunk length.</param>
/// <returns>Binary data chunk read from file.</returns>
public virtual byte[] GetTempFileBinaryChunk(string path, int offset, int length)
{
byte[] buffer = FileUtils.GetFileBinaryChunk(path, offset, length);
/// <summary>
/// Restores site collection under given url from backup.
/// </summary>
/// <param name="siteCollection">Site collection to be restored.</param>
/// <param name="filename">Backup file name to restore from.</param>
public void RestoreSiteCollection(SharePointSiteCollection siteCollection, string filename)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.RestoreSiteCollection(RootWebApplicationUri, siteCollection, filename);
return null;
});
}
// Delete temp file
if (buffer.Length < length)
{
FileUtils.DeleteFile(path);
}
return buffer;
}
/// <summary>
/// Gets binary data chunk of specified size from specified offset.
/// </summary>
/// <param name="path">Path to file to get bunary data chunk from.</param>
/// <param name="offset">Offset from which to start data reading.</param>
/// <param name="length">Binary data chunk length.</param>
/// <returns>Binary data chunk read from file.</returns>
public virtual byte[] GetTempFileBinaryChunk(string path, int offset, int length)
{
byte[] buffer = FileUtils.GetFileBinaryChunk(path, offset, length);
/// <summary>
/// Appends supplied binary data chunk to file.
/// </summary>
/// <param name="fileName">Non existent file name to append to.</param>
/// <param name="path">Full path to existent file to append to.</param>
/// <param name="chunk">Binary data chunk to append to.</param>
/// <returns>Path to file that was appended with chunk.</returns>
public virtual string AppendTempFileBinaryChunk(string fileName, string path, byte[] chunk)
{
if (path == null)
{
path = Path.Combine(Path.GetTempPath(), fileName);
if (FileUtils.FileExists(path))
{
FileUtils.DeleteFile(path);
}
}
// Delete temp file
if (buffer.Length < length)
{
FileUtils.DeleteFile(path);
}
return buffer;
}
FileUtils.AppendFileBinaryContent(path, chunk);
/// <summary>
/// Appends supplied binary data chunk to file.
/// </summary>
/// <param name="fileName">Non existent file name to append to.</param>
/// <param name="path">Full path to existent file to append to.</param>
/// <param name="chunk">Binary data chunk to append to.</param>
/// <returns>Path to file that was appended with chunk.</returns>
public virtual string AppendTempFileBinaryChunk(string fileName, string path, byte[] chunk)
{
if (path == null)
{
path = Path.Combine(Path.GetTempPath(), fileName);
if (FileUtils.FileExists(path))
{
FileUtils.DeleteFile(path);
}
}
FileUtils.AppendFileBinaryContent(path, chunk);
return path;
}
return path;
}
public override bool IsInstalled()
{
return IsSharePointInstalled();
}
/// <summary>
/// Deletes service items that represent SharePoint site collection.
/// </summary>
/// <param name="items">Items to be deleted.</param>
public override void DeleteServiceItems(ServiceProviderItem[] items)
{
foreach (ServiceProviderItem item in items)
{
if (item is SharePointSiteCollection)
{
try
{
DeleteSiteCollection((item as SharePointSiteCollection).Url);
}
catch (Exception ex)
{
Log.WriteError(String.Format("Error deleting '{0}' {1}", item.Name, item.GetType().Name), ex);
}
}
}
}
/// <summary>
/// Deletes service items that represent SharePoint site collection.
/// </summary>
/// <param name="items">Items to be deleted.</param>
public override void DeleteServiceItems(ServiceProviderItem[] items)
{
foreach (ServiceProviderItem item in items)
{
if (item is SharePointSiteCollection)
{
try
{
DeleteSiteCollection((SharePointSiteCollection)item);
}
catch (Exception ex)
{
Log.WriteError(String.Format("Error deleting '{0}' {1}", item.Name, item.GetType().Name), ex);
}
}
}
}
/// <summary>
/// Calculates diskspace used by supplied service items.
/// </summary>
/// <param name="items">Service items to get diskspace usage for.</param>
/// <returns>Calculated disk space usage statistics.</returns>
public override ServiceProviderItemDiskSpace[] GetServiceItemsDiskSpace(ServiceProviderItem[] items)
{
List<ServiceProviderItemDiskSpace> itemsDiskspace = new List<ServiceProviderItemDiskSpace>();
/// <summary>
/// Calculates diskspace used by supplied service items.
/// </summary>
/// <param name="items">Service items to get diskspace usage for.</param>
/// <returns>Calculated disk space usage statistics.</returns>
public override ServiceProviderItemDiskSpace[] GetServiceItemsDiskSpace(ServiceProviderItem[] items)
{
List<ServiceProviderItemDiskSpace> itemsDiskspace = new List<ServiceProviderItemDiskSpace>();
// update items with diskspace
foreach (ServiceProviderItem item in items)
{
if (item is SharePointSiteCollection)
{
try
{
Log.WriteStart(String.Format("Calculating '{0}' site logs size", item.Name));
// update items with diskspace
foreach (ServiceProviderItem item in items)
{
if (item is SharePointSiteCollection)
{
try
{
Log.WriteStart(String.Format("Calculating '{0}' site logs size", item.Name));
SharePointSiteCollection site = GetSiteCollection(item.Name);
ServiceProviderItemDiskSpace diskspace = new ServiceProviderItemDiskSpace();
diskspace.ItemId = item.Id;
diskspace.DiskSpace = site.Diskspace;
itemsDiskspace.Add(diskspace);
SharePointSiteCollection site = GetSiteCollection(item.Name);
ServiceProviderItemDiskSpace diskspace = new ServiceProviderItemDiskSpace();
diskspace.ItemId = item.Id;
diskspace.DiskSpace = site.Diskspace;
itemsDiskspace.Add(diskspace);
Log.WriteEnd(String.Format("Calculating '{0}' site logs size", item.Name));
}
catch (Exception ex)
{
Log.WriteError(ex);
}
}
}
return itemsDiskspace.ToArray();
}
Log.WriteEnd(String.Format("Calculating '{0}' site logs size", item.Name));
}
catch (Exception ex)
{
Log.WriteError(ex);
}
}
}
return itemsDiskspace.ToArray();
}
/// <summary>
/// Checks whether Wss 3.0 is installed.
/// </summary>
/// <returns>true - if it is installed; false - otherwise.</returns>
private bool IsSharePointInstalled()
{
RegistryKey spKey = Registry.LocalMachine.OpenSubKey(Wss3RegistryKey);
/// <summary>
/// Checks whether Wss 3.0 is installed.
/// </summary>
/// <returns>true - if it is installed; false - otherwise.</returns>
private bool IsSharePointInstalled()
{
RegistryKey spKey = Registry.LocalMachine.OpenSubKey(Wss3RegistryKey);
RegistryKey spKey32 = Registry.LocalMachine.OpenSubKey(Wss3Registry32Key);
if (spKey == null && spKey32 == null)
{
return false;
}
{
return false;
}
string spVal = (string)spKey.GetValue("SharePoint");
return (String.Compare(spVal, "installed", true) == 0);
}
string spVal = (string)spKey.GetValue("SharePoint");
return (String.Compare(spVal, "installed", true) == 0);
}
/// <summary>
/// Executes supplied action within separate application domain.
/// </summary>
/// <param name="action">Action to be executed.</param>
/// <returns>Any object that results from action execution or null if nothing is supposed to be returned.</returns>
/// <exception cref="ArgumentNullException">Is thrown in case supplied action is null.</exception>
private static TReturn ExecuteSharePointAction<TReturn>(SharePointAction<TReturn> action)
{
if (action == null)
{
throw new ArgumentNullException("action");
}
/// <summary>
/// Executes supplied action within separate application domain.
/// </summary>
/// <param name="action">Action to be executed.</param>
/// <returns>Any object that results from action execution or null if nothing is supposed to be returned.</returns>
/// <exception cref="ArgumentNullException">Is thrown in case supplied action is null.</exception>
private static TReturn ExecuteSharePointAction<TReturn>(SharePointAction<TReturn> action)
{
if (action == null)
{
throw new ArgumentNullException("action");
}
AppDomain domain = null;
try
{
// Create instance of server implementation in a separate application domain for
// security and isolation purposes.
Type type = typeof (HostedSharePointServerImpl);
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
info.PrivateBinPath = "bin; bin/debug";
domain = AppDomain.CreateDomain("WSS30", null, info);
AppDomain domain = null;
try
{
// Create instance of server implementation in a separate application domain for
// security and isolation purposes.
Type type = typeof(HostedSharePointServerImpl);
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
info.PrivateBinPath = "bin; bin/debug";
domain = AppDomain.CreateDomain("WSS30", null, info);
HostedSharePointServerImpl impl =
(HostedSharePointServerImpl)
domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
HostedSharePointServerImpl impl =
(HostedSharePointServerImpl)
domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
// Execute requested action within created application domain.
return action(impl);
}
finally
{
if (domain != null)
{
AppDomain.Unload(domain);
}
}
}
// Execute requested action within created application domain.
return action(impl);
}
finally
{
if (domain != null)
{
AppDomain.Unload(domain);
}
}
}
public void UpdateQuotas(string url, long maxStorage, long warningStorage)
{
ExecuteSharePointAction<object>(delegate(HostedSharePointServerImpl impl)
{
impl.UpdateQuotas(RootWebApplicationUri, url, maxStorage, warningStorage);
return null;
});
{
impl.UpdateQuotas(RootWebApplicationUri, url, maxStorage, warningStorage);
return null;
});
}
public SharePointSiteDiskSpace[] CalculateSiteCollectionsDiskSpace(string []urls)
public SharePointSiteDiskSpace[] CalculateSiteCollectionsDiskSpace(string[] urls)
{
SharePointSiteDiskSpace []sd = null;
SharePointSiteDiskSpace[] sd = null;
sd = ExecuteSharePointAction<SharePointSiteDiskSpace[]>(delegate(HostedSharePointServerImpl impl)
{
return impl.CalculateSiteCollectionDiskSpace(RootWebApplicationUri, urls);
});
{
return impl.CalculateSiteCollectionDiskSpace(RootWebApplicationUri, urls);
});
return sd;
@ -366,5 +366,10 @@ namespace WebsitePanel.Providers.HostedSolution
return ret;
}
public virtual void SetPeoplePickerOu(string site, string ou)
{
}
}
}