コード例 #1
0
ファイル: Fop2Client.cs プロジェクト: KeenSystemsNL/Fop2DD
        /// <summary>
        /// Extracts the current ID (or "myposition", "position", "button id") from a zbuttons message
        /// </summary>
        /// <param name="message">The message to extract</param>
        /// <remarks>
        /// This was straight lifted from fop2.js and then refactored/rewritten to C#. The exact inner working is not entirely clear
        /// hence the somewhat "unclear" variablenames. Feel free to refactor away; removing this function entirely would be preferred.
        /// </remarks>
        private int ExtractCurrentId(Fop2Message message)
        {
            var lines = message.Data.Split('\n');

            for (var x = 0; x < lines.Length; x++)
            {
                var linedata    = lines[x].Split('!');
                var numberparts = linedata[0].Split('@');
                for (var s = 0; s < linedata.Length; s++)
                {
                    var parts = linedata[s].Split(new[] { '=' }, 2);
                    if ((parts[0] != string.Empty) && (parts.Length >= 2) && (parts[0].Equals("EXTENSION", StringComparison.OrdinalIgnoreCase)) && (parts[1].Equals(this.Username, StringComparison.OrdinalIgnoreCase)))
                    {
                        int id;
                        if (int.TryParse(numberparts[0], out id))
                        {
                            return(id);
                        }
                    }
                }
            }
            //We should have an "Id" (position) by now and exited
            throw new Exception("Error parsing Id (position) from zbuttons response");

            #region Original code (for reference)
            //var lineas = textReader.readToEnd().split("\n");
            //for (var x = 0; x < lineas.length; x++) {
            //    var pepe = lineas[x].split("!");
            //    var nritoPartes = pepe[0].split("@");
            //    var nrito = nritoPartes[0];
            //    for (var s = 0; s < pepe.length; s++) {
            //        var partos = pepe[s].split("=", 2);
            //        if (partos[0] !== "") {
            //          ...
            //                botonitos[nrito][partos[0]] = partos[1];
            //                if (partos[0] == "EXTENSION") {
            //                    extenpos[partos[1]] = nrito;
            //                    if (partos[1] == $('myextension').value) {
            //                        myposition = nrito
            //                    }
            //                }
            //        }
            //    }
            //}
            #endregion
        }
コード例 #2
0
ファイル: Fop2Client.cs プロジェクト: KeenSystemsNL/Fop2DD
        /// <summary>
        /// Internal method to check is an "auth" message returned an "incorrect" (e.g. authentication failed) message or otherwise.
        /// </summary>
        /// <param name="parsedmessage">The message to determine the auth result from.</param>
        private void CheckAuthResult(Fop2Message parsedmessage)
        {
            AuthenticationStatus status = AuthenticationStatus.Failed;

            //We're checking already, do not check again
            _checkauthresult = false;
            //Check the actual result
            if (parsedmessage.Command.Equals("incorrect", StringComparison.OrdinalIgnoreCase))
            {
                //Nope, authentication failed
                this.ResetState();


                if (this.AuthenticationResultReceived != null)
                {
                    this.AuthenticationResultReceived(this, new AuthenticationResultReceivedEventArgs(AuthenticationStatus.Failed));
                }
            }
            else
            {
                //Authentication is OK, invoke our authok-callback
                if (_authokcallback != null)
                {
                    _authokcallback.Invoke();
                    _authokcallback = null;
                }

                //Start heartbeat
                this.SendPing();

                status = AuthenticationStatus.Success;
            }

            //Notify subscribers about the authentication status
            if (this.AuthenticationResultReceived != null)
            {
                this.AuthenticationResultReceived(this, new AuthenticationResultReceivedEventArgs(status));
            }
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new MessageReceivedEventArgs.
 /// </summary>
 /// <param name="message">Message that was received.</param>
 internal MessageReceivedEventArgs(Fop2Message message)
 {
     this.Message = message;
 }