Exemple #1
0
 public void RemoveEventListener(Event e)
 {
     if (EventDictionary.ContainsKey(e))
     {
         EventDictionary.Remove(e);
     }
 }
Exemple #2
0
 public void AddEventListener(Event e, EventHandler handler)
 {
     if (!EventDictionary.ContainsKey(e))
     {
         EventDictionary.Add(e, handler);
     }
 }
        public void StartService()
        {
            if (ServiceStarted)
            {
                return;
            }
            ServiceStarted = true;
            MDNS.Start();
            SD.ServiceInstanceDiscovered += (s, e) => MDNS.SendQuery(e.ServiceInstanceName, type: DnsType.SRV);

            MDNS.AnswerReceived += (s, e) =>
            {
                var servers = e.Message.Answers.OfType <SRVRecord>();
                foreach (var server in servers)
                {
                    var target = server.Target.ToString();
                    var name   = string.Join(".", server.Name.Labels.TakeLast(3));
                    lock (_dictLock)
                    {
                        if (TargetDictionary.ContainsKey(target))
                        {
                            if (!TargetDictionary[target].Contains(name))
                            {
                                TargetDictionary[target].Add(name);
                            }
                        }
                        else
                        {
                            TargetDictionary.Add(target, new HashSet <string> {
                                name
                            });
                        }
                    }

                    Logger.LogInformation($"Receive service record: {name} = {target}");
                    MDNS.SendQuery(server.Target, type: DnsType.A);
                }

                var addresses = e.Message.Answers.OfType <AddressRecord>();
                foreach (var address in addresses)
                {
                    if (!DomainNameDictionary.TryAdd(address.Name.ToString(), address.Address))
                    {
                        DomainNameDictionary[address.Name.ToString()] = address.Address;
                    }
                    Logger.LogInformation($"Receive address record: {address.Name} = {address.Address}");
                    if (TargetDictionary.ContainsKey(address.Name.ToString()))
                    {
                        TargetDictionary[address.Name.ToString()]
                        .Where(t => EventDictionary.ContainsKey(t))
                        .Foreach(t => EventDictionary[t].Invoke(this, new IPAddressEventArgs(address.Address)));
                    }
                }
            };

            Logger.LogInformation("Service discovery started");
        }
 private void FireEventHandlers(List <RawEvent> finalEvents)
 {
     foreach (RawEvent rawEvent in finalEvents)
     {
         if (EventDictionary.ContainsKey(rawEvent.@event))
         {
             AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\t{EventDictionary[rawEvent.@event].Method.Name}({rawEvent.time}, {JsonConvert.SerializeObject(rawEvent.args)})");
             EventDictionary[rawEvent.@event].Invoke(rawEvent.time, rawEvent.args);
         }
     }
 }
        private void ReadEvents()
        {
            while (IsActive)
            {
                if (AmeisenCore.IsInLoadingScreen())
                {
                    Thread.Sleep(50);
                    continue;
                }

                // Unminified lua code can be found im my github repo "WowLuaStuff"
                string eventJson = AmeisenCore.GetLocalizedText("abEventJson='['for a,b in pairs(abEventTable)do abEventJson=abEventJson..'{'for c,d in pairs(b)do if type(d)==\"table\"then abEventJson=abEventJson..'\"args\": ['for e,f in pairs(d)do abEventJson=abEventJson..'\"'..f..'\"'if e<=table.getn(d)then abEventJson=abEventJson..','end end;abEventJson=abEventJson..']}'if a<table.getn(abEventTable)then abEventJson=abEventJson..','end else if type(d)==\"string\"then abEventJson=abEventJson..'\"event\": \"'..d..'\",'else abEventJson=abEventJson..'\"time\": \"'..d..'\",'end end end end;abEventJson=abEventJson..']'abEventTable={}", "abEventJson");
                AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"LUA Events Json: {eventJson}", this);

                List <RawEvent> rawEvents = new List <RawEvent>();
                try
                {
                    // parse the events from JSON
                    List <RawEvent> finalEvents = new List <RawEvent>();
                    rawEvents = JsonConvert.DeserializeObject <List <RawEvent> >(eventJson);

                    foreach (RawEvent rawEvent in rawEvents)
                    {
                        if (!finalEvents.Contains(rawEvent))
                        {
                            finalEvents.Add(rawEvent);
                        }
                    }

                    // Fire the events
                    AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"Parsed {finalEvents.Count} events", this);
                    if (finalEvents.Count > 0)
                    {
                        foreach (RawEvent rawEvent in finalEvents)
                        {
                            if (EventDictionary.ContainsKey(rawEvent.@event))
                            {
                                EventDictionary[rawEvent.@event].Invoke(rawEvent.time, rawEvent.args);
                                AmeisenLogger.Instance.Log(LogLevel.VERBOSE, $"Fired OnEventFired: {rawEvent.@event}", this);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    AmeisenLogger.Instance.Log(LogLevel.ERROR, $"Failed to parse events Json: {e}", this);
                }

                Thread.Sleep(1000);
            }
        }
Exemple #6
0
        private void addToFavoritesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddToFavoritesDialog dialog = new AddToFavoritesDialog();
            RegistryKey          key    = (RegistryKey)tvwKeys.SelectedNode.Tag;
            int i = key.Name.LastIndexOf('\\');

            dialog.txtName.SelectedText = i >= 0 ? key.Name.Substring(i + 1) : key.Name;
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                if (favorites.ContainsKey(dialog.txtName.Text))
                {
                    UIUtility.DisplayError(this, Properties.Resources.Error_AlreadyFavorite);
                }
                else
                {
                    string path = "My Computer\\" + key.Name;
                    Microsoft.Win32.Registry.SetValue(RegExplorer.RegistryFavoritePath, dialog.txtName.Text, path);
                    favorites[dialog.txtName.Text] = key.Name;
                }
            }
        }
Exemple #7
0
 public bool Contains(Type declaredType)
 {
     return(_eventsByDeclaredType.ContainsKey(declaredType));
 }
Exemple #8
0
 public bool Contains(RuntimeTypeKey key)
 {
     return(_eventsByKey.ContainsKey(key));
 }