Thanks Michal! That is exactly what I was looking for. I did find the Scheduler documentation yesterday and was able to use it and my custom code to run the process.
One last question I have is when I run through the process of creating the new documents, it takes some time to do this. First the module looks to see if there are any existing documents, if so, it deletes them then it create between 400 and 450 new records each day. Just in my testing yesterday it took about 15-20 minutes to run. Is there a way to speed this up? I have what I believe to be some pretty simple code:
public string Execute(TaskInfo ti)
{
switch (ti.TaskName)
{
case "Import_Stores":
GetStores();
break;
}
string details = "Executed from: '/App_Code/KT/Classes/KTTasks.cs'. Class: " + ti.TaskAssemblyName + "." + ti.TaskClass + ". Task data: " + ti.TaskData;
EventLogProvider.LogInformation("KT.KTTasks", "Execute", details);
return null;
}
protected void GetStores()
{
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
CMS.TreeEngine.TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/Locations", "en-us");
if (parentNode != null)
{
KT.RetailStructure.RetailStructureService rss = new KT.RetailStructure.RetailStructureService();
DataTable dt = new DataTable();
KT.RetailStructure.ServiceCallResult scr = rss.GetStoreData("Kentico");
// delete all the current documents first
foreach (CMS.TreeEngine.TreeNode childNode in parentNode.Children)
{
DocumentHelper.DeleteDocument(childNode, tree, true, true, true);
}
if (!scr.HasErrors)
{
if (scr.DataSetResults.Tables[0].Rows.Count > 0)
{
dt = scr.DataSetResults.Tables[0];
DataRow[] rows = dt.Select("Division=1 AND ZoneNumber < 9000 AND DistrictNumber < 9000");
foreach (DataRow dr in rows)
{
CMS.TreeEngine.TreeNode newNode = CMS.TreeEngine.TreeNode.New("KT.Store", tree);
newNode.DocumentName = Convert.ToString(dr["StoreNumber"]);
newNode.DocumentCulture = "en-us";
newNode.SetValue("Address1", dr["Address1"]);
newNode.SetValue("Address2", dr["Address2"]);
newNode.SetValue("City", dr["City"]);
newNode.SetValue("St", dr["St"]);
newNode.SetValue("Longitude", dr["Longitude"]);
newNode.SetValue("Latitude", dr["Latitude"]);
......
//save the new document
newNode.Insert(parentNode);
// workflow
WorkflowManager workflowManager = new WorkflowManager(tree);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(newNode);
// check to see if using workflow
if (workflow != null)
{
if (!workflow.WorkflowAutoPublishChanges)
{
if (workflowManager.CanUserApprove(newNode))
{
// publish the document
WorkflowStepInfo step = WorkflowStepInfoProvider.GetWorkflowStepInfo("Published", workflow.WorkflowID);
workflowManager.MoveToSpecificStep(newNode, step, "Published by Import");
}
else
{
EventLogProvider ev = new EventLogProvider();
ev.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "KTTasks.GetStores()", "Execute", null, "The user is not authorized to approve this document.");
}
}
else
{
EventLogProvider ev = new EventLogProvider();
ev.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "KTTasks.GetStores()", "Execute", null, "The document uses versioning without workflow, changes are published automatically.");
}
}
else
{
// not using workflow
}
}
}
}
else
{
SystemException e = new SystemException(scr.ErrorMessage);
EventLogProvider.LogException("KTTasks.GetStores", "", e);
}
}
}