protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            using (var context = new TaskSchedulerDbContext())
            {
                if (localSettings.Values.ContainsKey(Settings.JOBNAME))
                {
                    JobName = (string)localSettings.Values[Settings.JOBNAME];
                }

                if (localSettings.Values.ContainsKey(Settings.JOBCRON))
                {
                    JobCron = (string)localSettings.Values[Settings.JOBCRON];
                }

                if ((int)localSettings.Values[Settings.JOBACTION] == Settings.Actions.CREATE)
                {
                    return;
                }

                Job job = context.Jobs.Where(x => x.Id == (int)localSettings.Values[Settings.JOBID]).First();
                predicate = x => x.JobId == job.Id || x.JobId == null;

                if (!localSettings.Values.ContainsKey(Settings.JOBNAME))
                {
                    JobName = job.Name;
                }

                if (!localSettings.Values.ContainsKey(Settings.JOBCRON))
                {
                    JobCron = job.Cron;
                }
            }
        }
Beispiel #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            AudioBox.ItemsSource = AudioList;

            if ((int)localSettings.Values[Settings.ACTIONACTION] == Settings.Actions.CREATE)
            {
                return;
            }

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

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

                case ActionType.NOTIFICATION:
                {
                    NotificationAction notificationAction = context.NotificationActions.Where(x => x.Id == action.ActionId).First();
                    Text  = notificationAction.Text;
                    Image = notificationAction.Image;
                    Audio = notificationAction.Audio.GetValueOrDefault(0);
                    if (notificationAction.Timeout.HasValue)
                    {
                        Timeout = notificationAction.Timeout.Value.ToString();
                    }
                    Index = 1;
                }; break;

                case ActionType.APPLICATION:
                {
                    ApplicationAction applicationAction = context.ApplicationActions.Where(x => x.Id == action.ActionId).First();
                    appListProvider.IsDoneTask.ContinueWith(async(result) =>
                        {
                            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                bool ok = appListProvider.AppList.Where(x => x.Package.Id.FullName == applicationAction.ApplicationName).Any();
                                if (ok)
                                {
                                    AppEntry entry             = appListProvider.AppList.Where(x => x.Package.Id.FullName == applicationAction.ApplicationName).First();
                                    LoadedContent.SelectedItem = entry;
                                    LoadedContent.ScrollIntoView(entry);
                                }
                            });
                        });
                    Index = 2;
                }; break;
                }
            }
        }
Beispiel #3
0
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var context = new TaskSchedulerDbContext())
            {
                context.Database.Migrate();
            }

            // Start Background Tasks
            BackgroundTaskBuilder backgroundTaskBuildier = new BackgroundTaskBuilder();

            backgroundTaskBuildier.Name = "Reccuring";
            backgroundTaskBuildier.SetTrigger(new TimeTrigger(15U, false));
            BackgroundTaskRegistration task = backgroundTaskBuildier.Register();
        }
 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();
         }
     };
 }
        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();
        }
Beispiel #6
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();
            }
        }
        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();
        }
 public SqlCommandJobController(TaskSchedulerDbContext db)
 {
     _db = db;
 }
Beispiel #9
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();
        }
Beispiel #10
0
 public HomeController(ILogger <HomeController> logger, TaskSchedulerDbContext db)
 {
     _logger = logger;
     _db     = db;
 }
Beispiel #11
0
 public JobPersister(TaskSchedulerDbContext db, IHubContext <JobHub> hubContext)
 {
     _db         = db;
     _hubContext = hubContext;
 }
Beispiel #12
0
 public Scheduler(TaskSchedulerDbContext db)
 {
     _db = db;
 }