public static string GiveDescription(this IBackgroundTask background) { var type = background.GetType(); var bgt = type.GetCustomAttribute <BackgroundTaskAttribute>(); if (bgt == null) { return(null); } return(bgt.Description); }
private string GetGroupName(IBackgroundTask task) { var attributes = task.GetType().GetTypeInfo().GetCustomAttributes <BackgroundTaskAttribute>().ToList(); if (attributes.Count == 0) { return(""); } return(attributes.First().Group ?? ""); }
/// <summary> /// Updates the list view item to display the changed property. /// </summary> /// <param name="p_tskTask">The task whose property has changed.</param> /// <param name="p_strPropertyName">The name of the propety that has changed.</param> private void HandleChangedTaskProperty(IBackgroundTask p_tskTask, string p_strPropertyName) { try { if (p_tskTask.GetType() == typeof(BasicUninstallTask)) { if ((p_strPropertyName.Equals(ObjectHelper.GetPropertyName <IBackgroundTask>(x => x.ItemProgress))) && (p_tskTask.ItemProgress > 0)) { SubItems["Progress"].Text = "Uninstalling, please wait...(" + ((p_tskTask.ItemProgress * 100) / p_tskTask.ItemProgressMaximum).ToString() + "%)"; } } else { if ((p_tskTask.GetType() == typeof(PrepareModTask))) { if (p_strPropertyName.Equals(ObjectHelper.GetPropertyName <IBackgroundTask>(x => x.OverallProgress))) { SubItems["Progress"].Text = "Unpacking, please wait...(" + (((p_tskTask.OverallProgress * 100) / p_tskTask.OverallProgressMaximum) / 2).ToString() + "%)"; } } else { if (p_strPropertyName.Equals(ObjectHelper.GetPropertyName <IBackgroundTask>(x => x.OverallProgress))) { SubItems["Progress"].Text = "Installing, please wait...(" + ((((p_tskTask.OverallProgress * 100) / p_tskTask.OverallProgressMaximum) / 2) + 50).ToString() + "%)"; } } } } catch (NullReferenceException) { //this can happen if we try to update the form before its handle has been created // we should never get here, but if we do, we don't need to care } catch (ArgumentOutOfRangeException) { // we don't care if that happens } }
private static string GetQueueForTask(IBackgroundTask task) { var taskType = task.GetType(); if (!_taskToQueue.TryGetValue(taskType, out var queue)) { var queueAttribute = taskType.GetAttributesIncludingInterface <QueueAttribute>().SingleOrDefault(); queue = queueAttribute == null ? EnqueuedState.DefaultQueue : queueAttribute.Queue; _taskToQueue[taskType] = queue; } return(queue); }
public static BackgroundTaskSettings GetDefaultSettings(this IBackgroundTask task) { var type = task.GetType(); var attribute = type.GetCustomAttribute <BackgroundTaskAttribute>(); if (attribute != null) { return(new BackgroundTaskSettings { Name = type.FullName, Enable = attribute.Enable, Schedule = attribute.Schedule, Description = attribute.Description }); } return(new BackgroundTaskSettings { Name = type.FullName }); }
/// <summary> /// Enqueues the specified work item. /// </summary> /// <param name="backgroundTask">The work item.</param> public void Enqueue(IBackgroundTask backgroundTask) { var task = (BackgroundTask)backgroundTask; lock (syncroot) { if (backgroundTask.MaxQueuedInstances == GetQueuedInstances(backgroundTask.GetType(), (BackgroundTask)backgroundTask)) { Trace.WriteLine(String.Format("Task {0} has allready reached maximum allowed instances in the queue, ignoring enqueue...", backgroundTask.GetType())); task.OnFinished(); return; } // Else Tasks.Add(task); } // Signal the processing pool to start (if it wasn't allready running) ProcessingPool.Process(); }
public static void RunBackgroundTask(IBackgroundTask task, IBackgroundTaskInstance taskInstance, IShinyStartup startup) { if (!ShinyHost.IsInitialized) { UwpPlatform.SetBackgroundTask(task.GetType()); ShinyHost.Init(new UwpPlatform(null), startup); } var services = ShinyHost.ServiceProvider; //if (taskInstance.Task.Name.StartsWith("JOB-")) //{ // services // .Resolve<JobManager>(true)! // .Process(taskInstance); //} //else //{ // var targetType = Type.GetType(taskInstance.Task.Name); // var processor = ActivatorUtilities.GetServiceOrCreateInstance(services, targetType) as IBackgroundTaskProcessor; // processor?.Process(taskInstance); //} }
public static string GetTaskName(this IBackgroundTask task) => task.GetType().FullName;
public static string GetTaskName(this IBackgroundTask task) { return(task.GetType().FullName); }
/// <summary> /// Updates the list view item to display the changed property. /// </summary> /// <param name="p_tskTask">The task whose property has changed.</param> /// <param name="p_strPropertyName">The name of the propety that has changed.</param> private void HandleChangedTaskProperty(IBackgroundTask p_tskTask, string p_strPropertyName) { try { if (p_tskTask.GetType() == typeof(BasicUninstallTask)) { if ((p_strPropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.ItemProgress))) && (p_tskTask.ItemProgress > 0)) SubItems["Progress"].Text = "Uninstalling, please wait...(" + ((p_tskTask.ItemProgress * 100) / p_tskTask.ItemProgressMaximum).ToString() + "%)"; } else { if ((p_tskTask.GetType() == typeof(PrepareModTask))) { if (p_strPropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.OverallProgress))) SubItems["Progress"].Text = "Unpacking, please wait...(" + (((p_tskTask.OverallProgress * 100) / p_tskTask.OverallProgressMaximum)/2).ToString() + "%)"; } else { if (p_strPropertyName.Equals(ObjectHelper.GetPropertyName<IBackgroundTask>(x => x.OverallProgress))) SubItems["Progress"].Text = "Installing, please wait...(" + ((((p_tskTask.OverallProgress * 100) / p_tskTask.OverallProgressMaximum)/2)+50).ToString() + "%)"; } } } catch (NullReferenceException) { //this can happen if we try to update the form before its handle has been created // we should never get here, but if we do, we don't need to care } catch (ArgumentOutOfRangeException) { // we don't care if that happens } }
private string GetGroupName(IBackgroundTask task) { var attributes = task.GetType().GetTypeInfo().GetCustomAttributes<BackgroundTaskAttribute>().ToList(); if (attributes.Count == 0) { return ""; } return attributes.First().Group ?? ""; }