Пример #1
0
        public ScheduledTaskDetails GetScheduledTaskDetails(string machineName, string taskName)
        {
            Guard.NotNullNorEmpty(machineName, "machineName");
              Guard.NotNullNorEmpty(taskName, "taskName");

              using (var taskService = CreateTaskService(machineName))
              {
            Task task = taskService.FindTask(taskName, false);

            if (task == null)
            {
              return null;
            }

            ExecAction action =
              (ExecAction)task.Definition.Actions
            .Single(x => x is ExecAction);

            string execPath = action.Path;

            DailyTrigger trigger =
              (DailyTrigger)task.Definition.Triggers
            .Single();

            int startHour = trigger.StartBoundary.Hour;
            int startMinute = trigger.StartBoundary.Minute;
            int executionTimeLimits = (int)trigger.ExecutionTimeLimit.TotalMinutes;

            var repetition =
              new ScheduledTaskRepetition(
            trigger.Repetition.Interval,
            trigger.Repetition.Duration,
            trigger.Repetition.StopAtDurationEnd);

            return
              new ScheduledTaskDetails(
            task.Name,
            task.Enabled,
            task.State == TaskState.Running,
            task.LastRunTime,
            task.NextRunTime,
            execPath,
            startHour,
            startMinute,
            executionTimeLimits,
            repetition);
              }
        }
Пример #2
0
        public ScheduledTaskDetails GetScheduledTaskDetails(string machineName, string taskName)
        {
            Guard.NotNullNorEmpty(machineName, "machineName");
            Guard.NotNullNorEmpty(taskName, "taskName");

            using (var taskService = CreateTaskService(machineName))
            {
                Task task = taskService.FindTask(taskName, false);

                if (task == null)
                {
                    return(null);
                }

                ExecAction action =
                    (ExecAction)task.Definition.Actions
                    .Single(x => x is ExecAction);

                string execPath = action.Path;

                DailyTrigger trigger =
                    (DailyTrigger)task.Definition.Triggers
                    .Single();

                int startHour           = trigger.StartBoundary.Hour;
                int startMinute         = trigger.StartBoundary.Minute;
                int executionTimeLimits = (int)trigger.ExecutionTimeLimit.TotalMinutes;

                var repetition =
                    new ScheduledTaskRepetition(
                        trigger.Repetition.Interval,
                        trigger.Repetition.Duration,
                        trigger.Repetition.StopAtDurationEnd);

                return
                    (new ScheduledTaskDetails(
                         task.Name,
                         task.Enabled,
                         task.State == TaskState.Running,
                         task.LastRunTime,
                         task.NextRunTime,
                         execPath,
                         startHour,
                         startMinute,
                         executionTimeLimits,
                         repetition));
            }
        }
Пример #3
0
        public ScheduledTaskDetails(string name, bool isEnabled, bool isRunning, DateTime lastRunTime, DateTime nextRunTime, string exeAbsolutePath, int scheduledHour, int scheduledMinute, int executionTimeLimitInMinutes, ScheduledTaskRepetition repetition)
        {
            Guard.NotNullNorEmpty(name, "name");
              Guard.NotNull(repetition, "repetition");

              Name = name;
              IsEnabled = isEnabled;
              IsRunning = isRunning;
              LastRunTime = lastRunTime;
              NextRunTime = nextRunTime;
              ExeAbsolutePath = exeAbsolutePath;
              ScheduledHour = scheduledHour;
              ScheduledMinute = scheduledMinute;
              ExecutionTimeLimitInMinutes = executionTimeLimitInMinutes;
              Repetition = repetition;
        }
