public TestableJobStatusReportingHelper(VstsMessage vstsMessage, ILogger traceLogger, ITaskClient mockTaskHttpClient, IReleaseClient releaseClient, MockBuildClient mockBuildClient, string timeLineRecordName = null)
     : base(vstsMessage, traceLogger, timeLineRecordName)
 {
     this.mockTaskHttpClient = mockTaskHttpClient;
     this.releaseClient      = releaseClient;
     this.mockBuildClient    = mockBuildClient;
 }
        public GivenAnAssignmentClientInstance()
        {
            IApplicationContext  applicationContext  = new ApplicationContext();
            IConfigurationRoot   configurationRoot   = ConfigurationRootFactory.Create(applicationContext);
            IConfigurationGetter configurationGetter = new ConfigurationGetter(configurationRoot);

            var projectContextOptions = configurationGetter.GetOptions <ProjectContextOptions>();
            var clientOptions         = configurationGetter.GetOptions <CsomClientOptions>();

            var projectContext = ProjectContextFactory.Build(projectContextOptions);

            _projectClient  = new ProjectClient(projectContext, clientOptions);
            _taskClient     = new TaskClient(projectContext, clientOptions);
            _resourceClient = new EnterpriseResourceClient(projectContext, clientOptions);

            _client = new AssignmentClient(projectContext, clientOptions);

            _publishedProject = CreateTestProject().Result;
            _publishedTask    = CreateTestTask().Result;

            _enterpriseResource  = CreateTestResource().Result;
            _enterpriseResource2 = CreateTestResource().Result;

            _publishedProject = _projectClient.LinkToEnterpriseResources(_publishedProject, new [] { _enterpriseResource, _enterpriseResource2 }).Result;
        }
Esempio n. 3
0
 public TestableServiceBusQueueMessageHandler(IServiceBusQueueMessageListener serviceBusQueueMessageListener, IVstsScheduleHandler <TestVstsMessage> handler, ServiceBusQueueMessageHandlerSettings settings, ILogger logger, ITaskClient taskClient, IBuildClient buildClient, IJobStatusReportingHelper jobStatusReportingHelper, IReleaseClient releaseClient)
     : base(serviceBusQueueMessageListener, handler, settings, logger)
 {
     this.taskClient               = taskClient;
     this.buildClient              = buildClient;
     this.releaseClient            = releaseClient;
     this.jobStatusReportingHelper = jobStatusReportingHelper;
 }
 public VstsBrokerInstrumentation(IBrokerInstrumentation baseInstrumentation, ITaskClient taskClient, string hubName, Guid scopeIdentifier, Guid planId, int taskLogId, IDictionary <string, string> eventProperties)
 {
     this.baseInstrumentation = baseInstrumentation;
     this.taskClient          = taskClient;
     this.scopeIdentifier     = scopeIdentifier;
     this.planId              = planId;
     this.taskLogId           = taskLogId;
     this.hubName             = hubName;
     this.baseEventProperties = eventProperties ?? new Dictionary <string, string>();
 }
 public UserTaskManager(ILogger <UserTaskManager> logger,
                        CronSchedulerService cronScheduler,
                        ITaskClient taskClient,
                        UserTaskCollectionService taskCollection)
 {
     _logger         = logger;
     _cronScheduler  = cronScheduler;
     _taskClient     = taskClient;
     _taskCollection = taskCollection;
 }
 public WorkflowTaskExecutor(ITaskClient taskClient,
                             IServiceProvider serviceProvider,
                             ILogger <WorkflowTaskExecutor> logger,
                             ConductorClientSettings conductorClientSettings)
 {
     _taskClient              = taskClient;
     _serviceProvider         = serviceProvider;
     _logger                  = logger;
     _conductorClientSettings = conductorClientSettings;
 }
