Exemplo n.º 1
0
        public static string RunJob(long jobId)
        {
            string returnMessage = string.Format("Could not set job {0} to status 'Ready'.", jobId);

            try
            {
                using (AccessPointClient client = new AccessPointClient())
                {
                    SetJobStatusesResponse response = client.SetJobStatuses(new SetJobStatusesRequest
                    {
                        JobIds    = new long[] { jobId },
                        NewStatus = JobStatus.Ready,
                    });
                    if (response.Success)
                    {
                        returnMessage = string.Format("Successfully set job {0} to be run.", jobId);
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage += "<br /><br />" + ex.Message;
            }
            return(returnMessage);
        }
Exemplo n.º 2
0
        public static string DeleteAllAlerts()
        {
            string returnMessage = string.Format("Could not delete all alerts");

            try
            {
                using (AccessPointClient client = new AccessPointClient())
                {
                    DeleteAlertsResponse response = client.DeleteAlerts(new DeleteAlertsRequest
                    {
                        Ids = null,
                    });
                    if (response.Success)
                    {
                        returnMessage = string.Format("Successfully deleted all alerts.");
                        GetAlertsView();
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage += "<br /><br />" + ex.Message;
            }
            return(returnMessage);
        }
Exemplo n.º 3
0
        public static string GetAlertsView()
        {
            List <Alert> alerts = new List <Alert>();

            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                Alert[] page;
                do
                {
                    page = accessPoint.GetAlerts(new GetAlertsRequest
                    {
                        Skip = (uint)alerts.Count,
                        Take = PageSize,
                    }).Alerts;
                    alerts.AddRange(page);
                }while (page != null && page.Length == PageSize);

                long[]         jobIds = alerts.Select(a => a.JobId).ToArray();
                List <JobData> jobs   = new List <JobData>();
                JobData[]      jobPage;
                do
                {
                    jobPage = accessPoint.GetJobs(new GetJobsRequest
                    {
                        Skip = (uint)jobs.Count,
                        Take = PageSize,
                    }).Jobs;
                    jobs.AddRange(jobPage);
                }while (jobPage != null && jobPage.Length == PageSize);

                if (jobs.Count > 0)
                {
                    foreach (var alert in alerts)
                    {
                        var job = jobs.FirstOrDefault(j => j.Id == alert.JobId);
                        if (job != null)
                        {
                            alert.JobName = job.Name;
                        }
                    }
                }
            }

            System.Web.HttpRuntime.Cache.Remove(Constants.AlertsListCacheKey);
            System.Web.HttpRuntime.Cache.Add(Constants.AlertsListCacheKey, alerts, null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.NotRemovable, null);

            AlertNotifier alertNotifierControl = AjaxUtility.LoadControl("/UserControls/AlertNotifier.ascx") as AlertNotifier;

            alertNotifierControl.AlertCount = alerts.Count;
            return(AjaxUtility.RenderUserControl(alertNotifierControl));
        }
Exemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                btnRefresh.OnClientClick = $"refreshJobsList{ApplicationName}();return false;";
                lblLastRefresh.Text      = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
            }

            var selectedStatuses = GetSelectedStatuses().ToArray();

            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                List <JobData> jobs = new List <JobData>();
                JobData[]      page;
                do
                {
                    if (!string.IsNullOrWhiteSpace(ApplicationName))
                    {
                        page = accessPoint.GetJobs(new GetJobsRequest
                        {
                            Skip         = (uint)jobs.Count,
                            Take         = PageSize,
                            Applications = new string[] { ApplicationName },
                        }).Jobs;
                        jobs.AddRange(page);
                    }
                    else
                    {
                        page = accessPoint.GetJobs(new GetJobsRequest
                        {
                            Skip = (uint)jobs.Count,
                            Take = PageSize,
                        }).Jobs;
                        jobs.AddRange(page.Where(j => string.IsNullOrWhiteSpace(j.Application)));
                    }
                }while (page != null && page.Length == PageSize);

                foreach (string groupName in jobs.Select(j => j.Group ?? "").Distinct().OrderBy(gn => gn))
                {
                    var control = (JobsGroup)Page.LoadControl("~/UserControls/JobsGroup.ascx");
                    control.ID = "JobsGroup_" + ApplicationName + "_" + groupName;
                    control.ApplicationName = ApplicationName;
                    control.GroupName       = groupName;
                    control.PageSize        = PageSize;
                    control.ShownStatuses   = selectedStatuses.ToList();
                    JobGridsContainer.Controls.Add(control);
                }
            }
        }
        private static JobExecutionHistory GetJobHistory(long jobHistoryId)
        {
            JobExecutionHistory jobHistory = null;

            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                jobHistory = accessPoint.GetJobExecutionHistories(new GetJobExecutionHistoriesRequest
                {
                    Skip = 0,
                    Take = 1,
                    Ids  = new long[] { jobHistoryId },
                }).JobHistories.FirstOrDefault();
            }
            return(jobHistory);
        }
