private Trigger CreateTrigger(ITrigger poTrigger)
        {
            DateTimeOffset? loNextFireTime     = poTrigger.GetNextFireTimeUtc();
            DateTimeOffset? loPreviousFireTime = poTrigger.GetPreviousFireTimeUtc();
            CronTriggerImpl loCronTrigger      = poTrigger as CronTriggerImpl;

            Trigger loTrigger = new Trigger()
            {
                Name     = poTrigger.Key.Name,
                Group    = poTrigger.Key.Group,
                TypeName = poTrigger.GetType().FullName,
                State    = this.moScheduler.GetTriggerState(poTrigger.Key).ToString()
            };

            if (loNextFireTime.HasValue)
            {
                loTrigger.NextFireTime = loNextFireTime.Value.LocalDateTime;
            }

            if (loPreviousFireTime.HasValue)
            {
                loTrigger.PreviousFireTime = loPreviousFireTime.Value.LocalDateTime;
            }

            if (loCronTrigger != null)
            {
                loTrigger.CronExpression = loCronTrigger.CronExpressionString;
            }

            return(loTrigger);
        }
Beispiel #2
0
        /// <summary>
        /// XML化する
        /// </summary>
        /// <param name="t"></param>
        /// <returns>XML</returns>
        public static Task <string> ToXMLAsync(
            this ITrigger t)
        => Task.Run(() =>
        {
            if (t == null)
            {
                return(string.Empty);
            }

            var xws = new XmlWriterSettings()
            {
                OmitXmlDeclaration = true,
                Indent             = true,
            };

            var ns = new XmlSerializerNamespaces();
            ns.Add(string.Empty, string.Empty);

            var sb = new StringBuilder();
            using (var xw = XmlWriter.Create(sb, xws))
            {
                var xs = new XmlSerializer(t.GetType());
                WPFHelper.Invoke(() => xs.Serialize(xw, t, ns));
            }

            sb.Replace("utf-16", "utf-8");

            return(sb.ToString() + Environment.NewLine);
        });
Beispiel #3
0
 public static RawEvent ToRawEvent(this ITrigger trigger, Guid?parent_id = null)
 {
     return
         (new RawEvent(Guid.NewGuid()
                       , trigger.ToBytes()
                       , new { parent_id }.ToBytes()  //Every event has a pointer to its parent event
                       , trigger.GetType().Name));
 }
Beispiel #4
0
 /// <summary>
 /// Check if the trigger matches
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 public virtual bool Matches(ITrigger t)
 {
     if (t.GetType() == GetType())
     {
         var ct = (Trigger <TData1>)t;
         return(ct.SubjectEquals(Subject));
     }
     return(false);
 }
            public void addTrigger(ITrigger trigger)
            {
                Type t = trigger.GetType();

                if (!_list.ContainsKey(t))
                    _list.Add(t, new List<ITrigger>());

                if( !_list[t].Contains(trigger) )
                    _list[t].Add(trigger);
            }
Beispiel #6
0
        public void Trigger(ITrigger trigger)
        {
            if (!transitionManagers.TryGetValue(trigger.GetType(), out TransitionManager result))
            {
                return;
            }

            prevTrigger = trigger;
            result.Process(this);
        }
Beispiel #7
0
 protected TriggerDetailDto(ITrigger trigger, ICalendar calendar)
 {
     Description   = trigger.Description;
     TriggerType   = trigger.GetType().AssemblyQualifiedNameWithoutVersion();
     Name          = trigger.Key.Name;
     Group         = trigger.Key.Group;
     CalendarName  = trigger.CalendarName;
     Priority      = trigger.Priority;
     StartTimeUtc  = trigger.StartTimeUtc;
     EndTimeUtc    = trigger.EndTimeUtc;
     NextFireTimes = TriggerUtils.ComputeFireTimes((IOperableTrigger)trigger, calendar, 10);
 }
 protected TriggerDetailDto(ITrigger trigger, ICalendar calendar)
 {
     Description = trigger.Description;
     TriggerType = trigger.GetType().AssemblyQualifiedNameWithoutVersion();
     Name = trigger.Key.Name;
     Group = trigger.Key.Group;
     CalendarName = trigger.CalendarName;
     Priority = trigger.Priority;
     StartTimeUtc = trigger.StartTimeUtc;
     EndTimeUtc = trigger.EndTimeUtc;
     NextFireTimes = TriggerUtils.ComputeFireTimes((IOperableTrigger) trigger, calendar, 10);
 }
