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);
 }
        private string GetTaskExecutablePath(SchedulerAppTask schedulerAppTask, EnvironmentInfo environmentInfo)
        {
            string targetDirPath = GetTargetDirPath(environmentInfo);

              return Path.Combine(targetDirPath, schedulerAppTask.ExecutableName);
        }
        private bool HasSettingsChanged(ScheduledTaskDetails taskDetails, SchedulerAppTask schedulerAppTask, EnvironmentInfo environmentInfo)
        {
            if (taskDetails == null)
              {
            return false;
              }

              string taskExecutablePath = GetTaskExecutablePath(schedulerAppTask, environmentInfo);

              return !(taskDetails.Name == schedulerAppTask.Name
              && taskDetails.ScheduledHour == schedulerAppTask.ScheduledHour
              && taskDetails.ScheduledMinute == schedulerAppTask.ScheduledMinute
              && taskDetails.ExecutionTimeLimitInMinutes == schedulerAppTask.ExecutionTimeLimitInMinutes
              && taskDetails.Repetition.Interval == schedulerAppTask.Repetition.Interval
              && taskDetails.Repetition.Duration == schedulerAppTask.Repetition.Duration
              && taskDetails.Repetition.StopAtDurationEnd == schedulerAppTask.Repetition.StopAtDurationEnd
              && taskDetails.ExeAbsolutePath == taskExecutablePath);
        }
        private void AddTaskConfigurationSteps(EnvironmentInfo environmentInfo, string schedulerServerTasksMachineName, SchedulerAppTask schedulerAppTask, ScheduledTaskDetails taskDetails = null)
        {
            bool hasSettingsChanged = HasSettingsChanged(taskDetails, schedulerAppTask, environmentInfo);
              bool taskExists = taskDetails != null;

              EnvironmentUser environmentUser =
            environmentInfo.GetEnvironmentUserById(schedulerAppTask.UserId);

              string environmentUserPassword = null;

              if (!taskExists || hasSettingsChanged)
              {
            // collect password if not already collected
            if (!_collectedPasswordsByUserName.TryGetValue(environmentUser.UserName, out environmentUserPassword))
            {
              environmentUserPassword =
            PasswordCollectorHelper.CollectPasssword(
              _passwordCollector,
              DeploymentInfo.DeploymentId,
              environmentInfo,
              schedulerServerTasksMachineName,
              environmentUser,
              OnDiagnosticMessagePosted);

              _collectedPasswordsByUserName.Add(environmentUser.UserName, environmentUserPassword);
            }
              }

              string taskExecutablePath =
            GetTaskExecutablePath(schedulerAppTask, environmentInfo);

              if (!taskExists)
              {
            // create a step for scheduling a new app
            AddSubTask(
              new CreateSchedulerTaskDeploymentStep(
            schedulerServerTasksMachineName,
            schedulerAppTask.Name,
            taskExecutablePath,
            environmentUser.UserName,
            environmentUserPassword,
            schedulerAppTask.ScheduledHour,
            schedulerAppTask.ScheduledMinute,
            schedulerAppTask.ExecutionTimeLimitInMinutes,
            schedulerAppTask.Repetition,
            _taskScheduler));
              }
              else if (hasSettingsChanged)
              {
            // create a step for updating an existing scheduler app
            AddSubTask(
              new UpdateSchedulerTaskDeploymentStep(
            schedulerServerTasksMachineName,
            schedulerAppTask.Name,
            taskExecutablePath,
            environmentUser.UserName,
            environmentUserPassword,
            schedulerAppTask.ScheduledHour,
            schedulerAppTask.ScheduledMinute,
            schedulerAppTask.ExecutionTimeLimitInMinutes,
            schedulerAppTask.Repetition,
            _taskScheduler));
              }
        }