public void ItOnlyReturnsTriggeredBundles() { var collection = new TriggerCollection(); var bundles = new[] { new TriggerBundle(TriggerTestHelpers.StaticTrigger(true)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(true)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)) }; var expected = new[] { bundles[0], bundles[2], }; foreach(var bundle in bundles) { collection.Add(bundle); } var actual = collection.Check(); CollectionAssert.AreEqual(expected, actual); }
public void ItOnlyReturnsTriggeredBundles() { var collection = new TriggerCollection(); var bundles = new[] { new TriggerBundle(TriggerTestHelpers.StaticTrigger(true)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(true)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)), new TriggerBundle(TriggerTestHelpers.StaticTrigger(false)) }; var expected = new[] { bundles[0], bundles[2], }; foreach (var bundle in bundles) { collection.Add(bundle); } var actual = collection.Check(); CollectionAssert.AreEqual(expected, actual); }
public ITrigger Add(ITrigger unboundTrigger) { Trigger instance = unboundTrigger.Instance; Trigger trigger = _nativeInstance.Add(instance); return(_taskServiceConvertorFactory.CreateTrigger(trigger)); }
private static StubTrigger AttachActionToObject(InvokeCommandAction invokeCommandAction, SysWindows.DependencyObject dependencyObject) { TriggerCollection triggersCollection = Interaction.GetTriggers(dependencyObject); StubTrigger stubTrigger = CreateTrigger(); triggersCollection.Add(stubTrigger); stubTrigger.Actions.Add(invokeCommandAction); return(stubTrigger); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); TemplateWithTriggers twt = (TemplateWithTriggers)source; TriggerCollection triggers = Triggers; foreach (TriggerBase t in twt.Triggers) { triggers.Add(copyManager.GetCopy(t)); } }
public void AddTriggerTest() { Button button = new Button(); StubTrigger trigger = new StubTrigger(); TriggerCollection tc = Interaction.GetTriggers(button); tc.Add(trigger); Assert.IsTrue(trigger.AddedHost, "Trigger has been parented."); Assert.IsFalse(trigger.ChangedHost, "Trigger has not changed parents."); Assert.IsFalse(trigger.RemovedHost, "Trigger has not been unparented."); }
public void RemoveTriggerTest() { Button button = new Button(); StubTrigger trigger = new StubTrigger(); TriggerCollection tc = Interaction.GetTriggers(button); tc.Add(trigger); Assert.AreEqual(trigger.HostObject, button, "trigger.AssociatedObject == button"); tc.Remove(trigger); Assert.IsTrue(trigger.AddedHost, "Trigger has been parented."); Assert.IsFalse(trigger.ChangedHost, "Trigger has not changed parents."); Assert.IsTrue(trigger.RemovedHost, "Trigger has been unparented."); }
public void ActionInvocationOrderTest() { Rectangle rectangle = new Rectangle(); TimedAction action1 = new TimedAction(); TimedAction action2 = new TimedAction(); TimedAction action3 = new TimedAction(); TriggerCollection collection = Interaction.GetTriggers(rectangle); StubTrigger trigger = new StubTrigger(); trigger.Actions.Add(action1); trigger.Actions.Add(action2); trigger.Actions.Add(action3); collection.Add(trigger); trigger.FireStubTrigger(); Assert.IsTrue(action1.Order < action2.Order, "action1.Order < action2.Order"); Assert.IsTrue(action2.Order < action3.Order, "action2.Order < action3.Order"); }
public void AttachMultipleTimesTest() { EventTriggerBase trigger = new StubTrigger(); Rectangle rectangle1 = new Rectangle(); Rectangle rectangle2 = new Rectangle(); TriggerCollection collection1 = Interaction.GetTriggers(rectangle1); TriggerCollection collection2 = Interaction.GetTriggers(rectangle2); collection1.Add(trigger); // it is illegal to add the same trigger to more than one object try { collection2.Add(trigger); Debug.Fail("Attaching the same trigger twice should throw a InvalidOperationException"); } catch (InvalidOperationException) { } }
public void MoveTriggerTest() { Button button = new Button(); Rectangle rectangle = new Rectangle(); StubTrigger trigger = new StubTrigger(); TriggerCollection tc = Interaction.GetTriggers(rectangle); TriggerCollection tc2 = Interaction.GetTriggers(button); tc.Add(trigger); tc.Remove(trigger); tc2.Add(trigger); Assert.IsTrue(trigger.AddedHost, "Trigger has been parented."); Assert.IsTrue(trigger.ChangedHost, "Trigger has changed parents."); Assert.IsTrue(trigger.RemovedHost, "Trigger has been unparented."); Assert.AreEqual(trigger.HostObject, button, "trigger.AssociatedObject == button"); Assert.AreEqual(Interaction.GetTriggers(rectangle).Count, 0, "rectangle.Triggers.Count == 0"); }
private void FillTriggers(TriggerCollection triggersCollection) { dynamic triggersElement = _navigationPlanJson?.triggersStorage?.triggers; if (triggersElement == null) { return; } foreach (var triggerElement in triggersElement) { string actionName = ConvertDynamicValue <string>(triggerElement.actionName); if (!TriggerAction.POSSIBLE_ACTION_NAMES.Contains(actionName)) { continue; } Trigger trigger = new Trigger(ConvertDynamicValue <string>(triggerElement.name), ConvertDynamicValue <int>(triggerElement.priority)); var action = new TriggerAction(actionName); foreach (var conditionElement in triggerElement.conditions) { var condition = new Condition(ConvertDynamicValue <string>(conditionElement.updateType), ConvertDynamicValue <string>(conditionElement.type), ConvertDynamicValue <string>(conditionElement.equationType)); foreach (var value in conditionElement.values) { condition.Values.Add(new ConditionValue(ConvertDynamicValue <string>(value))); } action.Conditions.Add(condition); } trigger.Actions.Add(action); triggersCollection.Add(trigger); } }
public void ScheduleRenewTask() { string taskName = $"Lets encrypt renew {CleanFileName(_options.HostName)}"; Log.Information($"Creating Task {taskName} with Windows Task scheduler at 9am every day."); DateTime now = DateTime.UtcNow; DateTime runtime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0, DateTimeKind.Utc); string currentExec = Assembly.GetExecutingAssembly().Location; // Create an action that will launch the app with the renew parameters whenever the trigger fires string actionString = $"\"{string.Join("\" \"", Environment.GetCommandLineArgs().Skip(1))}\" --renew"; using (TaskService taskService = new TaskService()) using (DailyTrigger trigger = new DailyTrigger { DaysInterval = 1, StartBoundary = runtime }) using (ExecAction action = new ExecAction(currentExec, actionString, Path.GetDirectoryName(currentExec))) using (TaskFolder rootFolder = taskService.RootFolder) using (TaskDefinition task = taskService.NewTask()) using (TaskRegistrationInfo reginfo = task.RegistrationInfo) using (TriggerCollection triggers = task.Triggers) using (ActionCollection actions = task.Actions) using (TaskPrincipal principal = task.Principal) { rootFolder.DeleteTask(taskName, false); reginfo.Description = $"Check for renewal of ACME certificates for {_options.HostName}."; triggers.Add(trigger); actions.Add(action); principal.RunLevel = TaskRunLevel.Highest; // need admin principal.LogonType = TaskLogonType.ServiceAccount; principal.UserId = "SYSTEM"; rootFolder.RegisterTaskDefinition(taskName, task); } }
private void AddTrigger(MidiTrigger trigger) { var toRemove = TriggerCollection.Where(x => x.Trigger.PinNumber == trigger.PinNumber).ToList(); toRemove.ForEach(x => TriggerCollection.Remove(x)); TriggerCollection.Add(new MidiTriggerViewModel(_eventAggregator, DrumManager, trigger)); var seriesToRemove = CurrentValuePlot.Series.Where(x => x.Tag as Pins? == trigger.PinNumber).ToList(); seriesToRemove.ForEach(x => CurrentValuePlot.Series.Remove(x)); var newSeries = new LineSeries { Title = trigger.PinNumber.ToString(), Tag = trigger.PinNumber }; int insertIndex = 0; for (int i = CurrentValuePlot.Series.Count - 1; i >= 0; i--) { Pins currentPin = (Pins)CurrentValuePlot.Series[i].Tag; if (currentPin < trigger.PinNumber) { insertIndex = i + 1; break; } } CurrentValuePlot.Series.Insert(insertIndex, newSeries); //public active / inactive _eventAggregator.GetEvent <TriggerActiveChangedEvent>() .Publish(new KeyValuePair <Pins, bool>(trigger.PinNumber, trigger.Type != TriggerType.Disabled)); }
private void FillTriggers(TriggerCollection triggers) { var triggersElement = _skinXml.Root.Element(XmlNames.triggers); if (triggersElement == null) { return; } foreach (var triggerElement in triggersElement.Elements(XmlNames.trigger)) { var actionsElements = triggerElement.Elements(XmlNames.action).Where(e => TriggerAction.POSSIBLE_ACTION_NAMES.Contains(e.GetAttributeValue(XmlNames.name))).ToArray(); if (actionsElements.Length == 0) { continue; } var trigger = new Trigger(triggerElement.GetAttributeValue(XmlNames.name), triggerElement.GetAttributeValue <int>(XmlNames.priority)); foreach (var actionElement in actionsElements) { var action = new TriggerAction(actionElement.GetAttributeValue(XmlNames.name)); trigger.Actions.Add(action); var conditionsElement = actionElement.Element(XmlNames.conditions); if (conditionsElement == null) { continue; } foreach (var conditionElement in conditionsElement.Elements(XmlNames.condition)) { var condition = new Condition(conditionElement.GetAttributeValue(XmlNames.updateType), conditionElement.GetAttributeValue(XmlNames.type), conditionElement.GetAttributeValue(XmlNames.equationType)); condition.UpdateType = conditionElement.GetAttributeValue(XmlNames.updateType); condition.Type = conditionElement.GetAttributeValue(XmlNames.type); condition.EquationType = conditionElement.GetAttributeValue(XmlNames.equationType); var valueAttribute = conditionElement.Attribute(XmlNames.value); if (valueAttribute != null) { condition.Values.Add(new ConditionValue(valueAttribute.Value)); } else { foreach (var valueElement in conditionElement.Elements(XmlNames.value)) { condition.Values.Add(new ConditionValue(valueElement.Value)); } } action.Conditions.Add(condition); } } triggers.Add(trigger); } }
public void AddTrigger(UITriggerBase objTrigger) { Debug.Assert(null != objTrigger); TriggerCollection.Add(objTrigger); }
public ProgressAdorner(UIElement adornedElement) : base(adornedElement) { VisualChildren = new VisualCollection(this); RowDefinitionCollection rows = Grid.RowDefinitions; rows.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); rows.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Pixel) }); rows.Add(new RowDefinition() { Height = new GridLength(25, GridUnitType.Pixel) }); rows.Add(new RowDefinition() { Height = new GridLength(25, GridUnitType.Pixel) }); rows.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); Ellipse Ellipse = new Ellipse() { Name = "Icon", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Height = 50, Width = 50, Stroke = Brushes.Black, Fill = Brushes.RoyalBlue }; Grid.SetRow(Ellipse, 1); TriggerCollection Triggers = Ellipse.Triggers; EventTrigger Event = new EventTrigger(Ellipse.LoadedEvent); BeginStoryboard BeginStoryboard = new BeginStoryboard(); Event.Actions.Add(BeginStoryboard); Triggers.Add(Event); Storyboard Storyboard = new Storyboard(); BeginStoryboard.Storyboard = Storyboard; DoubleAnimation Animation1 = new DoubleAnimation() { From = 20.0, To = 50.0, Duration = new Duration(new TimeSpan(TimeSpan.TicksPerSecond)), AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; DoubleAnimation Animation2 = new DoubleAnimation() { From = 20.0, To = 50.0, Duration = new Duration(new TimeSpan(TimeSpan.TicksPerSecond)), AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }; Storyboard.SetTarget(Animation1, Ellipse); Storyboard.SetTarget(Animation2, Ellipse); Storyboard.SetTargetProperty(Animation1, new PropertyPath(Ellipse.HeightProperty)); Storyboard.SetTargetProperty(Animation2, new PropertyPath(Ellipse.WidthProperty)); TimelineCollection storyboard = Storyboard.Children; storyboard.Add(Animation1); storyboard.Add(Animation2); ProgressBar ProgressBar = new ProgressBar() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Height = 20, Width = 200 }; Grid.SetRow(ProgressBar, 2); Button Button = new Button() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Width = 100, Height = 25, FontSize = 12, Content = "Cancel" }; Button.Click += new RoutedEventHandler(CancelTask); Binding Binding = new Binding("CancelButtonEnabled"); Binding.Source = this; Button.SetBinding(Button.IsEnabledProperty, Binding); Loaded += new RoutedEventHandler((sender, e) => { Timer ButtonTimer = new Timer(3000); ButtonTimer.Elapsed += new ElapsedEventHandler((sender2, e2) => { CancelButtonEnabled = true; }); ButtonTimer.AutoReset = false; ButtonTimer.Start(); }); Grid.SetRow(Button, 3); UIElementCollection GridUIElements = Grid.Children; GridUIElements.Add(Ellipse); GridUIElements.Add(ProgressBar); GridUIElements.Add(Button); Brush Brush = Brushes.LightGray.Clone(); Brush.Opacity = 0.5; Grid.Background = Brush; VisualChildren.Add(Grid); }