public void RunJob(Item[] itemArray, CommandItem commandItem, ScheduleItem scheduledItem) { try { if (scheduledItem != null) { var itemIds = scheduledItem["Items"]; if (!String.IsNullOrEmpty(itemIds)) { var idList = itemIds.Split('|'); if (idList.Any()) { foreach (var id in idList) { if (ID.IsID(id)) { var userSyncItem = scheduledItem.Database.GetItem(new ID(id)); try { if (userSyncItem != null) { var startedAt = DateTime.Now.ToLongDateString(); Logging logBuilder = new Logging(); var userSyncManager = new UserSyncManager(); userSyncManager.RunUserSyncJob(userSyncItem, ref logBuilder); var finishededAt = DateTime.Now.ToLongDateString(); if (logBuilder != null) { try { MailManager.SendLogReport(ref logBuilder, GetUserSyncIdentifier(userSyncItem), userSyncItem); } catch (Exception exception) { Diagnostics.Log.Error( GetIdentifierText(userSyncItem, startedAt, finishededAt) + " failed in sending out the mail. Please see the exception message for more details. Exception:" + exception.Message + ". Status:\r\n" + logBuilder.GetStatusText(), typeof(UserSyncTask)); } if (logBuilder.LogBuilder != null) { if (!String.IsNullOrEmpty(logBuilder.LogBuilder.ToString())) { Diagnostics.Log.Error( GetIdentifierText(userSyncItem, startedAt, finishededAt) + " failed. " + logBuilder.LogBuilder + "\r\nStatus:\r\n" + logBuilder.GetStatusText(), typeof(UserSyncTask)); } else { Diagnostics.Log.Debug( GetIdentifierText(userSyncItem, startedAt, finishededAt) + " completed with success.\r\nStatus:\r\n" + logBuilder.GetStatusText(), typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( GetIdentifierText(userSyncItem, startedAt, finishededAt) + " failed. The Logging.LogBuilder object was null. " + logBuilder + "\r\nStatus:\r\n" + logBuilder.GetStatusText(), typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( GetIdentifierText(userSyncItem, startedAt, finishededAt) + " - The Log object was null. This should not happen.", typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( " - The Task item had Items defined in Items[] that was null. This should not happen.", typeof(UserSyncTask)); } } catch (Exception exception) { var itemId = userSyncItem != null ? userSyncItem.ID.ToString() : string.Empty; Diagnostics.Log.Error( Identifier + String.Format( " - An exception occured in the execution of the task in the foreach (Item UserSyncItem in itemArray) of the UserSync item: {0}. This UserSync job wasn't completed. Exception: {1}", itemId, exception.Message), typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( Identifier + " - The provided value wasn't a correct Sitecore id. Please add at least one id to 'Items' field of the ScheduledItem. You can also use | to seperate ids. Therefore nothing was done.", typeof(UserSyncTask)); } } } else { Diagnostics.Log.Error( Identifier + " - There wasn't defined any UserSync items to run. Please add at least one id to 'Items' field of the ScheduledItem. You can also use | to seperate ids. Therefore nothing was done.", typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( Identifier + " - There wasn't defined any UserSync items to run. Therefore nothing was done.", typeof(UserSyncTask)); } } else { Diagnostics.Log.Error( Identifier + " - The ScheduledItem was null. Therefore nothing was done.", typeof(UserSyncTask)); } } catch (Exception exception) { Diagnostics.Log.Error(Identifier + " - An exception occured in the execution of the task.", exception); } }
protected void StartImport() { var userSyncItem = GetUserSyncItem(); var userSyncManager = new UserSyncManager(); string errorMessage = String.Empty; var map = userSyncManager.InstantiateDataMap(userSyncItem, ref errorMessage); if (map != null) { if (!String.IsNullOrEmpty(DataValue)) { map.Data = DataValue; } var options = new JobOptions("FromFileUserSyncWizard", "Job category name", Context.Site.Name, new FromFileUserSyncWizard(), "Run", new object[] { map, map.LogBuilder }); var job = JobManager.Start(options); job.Options.CustomData = map.LogBuilder; JobHandle = job.Handle.ToString(); SheerResponse.Timer("CheckStatus", 5); } else { Active = "LastPage"; BackButton.Disabled = true; if (!string.IsNullOrEmpty(errorMessage)) { ResultText.Value = errorMessage; } } }