Beispiel #9
0
        /// <summary>
        /// プロパティを取り込む
        /// </summary>
        /// <param name="t"></param>
        /// <param name="source">取り込む元のオブジェクト</param>
        public static async void ImportProperties(
            this ITrigger t,
            ITrigger source)
        {
            if (source == null ||
                t == null)
            {
                return;
            }

            var properties = source.GetType().GetProperties(
                BindingFlags.Public |
                BindingFlags.Instance)
                             .Where(x =>
                                    x.CanRead &&
                                    x.CanWrite);

            await WPFHelper.InvokeAsync(() =>
            {
                foreach (var pi in properties)
                {
                    if (t.GetType().GetProperty(pi.Name) == null ||
                        ImportIgnoreProperties.Contains(pi.Name))
                    {
                        continue;
                    }

                    var attrs = pi.GetCustomAttributes(true);
                    if (attrs.Any(a => a is XmlIgnoreAttribute))
                    {
                        continue;
                    }

                    pi.SetValue(t, pi.GetValue(source));
                    Thread.Yield();

                    (t as TreeItemBase)?.ExecuteRaisePropertyChanged(pi.Name);
                    Thread.Yield();
                }

                switch (t)
                {
                case Spell spell:
                    spell.Enabled = true;
                    break;

                case Ticker ticker:
                    ticker.Enabled = true;
                    break;
                }
            });
        }
Beispiel #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="trigger"></param>
 /// <param name="calendar"></param>
 public static TriggerDetailDto ToDto(this ITrigger trigger, ICalendar calendar)
 {
     return(new TriggerDetailDto()
     {
         Description = trigger.Description,
         TriggerType = trigger.GetType().AssemblyQualifiedNameWithoutVersion(),
         Name = trigger.Key.Name,
         Group = trigger.Key.Group,
         CalendarName = trigger.CalendarName,
         Priority = trigger.Priority,
         StartTimeUtc = trigger.StartTimeUtc,
         EndTimeUtc = trigger.EndTimeUtc,
         NextFireTimes = TriggerUtils.ComputeFireTimes((IOperableTrigger)trigger, calendar, 10)
     });
 }
Beispiel #11
0
 internal virtual void Bind(ITaskDefinition iTaskDef)
 {
     var o = iTaskDef.Triggers;
     _v2Trigger = o.Create(_ttype);
     Marshal.ReleaseComObject(o);
     foreach (string str in unboundValues.Keys)
     {
         try
         {
             var obj2 = unboundValues[str];
             CheckBindValue(str, ref obj2);
             _v2Trigger.GetType().InvokeMember(str, BindingFlags.SetProperty, null, _v2Trigger, new object[] { obj2 });
         }
         catch (TargetInvocationException ex) { throw ex.InnerException; }
         catch { }
     }
     unboundValues.Clear();
     unboundValues = null;
     _repititionPattern = new RepetitionPattern(this);
     _repititionPattern.Bind();
 }
