예제 #1
0
        public void InternalEvent(bool bAttach, global::System.Delegate e, EventNames n)
        {
            // http://help.dottoro.com/ljrtxexf.php

            IFunction z = ((BCLImplementation.System.__Delegate)(object)e).InvokePointer;

            // does IE9 define both functions?

            if (bAttach)
            {
                if (Expando.InternalIsMember(this, "addEventListener"))
                {
                    // https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener
                    addEventListener(n.EventListener, z);

                    if (n.EventListenerAlt != null)
                        addEventListener(n.EventListenerAlt, z);
                }
                else if (Expando.InternalIsMember(this, "attachEvent"))
                {
                    attachEvent(n.Event, z);

                    if (n.EventAlt != null)
                    {
                        attachEvent(n.EventAlt, z);
                    }

                }

                return;
            }

            #region remove
            if (Expando.InternalIsMember(this, "removeEventListener"))
            {
                removeEventListener(n.EventListener, z, false);

                if (n.EventListenerAlt != null)
                    removeEventListener(n.EventListenerAlt, z, false);
            }
            else if (Expando.InternalIsMember(this, "detachEvent"))
            {
                detachEvent(n.Event, z);

                if (n.EventAlt != null)
                {
                    detachEvent(n.EventAlt, z);
                }
            }
            #endregion

        }
예제 #2
0
 /// <summary>
 /// Remove the specified callback.
 /// </summary>
 public void Off(SocketIOEventTypes type, SocketIOCallback callback)
 {
     EventCallbacks.Unregister(EventNames.GetNameFor(type), callback);
 }
예제 #3
0
 /// <summary>
 /// Removes all callbacks to the given event.
 /// </summary>
 public void Off(SocketIOEventTypes type)
 {
     Off(EventNames.GetNameFor(type));
 }
