public App() { _actionProvider = new PropertyActionProvider(this); actions = _actionProvider.GetActions(); actionLog = _actionProvider.GetActionLog(); actions.actionDeleted += actionLog.OnActionRemoved; Logging.logger.WriteMessage(actionLog); InitializeComponent(); MainPage = new NavigationPage(new TimeLoggingApp.MainPage()); }
public void DoWorkAsync(IActionProvider provider) { exitState = ExitState.NORMAL; CancellationToken token = tokenSource.Token; Task mainTask = Task.Factory.StartNew(() => { while (true) { if (token.IsCancellationRequested) break; try { Action[] actions = provider.GetActions(); if (actions.Length == 0) break; List<Task> tasks = new List<Task>(); foreach (Action action in actions) { if (token.IsCancellationRequested) break; try { Task subtask = Task.Factory.StartNew(action, token); subtask.ContinueWith(TaskFailed, TaskContinuationOptions.OnlyOnFaulted); tasks.Add(subtask); } catch { exitState = ExitState.ERROR; tokenSource.Cancel(); break; } } try { Task.WaitAll(tasks.ToArray(), tokenSource.Token); } catch (OperationCanceledException){} } catch { exitState = ExitState.ERROR; break; } } }, TaskCreationOptions.LongRunning); mainTask.ContinueWith(Done, scheduler); }
public void UpdateActions() { var actions = from key in actionDictionary.Keys.Cast <FrameworkElement>() select new KeyValuePair <FrameworkElement, ICollection <ShellAction> >(key, (ICollection <ShellAction>)actionDictionary[key]); //Rebuild actions foreach (KeyValuePair <FrameworkElement, ICollection <ShellAction> > item in actions.ToArray()) { FrameworkElement frameworkElement = item.Key; ICollection <ShellAction> actionCollection = item.Value; if (actionCollection != null) { foreach (ShellAction action in actionCollection) { ShellInteractionService.Actions.Remove(action); } } DependencyObject parent = frameworkElement; bool isActive = false; while (parent != null) { if (parent == ShellInteractionService.ActiveSmartPart) { isActive = true; break; } parent = VisualTreeHelper.GetParent(parent); } if (frameworkElement.IsVisible && isActive) { //Refresh actions for visible views IActionProvider actionProvider = frameworkElement as IActionProvider; if (actionCollection == null) { actionCollection = actionProvider.GetActions(); if (actionCollection == null) { actionCollection = new List <ShellAction>(); } actionDictionary[frameworkElement] = actionCollection; } PropertyInfo isDetailViewProperty = frameworkElement.GetType().GetProperty("IsDetailView"); bool isDetailAction = false; if (isDetailViewProperty != null) { if ((bool)isDetailViewProperty.GetValue(frameworkElement, null)) { isDetailAction = true; } } foreach (ShellAction action in actionCollection) { action.IsDetailAction = isDetailAction; ShellInteractionService.Actions.Add(action); } } } }