Beispiel #12
0
        internal static PersistentTriggerBase CreateTrigger(ITrigger trigger, Entities.PersistentTriggerState state, string instanceName)
        {
            if (trigger is ICronTrigger cronTrigger)
            {
                return(new PersistentCronTrigger(cronTrigger, state, instanceName));
            }
            if (trigger is ISimpleTrigger simpleTrigger)
            {
                return(new PersistentSimpleTrigger(simpleTrigger, state, instanceName));
            }
            if (trigger is ICalendarIntervalTrigger intervalTrigger)
            {
                return(new PersistentCalendarIntervalTrigger(intervalTrigger, state, instanceName));
            }
            if (trigger is IDailyTimeIntervalTrigger timeIntervalTrigger)
            {
                return(new PersistentDailyTimeIntervalTrigger(timeIntervalTrigger, state, instanceName));
            }

            throw new NotSupportedException($"Trigger of type {trigger.GetType().FullName} is not supported");
        }
        public static Trigger CreateTrigger(ITrigger trigger, Models.TriggerState state, string instanceName)
        {
            if (trigger is ICronTrigger)
            {
                return(new CronTrigger((ICronTrigger)trigger, state, instanceName));
            }
            if (trigger is ISimpleTrigger)
            {
                return(new SimpleTrigger((ISimpleTrigger)trigger, state, instanceName));
            }
            if (trigger is ICalendarIntervalTrigger)
            {
                return(new CalendarIntervalTrigger((ICalendarIntervalTrigger)trigger, state, instanceName));
            }
            if (trigger is IDailyTimeIntervalTrigger)
            {
                return(new DailyTimeIntervalTrigger((IDailyTimeIntervalTrigger)trigger, state, instanceName));
            }

            throw new NotSupportedException($"Trigger of type {trigger.GetType().FullName} is not supported");
        }
Beispiel #14
0
        internal virtual void Bind(ITaskDefinition iTaskDef)
        {
            var o = iTaskDef.Triggers;

            _v2Trigger = o.Create(_ttype);
            Marshal.ReleaseComObject(o);
            foreach (string str in unboundValues.Keys)
            {
                try
                {
                    var obj2 = unboundValues[str];
                    CheckBindValue(str, ref obj2);
                    _v2Trigger.GetType().InvokeMember(str, BindingFlags.SetProperty, null, _v2Trigger, new object[] { obj2 });
                }
                catch (TargetInvocationException ex) { throw ex.InnerException; }
                catch { }
            }
            unboundValues.Clear();
            unboundValues      = null;
            _repititionPattern = new RepetitionPattern(this);
            _repititionPattern.Bind();
        }
Beispiel #15
0
        /// <summary>
        /// Gets all triggers converted to trigger model
        /// </summary>
        /// <returns></returns>
        public static ICollection <TriggerModel> GetAllTriggers()
        {
            log.Info("About to get all triggers...");
            ICollection <TriggerModel> triggers = new List <TriggerModel>();

            log.Info("Finding trigger keys...");
            var triggerKeys = scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .AnyGroup());

            if (triggerKeys != null)
            {
                log.Info("At list one trigger key was found... Getting triggers");
                foreach (TriggerKey key in triggerKeys)
                {
                    ITrigger trigger = scheduler.GetTrigger(key);

                    if (trigger is ICronTrigger)
                    {
                        triggers.Add(new TriggerModel()
                        {
                            JobName              = trigger.JobKey.Name,
                            TriggerName          = trigger.Key.Name,
                            TriggerType          = trigger.GetType().Name,
                            StartTimeDate        = trigger.StartTimeUtc,
                            EndTimeDate          = trigger.EndTimeUtc,
                            PreviousFireTimeDate = trigger.GetPreviousFireTimeUtc(),
                            NextFireTimeDate     = trigger.GetNextFireTimeUtc(),
                            Message              = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("Message"),
                            MailSubject          = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("MailSubject"),
                            MailBody             = scheduler.GetJobDetail(trigger.JobKey).JobDataMap.GetString("MailBody"),
                            JobType              = scheduler.GetJobDetail(trigger.JobKey).JobType.Name,
                            CronExpression       = ((ICronTrigger)trigger).CronExpressionString
                        });
                    }
                }
                log.Info("Successfuly got all triggers");
            }

            return(triggers);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="trigger"></param>
        /// <param name="calendar"></param>
        public static TriggerDetailDto ToDto(this ITrigger trigger, ICalendar calendar)
        {
            TriggerDetailDto dto = null;

            if (trigger is ISimpleTrigger simpleTrigger)
            {
                dto = new SimpleTriggerDetailDto(simpleTrigger);
            }
            if (trigger is ICronTrigger cronTrigger)
            {
                dto = new CronTriggerDetailDto(cronTrigger);
            }
            if (trigger is ICalendarIntervalTrigger calendarIntervalTrigger)
            {
                dto = new CalendarIntervalTriggerDetailDto(calendarIntervalTrigger);
            }
            if (trigger is IDailyTimeIntervalTrigger dailyTimeIntervalTrigger)
            {
                dto = new DailyTimeIntervalTriggerDetailDto(dailyTimeIntervalTrigger);
            }
            else
            {
                dto = new TriggerDetailDto();
            }

            dto.Description   = trigger.Description;
            dto.TriggerType   = trigger.GetType().AssemblyQualifiedNameWithoutVersion();
            dto.Name          = trigger.Key.Name;
            dto.Group         = trigger.Key.Group;
            dto.CalendarName  = trigger.CalendarName;
            dto.Priority      = trigger.Priority;
            dto.StartTimeUtc  = trigger.StartTimeUtc;
            dto.EndTimeUtc    = trigger.EndTimeUtc;
            dto.NextFireTimes = TriggerUtils.ComputeFireTimes((IOperableTrigger)trigger, calendar, 10);

            return(dto);
        }
Beispiel #17
0
        public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            if (trigger is Trigger)
            {
                var propertyTrigger = trigger as Trigger;
                var nativeTrigger   = new System.Windows.Trigger();

                var dependencyProperty = dependencyService.GetDependencyProperty(targetType, propertyTrigger.Property);
                if (dependencyProperty == null)
                {
                    throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!");
                }

                nativeTrigger.Property = dependencyProperty;
                nativeTrigger.Value    = dependencyService.GetDependencyPropertyValue(targetType, nativeTrigger.Property.Name, nativeTrigger.Property, propertyTrigger.Value);
                foreach (var styleDeclaration in propertyTrigger.StyleDeclarationBlock)
                {
                    var propertyInfo = typeNameResolver.GetDependencyPropertyInfo(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                    if (propertyInfo == null)
                    {
                        continue;
                    }
                    try
                    {
                        var value = typeNameResolver.GetPropertyValue(propertyInfo.DeclaringType, styleResourceReferenceHolder, propertyInfo.Name, styleDeclaration.Value, propertyInfo.Property, styleSheet.Namespaces);
                        if (value == null)
                        {
                        }

                        nativeTrigger.Setters.Add(new Setter {
                            Property = propertyInfo.Property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in propertyTrigger.EnterActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" enter action: {e.Message}");
                    }
                }
                foreach (var action in propertyTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" exit action: {e.Message}");
                    }
                }

                var serialized = SerializeObject(nativeTrigger);
                //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger));

                Css.SetSerializedTrigger(nativeTrigger, serialized);

                return(nativeTrigger);
            }
            else if (trigger is DataTrigger)
            {
                var dataTrigger   = trigger as DataTrigger;
                var nativeTrigger = new System.Windows.DataTrigger();

                string expression = null;
                if (typeNameResolver.IsMarkupExtension(dataTrigger.Binding))
                {
                    expression = typeNameResolver.CreateMarkupExtensionExpression(dataTrigger.Binding);
                }
                else
                {
                    expression = "{Binding " + dataTrigger.Binding + "}";
                }

                var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null, styleSheet.Namespaces);
                nativeTrigger.Binding = binding;

                nativeTrigger.Value = GetBasicValue(dataTrigger);

                foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock)
                {
                    try
                    {
                        var propertyInfo = typeNameResolver.GetDependencyPropertyInfo(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                        if (propertyInfo == null)
                        {
                            continue;
                        }

                        var value = typeNameResolver.GetPropertyValue(propertyInfo.DeclaringType, styleResourceReferenceHolder, propertyInfo.Name, styleDeclaration.Value, propertyInfo.Property, styleSheet.Namespaces);
                        if (value == null)
                        {
                        }

                        nativeTrigger.Setters.Add(new Setter {
                            Property = propertyInfo.Property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.EnterActions)
                {
                    try
                    {
                        System.Windows.TriggerAction nativeTriggerAction = null;

                        nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" enter action: {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" exit action: {e.Message}");
                    }
                }

                var serialized = SerializeObject(nativeTrigger);
                //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger));

                Css.SetSerializedTrigger(nativeTrigger, serialized);

                return(nativeTrigger);
            }
            else if (trigger is EventTrigger)
            {
                var eventTrigger  = trigger as EventTrigger;
                var nativeTrigger = new System.Windows.EventTrigger();

                nativeTrigger.RoutedEvent = (RoutedEvent)TypeHelpers.GetFieldValue(targetType, eventTrigger.Event + "Event");
                foreach (var action in eventTrigger.Actions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.Actions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in event trigger ""{eventTrigger.Event} {action.Action}"": {e.Message}");
                    }
                }

                var serialized = SerializeObject(nativeTrigger);
                //serialized = $"pre XamlWriter.Save({nativeTrigger.GetType().Name})".Measure(() => XamlWriter.Save(nativeTrigger));

                Css.SetSerializedTrigger(nativeTrigger, serialized);

                return(nativeTrigger);
            }

            throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!");
        }
Beispiel #18
0
        internal virtual void Bind(ITaskDefinition iTaskDef)
        {
            var iTriggers = iTaskDef.Triggers;
            v2Trigger = iTriggers.Create(ttype);
            Marshal.ReleaseComObject(iTriggers);
            foreach (var key in unboundValues.Keys) {
                try {
                    var o = unboundValues[key];
                    CheckBindValue(key, ref o);
                    v2Trigger.GetType().InvokeMember(key, BindingFlags.SetProperty, null, v2Trigger, new[] {o});
                } catch (TargetInvocationException tie) {
                    throw tie.InnerException;
                } catch {
                }
            }
            unboundValues.Clear();
            unboundValues = null;

            repititionPattern = new RepetitionPattern(this);
            repititionPattern.Bind();
        }
 private ViewResult EditView(ITrigger trigger)
 {
     ITriggerViewModel viewModel = _mappingEngine.Map<ITrigger, ITriggerViewModel>(trigger);
     string viewName = string.Format("Edit{0}", trigger.GetType().Name);
     return View(viewName, viewModel);
 }
Beispiel #20
0
        public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            if (trigger is Trigger)
            {
                var propertyTrigger = trigger as Trigger;
                var nativeTrigger   = new System.Windows.Trigger();

                var dependencyProperty = dependencyService.GetBindableProperty(targetType, propertyTrigger.Property);
                if (dependencyProperty == null)
                {
                    throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!");
                }

                nativeTrigger.Property = dependencyProperty;
                nativeTrigger.Value    = dependencyService.GetBindablePropertyValue(targetType, nativeTrigger.Property, propertyTrigger.Value);

                foreach (var styleDeclaration in propertyTrigger.StyleDeclarationBlock)
                {
                    var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                    if (property == null)
                    {
                        continue;
                    }
                    try
                    {
                        var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces);

                        if (value is string valueString)
                        {
                            value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value;
                        }

                        nativeTrigger.Setters.Add(new Setter {
                            Property = property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in propertyTrigger.EnterActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" enter action: {e.Message}");
                    }
                }

                foreach (var action in propertyTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" exit action: {e.Message}");
                    }
                }

                return(nativeTrigger);
            }
            else if (trigger is DataTrigger)
            {
                var dataTrigger   = trigger as DataTrigger;
                var nativeTrigger = new System.Windows.DataTrigger();

                var expression = "{Binding " + dataTrigger.Binding + "}";

                var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null, styleSheet.Namespaces);
                nativeTrigger.Binding = binding;

                nativeTrigger.Value = GetBasicValue(dataTrigger);

                foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock)
                {
                    try
                    {
                        var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                        if (property == null)
                        {
                            continue;
                        }

                        var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces);

                        if (value is string valueString)
                        {
                            value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value;
                        }

                        nativeTrigger.Setters.Add(new Setter {
                            Property = property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.EnterActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" enter action: {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" exit action: {e.Message}");
                    }
                }

                return(nativeTrigger);
            }
            else if (trigger is EventTrigger)
            {
                var eventTrigger  = trigger as EventTrigger;
                var nativeTrigger = new System.Windows.EventTrigger();

                var fieldInfo = targetType.GetField(eventTrigger.Event + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);

                nativeTrigger.RoutedEvent = (RoutedEvent)fieldInfo.GetValue(null);

                foreach (var action in eventTrigger.Actions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.Actions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in event trigger ""{eventTrigger.Event} {action.Action}"": {e.Message}");
                    }
                }

                return(nativeTrigger);
            }

            throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!");
        }
            public bool removeTrigger(ITrigger trigger)
            {
                Type t = trigger.GetType();

                if (_list.ContainsKey(t) && _list[t].Contains(trigger))
                {
                    _list[t].Remove(trigger);

                    if (_list[t].Count == 0)
                        _list.Remove(t);

                    return true;
                }
                else return false;
            }