Exemplo n.º 6
0
        private static JobData GetJob(long jobId)
        {
            JobData job = null;

            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                job = accessPoint.GetJobs(new GetJobsRequest
                {
                    Skip   = 0,
                    Take   = 1,
                    JobIds = new long[] { jobId },
                }).Jobs.FirstOrDefault();
            }
            return(job);
        }
Exemplo n.º 7
0
        private void ShowJobs()
        {
            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                JobData[] jobs = accessPoint.GetJobs(new GetJobsRequest
                {
                    Skip = 0,
                    Take = int.MaxValue,
                }).Jobs;

                JobsList.DataSource = jobs;
                JobsList.DataBind();
                JobsListPager.Visible = jobs.Length > JobsListPager.MaximumRows;
            }
        }
Exemplo n.º 8
0
        protected void JobsList_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            long jobId;

            if (long.TryParse((string)e.CommandArgument, out jobId))
            {
                switch (e.CommandName.ToUpper())
                {
                case "RUN":
                    using (AccessPointClient accessPoint = new AccessPointClient())
                    {
                        JobData job = accessPoint.GetJobs(new GetJobsRequest
                        {
                            Skip   = 0,
                            Take   = 1,
                            JobIds = new long[] { jobId },
                        }).Jobs.FirstOrDefault();

                        if (job != null)
                        {
                            if (job.CalendarSchedule == null)
                            {
                                job.Status = JobStatus.Ready;
                                accessPoint.UpdateJob(new UpdateJobRequest {
                                    JobData = job
                                });
                            }
                            else
                            {
                                accessPoint.RunScheduledJob(new RunScheduledJobRequest {
                                    JobId = jobId
                                });
                            }
                        }
                    }
                    break;

                case "DELETE":
                    using (AccessPointClient accessPoint = new AccessPointClient())
                    {
                        accessPoint.DeleteJob(new DeleteJobRequest {
                            JobId = jobId
                        });
                    }
                    break;
                }
            }
        }
        private static void CreateNewJob(Guid?uniqueId, string name, string description, string data, string metaData, string jobType, TimeSpan?absoluteTimeout, byte queueId, string application, string group, bool suppressHistory, bool deleteWhenDone, SimpleSchedule schedule)
        {
            CreateJobRequest request = new CreateJobRequest
            {
                UniqueId        = uniqueId,
                Application     = application,
                DeleteWhenDone  = deleteWhenDone,
                Description     = description,
                Name            = name,
                QueueId         = queueId,
                Type            = jobType,
                MetaData        = metaData,
                Data            = data,
                SuppressHistory = suppressHistory,
                AbsoluteTimeout = absoluteTimeout,
                Group           = group,
                Status          = JobStatus.Pending,
            };

            if (schedule != null)
            {
                if (!schedule.StartDailyAt.HasValue)
                {
                    schedule.StartDailyAt = new TimeSpan();
                }
                request.CalendarSchedule = new CalendarSchedule
                {
                    ScheduleType = typeof(global::BackgroundWorkerService.Logic.DataModel.Scheduling.CalendarSchedule).AssemblyQualifiedName,
                    DaysOfWeek   = schedule.DaysOfWeek.ToArray(),
                    StartDailyAt = new TimeOfDay {
                        Hour = schedule.StartDailyAt.Value.Hours, Minute = schedule.StartDailyAt.Value.Minutes, Second = schedule.StartDailyAt.Value.Seconds
                    },
                    RepeatInterval = schedule.RepeatInterval,
                    EndDateTime    = null,
                    StartDateTime  = !string.IsNullOrEmpty(schedule.StartDateTime) ? DateTime.ParseExact(schedule.StartDateTime, "dd-MM-yyyy HH:mm:ss", CultureInfo.CurrentCulture) : DateTime.Now,
                };
            }

            using (AccessPointClient client = new AccessPointClient())
            {
                client.CreateJob(request);
            }
        }
