Ejemplo n.º 1
0
        private static void HandleInitialize(ClientInitialize msg)
        {
            try
            {
                var address = msg.Options[Globals.E4_SERVER_ADDRESS].String;
                var port    = Convert.ToInt32(msg.Options[Globals.E4_SERVER_PORT].Double);
                var e4id    = msg.Options[Globals.E4_ID].String;

                // reconnect according to provided options, closes current connection
                provider?.Close();

                provider = new EmpaticaProvider(address, port);
                provider.Initialize(e4id);

                Send(new ClientInitialized
                {
                    Modifications = new List <string>
                    {
                        Globals.EDA_ID,
                        Globals.HEART_RATE_ID,
                        Globals.TEMPERATURE_ID
                    }
                }.ToJson());
            }
            catch (Exception e)
            {
                // initialization failed
                Console.Error.WriteLineAsync(e.Message);

                provider = null;
                Send(new ClientInitialized {
                    Modifications = new List <string>()
                }.ToJson());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Automatically initializes all modifications (no dependencies on options)
        /// </summary>
        /// <param name="msg"></param>
        private static void HandleInitialize(ClientInitialize msg)
        {
            var mods = new List <string>();

            mods.AddRange(AudioProvider.AudioFiles.Select(a => a.Id));
            mods.Add(SwapMouseClicks.MODIFICATION_ID);

            Send(new ClientInitialized {
                Modifications = mods
            }.ToJson());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles incoming messages from SHF.
        /// </summary>
        private static void OnMessage(object sender, MessageEventArgs e)
        {
            if (!e.IsText)
            {
                return;
            }

            switch (JObject.Parse(e.Data)["type"].ToObject <string>())
            {
            case "Client.Initialize":
                HandleInitialize(ClientInitialize.FromJson(e.Data));
                return;

            case "Execution.StartRequest":
                HandleExecutionRequest(ExecutionStartRequest.FromJson(e.Data));
                return;

            default:
                return;
            }
        }