예제 #4
0
 public void Once(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
 {
     EventCallbacks.Register(EventNames.GetNameFor(type), callback, true, autoDecodePayload);
 }
예제 #5
0
 public void registerEventListener(EventNames name, Module mod)
 {
     eventList[name].Add(mod);
 }
예제 #6
0
 private void SpellChecker_MisspelledWord(object sender, SpellingEventArgs e)
 {
     _lastSpellingEvent = e;
     _lastEvent = EventNames.MisspelledWord;
 }
예제 #7
0
 private void ResetEvents()
 {
     // reset event data
     _lastSpellingEvent = null;
     _lastReplaceEvent = null;
     _lastEvent = EventNames.None;
 }
예제 #8
0
파일: Socket.cs 프로젝트: Smoothstep/VRChat
        public Socket Emit(string eventName, SocketIOAckCallback callback, params object[] args)
        {
            bool blackListed = EventNames.IsBlacklisted(eventName);

            if (blackListed)
            {
                throw new ArgumentException("Blacklisted event: " + eventName);
            }

            arguments.Clear();
            arguments.Add(eventName);

            // Find and swap any binary data(byte[]) to a placeholder string.
            // Server side these will be swapped back.
            List <byte[]> attachments = null;

            if (args != null && args.Length > 0)
            {
                int idx = 0;
                for (int i = 0; i < args.Length; ++i)
                {
                    byte[] binData = args[i] as byte[];
                    if (binData != null)
                    {
                        if (attachments == null)
                        {
                            attachments = new List <byte[]>();
                        }

                        Dictionary <string, object> placeholderObj = new Dictionary <string, object>(2);
                        placeholderObj.Add(Packet.Placeholder, true);
                        placeholderObj.Add("num", idx++);

                        arguments.Add(placeholderObj);

                        attachments.Add(binData);
                    }
                    else
                    {
                        arguments.Add(args[i]);
                    }
                }
            }

            string payload = null;

            try
            {
                payload = Manager.Encoder.Encode(arguments);
            }
            catch (Exception ex)
            {
                (this as ISocket).EmitError(SocketIOErrors.Internal, "Error while encoding payload: " + ex.Message + " " + ex.StackTrace);

                return(this);
            }

            // We don't use it further in this function, so we can clear it to not hold any unwanted reference.
            arguments.Clear();

            if (payload == null)
            {
                throw new ArgumentException("Encoding the arguments to JSON failed!");
            }

            int id = 0;

            if (callback != null)
            {
                id = Manager.NextAckId;

                if (AckCallbacks == null)
                {
                    AckCallbacks = new Dictionary <int, SocketIOAckCallback>();
                }

                AckCallbacks[id] = callback;
            }

            Packet packet = new Packet(TransportEventTypes.Message,
                                       attachments == null ? SocketIOEventTypes.Event : SocketIOEventTypes.BinaryEvent,
                                       this.Namespace,
                                       payload,
                                       0,
                                       id);

            if (attachments != null)
            {
                packet.Attachments = attachments; // This will set the AttachmentCount property too.
            }
            (Manager as IManager).SendPacket(packet);

            return(this);
        }
예제 #9
0
        public void On(SocketIOEventTypes type, SocketIOCallback callback, bool autoDecodePayload)
        {
            string nameFor = EventNames.GetNameFor(type);

            this.EventCallbacks.Register(nameFor, callback, false, autoDecodePayload);
        }
예제 #10
0
        public Socket Emit(string eventName, SocketIOAckCallback callback, params object[] args)
        {
            bool flag = EventNames.IsBlacklisted(eventName);

            if (flag)
            {
                throw new ArgumentException("Blacklisted event: " + eventName);
            }
            this.arguments.Clear();
            this.arguments.Add(eventName);
            List <byte[]> list = null;

            if (args != null && args.Length > 0)
            {
                int num = 0;
                for (int i = 0; i < args.Length; i++)
                {
                    byte[] array = args[i] as byte[];
                    if (array != null)
                    {
                        if (list == null)
                        {
                            list = new List <byte[]>();
                        }
                        this.arguments.Add(string.Format("{{\"_placeholder\":true,\"num\":{0}}}", num++.ToString()));
                        list.Add(array);
                    }
                    else
                    {
                        this.arguments.Add(args[i]);
                    }
                }
            }
            string text = null;

            try
            {
                text = this.Manager.Encoder.Encode(this.arguments);
            }
            catch (Exception ex)
            {
                ((ISocket)this).EmitError(SocketIOErrors.Internal, "Error while encoding payload: " + ex.Message + " " + ex.StackTrace);
                return(this);
            }
            this.arguments.Clear();
            if (text == null)
            {
                throw new ArgumentException("Encoding the arguments to JSON failed!");
            }
            int num2 = 0;

            if (callback != null)
            {
                num2 = this.Manager.NextAckId;
                if (this.AckCallbacks == null)
                {
                    this.AckCallbacks = new Dictionary <int, SocketIOAckCallback>();
                }
                this.AckCallbacks[num2] = callback;
            }
            Packet packet = new Packet(TransportEventTypes.Message, (list != null) ? SocketIOEventTypes.BinaryEvent : SocketIOEventTypes.Event, this.Namespace, text, 0, num2);

            if (list != null)
            {
                packet.Attachments = list;
            }
            ((IManager)this.Manager).SendPacket(packet);
            return(this);
        }
예제 #11
0
 private void SpellChecker_ReplacedWord(object sender, ReplaceWordEventArgs e)
 {
     _lastReplaceEvent = e;
     _lastEvent        = EventNames.ReplacedWord;
 }
예제 #12
0
 private void SpellChecker_MisspelledWord(object sender, SpellingEventArgs e)
 {
     _lastSpellingEvent = e;
     _lastEvent         = EventNames.MisspelledWord;
 }
예제 #13
0
 private void SpellChecker_EndOfText(object sender, EventArgs e)
 {
     _lastEvent = EventNames.EndOfText;
 }
예제 #14
0
 public void deleteEventListener(EventNames name, Module mod)
 {
     eventList[name].Remove(mod);
 }
예제 #15
0
        /// <summary>
        /// Last call of the OnPacket chain(Transport -> Manager -> Socket), we will dispatch the event if there is any callback
        /// </summary>
        void ISocket.OnPacket(Packet packet)
        {
            // Some preprocessing of the packet
            switch (packet.SocketIOEvent)
            {
            case SocketIOEventTypes.Connect:
                if (this.Manager.Options.ServerVersion != SupportedSocketIOVersions.v3)
                {
                    this.Id = this.Namespace != "/" ? this.Namespace + "#" + this.Manager.Handshake.Sid : this.Manager.Handshake.Sid;
                }
                else
                {
                    var data = JSON.Json.Decode(packet.Payload) as Dictionary <string, object>;
                    this.Id = data["sid"].ToString();
                }
                this.IsOpen = true;
                break;

            case SocketIOEventTypes.Disconnect:
                if (IsOpen)
                {
                    IsOpen = false;
                    EventCallbacks.Call(EventNames.GetNameFor(SocketIOEventTypes.Disconnect), packet);
                    Disconnect();
                }
                break;

            // Create an Error object from the server-sent json string
            case SocketIOEventTypes.Error:
                bool   success = false;
                object result  = JSON.Json.Decode(packet.Payload, ref success);
                if (success)
                {
                    var   errDict = result as Dictionary <string, object>;
                    Error err     = null;

                    if (errDict != null)
                    {
                        object tmpObject = null;
                        string code      = null;
                        if (errDict.TryGetValue("code", out tmpObject))
                        {
                            code = tmpObject.ToString();
                        }

                        int errorCode;
                        if (code != null && int.TryParse(code, out errorCode) && errorCode >= 0 && errorCode <= 7)
                        {
                            errDict.TryGetValue("message", out tmpObject);
                            err = new Error((SocketIOErrors)errorCode, tmpObject != null ? tmpObject.ToString() : string.Empty);
                        }
                    }

                    if (err == null)
                    {
                        err = new Error(SocketIOErrors.Custom, packet.Payload);
                    }

                    EventCallbacks.Call(EventNames.GetNameFor(SocketIOEventTypes.Error), packet, err);

                    return;
                }
                break;
            }

            // Dispatch the event to all subscriber
            EventCallbacks.Call(packet);

            // call Ack callbacks
            if ((packet.SocketIOEvent == SocketIOEventTypes.Ack || packet.SocketIOEvent == SocketIOEventTypes.BinaryAck) && AckCallbacks != null)
            {
                SocketIOAckCallback ackCallback = null;
                if (AckCallbacks.TryGetValue(packet.Id, out ackCallback) &&
                    ackCallback != null)
                {
                    try
                    {
                        ackCallback(this, packet, this.AutoDecodePayload ? packet.Decode(Manager.Encoder) : null);
                    }
                    catch (Exception ex)
                    {
                        HTTPManager.Logger.Exception("Socket", "ackCallback", ex);
                    }
                }

                AckCallbacks.Remove(packet.Id);
            }
        }
 /// <summary>
 /// Invoked when none of the transitions for the current state have a trigger event matching the current event type
 /// </summary>
 protected void InvalidTransition()
 {
     throw new UnexpectedEventException(this,
                                        (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                        (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));
 }
예제 #17
0
 /// <summary>
 /// Emits an internal packet-less event to the user level.
 /// </summary>
 void ISocket.EmitEvent(SocketIOEventTypes type, params object[] args)
 {
     (this as ISocket).EmitEvent(EventNames.GetNameFor(type), args);
 }
        /// <summary>
        /// Invoked to execute the state machine.
        /// </summary>
        /// <param name="e">Provides an optional event type to post at normal priority before starting execution</param>
        /// <exception cref="System.InvalidOperationException">Thrown if an event is chosen for
        /// execution and no transition from the current state maches the event.
        /// </exception>
        /// <exception cref="EnteredErrorStateException">Thrown if execution enters an error state</exception>
        /// <remarks>
        /// The state machine runs until one of the following conditions is met:
        /// - There are no remaining events to process
        /// - A stop or error state is entered
        /// - An event is encountered and no transition matches the event type
        /// - An action raises an exception
        /// For each state, the next event to be processed is chosen from the head of the
        /// internal event queue, and if no event is found, then the external event queue.
        /// </remarks>
        public void Execute(int?e)
        {
            if (e.HasValue)
            {
                PostNormalPriorityEvent(e.Value);
            }

            switch (ExecutionState)
            {
            case ExecutionStates.Idle:
                ExecutionState = ExecutionStates.Executing;

                while (StateClassifications[CurrentState] == StateTypes.Normal && (CurrentEvent = GetNextEvent()).HasValue)
                {
                    EventTrace.Add(new EventTraceInstance(CurrentState, CurrentEvent.Value));
                    Transition <Action> transition = Transitions[CurrentState, CurrentEvent.Value];
                    foreach (Action a in transition.Actions)
                    {
                        try
                        {
                            a();
                        }
                        catch (UnexpectedEventException)
                        {
                            throw;
                        }
                        catch (Exception exc)
                        {
                            ExecutionState = ExecutionStates.Exception;
                            throw new ActionRaisedException(this,
                                                            (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()),
                                                            exc);
                        }
                    }
                    CurrentState = transition.NextState;
                }

                if (StateClassifications[CurrentState] == StateTypes.Error)
                {
                    ExecutionState = ExecutionStates.Errored;
                    throw new EnteredErrorStateException(this,
                                                         (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                                         (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));
                }

                ExecutionState = ExecutionStates.Idle;
                return;

            case ExecutionStates.Errored:
            case ExecutionStates.Exception:
                throw new EnteredErrorStateException(this,
                                                     (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                                     (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));

            case ExecutionStates.Executing:
            case ExecutionStates.Finished:
                return;

            default:
                throw new NotImplementedException();
            }
        }
예제 #19
0
파일: Socket.cs 프로젝트: Smoothstep/VRChat
        public void On(SocketIOEventTypes type, SocketIOCallback callback)
        {
            string eventName = EventNames.GetNameFor(type);

            EventCallbacks.Register(eventName, callback, false, this.AutoDecodePayload);
        }
예제 #20
0
 void IManager.EmitEvent(SocketIOEventTypes type, params object[] args)
 {
     ((IManager)this).EmitEvent(EventNames.GetNameFor(type), args);
 }
예제 #21
0
 private void SpellChecker_EndOfText(object sender, EventArgs e)
 {
     _lastEvent = EventNames.EndOfText;
 }
예제 #22
0
        private void OnCommencing(object sender, EventArgs e)
        {
            dataToWriteToDb = null;
            // sanitise the variable names and remove duplicates
            IModel        zone          = Apsim.Parent(this, typeof(Zone));
            List <string> variableNames = new List <string>();

            if (VariableNames != null)
            {
                for (int i = 0; i < this.VariableNames.Length; i++)
                {
                    // each variable name is now a GrazeFoodStoreType
                    bool isDuplicate = StringUtilities.IndexOfCaseInsensitive(variableNames, this.VariableNames[i].Trim()) != -1;
                    if (!isDuplicate && this.VariableNames[i] != string.Empty)
                    {
                        if (this.VariableNames[i].StartsWith("["))
                        {
                            variableNames.Add(this.VariableNames[i]);
                        }
                        else
                        {
                            string[] splitName = this.VariableNames[i].Split('.');
                            if (splitName.Count() == 2)
                            {
                                // get specified grazeFoodStoreType
                                grazeStore = Resources.GetResourceItem(this, typeof(GrazeFoodStore), splitName[0], OnMissingResourceActionTypes.Ignore, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType;

                                // make each pool entry
                                for (int j = 0; j <= 12; j++)
                                {
//                                    variableNames.Add(splitName[0] + "-" + j.ToString() + "-" + splitName[1]);
                                    variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".Pool(" + j.ToString() + ")." + splitName[1] + " as " + splitName[0] + "" + j.ToString() + "" + splitName[1]);
                                }
                                if (splitName[1] == "Amount")
                                {
                                    // add amounts
                                    variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".Amount as TotalAmount");
                                    variableNames.Add("[Resources].GrazeFoodStore." + splitName[0] + ".KilogramsPerHa as TotalkgPerHa");
                                }
                            }
                            else
                            {
                                throw new ApsimXException(this, "Invalid report property. Expecting full property link or GrazeFoodStoreTypeName.Property");
                            }
                        }
                    }
                }
                // check if clock.today was included.
                if (!variableNames.Contains("[Clock].Today"))
                {
                    variableNames.Insert(0, "[Clock].Today");
                }
            }
            // Tidy up variable/event names.
            VariableNames = variableNames.ToArray();
            VariableNames = TidyUpVariableNames();
            EventNames    = TidyUpEventNames();
            this.FindVariableMembers();

            // Subscribe to events.
            if (EventNames == null || EventNames.Count() == 0)
            {
                events.Subscribe("[Clock].CLEMHerdSummary", DoOutputEvent);
            }
            else
            {
                foreach (string eventName in EventNames)
                {
                    if (eventName != string.Empty)
                    {
                        events.Subscribe(eventName.Trim(), DoOutputEvent);
                    }
                }
            }
        }
예제 #23
0
 private void SpellChecker_ReplacedWord(object sender, ReplaceWordEventArgs e)
 {
     _lastReplaceEvent = e;
     _lastEvent = EventNames.ReplacedWord;
 }
예제 #24
0
 public EventInfo(EventNames eventName, ActionParams action)
 {
     this.eventName = eventName;
     this.action    = action;
 }