Exemplo n.º 10
0
        private void ShowExecutionHistories()
        {
            try
            {
                using (AccessPointClient accessPoint = new AccessPointClient())
                {
                    JobExecutionHistory[] jobHistories = accessPoint.GetJobExecutionHistories(new GetJobExecutionHistoriesRequest
                    {
                        Skip   = 0,
                        Take   = HistoryCount,
                        JobIds = new long[] { JobId },
                    }).JobHistories;

                    this.Visible = true;
                    JobHistoryList.DataSource = jobHistories;
                    JobHistoryList.DataBind();
                }
            }
            catch { }
        }
Exemplo n.º 11
0
 private void ShowJobs()
 {
     using (AccessPointClient accessPoint = new AccessPointClient())
     {
         List <JobData> jobs = new List <JobData>();
         JobData[]      page;
         do
         {
             page = accessPoint.GetJobs(new GetJobsRequest
             {
                 Skip = (uint)jobs.Count,
                 Take = PageSize,
             }).Jobs;
             jobs.AddRange(page);
         }while (page != null && page.Length == PageSize);
         JobsList.DataSource = jobs;
         JobsList.DataBind();
         JobsListPager.Visible = jobs.Count > JobsListPager.MaximumRows;
     }
     lblLastRefresh.Text = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");
 }
        protected void Page_Load(object sender, EventArgs e)

        {
            List <string> jobs = new List <string>();

            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                var page = accessPoint.GetJobs(new GetJobsRequest
                {
                    Skip = 0,
                    Take = int.MaxValue,
                });

                jobs.AddRange(page.Jobs.Select(x => x.Application));
            }

            foreach (string applicationName in jobs.Distinct().OrderBy(an => an))
            {
                if (string.IsNullOrWhiteSpace(applicationName))
                {
                    continue;
                }
                var tab = new HtmlGenericControl("li");
                tab.Controls.Add(new HtmlAnchor()
                {
                    HRef = "#" + applicationName, InnerText = applicationName, ID = "tab" + applicationName
                });

                mainMenuDiv.FindControl("mainMenuUl").Controls.Add(tab);

                var div = new HtmlGenericControl("div");
                div.Attributes.Add("id", applicationName);

                mainMenuDiv.Controls.Add(div);
                var control = (WebUI.UserControls.Jobs)Page.LoadControl("~/UserControls/Jobs.ascx");
                control.ID = "Jobs_" + applicationName;
                control.ApplicationName = applicationName;
                div.Controls.Add(control);
            }
        }
Exemplo n.º 13
0
        private static void CreateNewJob(string name, string description, string data, string metaData, string jobType, TimeSpan?absoluteTimeout, byte queueId, string application, string group, bool suppressHistory, bool deleteWhenDone)
        {
            CreateJobRequest request = new CreateJobRequest
            {
                Application     = application,
                DeleteWhenDone  = deleteWhenDone,
                Description     = description,
                Name            = name,
                QueueId         = queueId,
                Type            = jobType,
                MetaData        = metaData,
                Data            = data,
                SuppressHistory = suppressHistory,
                AbsoluteTimeout = absoluteTimeout,
                Group           = group,
            };

            using (AccessPointClient client = new AccessPointClient())
            {
                client.CreateJob(request);
            }
        }
