예제 #1
0
 public EventHandlerInfo(IPlugin plugin, PluginEventHandler eventHandler, MethodInfo methodInfo, object instance = null)
 {
     Plugin   = plugin;
     Handler  = eventHandler;
     Instance = instance;
     Action   = ExpressionHelper.CreateDelegate <Action <EventArgs> >(methodInfo, instance);
 }
예제 #2
0
        internal CommunicationHandler(string ipPort, PluginEventHandler pluginEventHandler)
        {
            _ipPortEndpoint = ipPort;
            TcpClient       = new SimpleTcpClient(_ipPortEndpoint);
            TcpClient.Keepalive.TcpKeepAliveRetryCount = 5;
            TcpClient.Keepalive.EnableTcpKeepAlives    = true;
            _pluginEventHandler = pluginEventHandler;

            TcpClient.Events.Connected    += OnConnectedToHost;
            TcpClient.Events.Disconnected += OnDisconnectedFromHost;
            TcpClient.Events.DataReceived += OnReceivedData;

            try
            {
                TcpClient.Connect();
            }
            catch (Exception e)
            {
                Synapse.Api.Logger.Get.Error($"Failed to first connect to Syncord Bot ({_ipPortEndpoint}){Environment.NewLine}{e}");
                return;
            }

            if (SyncordPlugin.Config.AutoReconnect)
            {
                _reconnectWorker                     = new BackgroundWorker();
                _reconnectWorker.DoWork             += OnDoWorkReconnectWorker;
                _reconnectWorker.RunWorkerCompleted += OnReconnectWorkerCompleted;
                _reconnectWorker.RunWorkerAsync();
            }
        }
예제 #3
0
        public void RegisterHandler <T>(IPlugin plugin, PluginEventHandler <T> handler, EventType type)
        {
            IEventHandlerList handlers;

            if (!Handlers.TryGetValue(type, out handlers))
            {
                handlers       = new CustomNPCEventHandlerList <T>();
                Handlers[type] = handlers;
            }

            handlers.Register(plugin, handler);
        }
예제 #4
0
        public void RegisterEvent(IPlugin plugin, MethodInfo method, object instance = null)
        {
            PluginEventHandler listener = method.GetCustomAttribute <PluginEventHandler>();

            if (listener == null || method.GetParameters().Length != 1)
            {
                return;
            }
            Type eventType = method.GetParameters()[0].ParameterType;

            if (!EventsHandlers.ContainsKey(eventType))
            {
                EventsHandlers.Add(eventType, new List <EventHandlerInfo>());
            }
            EventsHandlers[eventType].Add(new EventHandlerInfo(plugin, listener, method, instance));
        }
예제 #5
0
        public override void Load()
        {
            Synapse.Api.Logger.Get.Info($"Syncord Plugin Version >>{Assembly.GetExecutingAssembly().GetName().Version}<<");

            if (Config.DebugMode)
            {
                Synapse.Api.Logger.Get.Info(Config.Serialize());
            }

            ServerIPv4 = FetchIPv4()
                         .GetAwaiter()
                         .GetResult();

            if (Config.DebugMode)
            {
                Synapse.Api.Logger.Get.Info($"Fetched {ServerIPv4}");
            }

            if (!string.IsNullOrWhiteSpace(ServerIPv4))
            {
                EventHandler = new PluginEventHandler($"{Config.DiscordBotAddress}:{Config.DiscordBotPort}");
            }
        }
예제 #6
0
        /// <summary>
        /// Main polling thread
        /// </summary>
        /// <param name="_state">Any required state information</param>
        private void PollTasks(object _state)
        {
            DateTime now   = DateTime.Now;
            string   s_now = now.ToString(m_timerFormat);

            //Debug.Print("Polling plugin list at: " + now.ToString(m_timerFormat));
            foreach (DictionaryEntry item in m_Tasks)
            {
                //Debug.Print(item.Key.ToString());
                if (item.Key.Equals(s_now))
                {
                    Debug.Print("Executing task");
                    // Execute task in Value
                    PluginTask         task     = (PluginTask)item.Value;
                    PluginEventHandler callback = (PluginEventHandler)task.CallBack;
                    if (callback != null)
                    {
                        callback(task.State);
                    }

                    if (task.Reschedule)
                    {
                        now     += task.Interval;
                        item.Key = now.ToString(m_timerFormat);
                        Debug.Print("Rescheduling task for " + now.ToString());
                    }
                    else
                    {
                        lock (m_Locker)
                        {
                            m_Tasks.Remove(item);
                        }
                    }
                }
            }
        }
        public override void Load()
        {
            SynapseController.Server.Logger.Info("<AdvancedDoctorPlus> Loaded");

            _ = new PluginEventHandler();
        }
 public PluginEventHandlerTests()
 {
     _sut = new PluginEventHandler(_mockPlugin.Object, new ClientArguments(123, "", ""));
 }