本文整理汇总了C#中SPSite.AddWorkItem方法的典型用法代码示例。如果您正苦于以下问题:C# SPSite.AddWorkItem方法的具体用法?C# SPSite.AddWorkItem怎么用?C# SPSite.AddWorkItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPSite
的用法示例。
在下文中一共展示了SPSite.AddWorkItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateJob
/// <summary>
/// The create job.
/// </summary>
/// <param name="site">
/// The site.
/// </param>
/// <param name="workItemType">
/// The work item type.
/// </param>
/// <returns>
/// The <see cref="Guid"/>.
/// </returns>
public Guid CreateJob(SPSite site, Guid workItemType)
{
var rootWeb = site.RootWeb;
var workItemId = site.AddWorkItem(Guid.NewGuid(), DateTime.Now.ToUniversalTime(), workItemType, rootWeb.ID, site.ID, 1, false, Guid.Empty, Guid.Empty, rootWeb.CurrentUser.ID, null, string.Empty, Guid.Empty, false);
return workItemId;
}
示例2: CreateExportJob
/// <summary>
/// Creates an ExportJob and schedules the WorkItem for the timer job that processes the exports.
/// </summary>
/// <param name="domainUid">The DominUid for the map being exported</param>
/// <param name="rootMapUid">The RootMapUid for the map being exported</param>
/// <param name="exportProperties">The export properties for the export</param>
/// <param name="mapType">The map type (schema) for the map being exported</param>
/// <param name="exportType">The output format for the export</param>
/// <returns>The ExportJob that was created</returns>
public ExportJobResponse CreateExportJob(Guid domainUid, Guid rootMapUid, IDictionary<string, string> exportProperties, MapType mapType, ExportType exportType)
{
ExportJobResponse response = new ExportJobResponse();
try
{
Guid webID = SPContext.Current.Web.ID;
Guid siteID = SPContext.Current.Site.ID;
SPUser currentUser = null;
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
if (web != null)
{
currentUser = web.CurrentUser;
}
}
}
SPSecurity.RunWithElevatedPrivileges(delegate()
{
int userId = -1;
SPList exportsList = null;
int listItemIdNum = -1;
using (SPSite site = new SPSite(siteID))
{
using (SPWeb web = site.OpenWeb(webID))
{
if (web != null)
{
if (currentUser == null)
{
//The current user shouldn't be null, it should have been resolved outside of this RunWithElevatedPrivileges delegate
currentUser = web.CurrentUser;
}
if (currentUser != null)
{
userId = currentUser.ID;
exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant
if (exportsList != null)
{
//the text payload will contain the properties serialized into a simple XML format
ExportPropertiesDictionary serializableDict = new ExportPropertiesDictionary(exportProperties);
string textPayload = serializableDict.ConvertToXml();
Guid workItemId = Guid.NewGuid(); // Create a unique id for the work item and export job
listItemIdNum = CreateExportJobListEntry(exportsList, domainUid, rootMapUid, mapType, exportType, workItemId, textPayload, userId);
// if the list item was created then create the export job, if it wasn't it was because an export
// for this particular root map of this type was already scheduled (changing the properties doesn't have effect)
if (listItemIdNum != -1)
{
site.AddWorkItem(workItemId, //gWorkItemId - A Guid that identifies the work item
DateTime.Now.ToUniversalTime(), //schdDateTime - represents a time in universal time for when the work item should take place
GlymaExportWorkItemTimerJob.WorkItemTypeId, //gWorkItemType - this must be the GUID used in the GlymaExportWorkItemTimerJob
web.ID, //gWebId - The identifier of the web containing the list
exportsList.ID, //gParentId - The list ID
listItemIdNum, //nItemId - The list item ID number
true, //fSetWebId - true to set the Web identifier
exportsList.Items.GetItemById(listItemIdNum).UniqueId, //gItemGuid - The unique identifier of the list item
domainUid, //gBatchId - A Guid context identifier for the work item engine
userId, //nUserId - SPUser ID number
null, //rgbBinaryPayload - not used
textPayload, //strTextPayload
Guid.Empty); //gProcessingId - needs to be Guid.Empty
ExportJob scheduledJob = new ExportJob();
scheduledJob.Created = (DateTime)exportsList.Items.GetItemById(listItemIdNum)[SPBuiltInFieldId.Created];
scheduledJob.CreatedBy = new GlymaUser() { Name = currentUser.Name };
scheduledJob.Id = workItemId;
scheduledJob.IsCurrent = true;
scheduledJob.Status = ExportStatus.Scheduled;
scheduledJob.Type = exportType;
scheduledJob.MapType = mapType;
scheduledJob.ExportProperties = exportProperties;
scheduledJob.PercentageComplete = 0;
response.ExportJob = scheduledJob;
}
else
{
//already scheduled so throw an exception to be handled with an error
throw new Exception(string.Format("A scheduled export job already exists for the Glyma map: DomainUid: {0}, RootMapUid: {1}, Export Type: {2}, Map Type: {3}",
domainUid.ToString(), rootMapUid.ToString(), exportType.ToString(), mapType.ToString()));
}
}
else
{
throw new Exception("Failed to find the Glyma Exports list.");
//.........这里部分代码省略.........