93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SharePoint;
|
|
using Microsoft.SharePoint.Administration;
|
|
using Taloyhtio.CompanyAutomation.CodeFiles;
|
|
using Taloyhtio.CompanyAutomation.Utils;
|
|
|
|
namespace MassCompanyCreationJobCreator
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
if (args == null || args.Length != 5)
|
|
{
|
|
Console.WriteLine("Usage: MassCompanyCreationJobCreator.exe {siteId} {listId} {itemIntegerId} {itemId} {userId}");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
log("Creating new job");
|
|
Guid siteId = new Guid(args[0]);
|
|
Guid listId = new Guid(args[1]);
|
|
int itemIntegerId = int.Parse(args[2]);
|
|
Guid itemId = new Guid(args[3]);
|
|
int userId = int.Parse(args[4]);
|
|
log("Job params: siteId = '{0}'; listId = '{1}'; itemIntegerId = '{2}'; itemId = '{3}'; userId = '{4}'",
|
|
siteId, listId, itemIntegerId, itemId, userId);
|
|
|
|
using (var site = new SPSite(siteId))
|
|
{
|
|
log("Create new work item");
|
|
site.AddWorkItem(Guid.NewGuid(),
|
|
DateTime.UtcNow, //.ToUniversalTime(),
|
|
Constants.Mass.WORK_ITEM_TYPE_ID,
|
|
site.RootWeb.ID,
|
|
listId,
|
|
itemIntegerId,
|
|
true,
|
|
itemId,
|
|
Guid.NewGuid(),
|
|
userId,
|
|
null,
|
|
string.Empty,
|
|
Guid.Empty);
|
|
|
|
log("Delete old jobs");
|
|
var webapplication = site.WebApplication;
|
|
if (webapplication != null)
|
|
{
|
|
foreach (SPJobDefinition job in webapplication.JobDefinitions)
|
|
{
|
|
if (job.Name == Constants.Mass.MASS_COMPANY_CREATION_JOB_NAME)
|
|
job.Delete();
|
|
}
|
|
}
|
|
|
|
log("Create new job");
|
|
var jobDefinition = new MassCompanyCreationJob(Constants.Mass.MASS_COMPANY_CREATION_JOB_NAME,
|
|
Constants.Mass.MASS_COMPANY_CREATION_JOB_TITLE, site.WebApplication);
|
|
var schedule = new SPOneTimeSchedule(DateTime.Now.AddSeconds(20));
|
|
jobDefinition.Schedule = schedule;
|
|
jobDefinition.Update();
|
|
log("Job was successfully created");
|
|
}
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
log("Error occured: {0}\n{1}", x.Message, x.StackTrace);
|
|
}
|
|
}
|
|
|
|
private static void log(string msg, params object[] args)
|
|
{
|
|
try
|
|
{
|
|
msg = string.Format(msg, args);
|
|
msg = string.Format("{0} (thread id: {1})\t{2}\n", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), Thread.CurrentThread.ManagedThreadId, msg);
|
|
File.AppendAllText("c://temp/_mass_company_creation_job_creator.txt", msg);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|