public TimeBasedSchedule(ITfsIntegrationJob job, Job configuration)
            : base(job, configuration)
        {
            DateTime configuredDateTime = DateTime.Parse(configuration.Trigger.Setting);

            CalcKickOffTimeRange(configuredDateTime, m_jobKickOffTimeOfDayTicksRange);
        }
        protected override void OnStart(string[] args)
        {
            try
            {
                // Uncomment to debug startup of service
                // Thread.Sleep(40000);

                TraceManager.TraceInformation("Starting TfsIntegrationJobService ...");
                this.EventLog.WriteEntry(String.Format("{0} starting...", this.ServiceName), EventLogEntryType.Information, 0, 0);

                // todo: use Jobs folder
                string jobsFolder = Microsoft.TeamFoundation.Migration.Toolkit.Constants.PluginsFolderName;
                IEnumerable <ProviderHandler> providers =
                    Microsoft.TeamFoundation.Migration.Toolkit.Utility.LoadProvider(new DirectoryInfo(jobsFolder));

                Dictionary <ITfsIntegrationJob, Job> jobAndConfig = new Dictionary <ITfsIntegrationJob, Job>();
                foreach (ProviderHandler handler in providers)
                {
                    try
                    {
                        IProvider          provider       = handler.Provider;
                        ITfsIntegrationJob integrationJob = provider.GetService(typeof(ITfsIntegrationJob)) as ITfsIntegrationJob;
                        if (null != integrationJob)
                        {
                            m_loadedJobs.Add(integrationJob);
                            if (TfsIntegrationJobsConfiguration.ConfiguredJobs.ContainsKey(integrationJob.ReferenceName))
                            {
                                if (TfsIntegrationJobsConfiguration.ConfiguredJobs[integrationJob.ReferenceName].Enabled)
                                {
                                    jobAndConfig[integrationJob] = TfsIntegrationJobsConfiguration.ConfiguredJobs[integrationJob.ReferenceName];
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        TraceManager.TraceError(e.ToString());

                        string failureMessage = string.Format(
                            "A failure occurred while trying to load the TfsIntegrationJob in: {0}.{1}  Exception: {2}",
                            handler.ProviderName, Environment.NewLine, e.Message);
                        this.EventLog.WriteEntry(failureMessage, EventLogEntryType.Error, 0, 0);
                    }
                }

                m_jobScheduler = new JobScheduler(jobAndConfig);
                m_jobScheduler.Start();
            }
            catch (Exception e)
            {
                TraceManager.TraceError(e.ToString());
                this.EventLog.WriteEntry(
                    String.Format("{0} error starting: {1}", this.ServiceName, e.Message),
                    EventLogEntryType.Error, 0, 0);
            }
        }
 public IntervalBasedSchedule(ITfsIntegrationJob job, Job configuration)
     : base(job, configuration)
 {
     try
     {
         this.m_intervalMilliSeconds = checked (int.Parse(configuration.Trigger.Setting) * 1000);
     }
     catch (OverflowException e)
     {
         TraceManager.TraceError(e.ToString());
         TraceManager.TraceError(string.Format(
                                     "Setting default interval time to {0} seconds", (int.MaxValue / 1000).ToString()));
         this.m_intervalMilliSeconds = int.MaxValue;
     }
 }
        public static bool TryCreateSchedule(ITfsIntegrationJob job, Job configuration, out ISchedule createdSchedule)
        {
            createdSchedule = null;
            bool retVal = false;

            if (configuration.Enabled)
            {
                try
                {
                    switch (configuration.Trigger.Option)
                    {
                    case TriggerOption.IntervalBased:
                        TraceManager.TraceInformation(string.Format(
                                                          "Created interval-based job schedule for job '{0}'", job.FriendlyName));
                        createdSchedule = new IntervalBasedSchedule(job, configuration);
                        retVal          = true;
                        break;

                    case TriggerOption.TimeBased:
                        TraceManager.TraceInformation(string.Format(
                                                          "Created time-based job schedule for job '{0}'.", job.FriendlyName));
                        createdSchedule = new TimeBasedSchedule(job, configuration);
                        retVal          = true;
                        break;

                    default:
                        TraceManager.TraceError(string.Format(
                                                    "'{0}' is not a supported job trigger type.", configuration.Trigger.Option.ToString()));
                        break;
                    }
                }
                catch (Exception e)
                {
                    TraceManager.TraceError(e.ToString());
                }
            }

            return(retVal);
        }
 public ScheduleBase(ITfsIntegrationJob job, Job configuration)
 {
     this.m_job           = job;
     this.m_configuration = configuration;
 }