예제 #1
0
 public void Cancel(ITaskLogger taskLogger, CancellationToken cancellationToken)
 {
     taskLogger.Log("ExecutionHandler.Cancel");
     // create timelinerecord if not provided
     // initialize logger
     // cancel
 }
        public async Task <ITaskExecutionHandlerResult> ExecuteAsync(ITaskLogger taskLogger, CancellationToken cancellationToken)
        {
            taskLogger.Log("Inside my sample task execution handler");

            return(await Task.FromResult(new TaskExecutionHandlerResult { Result = TaskResult.Succeeded }));
        }
        /// <summary>
        /// Executes the task.
        /// </summary>
        /// <returns>true if successful</returns>
        public override bool Execute()
        {
            string           errorCode        = null;
            LogMessageLevel  errorLevel       = ErrorOnMismatch ? LogMessageLevel.Error : LogMessageLevel.Warning;
            AssemblyInfoData asmInfo          = default;
            string           assemblyInfoPath = null;

            if (this.BuildEngine != null)
            {
                Logger = new LogWrapper(Log, GetType().Name);
            }
            else
            {
                Logger = new MockTaskLogger(GetType().Name);
            }
            try
            {
                if (!Util.MatchVersions(AssemblyVersion, PluginVersion))
                {
                    Logger.Log(null, MessageCodes.CompareVersions.VersionMismatch, "",
                               assemblyInfoPath, asmInfo.AssemblyVersionPosition, errorLevel,
                               "PluginVersion {0} does not match AssemblyVersion {1}.", PluginVersion,
                               AssemblyVersion);
                    if (ErrorOnMismatch)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (VersionMatchException ex)
            {
                if (BuildEngine != null)
                {
                    int line   = BuildEngine.LineNumberOfTaskNode;
                    int column = BuildEngine.ColumnNumberOfTaskNode;
                    Logger.LogError(null, MessageCodes.CompareVersions.InvalidVersion, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message);
                }
                else
                {
                    Logger.LogError(null, MessageCodes.CompareVersions.InvalidVersion, null, null, 0, 0, 0, 0, ex.Message);
                }
                return(false);
            }
            catch (ParsingException ex)
            {
                if (string.IsNullOrEmpty(errorCode))
                {
                    errorCode = MessageCodes.CompareVersions.GeneralFailure;
                }
                if (BuildEngine != null)
                {
                    int line   = BuildEngine.LineNumberOfTaskNode;
                    int column = BuildEngine.ColumnNumberOfTaskNode;
                    Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, ex.Message);
                }
                else
                {
                    Logger.LogError(null, errorCode, null, null, ex.LineNumber, ex.ColumnNumber, ex.EndLineNumber, ex.EndColumnNumber, ex.Message);
                }
                return(false);
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(errorCode))
                {
                    errorCode = MessageCodes.CompareVersions.GeneralFailure;
                }
                if (BuildEngine != null)
                {
                    int line   = BuildEngine.LineNumberOfTaskNode;
                    int column = BuildEngine.ColumnNumberOfTaskNode;
                    Logger.LogError(null, errorCode, null, BuildEngine.ProjectFileOfTaskNode, line, column, line, column, $"Error in {GetType().Name}: {ex.Message}");
                }
                else
                {
                    Logger.LogError(null, errorCode, null, null, 0, 0, 0, 0, $"Error in {GetType().Name}: {ex.Message}");
                }
                return(false);
            }
        }