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:
parent
38592df9e6
commit
a0d9e59db2
25 changed files with 3174 additions and 2256 deletions
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,18 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
|
||||
using WebsitePanel.Providers.Utils;
|
||||
using WebsitePanel.Server.Utils;
|
||||
|
||||
using WebsitePanel.Providers.SharePoint;
|
||||
|
||||
|
||||
namespace WebsitePanel.Providers.HostedSolution
|
||||
{
|
||||
public class HostedSharePointServer2010 : HostedSharePointServer
|
||||
|
@ -12,5 +23,239 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
this.Wss3Registry32Key = @"SOFTWARE\Wow6432Node\Microsoft\Shared Tools\Web Server Extensions\14.0";
|
||||
this.LanguagePacksPath = @"%commonprogramfiles%\microsoft shared\Web Server Extensions\14\HCCab\";
|
||||
}
|
||||
|
||||
#region PowerShell integration
|
||||
private static RunspaceConfiguration runspaceConfiguration = null;
|
||||
|
||||
internal virtual string SharepointSnapInName
|
||||
{
|
||||
get { return "Microsoft.SharePoint.Powershell"; }
|
||||
}
|
||||
|
||||
internal virtual Runspace OpenRunspace()
|
||||
{
|
||||
HostedSolutionLog.LogStart("OpenRunspace");
|
||||
|
||||
if (runspaceConfiguration == null)
|
||||
{
|
||||
runspaceConfiguration = RunspaceConfiguration.Create();
|
||||
PSSnapInException exception = null;
|
||||
|
||||
PSSnapInInfo info = runspaceConfiguration.AddPSSnapIn(SharepointSnapInName, out exception);
|
||||
HostedSolutionLog.LogInfo("Sharepoint snapin loaded");
|
||||
|
||||
if (exception != null)
|
||||
{
|
||||
HostedSolutionLog.LogWarning("SnapIn error", exception);
|
||||
}
|
||||
}
|
||||
Runspace runSpace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
|
||||
//
|
||||
runSpace.Open();
|
||||
//
|
||||
runSpace.SessionStateProxy.SetVariable("ConfirmPreference", "none");
|
||||
HostedSolutionLog.LogEnd("OpenRunspace");
|
||||
return runSpace;
|
||||
}
|
||||
|
||||
internal void CloseRunspace(Runspace runspace)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (runspace != null && runspace.RunspaceStateInfo.State == RunspaceState.Opened)
|
||||
{
|
||||
runspace.Close();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostedSolutionLog.LogError("Runspace error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd)
|
||||
{
|
||||
return ExecuteShellCommand(runSpace, cmd, true);
|
||||
}
|
||||
|
||||
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController)
|
||||
{
|
||||
object[] errors;
|
||||
return ExecuteShellCommand(runSpace, cmd, useDomainController, out errors);
|
||||
}
|
||||
|
||||
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd, out object[] errors)
|
||||
{
|
||||
return ExecuteShellCommand(runSpace, cmd, true, out errors);
|
||||
}
|
||||
|
||||
internal Collection<PSObject> ExecuteShellCommand(Runspace runSpace, Command cmd, bool useDomainController, out object[] errors)
|
||||
{
|
||||
HostedSolutionLog.LogStart("ExecuteShellCommand");
|
||||
List<object> errorList = new List<object>();
|
||||
|
||||
HostedSolutionLog.DebugCommand(cmd);
|
||||
Collection<PSObject> results = null;
|
||||
// Create a pipeline
|
||||
Pipeline pipeLine = runSpace.CreatePipeline();
|
||||
using (pipeLine)
|
||||
{
|
||||
// Add the command
|
||||
pipeLine.Commands.Add(cmd);
|
||||
// Execute the pipeline and save the objects returned.
|
||||
results = pipeLine.Invoke();
|
||||
|
||||
// Log out any errors in the pipeline execution
|
||||
// NOTE: These errors are NOT thrown as exceptions!
|
||||
// Be sure to check this to ensure that no errors
|
||||
// happened while executing the command.
|
||||
if (pipeLine.Error != null && pipeLine.Error.Count > 0)
|
||||
{
|
||||
foreach (object item in pipeLine.Error.ReadToEnd())
|
||||
{
|
||||
errorList.Add(item);
|
||||
string errorMessage = string.Format("Invoke error: {0}", item);
|
||||
HostedSolutionLog.LogWarning(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
pipeLine = null;
|
||||
errors = errorList.ToArray();
|
||||
HostedSolutionLog.LogEnd("ExecuteShellCommand");
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the distinguished name of the object from the shell execution result
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <returns></returns>
|
||||
internal string GetResultObjectDN(Collection<PSObject> result)
|
||||
{
|
||||
HostedSolutionLog.LogStart("GetResultObjectDN");
|
||||
if (result == null)
|
||||
throw new ArgumentNullException("result", "Execution result is not specified");
|
||||
|
||||
if (result.Count < 1)
|
||||
throw new ArgumentException("Execution result does not contain any object");
|
||||
|
||||
if (result.Count > 1)
|
||||
throw new ArgumentException("Execution result contains more than one object");
|
||||
|
||||
PSMemberInfo info = result[0].Members["DistinguishedName"];
|
||||
if (info == null)
|
||||
throw new ArgumentException("Execution result does not contain DistinguishedName property", "result");
|
||||
|
||||
string ret = info.Value.ToString();
|
||||
HostedSolutionLog.LogEnd("GetResultObjectDN");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the object from the shell execution result.
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <returns>Distinguished name of the object if object exists or null otherwise.</returns>
|
||||
internal string CheckResultObjectDN(Collection<PSObject> result)
|
||||
{
|
||||
HostedSolutionLog.LogStart("CheckResultObjectDN");
|
||||
|
||||
if (result == null)
|
||||
return null;
|
||||
|
||||
if (result.Count < 1)
|
||||
return null;
|
||||
|
||||
PSMemberInfo info = result[0].Members["DistinguishedName"];
|
||||
if (info == null)
|
||||
throw new ArgumentException("Execution result does not contain DistinguishedName property", "result");
|
||||
|
||||
string ret = info.Value.ToString();
|
||||
HostedSolutionLog.LogEnd("CheckResultObjectDN");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the identity of the object from the shell execution result
|
||||
/// </summary>
|
||||
/// <param name="result"></param>
|
||||
/// <returns></returns>
|
||||
internal string GetResultObjectIdentity(Collection<PSObject> result)
|
||||
{
|
||||
HostedSolutionLog.LogStart("GetResultObjectIdentity");
|
||||
if (result == null)
|
||||
throw new ArgumentNullException("result", "Execution result is not specified");
|
||||
|
||||
if (result.Count < 1)
|
||||
throw new ArgumentException("Execution result is empty", "result");
|
||||
|
||||
if (result.Count > 1)
|
||||
throw new ArgumentException("Execution result contains more than one object", "result");
|
||||
|
||||
PSMemberInfo info = result[0].Members["Identity"];
|
||||
if (info == null)
|
||||
throw new ArgumentException("Execution result does not contain Identity property", "result");
|
||||
|
||||
string ret = info.Value.ToString();
|
||||
HostedSolutionLog.LogEnd("GetResultObjectIdentity");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the identity of the PS object
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
internal string GetPSObjectIdentity(PSObject obj)
|
||||
{
|
||||
HostedSolutionLog.LogStart("GetPSObjectIdentity");
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException("obj", "PSObject is not specified");
|
||||
|
||||
|
||||
PSMemberInfo info = obj.Members["Identity"];
|
||||
if (info == null)
|
||||
throw new ArgumentException("PSObject does not contain Identity property", "obj");
|
||||
|
||||
string ret = info.Value.ToString();
|
||||
HostedSolutionLog.LogEnd("GetPSObjectIdentity");
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal object GetPSObjectProperty(PSObject obj, string name)
|
||||
{
|
||||
return obj.Members[name].Value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void SetPeoplePickerOu(string site, string ou)
|
||||
{
|
||||
HostedSolutionLog.LogStart("SetPeoplePickerOu");
|
||||
HostedSolutionLog.LogInfo(" Site: {0}", site);
|
||||
HostedSolutionLog.LogInfo(" OU: {0}", ou);
|
||||
|
||||
Runspace runSpace = null;
|
||||
try
|
||||
{
|
||||
List<SharePointSiteCollection> siteCollections = new List<SharePointSiteCollection>();
|
||||
|
||||
runSpace = OpenRunspace();
|
||||
Command cmd = new Command("Set-SPSite");
|
||||
cmd.Parameters.Add("Identity", site);
|
||||
cmd.Parameters.Add("UserAccountDirectoryPath", ou);
|
||||
ExecuteShellCommand(runSpace, cmd);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
CloseRunspace(runSpace);
|
||||
}
|
||||
|
||||
HostedSolutionLog.LogEnd("SetPeoplePickerOu");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -38,33 +38,48 @@ using Microsoft.SharePoint.Administration;
|
|||
|
||||
namespace WebsitePanel.Providers.HostedSolution
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents SharePoint management functionality implementation.
|
||||
/// </summary>
|
||||
public class HostedSharePointServerImpl : MarshalByRefObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets list of supported languages by this installation of SharePoint.
|
||||
/// </summary>
|
||||
/// <returns>List of supported languages</returns>
|
||||
/// <summary>
|
||||
/// Represents SharePoint management functionality implementation.
|
||||
/// </summary>
|
||||
public class HostedSharePointServerImpl : MarshalByRefObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets list of supported languages by this installation of SharePoint.
|
||||
/// </summary>
|
||||
/// <returns>List of supported languages</returns>
|
||||
public int[] GetSupportedLanguages(string languagePacksPath)
|
||||
{
|
||||
List<int> languages = new List<int>();
|
||||
string rootDirectory = FileUtils.EvaluateSystemVariables(languagePacksPath);
|
||||
foreach (string dir in Directory.GetDirectories(rootDirectory))
|
||||
{
|
||||
int languageId = 0;
|
||||
if (Int32.TryParse(dir.Replace(rootDirectory, String.Empty), out languageId))
|
||||
{
|
||||
languages.Add(languageId);
|
||||
}
|
||||
}
|
||||
{
|
||||
List<int> languages = new List<int>();
|
||||
|
||||
return languages.ToArray();
|
||||
}
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
public long GetSiteCollectionSize(Uri root,string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
SPLanguageCollection installedLanguages = SPRegionalSettings.GlobalInstalledLanguages;
|
||||
|
||||
foreach (SPLanguage lang in installedLanguages)
|
||||
{
|
||||
languages.Add(lang.LCID);
|
||||
}
|
||||
|
||||
return languages.ToArray();
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public long GetSiteCollectionSize(Uri root, string url)
|
||||
{
|
||||
WindowsImpersonationContext wic = null;
|
||||
|
||||
try
|
||||
|
@ -77,8 +92,8 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
site.RecalculateStorageUsed();
|
||||
else
|
||||
throw new ApplicationException(string.Format("SiteCollection {0} does not exist", url));
|
||||
|
||||
return site.Usage.Storage;
|
||||
|
||||
return site.Usage.Storage;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -91,28 +106,28 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
wic.Undo();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SharePointSiteDiskSpace[] CalculateSiteCollectionDiskSpace(Uri root, string[] urls)
|
||||
{
|
||||
{
|
||||
WindowsImpersonationContext wic = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(root);
|
||||
|
||||
List<SharePointSiteDiskSpace> ret = new List<SharePointSiteDiskSpace>();
|
||||
foreach (string url in urls)
|
||||
{
|
||||
SharePointSiteDiskSpace siteDiskSpace = new SharePointSiteDiskSpace();
|
||||
rootWebApplication.Sites[url].RecalculateStorageUsed();
|
||||
rootWebApplication.Sites[url].RecalculateStorageUsed();
|
||||
siteDiskSpace.Url = url;
|
||||
siteDiskSpace.DiskSpace = (long)Math.Round( rootWebApplication.Sites[url].Usage.Storage / 1024.0 / 1024.0);
|
||||
siteDiskSpace.DiskSpace = (long)Math.Round(rootWebApplication.Sites[url].Usage.Storage / 1024.0 / 1024.0);
|
||||
ret.Add(siteDiskSpace);
|
||||
}
|
||||
return ret.ToArray();
|
||||
return ret.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -125,97 +140,97 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
wic.Undo();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets list of SharePoint collections within root web application.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <returns>List of SharePoint collections within root web application.</returns>
|
||||
public SharePointSiteCollection[] GetSiteCollections(Uri rootWebApplicationUri)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
/// Gets list of SharePoint collections within root web application.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <returns>List of SharePoint collections within root web application.</returns>
|
||||
public SharePointSiteCollection[] GetSiteCollections(Uri rootWebApplicationUri)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
|
||||
List<SharePointSiteCollection> siteCollections = new List<SharePointSiteCollection>();
|
||||
List<SharePointSiteCollection> siteCollections = new List<SharePointSiteCollection>();
|
||||
|
||||
foreach(SPSite site in rootWebApplication.Sites)
|
||||
{
|
||||
foreach (SPSite site in rootWebApplication.Sites)
|
||||
{
|
||||
SharePointSiteCollection loadedSiteCollection = new SharePointSiteCollection();
|
||||
FillSiteCollection(loadedSiteCollection, site);
|
||||
siteCollections.Add(loadedSiteCollection);
|
||||
}
|
||||
FillSiteCollection(loadedSiteCollection, site);
|
||||
siteCollections.Add(loadedSiteCollection);
|
||||
}
|
||||
|
||||
return siteCollections.ToArray();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create site collection.", ex);
|
||||
}
|
||||
}
|
||||
return siteCollections.ToArray();
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets SharePoint collection within root web application with given name.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <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(Uri rootWebApplicationUri, string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
/// <summary>
|
||||
/// Gets SharePoint collection within root web application with given name.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <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(Uri rootWebApplicationUri, string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
|
||||
SPSite site = rootWebApplication.Sites[siteCollectionUrl];
|
||||
if (site != null)
|
||||
{
|
||||
SharePointSiteCollection loadedSiteCollection = new SharePointSiteCollection();
|
||||
FillSiteCollection(loadedSiteCollection, site);
|
||||
return loadedSiteCollection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create site collection.", ex);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
|
||||
private static void DeleteQuotaTemplate(string name)
|
||||
{
|
||||
SPSite site = rootWebApplication.Sites[siteCollectionUrl];
|
||||
if (site != null)
|
||||
{
|
||||
SharePointSiteCollection loadedSiteCollection = new SharePointSiteCollection();
|
||||
FillSiteCollection(loadedSiteCollection, site);
|
||||
return loadedSiteCollection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to create site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeleteQuotaTemplate(string name)
|
||||
{
|
||||
SPFarm farm = SPFarm.Local;
|
||||
|
||||
SPWebService webService = farm.Services.GetValue<SPWebService>("");
|
||||
SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates;
|
||||
quotaColl.Delete(name);
|
||||
}
|
||||
|
||||
quotaColl.Delete(name);
|
||||
}
|
||||
|
||||
|
||||
public void UpdateQuotas(Uri root, string url, long maxStorage, long warningStorage)
|
||||
{
|
||||
WindowsImpersonationContext wic = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
@ -230,10 +245,10 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
|
||||
|
||||
if (warningStorage != -1 && maxStorage != -1)
|
||||
quota.StorageWarningLevel = Math.Min(warningStorage, maxStorage)*1024*1024;
|
||||
quota.StorageWarningLevel = Math.Min(warningStorage, maxStorage) * 1024 * 1024;
|
||||
else
|
||||
quota.StorageWarningLevel = 0;
|
||||
|
||||
|
||||
rootWebApplication.GrantAccessToProcessIdentity(WindowsIdentity.GetCurrent().Name);
|
||||
rootWebApplication.Sites[url].Quota = quota;
|
||||
|
||||
|
@ -250,16 +265,17 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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>
|
||||
/// 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, SharePointSiteCollection siteCollection)
|
||||
{
|
||||
WindowsImpersonationContext wic = null;
|
||||
HostedSolutionLog.LogStart("CreateSiteCollection");
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -267,27 +283,29 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);
|
||||
|
||||
HostedSolutionLog.DebugInfo("rootWebApplicationUri: {0}", rootWebApplicationUri);
|
||||
HostedSolutionLog.DebugInfo("siteCollectionUrl: {0}", siteCollectionUrl);
|
||||
|
||||
SPQuota spQuota;
|
||||
|
||||
|
||||
SPSite spSite = rootWebApplication.Sites.Add(siteCollectionUrl,
|
||||
siteCollection.Title, siteCollection.Description,
|
||||
(uint) siteCollection.LocaleId, String.Empty,
|
||||
(uint)siteCollection.LocaleId, String.Empty,
|
||||
siteCollection.OwnerLogin, siteCollection.OwnerName,
|
||||
siteCollection.OwnerEmail,
|
||||
null, null, null, true);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
spQuota = new SPQuota();
|
||||
|
||||
|
||||
if (siteCollection.MaxSiteStorage != -1)
|
||||
spQuota.StorageMaximumLevel = siteCollection.MaxSiteStorage * 1024 * 1024;
|
||||
|
||||
if (siteCollection.WarningStorage != -1 && siteCollection.MaxSiteStorage != -1)
|
||||
spQuota.StorageWarningLevel = Math.Min(siteCollection.WarningStorage, siteCollection.MaxSiteStorage) * 1024 * 1024;
|
||||
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -298,7 +316,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
try
|
||||
{
|
||||
rootWebApplication.GrantAccessToProcessIdentity(WindowsIdentity.GetCurrent().Name);
|
||||
spSite.Quota = spQuota;
|
||||
spSite.Quota = spQuota;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
@ -308,8 +326,77 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
}
|
||||
|
||||
rootWebApplication.Update(true);
|
||||
|
||||
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 char[] { '\n' });
|
||||
bool bRecordExist = false;
|
||||
foreach (string s in contentArr)
|
||||
{
|
||||
if (s != string.Empty)
|
||||
{
|
||||
string IPAddr = 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
|
||||
IPAddr += c;
|
||||
}
|
||||
else
|
||||
bSeperator = true;
|
||||
}
|
||||
|
||||
if (hostName.ToLower() == siteCollection.RootWebApplicationFQDN.ToLower())
|
||||
{
|
||||
bRecordExist = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!bRecordExist)
|
||||
{
|
||||
string outPut = string.Empty;
|
||||
foreach (string o in contentArr)
|
||||
{
|
||||
if (o != string.Empty)
|
||||
outPut += o + "\r\n";
|
||||
}
|
||||
|
||||
outPut += siteCollection.RootWebApplicationInteralIpAddress + '\t' + siteCollection.RootWebApplicationFQDN + "\r\n";
|
||||
|
||||
FileUtils.UpdateFileTextContent(path, outPut);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostedSolutionLog.LogError(ex);
|
||||
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostedSolutionLog.LogError(ex);
|
||||
throw;
|
||||
|
@ -318,207 +405,267 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
{
|
||||
if (wic != null)
|
||||
wic.Undo();
|
||||
|
||||
HostedSolutionLog.LogEnd("CreateSiteCollection");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes site collection under given url.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <param name="url">Url that uniquely identifies 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, string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
||||
WindowsImpersonationContext wic = identity.Impersonate();
|
||||
/// <summary>
|
||||
/// Deletes site collection under given url.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <param name="url">Url that uniquely identifies 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, SharePointSiteCollection siteCollection)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsIdentity identity = WindowsIdentity.GetCurrent();
|
||||
WindowsImpersonationContext wic = identity.Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", siteCollection.Url, rootWebApplicationUri.Port);
|
||||
|
||||
//string args = String.Format("-o deletesite -url {0}", siteCollectionUrl);
|
||||
//string stsadm = @"c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE";
|
||||
//string args = String.Format("-o deletesite -url {0}", siteCollectionUrl);
|
||||
//string stsadm = @"c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE";
|
||||
|
||||
//// launch system process
|
||||
//ProcessStartInfo startInfo = new ProcessStartInfo(stsadm, args);
|
||||
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
//startInfo.RedirectStandardOutput = true;
|
||||
//startInfo.UseShellExecute = false;
|
||||
//Process proc = Process.Start(startInfo);
|
||||
//// launch system process
|
||||
//ProcessStartInfo startInfo = new ProcessStartInfo(stsadm, args);
|
||||
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
//startInfo.RedirectStandardOutput = true;
|
||||
//startInfo.UseShellExecute = false;
|
||||
//Process proc = Process.Start(startInfo);
|
||||
|
||||
//// analyze results
|
||||
//StreamReader reader = proc.StandardOutput;
|
||||
//string output = reader.ReadToEnd();
|
||||
//int exitCode = proc.ExitCode;
|
||||
//reader.Close();
|
||||
//// analyze results
|
||||
//StreamReader reader = proc.StandardOutput;
|
||||
//string output = reader.ReadToEnd();
|
||||
//int exitCode = proc.ExitCode;
|
||||
//reader.Close();
|
||||
|
||||
|
||||
rootWebApplication.Sites.Delete(siteCollectionUrl, true);
|
||||
rootWebApplication.Update(true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to delete site collection.", ex);
|
||||
}
|
||||
}
|
||||
rootWebApplication.Sites.Delete(siteCollectionUrl, true);
|
||||
rootWebApplication.Update(true);
|
||||
|
||||
/// <summary>
|
||||
/// Backups site collection under give url.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <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>
|
||||
/// <param name="tempPath">Custom temp path for backup</param>
|
||||
/// <returns>Full path to created backup.</returns>
|
||||
/// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
|
||||
public string BackupSiteCollection(Uri rootWebApplicationUri, string url, string filename, bool zip, string tempPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
try
|
||||
{
|
||||
if (siteCollection.RootWebApplicationInteralIpAddress != string.Empty)
|
||||
{
|
||||
string dirPath = FileUtils.EvaluateSystemVariables(@"%windir%\system32\drivers\etc");
|
||||
string path = dirPath + "\\hosts";
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
if (FileUtils.FileExists(path))
|
||||
{
|
||||
string content = FileUtils.GetFileTextContent(path);
|
||||
content = content.Replace("\r\n", "\n").Replace("\n\r", "\n");
|
||||
string[] contentArr = content.Split(new char[] { '\n' });
|
||||
string outPut = string.Empty;
|
||||
foreach (string s in contentArr)
|
||||
{
|
||||
if (s != string.Empty)
|
||||
{
|
||||
string IPAddr = 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
|
||||
IPAddr += c;
|
||||
}
|
||||
else
|
||||
bSeperator = true;
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(tempPath))
|
||||
{
|
||||
tempPath = Path.GetTempPath();
|
||||
}
|
||||
string backupFileName = Path.Combine(tempPath, (zip ? StringUtils.CleanIdentifier(siteCollectionUrl) + ".bsh" : StringUtils.CleanIdentifier(filename)));
|
||||
// Backup requested site.
|
||||
rootWebApplication.Sites.Backup(siteCollectionUrl, backupFileName, true);
|
||||
if (hostName.ToLower() != siteCollection.RootWebApplicationFQDN.ToLower())
|
||||
{
|
||||
outPut += s + "\r\n";
|
||||
}
|
||||
|
||||
if (zip)
|
||||
{
|
||||
string zipFile = Path.Combine(tempPath, filename);
|
||||
string zipRoot = Path.GetDirectoryName(backupFileName);
|
||||
}
|
||||
else
|
||||
outPut += s + "\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
FileUtils.ZipFiles(zipFile, zipRoot, new string[] { Path.GetFileName(backupFileName) });
|
||||
FileUtils.DeleteFile(backupFileName);
|
||||
FileUtils.UpdateFileTextContent(path, outPut);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HostedSolutionLog.LogError(ex);
|
||||
|
||||
backupFileName = zipFile;
|
||||
}
|
||||
return backupFileName;
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to backup site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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, SharePointSiteCollection siteCollection, string filename)
|
||||
{
|
||||
string url = siteCollection.Url;
|
||||
try
|
||||
{
|
||||
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
|
||||
string tempPath = Path.GetTempPath();
|
||||
// Unzip uploaded files if required.
|
||||
string expandedFile = filename;
|
||||
if (Path.GetExtension(filename).ToLower() == ".zip")
|
||||
{
|
||||
// Unpack file.
|
||||
expandedFile = FileUtils.UnzipFiles(filename, tempPath)[0];
|
||||
|
||||
// Delete zip archive.
|
||||
FileUtils.DeleteFile(filename);
|
||||
}
|
||||
|
||||
// Delete existent site and restore new one.
|
||||
rootWebApplication.Sites.Delete(siteCollectionUrl, false);
|
||||
rootWebApplication.Sites.Restore(siteCollectionUrl, expandedFile, true, true);
|
||||
|
||||
SPSite restoredSite = rootWebApplication.Sites[siteCollectionUrl];
|
||||
SPWeb web = restoredSite.OpenWeb();
|
||||
|
||||
SPUser owner = null;
|
||||
try
|
||||
{
|
||||
owner = web.SiteUsers[siteCollection.OwnerLogin];
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore this error.
|
||||
}
|
||||
if (owner == null)
|
||||
{
|
||||
web.SiteUsers.Add(siteCollection.OwnerLogin, siteCollection.OwnerEmail, siteCollection.OwnerName, String.Empty);
|
||||
owner = web.SiteUsers[siteCollection.OwnerLogin];
|
||||
}
|
||||
|
||||
restoredSite.Owner = owner;
|
||||
web.Close();
|
||||
|
||||
rootWebApplication.Update();
|
||||
|
||||
// Delete expanded file.
|
||||
FileUtils.DeleteFile(expandedFile);
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to restore site collection.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fills custom site collection with information from administration object.
|
||||
/// </summary>
|
||||
/// <param name="customSiteCollection">Custom site collection to fill.</param>
|
||||
/// <param name="site">Administration object.</param>
|
||||
private static void FillSiteCollection (SharePointSiteCollection customSiteCollection, SPSite site)
|
||||
{
|
||||
Uri siteUri = new Uri(site.Url);
|
||||
string url = (siteUri.Port > 0) ? site.Url.Replace(String.Format(":{0}", siteUri.Port), String.Empty) : site.Url;
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to delete site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
customSiteCollection.Url = url;
|
||||
customSiteCollection.OwnerLogin = site.Owner.LoginName;
|
||||
customSiteCollection.OwnerName = site.Owner.Name;
|
||||
customSiteCollection.OwnerEmail = site.Owner.Email;
|
||||
customSiteCollection.LocaleId = site.RootWeb.Locale.LCID;
|
||||
customSiteCollection.Title = site.RootWeb.Title;
|
||||
customSiteCollection.Description = site.RootWeb.Description;
|
||||
customSiteCollection.Bandwidth = site.Usage.Bandwidth;
|
||||
customSiteCollection.Diskspace = site.Usage.Storage;
|
||||
customSiteCollection.MaxSiteStorage = site.Quota.StorageMaximumLevel;
|
||||
customSiteCollection.WarningStorage = site.Quota.StorageWarningLevel;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Backups site collection under give url.
|
||||
/// </summary>
|
||||
/// <param name="rootWebApplicationUri">Root web application uri.</param>
|
||||
/// <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>
|
||||
/// <param name="tempPath">Custom temp path for backup</param>
|
||||
/// <returns>Full path to created backup.</returns>
|
||||
/// <exception cref="InvalidOperationException">Is thrown in case requested operation fails for any reason.</exception>
|
||||
public string BackupSiteCollection(Uri rootWebApplicationUri, string url, string filename, bool zip, string tempPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
|
||||
if (String.IsNullOrEmpty(tempPath))
|
||||
{
|
||||
tempPath = Path.GetTempPath();
|
||||
}
|
||||
string backupFileName = Path.Combine(tempPath, (zip ? StringUtils.CleanIdentifier(siteCollectionUrl) + ".bsh" : StringUtils.CleanIdentifier(filename)));
|
||||
// Backup requested site.
|
||||
rootWebApplication.Sites.Backup(siteCollectionUrl, backupFileName, true);
|
||||
|
||||
if (zip)
|
||||
{
|
||||
string zipFile = Path.Combine(tempPath, filename);
|
||||
string zipRoot = Path.GetDirectoryName(backupFileName);
|
||||
|
||||
FileUtils.ZipFiles(zipFile, zipRoot, new string[] { Path.GetFileName(backupFileName) });
|
||||
FileUtils.DeleteFile(backupFileName);
|
||||
|
||||
backupFileName = zipFile;
|
||||
}
|
||||
return backupFileName;
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to backup site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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, SharePointSiteCollection siteCollection, string filename)
|
||||
{
|
||||
string url = siteCollection.Url;
|
||||
try
|
||||
{
|
||||
|
||||
WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();
|
||||
|
||||
try
|
||||
{
|
||||
SPWebApplication rootWebApplication = SPWebApplication.Lookup(rootWebApplicationUri);
|
||||
string siteCollectionUrl = String.Format("{0}:{1}", url, rootWebApplicationUri.Port);
|
||||
|
||||
string tempPath = Path.GetTempPath();
|
||||
// Unzip uploaded files if required.
|
||||
string expandedFile = filename;
|
||||
if (Path.GetExtension(filename).ToLower() == ".zip")
|
||||
{
|
||||
// Unpack file.
|
||||
expandedFile = FileUtils.UnzipFiles(filename, tempPath)[0];
|
||||
|
||||
// Delete zip archive.
|
||||
FileUtils.DeleteFile(filename);
|
||||
}
|
||||
|
||||
// Delete existent site and restore new one.
|
||||
rootWebApplication.Sites.Delete(siteCollectionUrl, false);
|
||||
rootWebApplication.Sites.Restore(siteCollectionUrl, expandedFile, true, true);
|
||||
|
||||
SPSite restoredSite = rootWebApplication.Sites[siteCollectionUrl];
|
||||
SPWeb web = restoredSite.OpenWeb();
|
||||
|
||||
SPUser owner = null;
|
||||
try
|
||||
{
|
||||
owner = web.SiteUsers[siteCollection.OwnerLogin];
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore this error.
|
||||
}
|
||||
if (owner == null)
|
||||
{
|
||||
web.SiteUsers.Add(siteCollection.OwnerLogin, siteCollection.OwnerEmail, siteCollection.OwnerName, String.Empty);
|
||||
owner = web.SiteUsers[siteCollection.OwnerLogin];
|
||||
}
|
||||
|
||||
restoredSite.Owner = owner;
|
||||
web.Close();
|
||||
|
||||
rootWebApplication.Update();
|
||||
|
||||
// Delete expanded file.
|
||||
FileUtils.DeleteFile(expandedFile);
|
||||
}
|
||||
finally
|
||||
{
|
||||
wic.Undo();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException("Failed to restore site collection.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fills custom site collection with information from administration object.
|
||||
/// </summary>
|
||||
/// <param name="customSiteCollection">Custom site collection to fill.</param>
|
||||
/// <param name="site">Administration object.</param>
|
||||
private static void FillSiteCollection(SharePointSiteCollection customSiteCollection, SPSite site)
|
||||
{
|
||||
Uri siteUri = new Uri(site.Url);
|
||||
string url = (siteUri.Port > 0) ? site.Url.Replace(String.Format(":{0}", siteUri.Port), String.Empty) : site.Url;
|
||||
|
||||
customSiteCollection.Url = url;
|
||||
customSiteCollection.OwnerLogin = site.Owner.LoginName;
|
||||
customSiteCollection.OwnerName = site.Owner.Name;
|
||||
customSiteCollection.OwnerEmail = site.Owner.Email;
|
||||
customSiteCollection.LocaleId = site.RootWeb.Locale.LCID;
|
||||
customSiteCollection.Title = site.RootWeb.Title;
|
||||
customSiteCollection.Description = site.RootWeb.Description;
|
||||
customSiteCollection.Bandwidth = site.Usage.Bandwidth;
|
||||
customSiteCollection.Diskspace = site.Usage.Storage;
|
||||
customSiteCollection.MaxSiteStorage = site.Quota.StorageMaximumLevel;
|
||||
customSiteCollection.WarningStorage = site.Quota.StorageWarningLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
using System;
|
||||
using WebsitePanel.Providers.Common;
|
||||
using WebsitePanel.Server.Utils;
|
||||
using System.Text;
|
||||
using System.Management.Automation.Runspaces;
|
||||
|
||||
namespace WebsitePanel.Providers.HostedSolution
|
||||
{
|
||||
|
@ -121,6 +123,22 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
res.IsSuccess = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
internal static void DebugCommand(Command cmd)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder(cmd.CommandText);
|
||||
foreach (CommandParameter parameter in cmd.Parameters)
|
||||
{
|
||||
string formatString = " -{0} {1}";
|
||||
if (parameter.Value is string)
|
||||
formatString = " -{0} '{1}'";
|
||||
else if (parameter.Value is bool)
|
||||
formatString = " -{0} ${1}";
|
||||
sb.AppendFormat(formatString, parameter.Name, parameter.Value);
|
||||
}
|
||||
Log.WriteInfo("{0} {1}", LogPrefix, sb.ToString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue