예제 #1
0
        /// <summary>
        ///
        /// </summary>
        public DirectProxyFactory()
        {
            EmptyProxyFactory.MethodCalled += (sender, args) =>
            {
                if (sender == null ||
                    !Dictionary.TryGetValue(sender, out var obj))
                {
                    return;
                }

                MethodCalled?.Invoke(sender, args);

                if (args.IsCanceled)
                {
                    return;
                }

                var method = obj.GetType().GetMethod(args.MethodInfo.Name, args.MethodInfo
                                                     .GetParameters()
                                                     .Select(i => i.ParameterType)
                                                     .ToArray())
                             ?? throw new InvalidOperationException($"Method not found: {args.MethodInfo}");

                args.ReturnObject = method.Invoke(obj, args.Arguments.ToArray());

                MethodCompleted?.Invoke(sender, args);
            };
            EmptyProxyFactory.EventRaised    += (sender, args) => EventRaised?.Invoke(this, args);
            EmptyProxyFactory.EventCompleted += (sender, args) => EventCompleted?.Invoke(this, args);
        }
예제 #2
0
 public void RaiseConvention()
 {
     if (EventRaised != null)
     {
         EventRaised.Invoke(this, EventArgs.Empty);
     }
 }
예제 #3
0
        private void EventHandler(object[] objects)
        {
            var eventId   = (ulong)objects[0];
            var parameter = objects.Length > 2 ? objects[2] : null;

            EventRaised?.Invoke(this, new EventProxyEventArgs(eventId, objects[1], parameter));
        }
예제 #4
0
        public void EventLogEventRead(object obj, EventRecordWrittenEventArgs arg)
        {
            try
            {
                if (arg.EventRecord != null)
                {
                    // check on keywords in the General Description and send message to the Nagios server
                    if (supressedIDs != null && supressedIDs.Contains(arg.EventRecord.Id))
                    {
                        return;
                    }

                    if (EventRaised != null)
                    {
                        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); // need to fix MS bug

                        EventLogRecord r     = (EventLogRecord)arg.EventRecord;
                        string         msg   = r.FormatDescription();
                        string         mPath = "";

                        if (string.IsNullOrWhiteSpace(msg))
                        {
                            using (var eln = new System.Diagnostics.EventLog(r.LogName, r.MachineName))
                            {
                                System.Diagnostics.EventLogEntryCollection eCollection = eln.Entries;
                                int cnt = eCollection.Count;
                                for (int i = cnt - 1; i >= Math.Max(0, cnt - 200); i--)
                                {
                                    var xe = eCollection[i];
                                    if (xe.Index == r.RecordId)
                                    {
                                        msg   = xe.Message;
                                        mPath = " s";
                                        break;
                                    }
                                }
                            }
                        }

                        if (_rxFilter != null && string.IsNullOrWhiteSpace(msg) == false && !_rxFilter.IsMatch(msg))
                        {
                            return;
                        }

                        string fMsg = string.Format("{0}, EventID = {1}{2}{3}", arg.EventRecord.TimeCreated.HasValue ? arg.EventRecord.TimeCreated : DateTime.Now, r.Id & 0xFFFF, System.Environment.NewLine, msg);
                        EventRaised.Invoke(this, new EventWatcherArgs(this.EventDescription.NagiosServiceName, this.EventDescription.MessageLevel,
                                                                      fMsg));
                    }
                }
            }
            catch (Exception ex)
            {
                Nagios.Net.Client.Log.WriteLog(ex.Message + "\n" + ex.StackTrace, true);
            }
        }
예제 #5
0
 protected virtual void OnEventRaised(MSBuildLoggerEventArgs args)
 {
     EventRaised?.Invoke(this, args);
 }
예제 #6
0
 protected virtual void OnEventRaised(EventRaisedEventArgs e)
 {
     EventRaised?.Invoke(this, e);
 }
예제 #7
0
 public static void RaiseEvent(object sender, IEvent @event)
 {
     EventRaised?.Invoke(sender, @event);
 }
예제 #8
0
 private void AddEvent(EventType type, string message)
 => EventRaised?.Invoke(this, new WriterEventArgs(Thread.CurrentThread.Name, type, message));
예제 #9
0
 private void AddEvent(EventType type, string message)
 {
     EventRaised?.Invoke(this, new PhilosopherEventArgs(Name, type, message));
 }
예제 #10
0
 public void Trigger(TimeStamp stamp)
 {
     EventRaised?.Invoke(this, new EventEventArgs(stamp));
 }
 /// <summary>
 /// Raises the EventHandler when invoked.
 /// </summary>
 public void OnEventRaised()
 {
     EventRaised?.Invoke(this, null);
 }
예제 #12
0
 /// <summary>
 /// Raises <see cref="EventRaised"/>.
 /// </summary>
 /// <param name="args"></param>
 protected virtual void OnEventRaised(T args)
 {
     EventRaised?.Invoke(this, args);
 }