private static List<RecurringJobDto> GetRecurringJobDtos(IStorageConnection connection, IEnumerable<string> ids)
        {
            var result = new List<RecurringJobDto>();
            foreach (var id in ids)
            {
                var hash = connection.GetAllEntriesFromHash(String.Format("recurring-job:{0}", id));

                if (hash == null)
                {
                    result.Add(new RecurringJobDto { Id = id, Removed = true });
                    continue;
                }

                var dto = new RecurringJobDto { Id = id };
                dto.Cron = hash["Cron"];

                try
                {
                    var invocationData = JobHelper.FromJson<InvocationData>(hash["Job"]);
                    dto.Job = invocationData.Deserialize();
                }
                catch (JobLoadException ex)
                {
                    dto.LoadException = ex;
                }

                if (hash.ContainsKey("NextExecution"))
                {
                    dto.NextExecution = JobHelper.DeserializeDateTime(hash["NextExecution"]);
                }

                if (hash.ContainsKey("LastJobId") && !string.IsNullOrWhiteSpace(hash["LastJobId"]))
                {
                    dto.LastJobId = hash["LastJobId"];

                    var stateData = connection.GetStateData(dto.LastJobId);
                    if (stateData != null)
                    {
                        dto.LastJobState = stateData.Name;
                    }
                }

                if (hash.ContainsKey("LastExecution"))
                {
                    dto.LastExecution = JobHelper.DeserializeDateTime(hash["LastExecution"]);
                }

                if (hash.ContainsKey("TimeZoneId"))
                {
                    dto.TimeZoneId = hash["TimeZoneId"];
                }

                result.Add(dto);
            }

            return result;
        }
        public static List<RecurringJobDto> GetRecurringJobs([NotNull] this IStorageConnection connection)
        {
            if (connection == null) throw new ArgumentNullException("connection");

            var result = new List<RecurringJobDto>();

            var ids = connection.GetAllItemsFromSet("recurring-jobs");

            foreach (var id in ids)
            {
                var hash = connection.GetAllEntriesFromHash(String.Format("recurring-job:{0}", id));

                if (hash == null)
                {
                    result.Add(new RecurringJobDto { Id = id, Removed = true });
                    continue;
                }

                var dto = new RecurringJobDto { Id = id };
                dto.Cron = hash["Cron"];

                try
                {
                    var invocationData = JobHelper.FromJson<InvocationData>(hash["Job"]);
                    dto.Job = invocationData.Deserialize();
                }
                catch (JobLoadException ex)
                {
                    dto.LoadException = ex;
                }

                if (hash.ContainsKey("NextExecution"))
                {
                    dto.NextExecution = JobHelper.DeserializeDateTime(hash["NextExecution"]);
                }

                if (hash.ContainsKey("LastJobId"))
                {
                    dto.LastJobId = hash["LastJobId"];

                    var stateData = connection.GetStateData(dto.LastJobId);
                    if (stateData != null)
                    {
                        dto.LastJobState = stateData.Name;
                    }
                }

                if (hash.ContainsKey("LastExecution"))
                {
                    dto.LastExecution = JobHelper.DeserializeDateTime(hash["LastExecution"]);
                }

                result.Add(dto);
            }

            return result;
        }
예제 #3
0
        public RecurringJobsPage()
        {
            RecurringJobs = new List<RecurringJobDto>();

            using (var connection = JobStorage.Current.GetConnection())
            {
                var ids = connection.GetAllItemsFromSet("recurring-jobs");

                foreach (var id in ids)
                {
                    var hash = connection.GetAllEntriesFromHash(String.Format("recurring-job:{0}", id));

                    if (hash == null)
                    {
                        RecurringJobs.Add(new RecurringJobDto { Id = id, Removed = true });
                        continue;
                    }

                    var dto = new RecurringJobDto { Id = id };
                    dto.Cron = hash["Cron"];

                    try
                    {
                        var invocationData = JobHelper.FromJson<InvocationData>(hash["Job"]);
                        dto.Job = invocationData.Deserialize();
                    }
                    catch (JobLoadException ex)
                    {
                        dto.LoadException = ex;
                    }

                    if (hash.ContainsKey("NextExecution"))
                    {
                        dto.NextExecution = JobHelper.DeserializeDateTime(hash["NextExecution"]);
                    }

                    if (hash.ContainsKey("LastJobId"))
                    {
                        dto.LastJobId = hash["LastJobId"];

                        var stateData = connection.GetStateData(dto.LastJobId);
                        if (stateData != null)
                        {
                            dto.LastJobState = stateData.Name;
                        }
                    }

                    if (hash.ContainsKey("LastExecution"))
                    {
                        dto.LastExecution = JobHelper.DeserializeDateTime(hash["LastExecution"]);
                    }

                    RecurringJobs.Add(dto);
                }
            }
        }
        private static List <RecurringJobDto> GetRecurringJobDtos(IStorageConnection connection, IEnumerable <string> ids)
        {
            var result = new List <RecurringJobDto>();

            foreach (var id in ids)
            {
                var hash = connection.GetAllEntriesFromHash(String.Format("recurring-job:{0}", id));

                if (hash == null)
                {
                    result.Add(new RecurringJobDto {
                        Id = id, Removed = true
                    });
                    continue;
                }

                var dto = new RecurringJobDto {
                    Id = id
                };
                dto.Cron = hash["Cron"];

                try
                {
                    var invocationData = JobHelper.FromJson <InvocationData>(hash["Job"]);
                    dto.Job = invocationData.Deserialize();
                }
                catch (JobLoadException ex)
                {
                    dto.LoadException = ex;
                }

                if (hash.ContainsKey("NextExecution"))
                {
                    dto.NextExecution = JobHelper.DeserializeDateTime(hash["NextExecution"]);
                }

                if (hash.ContainsKey("LastJobId") && !string.IsNullOrWhiteSpace(hash["LastJobId"]))
                {
                    dto.LastJobId = hash["LastJobId"];

                    var stateData = connection.GetStateData(dto.LastJobId);
                    if (stateData != null)
                    {
                        dto.LastJobState = stateData.Name;
                    }
                }

                if (hash.ContainsKey("LastExecution"))
                {
                    dto.LastExecution = JobHelper.DeserializeDateTime(hash["LastExecution"]);
                }

                if (hash.ContainsKey("TimeZoneId"))
                {
                    dto.TimeZoneId = hash["TimeZoneId"];
                }

                if (hash.ContainsKey("CreatedAt"))
                {
                    dto.CreatedAt = JobHelper.DeserializeDateTime(hash["CreatedAt"]);
                }

                result.Add(dto);
            }

            return(result);
        }