Esempio n. 7
0
 public VstsLogger(ILogger logger, ITaskClient taskClient, string hubName, Guid scopeIdentifier, Guid planId, int taskLogId, Guid timelineId, Guid jobId)
 {
     this.logger          = logger;
     this.taskClient      = taskClient;
     this.scopeIdentifier = scopeIdentifier;
     this.planId          = planId;
     this.taskLogId       = taskLogId;
     this.hubName         = hubName;
     this.timelineId      = timelineId;
     this.jobId           = jobId;
 }
 public TaskController(UserTaskCollectionService taskCollection,
                       ILogger <TaskController> logger,
                       IMapper mapper,
                       ITaskClient client,
                       IProductRepository productRepository)
 {
     _taskCollection    = taskCollection;
     _logger            = logger;
     _mapper            = mapper;
     _client            = client;
     _productRepository = productRepository;
 }
Esempio n. 9
0
 public WorkflowTaskExecutor(ITaskClient taskClient,
                             IServiceProvider serviceProvider,
                             ILogger <WorkflowTaskExecutor> logger,
                             int sleepInterval,
                             string domain)
 {
     _taskClient      = taskClient;
     _serviceProvider = serviceProvider;
     _logger          = logger;
     _sleepInterval   = sleepInterval;
     _domain          = domain;
 }
Esempio n. 10
0
        public GivenATaskClientInstance()
        {
            IApplicationContext  applicationContext  = new ApplicationContext();
            IConfigurationRoot   configurationRoot   = ConfigurationRootFactory.Create(applicationContext);
            IConfigurationGetter configurationGetter = new ConfigurationGetter(configurationRoot);

            var projectContextOptions = configurationGetter.GetOptions <ProjectContextOptions>();
            var clientOptions         = configurationGetter.GetOptions <CsomClientOptions>();

            var projectContext = ProjectContextFactory.Build(projectContextOptions);

            _projectClient     = new ProjectClient(projectContext, clientOptions);
            _client            = new TaskClient(projectContext, clientOptions);
            _customFieldClient = new CustomFieldClient(projectContext, clientOptions);
            _entityTypeClient  = new EntityTypeClient(projectContext, clientOptions);

            _publishedProject = CreateTestProject().Result;
        }