Beispiel #22
0
        public async Task Respond(Message message)
        {
            _logger.LogInformation("Received message: {@message}", message);
            ITrigger responder = null;

            if (message.Sender.Type == PersonType.Bot)
            {
                _logger.LogDebug("Message was sent by a bot, ignoring");
                return;
            }

            if (message.RoomType == RoomType.Group)
            {
                responder = _triggers.FirstOrDefault(x => _triggerResponseTester.ShouldTriggerInRoom(message, x));
            }
            else if (message.RoomType == RoomType.Direct)
            {
                responder = _triggers.FirstOrDefault(x => _triggerResponseTester.ShouldTriggerInDirectMessage(message, x));
            }

            Message response = null;

            if (responder != null)
            {
                _logger.LogInformation("Responding to message with responder {responderName}", responder.GetType().Name);
                response = await responder.Respond(message).ConfigureAwait(false);
            }
            else
            {
                _logger.LogInformation("No responder found");
            }

            if (response != null)
            {
                _logger.LogInformation("Sending response message {@response}", response);
                if (response.RoomId == null)
                {
                    response.RoomId   = message.RoomId;
                    response.ParentId = message.Id;
                }

                await _chatHelper.Messages.SendMessageAsync(response).ConfigureAwait(false);
            }
        }
Beispiel #23
0
 /// <summary>
 /// Gets the <see cref="TriggerForAttribute"/>
 /// </summary>
 /// <param name="trigger">
 /// The trigger.
 /// </param>
 /// <returns>
 /// The <see cref="TriggerForAttribute"/>.
 /// </returns>
 internal static TriggerForAttribute TriggerFor(this ITrigger trigger)
 {
     return(trigger.GetType().GetCustomAttribute <TriggerForAttribute>(false));
 }