예제 #5
0
        public static List <RecurringJobDto> GetRecurringJobs([NotNull] this IStorageConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            var result = new List <RecurringJobDto>();

            var ids = connection.GetAllItemsFromSet("recurring-jobs");

            foreach (var id in ids)
            {
                var hash = connection.GetAllEntriesFromHash(String.Format("recurring-job:{0}", id));

                if (hash == null)
                {
                    result.Add(new RecurringJobDto {
                        Id = id, Removed = true
                    });
                    continue;
                }

                var dto = new RecurringJobDto {
                    Id = id
                };
                dto.Cron = hash["Cron"];

                try
                {
                    var invocationData = JobHelper.FromJson <InvocationData>(hash["Job"]);
                    dto.Job = invocationData.Deserialize();
                }
                catch (JobLoadException ex)
                {
                    dto.LoadException = ex;
                }

                if (hash.ContainsKey("NextExecution"))
                {
                    dto.NextExecution = JobHelper.DeserializeDateTime(hash["NextExecution"]);
                }

                if (hash.ContainsKey("LastJobId") && !string.IsNullOrWhiteSpace(hash["LastJobId"]))
                {
                    dto.LastJobId = hash["LastJobId"];

                    var stateData = connection.GetStateData(dto.LastJobId);
                    if (stateData != null)
                    {
                        dto.LastJobState = stateData.Name;
                    }
                }

                if (hash.ContainsKey("LastExecution"))
                {
                    dto.LastExecution = JobHelper.DeserializeDateTime(hash["LastExecution"]);
                }

                result.Add(dto);
            }

            return(result);
        }
        private static List <RecurringJobDto> GetRecurringJobDtos(IStorageConnection connection, IEnumerable <string> ids)
        {
            var result = new List <RecurringJobDto>();

            foreach (var id in ids)
            {
                var hash = connection.GetAllEntriesFromHash($"recurring-job:{id}");

                if (hash == null)
                {
                    result.Add(new RecurringJobDto {
                        Id = id, Removed = true
                    });
                    continue;
                }

                var dto = new RecurringJobDto
                {
                    Id   = id,
                    Cron = hash["Cron"]
                };

                try
                {
                    if (hash.TryGetValue("Job", out var payload) && !String.IsNullOrWhiteSpace(payload))
                    {
                        var invocationData = InvocationData.DeserializePayload(payload);
                        dto.Job = invocationData.DeserializeJob();
                    }
                }
                catch (JobLoadException ex)
                {
                    dto.LoadException = ex;
                }

                if (hash.ContainsKey("NextExecution"))
                {
                    dto.NextExecution = JobHelper.DeserializeNullableDateTime(hash["NextExecution"]);
                }

                if (hash.ContainsKey("LastJobId") && !string.IsNullOrWhiteSpace(hash["LastJobId"]))
                {
                    dto.LastJobId = hash["LastJobId"];

                    var stateData = connection.GetStateData(dto.LastJobId);
                    if (stateData != null)
                    {
                        dto.LastJobState = stateData.Name;
                    }
                }

                if (hash.ContainsKey("Queue"))
                {
                    dto.Queue = hash["Queue"];
                }

                if (hash.ContainsKey("LastExecution"))
                {
                    dto.LastExecution = JobHelper.DeserializeNullableDateTime(hash["LastExecution"]);
                }

                if (hash.ContainsKey("TimeZoneId"))
                {
                    dto.TimeZoneId = hash["TimeZoneId"];
                }

                if (hash.ContainsKey("CreatedAt"))
                {
                    dto.CreatedAt = JobHelper.DeserializeNullableDateTime(hash["CreatedAt"]);
                }

                if (hash.TryGetValue("Error", out var error))
                {
                    dto.Error = error;
                }

                dto.IsActive = !hash.TryGetValue("IsActive", out var status) || bool.Parse(status);
                result.Add(dto);
            }

            return(result);
        }