public override void ResetSelf() { base.ResetSelf(); InnerTask.ResetSelf(); RepetitionsCompleted = 0; }
public virtual void Dispose() { if (InnerTask != null) { InnerTask.Dispose(); } }
public override bool Execute() { logger = new BuildLogger(BuildEngine); logger.LogInfo($"SqlPersistenceScriptBuilderTask (version {assemblyVersion}) Executing"); var stopwatch = Stopwatch.StartNew(); try { ValidateInputs(); var innerTask = new InnerTask(AssemblyPath, IntermediateDirectory, ProjectDirectory, SolutionDirectory, logError: (error, file) => { logger.LogError(error, file); }); innerTask.Execute(); } catch (ErrorsException exception) { logger.LogError(exception.Message, exception.FileName); } catch (Exception exception) { logger.LogError(exception.ToFriendlyString()); } finally { logger.LogInfo($" Finished SqlPersistenceScriptBuilderTask {stopwatch.ElapsedMilliseconds}ms."); } return(!logger.ErrorOccurred); }
// TODO: TEST /// <summary> /// Empties an optional, if a specified predicate /// is not satisfied. /// </summary> /// <param name="predicate">The predicate.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(Func <T, Task <bool> > predicate) { return(InnerTask.FlatMap(option => option .Match( some: value => predicate(value).Map(option.Filter), none: () => Task.FromResult(option) )).ToAsyncOption()); }
protected virtual IEnumerable <TOutputMsg> ProcessInner(IEnumerable <TInputMsg> inputMsgs, out bool hasErrors) { hasErrors = false; var decoratedInputMsgs = DecorateInputMessages(inputMsgs); //Now process the inner... we have decorated the messages... return(InnerTask.Process(decoratedInputMsgs)); }
/// <summary> /// Transforms the inner value in an async optional /// into another async optional. The result is flattened, /// and if either is empty, an empty optional is returned. /// </summary> /// <param name="mapping">The transformation function.</param> /// <returns>The transformed optional.</returns> public AsyncOption <TResult> FlatMap <TResult>(Func <T, Task <Option <TResult> > > mapping) { return(InnerTask.FlatMap(option => option .Match( some: mapping, none: () => Task.FromResult(Option.None <TResult>()) )).ToAsyncOption()); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (InnerTask != null) { InnerTask.Dispose(); InnerTask = null; } if (_cancelSource != null) { _cancelSource.Dispose(); } } }
protected override void OnFiniteTaskFrameRun(float deltaTime) { while (HasRepetitionsRemaining && InnerTask.FrameRunFinishes(deltaTime)) { RepetitionsCompleted++; deltaTime = InnerTask.OverflowDeltaTime; InnerTask.ResetSelf(); } // A rare edge case could occur when the last task has a duration remaining close to 0, // and loss of floating point precision causes the base timer to activate // before activating the last task. if (IsFinished) { InnerTask.RunRemainingTime(); } }
/// <summary> /// Submits a new task to the thread pool using a function without arguments. /// </summary> /// <typeparam name="TResult">Type of task's result value.</typeparam> /// <param name="func">Function used to calculate the result.</param> /// <returns>A reference to the generated task.</returns> public IMyTask <TResult> Enqueue <TResult>(Func <TResult> func) { if (!cancelTokenSource.IsCancellationRequested) { lock (locker) { if (!cancelTokenSource.IsCancellationRequested) { var inner = new InnerTask <TResult>(func, this); OnShutdown += inner.Abort; queue.Enqueue(inner.Calculate); reset.Set(); return(new MyTask <TResult>(inner)); } } } throw new InvalidOperationException("Pool is stopped"); }
public async Task ExecuteAsync(BackgroundProcessContext context) { for (var i = 0; i <= MaxRetryAttempts; i++) { try { await InnerTask.ExecuteAsync(context).ConfigureAwait(false); return; } catch (OperationCanceledException) when(context.IsShutdownRequested) { throw; } catch (Exception ex) { // Break the loop after the retry attempts number exceeded. if (i >= MaxRetryAttempts - 1) { throw; } var nextTry = DelayCallback(i); var logLevel = GetLogLevel(i); _logger.Log( logLevel, // ReSharper disable once AccessToModifiedClosure () => $"Error occurred during execution of '{InnerTask}' process. Execution will be retried (attempt {i + 1} of {MaxRetryAttempts}) in {nextTry} seconds.", ex); await Task.Delay(nextTry, context.CancellationToken).ConfigureAwait(false); if (context.IsShutdownRequested) { break; } } } }
public void IntegrationTest() { var testDirectory = TestContext.CurrentContext.TestDirectory; var temp = Path.Combine(testDirectory, "InnerTaskTemp"); DirectoryExtensions.Delete(temp); var assemblyPath = Path.Combine(testDirectory, "ScriptBuilderTask.Tests.Target.dll"); var intermediatePath = Path.Combine(temp, "IntermediatePath"); var promotePath = Path.Combine(temp, "PromotePath"); Directory.CreateDirectory(temp); Directory.CreateDirectory(intermediatePath); Action <string, string> logError = (error, s1) => { throw new Exception(error); }; var innerTask = new InnerTask(assemblyPath, intermediatePath, "TheProjectDir", promotePath, logError); innerTask.Execute(); var files = Directory.EnumerateFiles(temp, "*.*", SearchOption.AllDirectories).Select(s => s.Replace(temp, "temp")).ToList(); ObjectApprover.VerifyWithJson(files); }
/// <summary> /// Transforms the inner value in an async optional /// into another optional. The result is flattened, /// and if either is empty, an empty optional is returned. /// If the option contains an exception, it is removed. /// </summary> /// <param name="mapping">The transformation function.</param> /// <returns>The transformed optional.</returns> public AsyncOption <TResult> FlatMap <TResult, TException>(Func <T, Option <TResult, TException> > mapping) { return(InnerTask.Map(option => option.FlatMap(mapping)).ToAsyncOption()); }
// TODO: TEST /// <summary> /// Evaluates a specified action, based on whether a value is present or not. /// </summary> /// <param name="some">The action to evaluate if the value is present.</param> /// <param name="none">The action to evaluate if the value is missing.</param> public Task Match(Func <T, Task> some, Func <Task> none) { return(InnerTask.FlatMap(option => option.Match(some, none))); }
/// <summary> /// Evaluates a specified action, based on whether a value is present or not. /// </summary> /// <param name="some">The action to evaluate if the value is present.</param> /// <param name="none">The action to evaluate if the value is missing.</param> public Task Match(Action <T> some, Action none) { return(InnerTask.Map(option => option.Match(some, none))); }
// TODO: TEST /// <summary> /// Evaluates a specified function, based on whether a value is present or not. /// </summary> /// <param name="some">The function to evaluate if the value is present.</param> /// <param name="none">The function to evaluate if the value is missing.</param> /// <returns>The result of the evaluated function.</returns> public Task <TResult> Match <TResult>(Func <T, Task <TResult> > some, Func <Task <TResult> > none) { return(InnerTask.FlatMap(option => option.Match(some, none))); }
/// <summary> /// Attaches an exceptional value to an empty optional. /// </summary> /// <param name="exceptionFactory">A factory function to create an exceptional value to attach.</param> /// <returns>An optional with an exceptional value.</returns> public AsyncOption <T, TException> WithException <TException>(Func <TException> exceptionFactory) { return(InnerTask.Map(option => option.WithException(exceptionFactory)).ToAsyncOption()); }
public override bool Execute() { var innerTask = new InnerTask { Overwrite = Overwrite, IncludeDebugSymbols = IncludeDebugSymbols, DeleteReferences = DeleteReferences, CreateTemporaryAssemblies = CreateTemporaryAssemblies, TargetPath = TargetPath, KeyFilePath = KeyFilePath, MessageImportance = MessageImportance, References = References, ReferenceCopyLocalPaths = ReferenceCopyLocalPaths, BuildEngine = BuildEngine }; return innerTask.Execute(); }
/// <summary> /// Empties an optional, if a specified predicate /// is not satisfied. /// </summary> /// <param name="predicate">The predicate.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(Func <T, bool> predicate) { return(InnerTask.Map(option => option.Filter(predicate)).ToAsyncOption()); }
/// <summary> /// Determines if the current optional contains a specified value. /// </summary> /// <param name="value">The value to locate.</param> /// <returns>A boolean indicating whether or not the value was found.</returns> public Task <bool> Contains(T value) { return(InnerTask.Map(option => option.Contains(value))); }
public virtual TOutputMsg CreateOutputMessage() { return(InnerTask.CreateOutputMessage()); }
public virtual void EndProcessingTask() { InnerTask.EndProcessingTask(); }
public virtual void BeginProcessingTask() { InnerTask.BeginProcessingTask(); }
// TODO: TEST /// <summary> /// Empties an optional, if a specified condition /// is not satisfied. /// </summary> /// <param name="condition">The condition.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(bool condition) { return(InnerTask.Map(option => option.Filter(condition)).ToAsyncOption()); }
// TODO: TEST /// <summary> /// Empties an optional, if a specified condition /// is not satisfied. /// </summary> /// <param name="condition">The condition.</param> /// <returns>The filtered optional.</returns> public AsyncOption <T> Filter(Task <bool> condition) { return(InnerTask.FlatMap(option => condition.Map(option.Filter)).ToAsyncOption()); }
public override string ToString() { return(InnerTask.ToString()); }
public AssemblyResolver(InnerTask config, Logger logger) { this.config = config; this.logger = logger; assemblyDefinitionCache = new Dictionary<string, AssemblyDefinition>(StringComparer.OrdinalIgnoreCase); }
public BackgroundParseTask ContinueWith(Action <GeneratorResults, BackgroundParseTask> continuation) { InnerTask.ContinueWith(t => RunContinuation(t, continuation)); return(this); }
// TODO: TEST /// <summary> /// Determines if the current optional contains a specified value. /// </summary> /// <param name="value">The value to locate.</param> /// <returns>A boolean indicating whether or not the value was found.</returns> public Task <bool> Contains(Task <T> value) { return(InnerTask.FlatMap(option => value.Map(option.Contains))); }
/// <summary> /// Uses an alternative value, if no existing value is present. /// </summary> /// <param name="alternative">The alternative value.</param> /// <returns>A new optional, containing either the existing or alternative value.</returns> public AsyncOption <T> Or(T alternative) { return(InnerTask.Map(option => option.Or(alternative)).ToAsyncOption()); }
public void Start() { InnerTask.Start(); }
/// <summary> /// Uses an alternative value, if no existing value is present. /// </summary> /// <param name="alternativeFactory">A factory function to create an alternative value.</param> /// <returns>A new optional, containing either the existing or alternative value.</returns> public AsyncOption <T> Or(Func <T> alternativeFactory) { return(InnerTask.Map(option => option.Or(alternativeFactory)).ToAsyncOption()); }
/// <summary> /// Attaches an exceptional value to an empty optional. /// </summary> /// <param name="exception">The exceptional value to attach.</param> /// <returns>An optional with an exceptional value.</returns> public AsyncOption <T, TException> WithException <TException>(TException exception) { return(InnerTask.Map(option => option.WithException(exception)).ToAsyncOption()); }
public ResourceEmbedder(InnerTask embedTask, Logger logger) { streams = new List<Stream>(); this.embedTask = embedTask; this.logger = logger; }