Пример #4
0
        public ScheduledTaskDetails(string name, bool isEnabled, bool isRunning, DateTime lastRunTime, DateTime nextRunTime, string exeAbsolutePath, int scheduledHour, int scheduledMinute, int executionTimeLimitInMinutes, ScheduledTaskRepetition repetition)
        {
            Guard.NotNullNorEmpty(name, "name");
            Guard.NotNull(repetition, "repetition");

            Name                        = name;
            IsEnabled                   = isEnabled;
            IsRunning                   = isRunning;
            LastRunTime                 = lastRunTime;
            NextRunTime                 = nextRunTime;
            ExeAbsolutePath             = exeAbsolutePath;
            ScheduledHour               = scheduledHour;
            ScheduledMinute             = scheduledMinute;
            ExecutionTimeLimitInMinutes = executionTimeLimitInMinutes;
            Repetition                  = repetition;
        }
 private static ScheduledTaskDetails GetTaskDetails(SchedulerAppTask schedulerAppTask, string exeAbsolutePath, bool isEnabled, bool isRunning, ScheduledTaskRepetition repetition)
 {
     return
     new ScheduledTaskDetails(
       schedulerAppTask.Name,
       isEnabled,
       isRunning,
       DateTime.Now,
       DateTime.Now,
       exeAbsolutePath,
       schedulerAppTask.ScheduledHour,
       schedulerAppTask.ScheduledMinute,
       schedulerAppTask.ExecutionTimeLimitInMinutes,
       repetition);
 }
        public void SetUp()
        {
            _projectInfoRepositoryFake = new Mock<IProjectInfoRepository>();
              _environmentInfoRepositoryFake = new Mock<IEnvironmentInfoRepository>();
              _artifactsRepositoryFake = new Mock<IArtifactsRepository>();
              _taskSchedulerFake = new Mock<ITaskScheduler>();
              _passwordCollectorFake = new Mock<IPasswordCollector>();
              _directoryAdapterFake = new Mock<IDirectoryAdapter>();
              _fileAdapterFake = new Mock<IFileAdapter>();
              _zipFileAdapterFake = new Mock<IZipFileAdapter>();

              _projectInfo = ProjectInfoGenerator.GetSchedulerAppProjectInfo();

              SchedulerAppTask schedulerAppTask1 = _projectInfo.SchedulerAppTasks.First();
              SchedulerAppTask schedulerAppTask2 = _projectInfo.SchedulerAppTasks.Second();

              _environmentInfo =
            DeploymentDataGenerator.GetEnvironmentInfo(
              new[]
              {
            new EnvironmentUser(schedulerAppTask1.UserId, "user_name_1"),
            new EnvironmentUser(schedulerAppTask2.UserId, "user_name_2"),
              });

              _projectInfoRepositoryFake.Setup(pir => pir.FindByName(It.IsAny<string>()))
            .Returns(_projectInfo);

              string exeAbsolutePath1 =
            Path.Combine(
              _environmentInfo.SchedulerAppsBaseDirPath,
              _projectInfo.SchedulerAppDirName,
              schedulerAppTask1.ExecutableName);

              var scheduledTaskRepetition1 =
            new ScheduledTaskRepetition(
              schedulerAppTask1.Repetition.Interval,
              schedulerAppTask1.Repetition.Duration,
              schedulerAppTask1.Repetition.StopAtDurationEnd);

              ScheduledTaskDetails taskDetails1 =
            GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, true, false, scheduledTaskRepetition1);

              ScheduledTaskDetails taskDetailsDisabled1 =
            GetTaskDetails(schedulerAppTask1, exeAbsolutePath1, false, false, scheduledTaskRepetition1);

              int timesCalled11 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask1.Name))
            .Returns(() =>
            {
              timesCalled11++;

              if (timesCalled11 == 1)
              {
            return taskDetails1;
              }

              if (timesCalled11 == 2)
              {
            return taskDetailsDisabled1;
              }

              throw new Exception("Unexpected number of calls!");
            });

              int timesCalled21 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask1.Name))
            .Returns(() =>
            {
              timesCalled21++;

              if (timesCalled21 == 1)
              {
            return taskDetails1;
              }

              if (timesCalled21 == 2)
              {
            return taskDetailsDisabled1;
              }

              throw new Exception("Unexpected number of calls!");
            });

              string exeAbsolutePath2 =
            Path.Combine(
              _environmentInfo.SchedulerAppsBaseDirPath,
              _projectInfo.SchedulerAppDirName,
              schedulerAppTask2.ExecutableName);

              var scheduledTaskRepetition2 =
            new ScheduledTaskRepetition(
              schedulerAppTask2.Repetition.Interval,
              schedulerAppTask2.Repetition.Duration,
              schedulerAppTask2.Repetition.StopAtDurationEnd);

              ScheduledTaskDetails taskDetails2 =
            GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, true, false, scheduledTaskRepetition2);

              ScheduledTaskDetails taskDetailsDisabled2 =
            GetTaskDetails(schedulerAppTask2, exeAbsolutePath2, false, false, scheduledTaskRepetition2);

              int timesCalled12 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.First(), schedulerAppTask2.Name))
            .Returns(() =>
            {
              timesCalled12++;

              if (timesCalled12 == 1)
              {
            return taskDetails2;
              }

              if (timesCalled12 == 2)
              {
            return taskDetailsDisabled2;
              }

              throw new Exception("Unexpected number of calls!");
            });

              int timesCalled22 = 0;

              _taskSchedulerFake
            .Setup(x => x.GetScheduledTaskDetails(_environmentInfo.SchedulerServerTasksMachineNames.Second(), schedulerAppTask2.Name))
            .Returns(() =>
            {
              timesCalled22++;

              if (timesCalled22 == 1)
              {
            return taskDetails2;
              }

              if (timesCalled22 == 2)
              {
            return taskDetailsDisabled2;
              }

              throw new Exception("Unexpected number of calls!");
            });

              _environmentInfoRepositoryFake
            .Setup(x => x.FindByName(It.IsAny<string>()))
            .Returns(_environmentInfo);

              _directoryAdapterFake
            .Setup(x => x.Exists(It.IsAny<string>()))
            .Returns(true);

              _deployTask =
            new DeploySchedulerAppDeploymentTask(
              _projectInfoRepositoryFake.Object,
              _environmentInfoRepositoryFake.Object,
              _artifactsRepositoryFake.Object,
              _taskSchedulerFake.Object,
              _passwordCollectorFake.Object,
              _directoryAdapterFake.Object,
              _fileAdapterFake.Object,
              _zipFileAdapterFake.Object);

              _deployTask.Initialize(DeploymentInfoGenerator.GetSchedulerAppDeploymentInfo());
        }