/// <summary> /// Attempts to get the configured provider of how to repeat the task processing. /// </summary> /// <param name="queueId">The queue ID</param> /// <param name="taskType">The task type ID</param> /// <param name="recurringOperation">The configured provider, if available.</param> /// <returns><see langword="true"/> if the provider is available, <see langword="false"/> otherwise.</returns> public bool TryGetValue(string queueId, string taskType, out IRecurrenceConfiguration recurringOperation) { var key = this.Keys.FirstOrDefault(c => c.QueueID == queueId && c.TaskType == taskType); if (null == key) { recurringOperation = null; return(false); } recurringOperation = this[key]; return(true); }
/// <summary> /// Returns some dashboard content that shows the background operations and their current status. /// </summary> /// <returns>The dashboard content.</returns> public IEnumerable <DashboardListItem> GetDashboardContent(TaskQueueResolver taskQueueResolver) { if (null == taskQueueResolver) { yield break; } foreach (var queue in taskQueueResolver.GetQueues()) { // Sanity. if (string.IsNullOrWhiteSpace(queue)) { continue; } // Get information about the queues. TaskQueueAttribute queueSettings = null; System.Reflection.FieldInfo fieldInfo = null; try { queueSettings = taskQueueResolver.GetQueueSettings(queue); fieldInfo = taskQueueResolver.GetQueueFieldInfo(queue); } catch { // Throws if the queue is incorrect. SysUtils.ReportToEventLog ($"Cannot load details for queue {queue}; is there a static field with the [TaskQueue] attribute?", System.Diagnostics.EventLogEntryType.Warning ); continue; } // Skip anything broken. if (null == queueSettings || null == fieldInfo) { continue; } // If it's marked as hidden then skip. { var attributes = fieldInfo.GetCustomAttributes(typeof(HideOnDashboardAttribute), true) ?? new HideOnDashboardAttribute[0]; if (attributes.Length != 0) { continue; } } // Get each task processor. foreach (var processor in taskQueueResolver.GetTaskProcessors(queue)) { // Sanity. if (null == processor) { continue; } // Get information about the processor.. TaskProcessorAttribute taskProcessorSettings = null; System.Reflection.MethodInfo methodInfo = null; try { taskProcessorSettings = taskQueueResolver.GetTaskProcessorSettings(queue, processor.Type); methodInfo = taskQueueResolver.GetTaskProcessorMethodInfo(queue, processor.Type); } catch { // Throws if the task processor is not found. SysUtils.ReportToEventLog ( $"Cannot load processor details for task type {processor.Type} on queue {queue}.", System.Diagnostics.EventLogEntryType.Warning ); continue; } // Skip anything broken. if (null == taskProcessorSettings || null == methodInfo) { continue; } // If it's marked as hidden then skip. { var attributes = methodInfo.GetCustomAttributes(typeof(HideOnDashboardAttribute), true) ?? new HideOnDashboardAttribute[0]; if (attributes.Length != 0) { continue; } } // This should be shown. Do we have any extended details? var showOnDashboardAttribute = methodInfo.GetCustomAttributes(typeof(ShowOnDashboardAttribute), true)? .FirstOrDefault() as ShowOnDashboardAttribute; // Show the description? var htmlString = ""; if (false == string.IsNullOrWhiteSpace(showOnDashboardAttribute?.Description)) { htmlString += new DashboardCustomContent($"<p><em>{System.Security.SecurityElement.Escape(showOnDashboardAttribute?.Description)}</em></p>").ToXmlString(); } // Does it have any configuration instructions? IRecurrenceConfiguration recurrenceConfiguration = null; if (this .VaultApplication? .RecurringOperationConfigurationManager? .TryGetValue(queue, processor.Type, out recurrenceConfiguration) ?? false) { htmlString += recurrenceConfiguration.ToDashboardDisplayString(); } else { htmlString += "<p>Does not repeat.<br /></p>"; } // Get known executions (prior, running and future). var executions = this .GetAllExecutions <TaskDirective>(queue, processor.Type) .ToList(); var isRunning = executions.Any(e => e.State == MFilesAPI.MFTaskState.MFTaskStateInProgress); var isScheduled = executions.Any(e => e.State == MFilesAPI.MFTaskState.MFTaskStateWaiting); // Create the (basic) list item. var listItem = new DashboardListItemWithNormalWhitespace() { Title = showOnDashboardAttribute?.Name ?? processor.Type, StatusSummary = new DomainStatusSummary() { Label = isRunning ? "Running" : isScheduled ? "Scheduled" : "Stopped" } }; // Should we show the run command? { var key = $"{queue}-{processor.Type}"; lock (this._lock) { if (this.TaskQueueRunCommands.ContainsKey(key)) { var cmd = new DashboardDomainCommand { DomainCommandID = this.TaskQueueRunCommands[key].ID, Title = this.TaskQueueRunCommands[key].DisplayName, Style = DashboardCommandStyle.Link }; listItem.Commands.Add(cmd); } } } // Set the list item content. listItem.InnerContent = new DashboardCustomContent ( htmlString + executions? .AsDashboardContent()? .ToXmlString() ); // Add the list item. yield return(listItem); } } }