Ejemplo n.º 1
0
        public ActionResult Delete(Guid id)
        {
            var job = _db.Jobs.Find(id);

            if (job == null)
            {
                return(NotFound());
            }

            _db.Jobs.Remove(job);

            _db.SaveChanges();

            RecurringJob.RemoveIfExists(job.Name);

            return(Json(job));
        }
Ejemplo n.º 2
0
 static JobPage()
 {
     SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
     {
         ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
         localSettings.Values.Remove(Settings.JOBNAME);
         localSettings.Values.Remove(Settings.JOBCRON);
         using (var context = new TaskSchedulerDbContext())
         {
             Func <Models.Action, bool> predicate = x => x.JobId == null;
             context.Actions.RemoveRange(context.ActionsForActionPredicate(predicate));
             context.UriActions.RemoveRange(context.UriActionsForActionPredicate(predicate));
             context.NotificationActions.RemoveRange(context.NotificationActionsForActionPredicate(predicate));
             context.ApplicationActions.RemoveRange(context.ApplicationActionsForActionPredicate(predicate));
             context.SaveChanges();
         }
     };
 }
Ejemplo n.º 3
0
        private void AppBarButton_Delete(object sender, RoutedEventArgs e)
        {
            if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.CREATE)
            {
                return;
            }

            using (var context = new TaskSchedulerDbContext())
            {
                Job job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First();
                context.Actions.RemoveRange(context.ActionsForActionPredicate(predicate));
                context.UriActions.RemoveRange(context.UriActionsForActionPredicate(predicate));
                context.NotificationActions.RemoveRange(context.NotificationActionsForActionPredicate(predicate));
                context.ApplicationActions.RemoveRange(context.ApplicationActionsForActionPredicate(predicate));
                context.Jobs.Remove(job);
                context.SaveChanges();
            }
            Frame.GoBack();
        }
Ejemplo n.º 4
0
        public ActionResult Save(RegisterModel model)
        {
            var job = model.Id.HasValue ? _db.SqlCommandJob.Find(model.Id) : new SqlCommandJob();

            if (job == null)
            {
                return(NotFound());
            }

            var oldName = job.Name;

            job.Name           = model.Name.Trim();
            job.Description    = model.Description;
            job.Cron           = model.Cron;
            job.Enabled        = model.Enabled;
            job.DatabaseInfoId = model.DatabaseInfoId;
            job.Command        = model.Command;

            if (!model.Id.HasValue)
            {
                _db.Jobs.Add(job);
            }

            _db.SaveChanges();

            if (!string.IsNullOrEmpty(oldName) && (oldName != job.Name || !job.Enabled))
            {
                RecurringJob.RemoveIfExists(oldName);
            }

            if (job.Enabled)
            {
                RecurringJob.AddOrUpdate(job.Name, () => JobHelper.Execute(_db, job.Name), job.Cron, TimeZoneInfo.Local);
            }

            return(Json(new { job.Id }));
        }
