Exemplo n.º 1
0
        public static string GiveDescription(this IBackgroundTask background)
        {
            var type = background.GetType();
            var bgt  = type.GetCustomAttribute <BackgroundTaskAttribute>();

            if (bgt == null)
            {
                return(null);
            }
            return(bgt.Description);
        }
Exemplo n.º 2
0
        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
     }
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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
            });
        }
Exemplo n.º 6
0
        /// <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();
        }
Exemplo n.º 7
0
        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);
            //}
        }
Exemplo n.º 8
0
 public static string GetTaskName(this IBackgroundTask task)
 => task.GetType().FullName;
Exemplo n.º 9
0
 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
			}
		}
Exemplo n.º 11
0
        private string GetGroupName(IBackgroundTask task)
        {
            var attributes = task.GetType().GetTypeInfo().GetCustomAttributes<BackgroundTaskAttribute>().ToList();

            if (attributes.Count == 0)
            {
                return "";
            }

            return attributes.First().Group ?? "";
        }