本文整理汇总了C#中ITask.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ITask.GetType方法的具体用法?C# ITask.GetType怎么用?C# ITask.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITask
的用法示例。
在下文中一共展示了ITask.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public IResponse Execute(ITask task)
{
Debug.WriteLine(string.Format("{0}: Received task", DateTime.Now));
bool successful = true;
Exception exception = null;
IResult result = null;
try
{
ITaskExecutor taskExecutor = taskExecuterFactory.CreateExecuterFor(task);
Debug.WriteLine(string.Format("{0}: Executing {1}", DateTime.Now, task.GetType().Name));
result = taskExecutor.Execute(task);
}
catch(Exception e)
{
Debug.WriteLine(string.Format("{0}: Error in {1}, {2} ({3})", DateTime.Now, task.GetType().Name, e.GetType().Name, e.Message));
successful = false;
exception = e;
logger.LogException(LogLevel.Debug, "Exception when executing task: " + task.GetType().Name, e);
}
var resultType = task.GetType().GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof (ITask<>)).GetGenericArguments()[0];
return CreateResponse(resultType, result, successful, exception);
}
示例2: Release
public virtual void Release(ITask task)
{
try
{
var disposable = task as IDisposable;
if (disposable == null)
{
return;
}
disposable.Dispose();
if (Logger.IsDebugEnabled)
{
Logger.Debug("Task {0} successfully disposed.", task);
}
}
catch (Exception ex)
{
if (!Logger.IsErrorEnabled) return;
var errorMessage = string.Format("Task {0} of type {1} throws exception on dispose.", task, task.GetType());
Logger.ErrorException(errorMessage, ex);
}
}
示例3: GetDescriptionFor
public static string GetDescriptionFor(ITask task)
{
var taskDescriptionAttribute = task.GetType().GetAttribute<TaskDescriptionAttribute>();
return taskDescriptionAttribute != null
? taskDescriptionAttribute.Description
: NoTaskDescriptionGivenMessage;
}
示例4: CreateExecuterFor
public ITaskExecutor CreateExecuterFor(ITask task)
{
Type taskType = task.GetType();
Type resultType = taskType.GetInterfaces().Single(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof (ITask<>)).GetGenericArguments()[0];
Type genericCommandHandler = typeof (ITaskExecutor<,>).MakeGenericType(taskType, resultType);
var type = typeof(StopWebsiteExecutor).Assembly.GetTypes().Single(genericCommandHandler.IsAssignableFrom);
return (ITaskExecutor)Activator.CreateInstance(type);
}
示例5: GetDependenciesFor
public IEnumerable<ITask> GetDependenciesFor(ITask task)
{
TypeDependencyGetter getter;
var type = task.GetType();
if (!DependencyGetters.TryGetValue(type, out getter)) {
getter = new TypeDependencyGetter(type);
}
return getter.GetDependencies(task);
}
示例6: Execute
public void Execute(ITask task, bool throwOnError = false)
{
JobsEventSource.Log.TaskExecuting(task.GetType().Name);
var startTime = DateTime.UtcNow;
try
{
task.Execute();
JobsEventSource.Log.TaskExecuted(task.GetType().Name, (DateTime.UtcNow - startTime).ToString());
}
catch (Exception ex)
{
JobsEventSource.Log.TaskExecutionError(task.GetType().Name, ex.GetType().Name, ex.Message, ex.StackTrace);
// Make sure the exception bubbles up and stops the execution of other tasks.
if (throwOnError)
throw;
}
}
示例7: FinishTask
private void FinishTask(ITask task)
{
var TaskType = task.GetType();
var NextTime = task.NextExecutionTime();
_TaskFactory.DestroyTask(task);
var Timer = new Timer();
Timer.Elapsed += (o, e) =>
{
Timer.Dispose();
CreateTask(TaskType);
};
Timer.Interval = NextTime.TotalMilliseconds;
Timer.Start();
}
示例8: TryMatch
public MatchResult TryMatch(ITask task)
{
Contract.Require(task != null, "task != null");
var type = task.GetType();
MatchResult result;
if (_cache.TryGetValue(type, out result))
{
return result;
}
result = ProbeNamespace(type);
CollectionUtils.ThreadSafeAdd(ref _cache, type, result);
return result;
}
示例9: Match
protected override bool Match(ITask task)
{
Contract.Require(task != null, "task != null");
var type = task.GetType();
bool result;
if (_cache.TryGetValue(type, out result))
{
return result;
}
result = PerformAttributesMatch(type);
CollectionUtils.ThreadSafeAdd(ref _cache, type, result);
return result;
}
示例10: RegisteredTask
public RegisteredTask(ITask task)
{
Argument.IsNotNull(task, nameof(task));
TaskInstance = task;
Name = task.GetType().Name;
}
示例11: CBTTaskLogHelper
public CBTTaskLogHelper(ITask task)
: this(task, task.GetType().Name)
{
}
示例12: GetInterceptorForTask
private static IInterceptor GetInterceptorForTask(ITask t)
{
if (cfgSec == null)
return null;
TaskElement te = cfgSec.FindTaskElementByType(t.GetType());
if (te == null || !te.UserInterceptor)
return null;
IInterceptor retVal = te.InterceptorElement.Interceptor;
if (retVal == null)
retVal = cfgSec.DefaultInterceptor;
return retVal;
}
示例13: BuildTaskLoggers
public BuildTaskLoggers(MSBuildFramework.IBuildEngine buildEngine, ITask task, IArgumentProvider arguments)
{
BuildLogger logger = new BuildLogger(buildEngine, task.GetType().ToString());
this.RegisterLogger(LoggerType.Result, logger);
this.RegisterLogger(LoggerType.Status, logger);
}
示例14: GetMemberValue
private string GetMemberValue(ITask task, string memberName)
{
var tuple = Tuple.Create(task.GetType(), memberName);
Func<ITask, string> getter;
if(_cachedGetters.TryGetValue(tuple, out getter))
{
return getter(task);
}
getter = _cachedGetters.GetOrAdd(tuple, BuildGetter);
return getter(task);
}
示例15: GetTaskAPs
public Decimal GetTaskAPs(ITask task)
{
if (task is Path) {
return this.GetPathAPs((Path)task);
} else {
throw new UnsupportedTaskType("No method implemented to calculate action points for task type '"+task.GetType().ToString()+"'");
}
}