Beispiel #24
0
        public override DependencyObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, DependencyObject styleResourceReferenceHolder)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            if (trigger is Trigger)
            {
                var propertyTrigger = trigger as Trigger;
                var nativeTrigger   = new System.Windows.Trigger();

                var dependencyProperty = dependencyService.GetBindableProperty(targetType, propertyTrigger.Property);
                if (dependencyProperty == null)
                {
                    throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!");
                }

                nativeTrigger.Property = dependencyProperty;
                nativeTrigger.Value    = dependencyService.GetBindablePropertyValue(targetType, nativeTrigger.Property, propertyTrigger.Value);

                foreach (var styleDeclaration in propertyTrigger.StyleDeclaraionBlock)
                {
                    var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                    if (property == null)
                    {
                        continue;
                    }
                    var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property);

                    if (value is string valueString)
                    {
                        value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value;
                    }

                    nativeTrigger.Setters.Add(new Setter {
                        Property = property, Value = value
                    });
                }

                return(nativeTrigger);
            }
            else if (trigger is DataTrigger)
            {
                var dataTrigger   = trigger as DataTrigger;
                var nativeTrigger = new System.Windows.DataTrigger();

                var expression = "{Binding " + dataTrigger.Binding + "}";

                var binding = (System.Windows.Data.BindingBase)markupExtensionParser.ProvideValue(expression, null);
                nativeTrigger.Binding = binding;

                nativeTrigger.Value = GetBasicValue(dataTrigger);

                foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock)
                {
                    var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                    if (property == null)
                    {
                        continue;
                    }

                    var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property);

                    if (value is string valueString)
                    {
                        value = TypeDescriptor.GetConverter(property.PropertyType)?.ConvertFromInvariantString(valueString) ?? value;
                    }

                    nativeTrigger.Setters.Add(new Setter {
                        Property = property, Value = value
                    });
                }

                return(nativeTrigger);
            }
            else if (trigger is EventTrigger)
            {
                var eventTrigger  = trigger as EventTrigger;
                var nativeTrigger = new System.Windows.EventTrigger();

                var fieldInfo = targetType.GetField(eventTrigger.Event + "Event", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);

                nativeTrigger.RoutedEvent = (RoutedEvent)fieldInfo.GetValue(null);

                foreach (var action in eventTrigger.Actions)
                {
                    var actionTypeName = typeNameResolver.ResolveFullTypeName(styleSheet.Namespaces, action.Action);
                    var actionType     = Type.GetType(actionTypeName);
                    var triggerAction  = (System.Windows.TriggerAction)Activator.CreateInstance(actionType);

                    var parameters = action.Parameters.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(x => x.Trim())
                                     .ToList();

                    foreach (var parameter in parameters)
                    {
                        var                parameterName            = parameter.Split(' ')[0];
                        object             value                    = null;
                        var                parameterValueExpression = parameter.Substring(parameterName.Length + 1).Trim();
                        DependencyProperty depProp;
                        var                type = typeNameResolver.GetClrPropertyType(styleSheet.Namespaces, triggerAction, parameterName);

                        if (typeNameResolver.IsMarkupExtension(parameterValueExpression))
                        {
                            value = typeNameResolver.GetMarkupExtensionValue(styleResourceReferenceHolder, parameterValueExpression);
                        }
                        else if ((depProp = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, actionType, parameterName)) != null)
                        {
                            value = typeNameResolver.GetPropertyValue(actionType, styleResourceReferenceHolder, parameterValueExpression, depProp);

                            if (value is DynamicResourceExtension)
                            {
                                var dyn             = value as DynamicResourceExtension;
                                var serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current);
                                value = dyn.ProvideValue(serviceProvider);
                            }
                            else if (value is StaticResourceExtension)
                            {
                                var dyn             = value as StaticResourceExtension;
                                var serviceProvider = (IServiceProvider)typeof(Application).GetProperty("ServiceProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Application.Current);
                                value = dyn.ProvideValue(serviceProvider);
                            }
                        }
                        else
                        {
                            value = parameterValueExpression;
                        }

                        if (value is string valueString)
                        {
                            value = TypeDescriptor.GetConverter(type)?.ConvertFromInvariantString(valueString) ?? value;
                        }

                        triggerAction.GetType().GetRuntimeProperty(parameterName).SetValue(triggerAction, value);
                    }

                    nativeTrigger.Actions.Add(triggerAction);
                }

                return(nativeTrigger);
            }

            throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!");
        }
 public Task TriggerMisfired(ITrigger trigger, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Task.Run(() => {
         LogsAppendersManager.Instance.Debug(trigger.GetType(), MethodBase.GetCurrentMethod(), "Trigger " + trigger.Key + " Misfired");
     }));
 }