Ejemplo n.º 5
0
        private void DeleteInitAction()
        {
            if ((int)localSettings.Values[Settings.ACTIONACTION] == Settings.Actions.CREATE)
            {
                return;
            }

            using (var context = new TaskSchedulerDbContext())
            {
                int           deleted_action_id = (int)localSettings.Values[Settings.ACTIONID];
                Models.Action action            = context.Actions.Where(x => x.Id == deleted_action_id).First();

                switch (action.Type)
                {
                case ActionType.URI:
                {
                    UriAction uriAction = context.UriActions.Where(x => x.Id == action.ActionId).First();
                    context.UriActions.Remove(uriAction);
                }; break;

                case ActionType.NOTIFICATION:
                {
                    NotificationAction notificationAction = context.NotificationActions.Where(x => x.Id == action.ActionId).First();
                    context.NotificationActions.Remove(notificationAction);
                }; break;

                case ActionType.APPLICATION:
                {
                    ApplicationAction applicationActions = context.ApplicationActions.Where(x => x.Id == action.ActionId).First();
                    context.ApplicationActions.Remove(applicationActions);
                }; break;
                }

                context.Actions.Remove(action);
                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        private void AppBarButton_Save(object sender, RoutedEventArgs e)
        {
            SolidColorBrush redBrush     = new SolidColorBrush(Colors.Red);
            SolidColorBrush defaultBrush = new SolidColorBrush();

            NameBox.BorderBrush      = (String.IsNullOrEmpty(JobName) ? redBrush : defaultBrush);
            CronBox.BorderBrush      = (String.IsNullOrEmpty(JobCron) ? redBrush : defaultBrush);
            ListView.BorderBrush     = (ListView.Items.Count == 0 ? redBrush : defaultBrush);
            ListView.BorderThickness = (ListView.Items.Count == 0 ? CronBox.BorderThickness : new Thickness());

            if (String.IsNullOrEmpty(JobName) || String.IsNullOrEmpty(JobCron) || ListView.Items.Count == 0)
            {
                return;
            }



            using (var context = new TaskSchedulerDbContext())
            {
                try
                {
                    Cron.CronStructure cs = Cron.ParseString(JobCron);
                }
                catch (Exception exc)
                {
                    Debug.WriteLine("SHOW ERROR");
                    Debug.WriteLine(exc.Message);
                    return;
                }

                Job job = null;
                if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.CREATE)
                {
                    job = new Job();
                    context.Add(job);
                    context.SaveChanges();
                }
                else
                {
                    job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First();
                    if (job.Cron != JobCron)
                    {
                        manager.RemoveJob(job);
                    }
                }

                Models.Action[] actions = context.ActionsForActionPredicate(predicate);
                foreach (var action in actions)
                {
                    action.JobId = job.Id;
                }

                job.Name = JobName;
                job.Cron = JobCron;
                context.SaveChanges();

                manager.AddJob(job);
            }

            Frame.GoBack();
        }
Ejemplo n.º 7
0
        private void AppBarButton_Save(object sender, RoutedEventArgs e)
        {
            SolidColorBrush redBrush     = new SolidColorBrush(Colors.Red);
            SolidColorBrush defaultBrush = new SolidColorBrush();

            switch (Index)
            {
            case 0:
            {
                URIBox.BorderBrush = (String.IsNullOrEmpty(Uri) ? redBrush : defaultBrush);
            }; break;

            case 1:
            {
                TextBox.BorderBrush = (String.IsNullOrEmpty(Text) ? redBrush : defaultBrush);
            }; break;

            case 2:
            {
                LoadedContent.BorderBrush     = (LoadedContent.SelectedItems.Count == 0 ? redBrush : defaultBrush);
                LoadedContent.BorderThickness = (LoadedContent.SelectedItems.Count == 0 ? URIBox.BorderThickness : new Thickness());
            }; break;
            }

            if (Index == 0 && String.IsNullOrEmpty(Uri) || Index == 1 && String.IsNullOrEmpty(Text) || Index == 2 && LoadedContent.SelectedItems.Count == 0)
            {
                return;
            }

            using (var context = new TaskSchedulerDbContext())
            {
                int        actionId   = 0;
                ActionType actionType = ActionType.URI;
                switch (Index)
                {
                case 0:
                {
                    UriAction act = new UriAction()
                    {
                        Uri = Uri
                    };
                    context.UriActions.Add(act);
                    context.SaveChanges();
                    actionId   = act.Id;
                    actionType = ActionType.URI;
                }; break;

                case 1:
                {
                    NotificationAction act = new NotificationAction()
                    {
                        Text = Text, Image = Image, Audio = Audio
                    };
                    if (!String.IsNullOrEmpty(Timeout))
                    {
                        act.Timeout = int.Parse(Timeout);
                    }
                    context.NotificationActions.Add(act);
                    context.SaveChanges();
                    actionId   = act.Id;
                    actionType = ActionType.NOTIFICATION;
                }; break;

                case 2:
                {
                    AppEntry          appEntry = (AppEntry)LoadedContent.SelectedItem;
                    ApplicationAction act      = new ApplicationAction()
                    {
                        ApplicationName = appEntry.Package.Id.FullName
                    };
                    context.ApplicationActions.Add(act);
                    context.SaveChanges();
                    actionId   = act.Id;
                    actionType = ActionType.APPLICATION;
                }; break;
                }



                Models.Action action = new Models.Action()
                {
                    ActionId = actionId, Type = actionType
                };
                if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.EDIT)
                {
                    Job job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First();
                    action.JobId = job.Id;
                }
                context.Actions.Add(action);
                context.SaveChanges();
                DeleteInitAction();
            }

            Frame rootFrame = Window.Current.Content as Frame;

            rootFrame.GoBack();
        }