本文整理汇总了C#中Tenant.DeleteSiteCollection方法的典型用法代码示例。如果您正苦于以下问题:C# Tenant.DeleteSiteCollection方法的具体用法?C# Tenant.DeleteSiteCollection怎么用?C# Tenant.DeleteSiteCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tenant
的用法示例。
在下文中一共展示了Tenant.DeleteSiteCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDeleteCreateSiteCollectionTest
public void CreateDeleteCreateSiteCollectionTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
//Create site collection test
string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
var siteExists = tenant.SiteExists(siteToCreateUrl);
Assert.IsTrue(siteExists, "Site collection creation failed");
//Delete site collection test: move to recycle bin
tenant.DeleteSiteCollection(siteToCreateUrl, true);
bool recycled = tenant.CheckIfSiteExists(siteToCreateUrl, "Recycled");
Assert.IsTrue(recycled, "Site collection recycling failed");
//Remove from recycle bin
tenant.DeleteSiteCollectionFromRecycleBin(siteToCreateUrl, true);
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Assert.IsFalse(siteExists2, "Site collection deletion from recycle bin failed");
//Create a site collection using the same url as the previously deleted site collection
siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
siteExists = tenant.SiteExists(siteToCreateUrl);
Assert.IsTrue(siteExists, "Second site collection creation failed");
}
}
示例2: CreateDeleteSiteCollectionTest
public void CreateDeleteSiteCollectionTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
//Create site collection test
string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
var siteExists = tenant.Context.WebExistsFullUrl(siteToCreateUrl);
Assert.IsTrue(siteExists, "Site collection creation failed");
//Delete site collection test
tenant.DeleteSiteCollection(siteToCreateUrl);
siteExists = tenant.Context.WebExistsFullUrl(siteToCreateUrl);
Assert.IsFalse(siteExists, "Site collection deletion failed");
}
}
示例3: Enforce
public virtual void Enforce(SiteInformation site, bool supressEmail)
{
var state = site.ComplianceState;
//If site is locked, then will not send any lock notification email, instead of sending delete email.
if (site.ComplianceState.IsLocked && !site.ComplianceState.DeleteNotificationSent)
SetNotifyDeleteState(site);
if (GovernanceWorkflowHelper.NeedNotifyLock(state.LockedDate, state))
{
ExtendOutdatedLockedDate(site); //Extend the LockedDate if it is earlier than current date
}
else if (GovernanceWorkflowHelper.NeedNotifyDelete(state.LockedDate, state))
{
ExtendOutdatedDeleteDate(site); //Extend the DeleteDate if it is earlier than current date
}
if (state.IsCompliant)
ChangeComplianceStateToDefault(site);
var tenant = new Tenant(TenentClientContext);
if (GovernanceWorkflowHelper.NeedNotifyLock(state.LockedDate, state))
{
Notifiy(site, TenentClientContext, supressEmail);
Log.Info(GetType().Name, "Notify Lock for site {0}", site.Url);
}
else if (GovernanceWorkflowHelper.NeedLock(state.LockedDate, state))
{
tenant.SetSiteLockState(site.Url, SiteLockState.NoAccess, true);
site.ComplianceState.IsLocked = true;
Log.Info(GetType().Name, "Site {0} was locked", site.Url);
}
else if (GovernanceWorkflowHelper.NeedNotifyDelete(state.LockedDate, state))
{
Notifiy(site, TenentClientContext, supressEmail);
Log.Info(GetType().Name, "Notify Delete for site {0}", site.Url);
}
else if (GovernanceWorkflowHelper.NeedDelete(state.LockedDate))
{
//set a flag to let us know that the site is deleted by Governance Job
//site.DeletedBy = AutoSiteDeleteBy.GovernanceJob;
tenant.DeleteSiteCollection(site.Url, true);
//Set a value to indicate that the site was just deleted
site.ComplianceState.DeleteDate = DateTime.MaxValue;
Log.Info(GetType().Name, "Site {0} was deleted", site.Url);
}
TenentClientContext.ExecuteQueryRetry();
}
示例4: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
var tenant = new Tenant(tenantContext);
for (int i = 0; i <= 9; i++)
{
try
{
string site = string.Format("TestPnPSC_123456789_{0}", i);
site = GetTestSiteCollectionName(ConfigurationManager.AppSettings["SPODevSiteUrl"], site);
// ensure the site collection in unlocked state before deleting
tenant.SetSiteLockState(site, SiteLockState.Unlock);
// delete the site collection, do not use the recyle bin
tenant.DeleteSiteCollection(site, false);
}
catch (Exception ex)
{
// eat all exceptions
Console.WriteLine(ex.ToString());
}
}
}
示例5: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
var tenant = new Tenant(tenantContext);
var siteCols = tenant.GetSiteCollections();
foreach (var siteCol in siteCols)
{
if (siteCol.Url.Contains(sitecollectionNamePrefix))
{
try
{
// Drop the site collection from the recycle bin
if (tenant.CheckIfSiteExists(siteCol.Url, "Recycled"))
{
tenant.DeleteSiteCollectionFromRecycleBin(siteCol.Url, false);
}
else
{
// Eat the exceptions: would occur if the site collection is already in the recycle bin.
try
{
// ensure the site collection in unlocked state before deleting
tenant.SetSiteLockState(siteCol.Url, SiteLockState.Unlock);
}
catch { }
// delete the site collection, do not use the recyle bin
tenant.DeleteSiteCollection(siteCol.Url, false);
}
}
catch (Exception ex)
{
// eat all exceptions
Console.WriteLine(ex.ToString());
}
}
}
}
示例6: ClassCleanupBase
public static void ClassCleanupBase()
{
if (!debugMode)
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
#if !ONPREMISES
CleanupAllTestSiteCollections(tenantContext);
#else
// first cleanup the just created one...most likely it's not indexed yet
try
{
Tenant t = new Tenant(tenantContext);
t.DeleteSiteCollection(centralSiteCollectionUrl);
}
catch { }
// Use search based site collection retrieval to delete the one's that are left over from failed test cases
CleanupAllTestSiteCollections(tenantContext);
#endif
}
}
}
示例7: DumpTemplate
private void DumpTemplate(ClientContext ctx, string template, string subSiteTemplate = "", string saveAsTemplate = "")
{
Uri devSiteUrl = new Uri(ConfigurationManager.AppSettings["SPODevSiteUrl"]);
string baseUrl = String.Format("{0}://{1}", devSiteUrl.Scheme, devSiteUrl.DnsSafeHost);
string siteUrl = "";
if (subSiteTemplate.Length > 0)
{
siteUrl = string.Format("{1}/sites/template{0}/template{2}", template.Replace("#", ""), baseUrl, subSiteTemplate.Replace("#", ""));
#if !CLIENTSDKV15
var siteCollectionUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
CreateSiteCollection(template, siteCollectionUrl);
using (var sitecolCtx = ctx.Clone(siteCollectionUrl))
{
sitecolCtx.Web.Webs.Add(new WebCreationInformation()
{
Title = string.Format("template{0}", subSiteTemplate),
Language = 1033,
Url = string.Format("template{0}", subSiteTemplate.Replace("#", "")),
UseSamePermissionsAsParentSite = true
});
sitecolCtx.ExecuteQueryRetry();
}
#endif
}
else
{
siteUrl = string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl);
#if !CLIENTSDKV15
CreateSiteCollection(template, siteUrl);
#endif
}
using (ClientContext cc = ctx.Clone(siteUrl))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
creationInfo.BaseTemplate = null;
// Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
// blankinternet#0 as web template using CSOM/SSOM API
if (saveAsTemplate.Length > 0)
{
template = saveAsTemplate;
}
ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
if (subSiteTemplate.Length > 0)
{
p.Id = String.Format("{0}template", subSiteTemplate.Replace("#", ""));
}
else
{
p.Id = String.Format("{0}template", template.Replace("#", ""));
}
// Cleanup before saving
p.Security.AdditionalAdministrators.Clear();
XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(".", "");
if (subSiteTemplate.Length > 0)
{
provider.SaveAs(p, String.Format("{0}Template.xml", subSiteTemplate.Replace("#", "")));
}
else
{
provider.SaveAs(p, String.Format("{0}Template.xml", template.Replace("#", "")));
}
#if !CLIENTSDKV15
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
Tenant tenant = new Tenant(tenantCtx);
Console.WriteLine("Deleting new site {0}", string.Format("{1}/sites/template{0}", template.Replace("#", ""), baseUrl));
tenant.DeleteSiteCollection(siteUrl, false);
}
#endif
}
}
示例8: CreateSiteCollection
private static void CreateSiteCollection(string template, string siteUrl)
{
// check if site exists
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
Tenant tenant = new Tenant(tenantCtx);
if (tenant.SiteExists(siteUrl))
{
Console.WriteLine("Deleting existing site {0}", siteUrl);
tenant.DeleteSiteCollection(siteUrl, false);
}
Console.WriteLine("Creating new site {0}", siteUrl);
tenant.CreateSiteCollection(new Entities.SiteEntity()
{
Lcid = 1033,
TimeZoneId = 4,
SiteOwnerLogin = (TestCommon.Credentials as SharePointOnlineCredentials).UserName,
Title = "Template Site",
Template = template,
Url = siteUrl,
}, true, true);
}
}
示例9: SetSiteLockStateTest
public void SetSiteLockStateTest()
{
try
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
tenantContext.RequestTimeout = Timeout.Infinite;
var tenant = new Tenant(tenantContext);
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
Console.WriteLine("SetSiteLockStateTest: step 1");
if (!tenant.SiteExists(siteToCreateUrl))
{
siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
Console.WriteLine("SetSiteLockStateTest: step 1.1");
var siteExists = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("SetSiteLockStateTest: step 1.2");
Assert.IsTrue(siteExists, "Site collection creation failed");
}
Console.WriteLine("SetSiteLockStateTest: step 2");
// Set Lockstate NoAccess test
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.NoAccess, true);
Console.WriteLine("SetSiteLockStateTest: step 2.1");
var siteProperties = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
Console.WriteLine("SetSiteLockStateTest: step 2.1");
tenantContext.Load(siteProperties);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties.LockState == SiteLockState.NoAccess.ToString(), "LockState wasn't set to NoAccess");
// Set Lockstate NoAccess test
Console.WriteLine("SetSiteLockStateTest: step 3");
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.Unlock, true);
Console.WriteLine("SetSiteLockStateTest: step 3.1");
var siteProperties2 = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
Console.WriteLine("SetSiteLockStateTest: step 3.2");
tenantContext.Load(siteProperties2);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties2.LockState == SiteLockState.Unlock.ToString(), "LockState wasn't set to UnLock");
//Delete site collection, also
Console.WriteLine("SetSiteLockStateTest: step 4");
tenant.DeleteSiteCollection(siteToCreateUrl, false);
Console.WriteLine("SetSiteLockStateTest: step 4.1");
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("SetSiteLockStateTest: step 4.2");
Assert.IsFalse(siteExists2, "Site collection deletion, including from recycle bin, failed");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
}
示例10: SetSiteLockStateTest
public void SetSiteLockStateTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
if (!tenant.SiteExists(siteToCreateUrl))
{
siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
var siteExists = tenant.SiteExists(siteToCreateUrl);
Assert.IsTrue(siteExists, "Site collection creation failed");
}
// Set Lockstate NoAccess test
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.NoAccess, true);
var siteProperties = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
tenantContext.Load(siteProperties);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties.LockState == SiteLockState.NoAccess.ToString(), "LockState wasn't set to NoAccess");
// Set Lockstate NoAccess test
tenant.SetSiteLockState(siteToCreateUrl, SiteLockState.Unlock, true);
var siteProperties2 = tenant.GetSitePropertiesByUrl(siteToCreateUrl, true);
tenantContext.Load(siteProperties2);
tenantContext.ExecuteQueryRetry();
Assert.IsTrue(siteProperties2.LockState == SiteLockState.Unlock.ToString(), "LockState wasn't set to UnLock");
//Delete site collection, also
tenant.DeleteSiteCollection(siteToCreateUrl, false);
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Assert.IsFalse(siteExists2, "Site collection deletion, including from recycle bin, failed");
}
}
示例11: CleanupAllTestSiteCollections
private static void CleanupAllTestSiteCollections(ClientContext tenantContext)
{
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
var tenant = new Tenant(tenantContext);
try
{
using (ClientContext cc = tenantContext.Clone(devSiteUrl))
{
var sites = cc.Web.SiteSearch();
foreach(var site in sites)
{
if (site.Url.ToLower().Contains(sitecollectionNamePrefix.ToLower()))
{
tenant.DeleteSiteCollection(site.Url);
}
}
}
}
catch
{ }
}
示例12: TryDeleteSiteCollection
public void TryDeleteSiteCollection()
{
var tenant = new Tenant(_ctx);
var webUrl =
$"https://{_actionRequest.TenantName}.sharepoint.com/{_siteCollectionRequest.ManagedPath}/{_actionRequest.Name}";
if (!tenant.SiteExists(webUrl))
{
tenant.DeleteSiteCollection(webUrl, false);
}
}
示例13: ProcessBaseTemplates
private void ProcessBaseTemplates(List<BaseTemplate> templates, bool deleteSites, bool createSites)
{
using (var tenantCtx = TestCommon.CreateTenantClientContext())
{
tenantCtx.RequestTimeout = Timeout.Infinite;
Tenant tenant = new Tenant(tenantCtx);
#if !CLIENTSDKV15
if (deleteSites)
{
// First delete all template site collections when in SPO
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template);
try
{
Console.WriteLine("Deleting existing site {0}", siteUrl);
tenant.DeleteSiteCollection(siteUrl, false);
}
catch{ }
}
}
if (createSites)
{
// Create site collections
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template);
Console.WriteLine("Creating site {0}", siteUrl);
bool siteExists = false;
if (template.SubSiteTemplate.Length > 0)
{
siteExists = tenant.SiteExists(siteUrl);
}
if (!siteExists)
{
tenant.CreateSiteCollection(new Entities.SiteEntity()
{
Lcid = 1033,
TimeZoneId = 4,
SiteOwnerLogin = (TestCommon.Credentials as SharePointOnlineCredentials).UserName,
Title = "Template Site",
Template = template.Template,
Url = siteUrl,
}, false, true);
}
if (template.SubSiteTemplate.Length > 0)
{
using (ClientContext ctx = TestCommon.CreateClientContext())
{
using (var sitecolCtx = ctx.Clone(siteUrl))
{
sitecolCtx.Web.Webs.Add(new WebCreationInformation()
{
Title = string.Format("template{0}", template.SubSiteTemplate),
Language = 1033,
Url = string.Format("template{0}", template.SubSiteTemplate.Replace("#", "")),
UseSamePermissionsAsParentSite = true
});
sitecolCtx.ExecuteQueryRetry();
}
}
}
}
}
#endif
}
// Export the base templates
using (ClientContext ctx = TestCommon.CreateClientContext())
{
foreach (var template in templates)
{
string siteUrl = GetSiteUrl(template, false);
// Export the base templates
using (ClientContext cc = ctx.Clone(siteUrl))
{
// Specify null as base template since we do want "everything" in this case
ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(cc.Web);
creationInfo.BaseTemplate = null;
// Do not extract the home page for the base templates
creationInfo.HandlersToProcess ^= Handlers.PageContents;
// Override the save name. Case is online site collection provisioned using blankinternetcontainer#0 which returns
// blankinternet#0 as web template using CSOM/SSOM API
string templateName = template.Template;
if (template.SaveAsTemplate.Length > 0)
{
templateName = template.SaveAsTemplate;
}
ProvisioningTemplate p = cc.Web.GetProvisioningTemplate(creationInfo);
if (template.SubSiteTemplate.Length > 0)
//.........这里部分代码省略.........
示例14: CleanupCreatedTestSiteCollections
private void CleanupCreatedTestSiteCollections(ClientContext tenantContext)
{
string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
String testSiteCollection = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);
//Ensure the test site collection was deleted and removed from recyclebin
var tenant = new Tenant(tenantContext);
try
{
tenant.DeleteSiteCollection(testSiteCollection);
}
catch
{ }
}
示例15: CreateDeleteSiteCollectionTest
public void CreateDeleteSiteCollectionTest()
{
using (var tenantContext = TestCommon.CreateTenantClientContext())
{
var tenant = new Tenant(tenantContext);
//Create site collection test
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1");
string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1.1");
var siteExists = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 1.2");
Assert.IsTrue(siteExists, "Site collection creation failed");
//Delete site collection test: move to recycle bin
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2");
tenant.DeleteSiteCollection(siteToCreateUrl, true);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2.1");
bool recycled = tenant.CheckIfSiteExists(siteToCreateUrl, "Recycled");
Console.WriteLine("CreateDeleteSiteCollectionTest: step 2.2");
Assert.IsTrue(recycled, "Site collection recycling failed");
//Remove from recycle bin
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3");
tenant.DeleteSiteCollectionFromRecycleBin(siteToCreateUrl, true);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3.1");
var siteExists2 = tenant.SiteExists(siteToCreateUrl);
Console.WriteLine("CreateDeleteSiteCollectionTest: step 3.2");
Assert.IsFalse(siteExists2, "Site collection deletion from recycle bin failed");
}
}