Beispiel #26
0
        public override BindableObject CreateTrigger(StyleSheet styleSheet, ITrigger trigger, Type targetType, BindableObject styleResourceReferenceHolder)
        {
            if (trigger == null)
            {
                throw new ArgumentNullException(nameof(trigger));
            }

            if (trigger is Trigger)
            {
                var propertyTrigger = trigger as Trigger;
                var nativeTrigger   = new Xamarin.Forms.Trigger(targetType);

                var bindableProperty = dependencyService.GetBindableProperty(targetType, propertyTrigger.Property);
                if (bindableProperty == null)
                {
                    throw new NullReferenceException($"Property '{propertyTrigger.Property}' may not be null (targetType '{targetType.Name}')!");
                }

                nativeTrigger.Property = bindableProperty;
                nativeTrigger.Value    = dependencyService.GetBindablePropertyValue(targetType, nativeTrigger.Property, propertyTrigger.Value);

                foreach (var styleDeclaration in propertyTrigger.StyleDeclarationBlock)
                {
                    var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                    if (property == null)
                    {
                        continue;
                    }
                    try
                    {
                        var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces);

                        nativeTrigger.Setters.Add(new Setter {
                            Property = property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in propertyTrigger.EnterActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" enter action: {e.Message}");
                    }
                }

                foreach (var action in propertyTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in property trigger ""{propertyTrigger.Property} {propertyTrigger.Value}"" exit action: {e.Message}");
                    }
                }

                return(nativeTrigger);
            }
            else if (trigger is DataTrigger)
            {
                var dataTrigger   = trigger as DataTrigger;
                var nativeTrigger = new Xamarin.Forms.DataTrigger(targetType);

                var expression = "{Binding " + dataTrigger.Binding + "}";

                var binding = (Binding)markupExtensionParser.ProvideValue(expression, null, styleSheet.Namespaces);
                nativeTrigger.Binding = binding;

                nativeTrigger.Value = GetBasicValue(dataTrigger);

                foreach (var styleDeclaration in dataTrigger.StyleDeclarationBlock)
                {
                    try
                    {
                        var property = typeNameResolver.GetDependencyProperty(styleSheet.Namespaces, targetType, styleDeclaration.Property);
                        if (property == null)
                        {
                            continue;
                        }

                        var value = typeNameResolver.GetPropertyValue(targetType, styleResourceReferenceHolder, styleDeclaration.Value, property, styleSheet.Namespaces);

                        nativeTrigger.Setters.Add(new Setter {
                            Property = property, Value = value
                        });
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {styleDeclaration.Property}: {styleDeclaration.Value}"": {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.EnterActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.EnterActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" enter action: {e.Message}");
                    }
                }

                foreach (var action in dataTrigger.ExitActions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.ExitActions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in data trigger ""{dataTrigger.Binding} {dataTrigger.Value} - {action}"" exit action: {e.Message}");
                    }
                }

                return(nativeTrigger);
            }
            else if (trigger is EventTrigger)
            {
                var eventTrigger  = trigger as EventTrigger;
                var nativeTrigger = new Xamarin.Forms.EventTrigger();

                nativeTrigger.Event = eventTrigger.Event;

                foreach (var action in eventTrigger.Actions)
                {
                    try
                    {
                        var nativeTriggerAction = CreateTriggerAction(styleSheet, styleResourceReferenceHolder, action);

                        nativeTrigger.Actions.Add(nativeTriggerAction);
                    }
                    catch (Exception e)
                    {
                        styleSheet.Errors.Add($@"ERROR in event trigger ""{eventTrigger.Event} {action.Action}"": {e.Message}");
                    }
                }

                return(nativeTrigger);
            }

            throw new NotSupportedException($"Trigger '{trigger.GetType().FullName}' is not supported!");
        }