Exemplo n.º 14
0
        public static string UpdateJob(string name, string description, string data, string metaData, string absoluteTimeout, string queueId, string application, string group, bool suppressHistory, bool deleteWhenDone)
        {
            try
            {
                long    jobId = GetJobIdFromQueryString();
                JobData job   = GetJob(jobId);
                if (job != null)
                {
                    job.Name        = name;
                    job.Description = description;
                    job.Data        = data;
                    job.MetaData    = metaData;
                    if (!string.IsNullOrEmpty(absoluteTimeout))
                    {
                        job.AbsoluteTimeout = TimeSpan.Parse(absoluteTimeout);
                    }
                    if (!string.IsNullOrEmpty(queueId))
                    {
                        job.QueueId = byte.Parse(queueId);
                    }
                    job.Application     = application;
                    job.Group           = group;
                    job.SuppressHistory = suppressHistory;
                    job.DeleteWhenDone  = deleteWhenDone;

                    using (AccessPointClient accessPoint = new AccessPointClient())
                    {
                        accessPoint.UpdateJob(new UpdateJobRequest {
                            JobData = job
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(string.Empty);
        }
Exemplo n.º 15
0
        public void ShowJobs()
        {
            using (AccessPointClient accessPoint = new AccessPointClient())
            {
                List <JobData> jobs = new List <JobData>();
                JobData[]      page;
                do
                {
                    if (!string.IsNullOrWhiteSpace(ApplicationName))
                    {
                        page = accessPoint.GetJobs(new GetJobsRequest
                        {
                            Skip         = (uint)jobs.Count,
                            Take         = PageSize,
                            Applications = new string[] { ApplicationName },
                            JobStatuses  = ShownStatuses.ToArray(),
                        }).Jobs;
                        jobs.AddRange(page);
                    }
                    else
                    {
                        page = accessPoint.GetJobs(new GetJobsRequest
                        {
                            Skip        = (uint)jobs.Count,
                            Take        = PageSize,
                            JobStatuses = ShownStatuses.ToArray(),
                        }).Jobs;
                        jobs.AddRange(page.Where(j => string.IsNullOrWhiteSpace(j.Application)));
                    }
                }while (page != null && page.Length == PageSize);

                jobs = jobs.Where(j => string.IsNullOrWhiteSpace(GroupName) ? j.Group == null || j.Group == "" : j.Group == GroupName).ToList();

                JobsList.DataSource = jobs;
                JobsList.DataBind();
                JobsListPager.Visible = jobs.Count > JobsListPager.MaximumRows;
            }
        }
Exemplo n.º 16
0
        private static void ScheduleJob(string name, string description, string data, string metaData, string jobType, TimeSpan?absoluteTimeout, byte queueId, string application, string group, bool suppressHistory, bool deleteWhenDone, SimpleSchedule schedule)
        {
            if (!schedule.StartDailyAt.HasValue)
            {
                schedule.StartDailyAt = new TimeSpan();
            }
            ScheduleJobRequest request = new ScheduleJobRequest
            {
                Application      = application,
                DeleteWhenDone   = deleteWhenDone,
                Description      = description,
                Name             = name,
                QueueId          = queueId,
                Type             = jobType,
                MetaData         = metaData,
                Data             = data,
                AbsoluteTimeout  = absoluteTimeout,
                Group            = group,
                CalendarSchedule = new CalendarSchedule
                {
                    ScheduleType = typeof(global::BackgroundWorkerService.Logic.DataModel.Scheduling.CalendarSchedule).AssemblyQualifiedName,
                    DaysOfWeek   = schedule.DaysOfWeek.ToArray(),
                    StartDailyAt = new TimeOfDay {
                        Hour = schedule.StartDailyAt.Value.Hours, Minute = schedule.StartDailyAt.Value.Minutes, Second = schedule.StartDailyAt.Value.Seconds
                    },
                    RepeatInterval = schedule.RepeatInterval,
                    EndDateTime    = null,
                    StartDateTime  = DateTime.Now,
                },
            };

            using (AccessPointClient client = new AccessPointClient())
            {
                client.ScheduleJob(request);
            }
        }
Exemplo n.º 17
0
        public static string DeleteJob(long jobId)
        {
            string returnMessage = string.Format("Could not delete job {0}.", jobId);

            try
            {
                using (AccessPointClient client = new AccessPointClient())
                {
                    DeleteJobResponse response = client.DeleteJob(new DeleteJobRequest
                    {
                        JobId = jobId,
                    });
                    if (response.Success)
                    {
                        returnMessage = string.Format("Successfully deleted job {0}.", jobId);
                    }
                }
            }
            catch (Exception ex)
            {
                returnMessage += "<br /><br />" + ex.Message;
            }
            return(returnMessage);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            using (AccessPointClient client = new AccessPointClient())
            {
                for (int i = 0; i < 100; i++)
                {
                    var job = client.CreateJob(new CreateJobRequest
                    {
                        Type        = typeof(BackgroundWorkerService.Logic.TestJobs.ShortRunningJob).AssemblyQualifiedName,
                        QueueId     = (byte)new Random().Next(3),
                        Name        = "Job " + new Random().Next(int.MaxValue),
                        Description = "This is a test description to see what it looks like : " + new Random().Next(int.MaxValue),
                        Status      = JobStatus.Ready,
                    });
                }

                //for (int i = 0; i < 20; i++)
                //{
                //  var job = client.CreateJob(new CreateJobRequest
                //  {
                //    Data = "bob",
                //    MetaData =
                //      JobBuilder.CreateBasicHttpSoap_BasicCallbackJobMetaData(
                //        "metaData",
                //        "http://*****:*****@b.com", "*****@*****.**"), null, out data, out metadata);
                //var job3 = client.CreateJob(new CreateJobRequest
                //{
                //  Data = data,
                //  MetaData = metadata,
                //  Type = typeof(SendMailJob).AssemblyQualifiedName,
                //  QueueId = 1,
                //  CalendarSchedule = new CalendarSchedule
                //  {
                //    ScheduleType = typeof(BackgroundWorkerService.Logic.DataModel.Scheduling.CalendarSchedule).AssemblyQualifiedName, //Must set this
                //    DaysOfWeek = new List<DayOfWeek> { DayOfWeek.Monday }.ToArray(),
                //    StartDateTime = DateTime.Now,
                //    StartDailyAt = new TimeOfDay { Hour = 0, Minute = 30, Second = 0 },
                //  }
                //});
                //var job4 = client.CreateJob(new CreateJobRequest
                //{
                //  Data = "",
                //  MetaData =
                //    JobBuilder.GetWebRequestJobMetaData(
                //      "http://localhost:2048/default.aspx",
                //      System.Net.HttpStatusCode.OK,
                //      true).Serialize(),
                //  Type = typeof(WebRequestJob).AssemblyQualifiedName,
                //  QueueId = 0,
                //  DeleteWhenDone = false,
                //  SuppressHistory = false,
                //  Name = "Ping Service WebUI",
                //  Description = "This pings the web ui to check whether it's still running.",
                //});
            }
        }
Exemplo n.º 19
0
 static void Main(string[] args)
 {
     using (AccessPointClient client = new AccessPointClient())
     {
         var job = client.CreateJob(new CreateJobRequest
         {
             Data     = "bob",
             MetaData =
                 JobBuilder.CreateBasicHttpSoap_BasicCallbackJobMetaData(
                     "metaData",
                     "http://*****:*****@b.com", "*****@*****.**"), null, out data, out metadata);
         var job3 = client.ScheduleJob(new ScheduleJobRequest
         {
             Data             = data,
             MetaData         = metadata,
             Type             = typeof(SendMailJob).AssemblyQualifiedName,
             QueueId          = 1,
             CalendarSchedule = new CalendarSchedule
             {
                 ScheduleType = typeof(BackgroundWorkerService.Logic.DataModel.Scheduling.CalendarSchedule).AssemblyQualifiedName,                         //Must set this
                 DaysOfWeek   = new List <DayOfWeek> {
                     DayOfWeek.Monday
                 }.ToArray(),
                 StartDateTime = DateTime.Now,
                 StartDailyAt  = new TimeOfDay {
                     Hour = 0, Minute = 30, Second = 0
                 },
             }
         });
         var job4 = client.CreateJob(new CreateJobRequest
         {
             Data     = "",
             MetaData =
                 JobBuilder.GetWebRequestJobMetaData(
                     "http://localhost:2048/default.aspx",
                     System.Net.HttpStatusCode.OK,
                     true).Serialize(),
             Type            = typeof(WebRequestJob).AssemblyQualifiedName,
             QueueId         = 0,
             DeleteWhenDone  = false,
             SuppressHistory = false,
             Name            = "Ping Service WebUI",
             Description     = "This pings the web ui to check whether it's still running.",
         });
     }
 }
Exemplo n.º 20
0
        public static string UpdateJob(long jobId, string uniqueId, string name, string description, string data, string metaData, string statusId, string absoluteTimeout, string queueId, string application, string group, string suppressHistory, string deleteWhenDone, SimpleSchedule schedule)
        {
            try
            {
                JobData job = GetJob(jobId);
                if (job != null)
                {
                    if (!string.IsNullOrEmpty(statusId))
                    {
                        job.Status = (JobStatus)(int.Parse(statusId));
                    }

                    job.UniqueId    = Guid.Parse(uniqueId);
                    job.Name        = name;
                    job.Description = description;
                    job.Data        = data;
                    job.MetaData    = metaData;
                    if (!string.IsNullOrEmpty(absoluteTimeout))
                    {
                        job.AbsoluteTimeout = TimeSpan.Parse(absoluteTimeout);
                    }
                    if (!string.IsNullOrEmpty(queueId))
                    {
                        job.QueueId = byte.Parse(queueId);
                    }
                    job.Application     = application;
                    job.Group           = group;
                    job.SuppressHistory = bool.Parse(suppressHistory);
                    job.DeleteWhenDone  = bool.Parse(deleteWhenDone);

                    if (schedule != null)
                    {
                        if (!schedule.StartDailyAt.HasValue)
                        {
                            schedule.StartDailyAt = new TimeSpan();
                        }
                        job.CalendarSchedule = new CalendarSchedule
                        {
                            ScheduleType = typeof(global::BackgroundWorkerService.Logic.DataModel.Scheduling.CalendarSchedule).AssemblyQualifiedName,
                            DaysOfWeek   = schedule.DaysOfWeek.ToArray(),
                            StartDailyAt = new TimeOfDay {
                                Hour = schedule.StartDailyAt.Value.Hours, Minute = schedule.StartDailyAt.Value.Minutes, Second = schedule.StartDailyAt.Value.Seconds
                            },
                            RepeatInterval = schedule.RepeatInterval,
                            EndDateTime    = null,
                            StartDateTime  = !string.IsNullOrEmpty(schedule.StartDateTime) ? DateTime.ParseExact(schedule.StartDateTime, "dd-MM-yyyy HH:mm:ss", CultureInfo.CurrentCulture) : job.CalendarSchedule.StartDateTime,
                        };
                    }
                    else
                    {
                        job.CalendarSchedule = null;
                    }

                    using (AccessPointClient accessPoint = new AccessPointClient())
                    {
                        accessPoint.UpdateJob(new UpdateJobRequest {
                            JobData = job
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
            return(string.Empty);
        }