コード例 #1
0
        public void AttachNuiHandler(string pipe, EventCallback callback)
        {
            API.RegisterNuiCallbackType(pipe);

            EventHandlers[$"__cfx_nui:{pipe}"] += new Action <ExpandoObject, CallbackDelegate>((body, result) =>
            {
                var metadata   = new EventMetadata();
                var properties = (IDictionary <string, object>)body;

                if (properties != null)
                {
                    foreach (var entry in properties)
                    {
                        if (!int.TryParse(entry.Key, out var index))
                        {
                            Logger.Info(
                                $"[Nui] [{pipe}] Payload `{entry.Key}` is not a number and therefore not written to.");

                            continue;
                        }

                        metadata.Write(index, entry.Value);
                    }
                }

                if (callback.GetType() == typeof(AsyncEventCallback))
                {
#pragma warning disable 4014
                    ((AsyncEventCallback)callback).AsyncTask(metadata);
#pragma warning restore 4014
                }
                else
                {
                    callback.Task(metadata);
                }
            });
        }