本文整理汇总了C#中SPSite.GetWorkItems方法的典型用法代码示例。如果您正苦于以下问题:C# SPSite.GetWorkItems方法的具体用法?C# SPSite.GetWorkItems怎么用?C# SPSite.GetWorkItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPSite
的用法示例。
在下文中一共展示了SPSite.GetWorkItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanupErrorWorkItems
/// <summary>
/// Deletes and of the TimerJob WorkItems for the GlymaExportWorkItemTimerJob if they still exist and are in error state.
/// </summary>
/// <param name="job">The ExportJob</param>
/// <param name="site">The SPSite</param>
/// <param name="web">The SPWeb</param>
private void CleanupErrorWorkItems(ExportJob job, SPSite site, SPWeb web)
{
//ensure that only jobs in error state are attempted to be removed
if (job.Status == ExportStatus.Error)
{
try
{
SPWorkItemCollection workItemsCollection = new SPWorkItemCollection(site, GlymaExportWorkItemTimerJob.WorkItemTypeId);
uint colCount, rowCount = 0;
object workItems = null;
site.GetWorkItems(workItemsCollection, out colCount, out rowCount, out workItems);
if (workItemsCollection.Count > 0)
{
SPWorkItemCollection subCollection = workItemsCollection.SubCollection(site, web, 0, (uint)workItemsCollection.Count);
subCollection.DeleteWorkItem(job.Id);
}
}
catch (Exception)
{
}
}
}
示例2: DeleteExportJob
/// <summary>
/// Deletes an ExportJob if it's in the Scheduled, Completed, or Error ExportStates.
/// </summary>
/// <param name="job">The ExportJob to delete</param>
/// <returns>The ExportJob that was deleted</returns>
public ExportJobResponse DeleteExportJob(ExportJob job)
{
ExportJobResponse response = new ExportJobResponse();
try
{
Guid webID = SPContext.Current.Web.ID;
Guid siteID = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPList exportsList = null;
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
if (web != null && site != null)
{
exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports");
if (exportsList != null)
{
SPQuery query = new SPQuery();
query.Query = "<Where>" +
"<Eq><FieldRef Name='Title' /><Value Type='Text'>" + job.Id.ToString() + "</Value></Eq>" +
"</Where>";
SPListItemCollection exports = exportsList.GetItems(query);
// There can only be one ExportJob with the job ID (unique values enforced in SP list for Title column)
if (exports.Count > 0)
{
SPListItem exportItem = exports[0];
if (exportItem != null)
{
string exportStatusStr = exportItem["ExportStatus"] as string;
ExportStatus exportStatus = (ExportStatus)Enum.Parse(typeof(ExportStatus), exportStatusStr, true);
if (exportStatus == ExportStatus.Scheduled)
{
SPWorkItemCollection workItemsCollection = new SPWorkItemCollection(site, GlymaExportWorkItemTimerJob.WorkItemTypeId);
uint colCount, rowCount = 0;
object workItems = null;
site.GetWorkItems(workItemsCollection, out colCount, out rowCount, out workItems); //gets all work items for this site of the type GlymaExportWorkItemTimerJob
if (workItemsCollection.Count > 0)
{
// Delete the work item that this export job created
SPWorkItemCollection subCollection = workItemsCollection.SubCollection(site, web, 0, (uint)workItemsCollection.Count);
subCollection.DeleteWorkItem(job.Id);
}
}
if (exportStatus == ExportStatus.Scheduled || exportStatus == ExportStatus.Completed || exportStatus == ExportStatus.Error)
{
exportItem.Delete(); //delete the item after it has been cancelled
}
else if (exportStatus == ExportStatus.Processing)
{
throw new Exception("The export job is currently processing and cannot be deleted.");
}
}
response.ExportJob = job;
}
}
else
{
throw new Exception("Failed to find the Glyma Exports list.");
}
}
else
{
throw new Exception("The SPSite and/or the SPWeb were null.");
}
}
}
});
}
catch (Exception ex)
{
ExportError error = new ExportError() { ErrorMessage = "Failed to cancel the Glyma map export job." };
throw new FaultException<ExportError>(error, ex.ToString());
}
return response;
}