Esempio n. 11
0
        private async void AppendTimelineRecordFeed(ITaskClient taskHttpClient, Guid scopeIdentifier, Guid planId, string logMessage, CancellationToken cancellationToken)
        {
            //Web console line is more than 1024 chars, truncate to first 1024 chars
            if (!string.IsNullOrEmpty(logMessage) && logMessage.Length > 1024)
            {
                logMessage = $"{logMessage.Substring(0, 1024)}...";
            }

            await taskHttpClient.AppendTimelineRecordFeedAsync(
                scopeIdentifier,
                this.hubName,
                planId,
                this.timelineId,
                this.jobId,
                new List <string>
            {
                logMessage
            },
                cancellationToken : cancellationToken,
                userState : null)
            .ConfigureAwait(false);
        }
        private async Task AppendLogAsync(string logMessage, IDictionary <string, string> eventProperties, ITaskClient taskClient, Guid scopeIdentifier, Guid planId, int taskLogId, CancellationToken cancellationToken)
        {
            Exception exception = null;

            try
            {
                using (var logStream = GenerateStreamFromString(logMessage))
                {
                    var taskLogResponse = await taskClient.AppendLogContentAsync(scopeIdentifier, this.hubName, planId, taskLogId, logStream, userState : null, cancellationToken : cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // c#6.0 allows await inside catch but this code is not 6.0 yet :-(
            if (exception != null && exception.GetType() != typeof(OperationCanceledException))
            {
                await this.baseInstrumentation.HandleException(exception, "VstsLogAppend", "Failed to append log to VSTS", eventProperties, cancellationToken).ConfigureAwait(false);
            }
        }
Esempio n. 13
0
        internal async Task CompleteTimelineRecords(Guid projectId, Guid planId, string hubName, Guid parentTimelineId, TaskResult result, CancellationToken cancellationToken, ITaskClient taskClient)
        {
            // Find all existing timeline records and close them
            var records = await taskClient.GetRecordsAsync(projectId, hubName, planId, parentTimelineId, userState : null, cancellationToken : cancellationToken).ConfigureAwait(false);

            var recordsToUpdate = GetTimelineRecordsToUpdate(records);

            foreach (var record in recordsToUpdate)
            {
                record.State           = TimelineRecordState.Completed;
                record.PercentComplete = 100;
                record.Result          = result;
                record.FinishTime      = DateTime.UtcNow;
            }

            await taskClient.UpdateTimelineRecordsAsync(projectId, hubName, planId, parentTimelineId, recordsToUpdate, cancellationToken).ConfigureAwait(false);
        }
 public TaskCountSchedulerJob(ITaskClient client, ITaskRepository repository, IDateTimeProvider dateTimeProvider)
 {
     this.client           = client;
     this.repository       = repository;
     this.dateTimeProvider = dateTimeProvider;
 }
        private async Task <int> GetOrCreateTaskLogId(IServiceBusMessage message, CancellationToken cancellationToken, ITaskClient taskClient, Guid projectId, Guid planId, Guid jobId, Guid parentTimelineId, string timelineName, string hubName)
        {
            // attempt to get from message
            var logIdObject = message.GetProperty(VstsMessageConstants.TaskLogIdPropertyName);
            var taskLogId   = 0;
            var gotLogId    = logIdObject != null && int.TryParse(logIdObject.ToString(), out taskLogId);

            if (gotLogId)
            {
                return(taskLogId);
            }

            // attempt to find existing
            var records = await taskClient.GetRecordsAsync(projectId, hubName, planId, parentTimelineId, userState : null, cancellationToken : cancellationToken).ConfigureAwait(false);

            foreach (var record in records)
            {
                if (string.Equals(record.Name, timelineName, StringComparison.OrdinalIgnoreCase))
                {
                    return(record.Log.Id);
                }
            }

            // Create a new timeline
            var subTimelineId = Guid.NewGuid();

            // create a log file
            var logsSubtimelineId = string.Format(@"logs\{0:D}", subTimelineId);
            var taskLog           = await taskClient.CreateLogAsync(projectId, hubName, planId, new TaskLog(logsSubtimelineId), userState : null, cancellationToken : cancellationToken).ConfigureAwait(false);

            // create a sub-timeline
            var timelineRecord = new TimelineRecord
            {
                Id              = subTimelineId,
                Name            = timelineName,
                StartTime       = DateTime.UtcNow,
                State           = TimelineRecordState.InProgress,
                RecordType      = "task", // Record type can be job or task, as we will be dealing only with task here
                WorkerName      = this.settings.WorkerName,
                Order           = 1,      // The job timeline record must be at order 1
                Log             = taskLog,
                ParentId        = jobId,
                PercentComplete = 0,
                ErrorCount      = 0,
                WarningCount    = 0
            };

            await taskClient.UpdateTimelineRecordsAsync(projectId, hubName, planId, parentTimelineId, new List <TimelineRecord> {
                timelineRecord
            }, cancellationToken).ConfigureAwait(false);

            // save the taskLogId on the message
            taskLogId = taskLog.Id;

            return(taskLogId);
        }
Esempio n. 16
0
 private async Task AppendLogAsync(string logMessage, IDictionary <string, string> eventProperties, ITaskClient taskClient, Guid scopeIdentifier, Guid planId, int taskLogId, CancellationToken cancellationToken)
 {
     try
     {
         using (var logStream = GenerateStreamFromString(logMessage))
         {
             this.AppendTimelineRecordFeed(taskClient, scopeIdentifier, planId, logMessage, cancellationToken);
             await taskClient.AppendLogContentAsync(scopeIdentifier, this.hubName, planId, taskLogId, logStream, userState : null, cancellationToken : cancellationToken).ConfigureAwait(false);
         }
     }
     catch (OperationCanceledException)
     {
     }
     catch (Exception ex)
     {
         await logger.LogException(ex, "VstsLogAppend",
                                   "Failed to append log to VSTS",
                                   eventProperties, cancellationToken).ConfigureAwait(false);
     }
 }