Exemplo n.º 1
0
        public bool JobsetHasExpired(MonitorJobSet monitorJobSet)
        {
            var timeThisJobsetShouldExpire = monitorJobSet.CreatedDate.AddMinutes(_applicationSettings.MinutesBetweenCheckingForNewMonitorJobs);
            var rightNow = _timeActions.Now();
            var result   = timeThisJobsetShouldExpire < rightNow;

            Log.DebugFormat("JobsetHasExpired is returning '{0}'", result);
            return(result);
        }
Exemplo n.º 2
0
        public void JobsetHasExpiredReturnsFalseWhenTheCreateDatePlusTimeForJobSetToLiveIsMoreThanNow()
        {
            MonitorJobSet monitorJobSet = new MonitorJobSet();                  //create date set right now

            _timeActions.Stub(x => x.Now()).Return(DateTime.Now.AddDays(-100)); //this means that the job cannot have expired
            _applicationSettings.Stub(x => x.MinutesBetweenCheckingForNewMonitorJobs).Return(15);
            var result = _monitorJobActions.JobsetHasExpired(monitorJobSet);

            Assert.That(result, Is.False);
        }
Exemplo n.º 3
0
        public MonitorJobSet GetAllCurrentMonitorJobsForThisServer(string machineName)
        {
            Log.DebugFormat("Entering GetAllCurrentMonitorJobsForThisServer for machineName '{0}'", machineName);
            var monitorJobSet  = new MonitorJobSet();
            var individualJobs = new List <MonitorJob>();

            using (var connection = new SqlConnection(_applicationSettings.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("usp_FolderMonitor_GetJobsByServerName", connection)
                {
                    CommandType = CommandType.StoredProcedure
                })
                {
                    try
                    {
                        command.Parameters.Add("@MachineName", SqlDbType.VarChar).Value = machineName;

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                var monitorJob = new MonitorJob
                                {
                                    ID = (int)reader["id"],
                                    MontiredJobType      = (MontiredJobType)reader.GetInt32(Convert.ToInt32("MonitorJobType")),
                                    Path                 = reader["PathToMonitor"].ToString(),
                                    Threshold            = reader["Threshold"] != null ? (int)reader["Threshold"] : 0,
                                    ThresholdType        = reader["ThresholdType"] != null ? (ThresholdType)((int)reader["ThresholdType"]) : ThresholdType.Minutes,
                                    FileExtensionToWatch = reader["FileExtensionToWatch"] == null ? "*" : reader["FileExtensionToWatch"].ToString(),
                                    MinFileSizeInBytes   = reader["MinFileSizeInBytes"] != null ? (int)reader["MinFileSizeInBytes"] : int.MinValue,
                                };
                                individualJobs.Add(monitorJob);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.ErrorFormat("GetQueueItemsToProcess threw the exception '{0}' for machineName: '{1}'", ex, machineName);
                        throw;
                    }
                }
            }

            monitorJobSet.MonitorJobs = individualJobs;

            return(monitorJobSet);
        }