public void ClientContinue()
 {
     if (currentPinTested == PINS_PER_PARTICIPANT)
     {
         return;
     }
     LoggingClass.AppendToLog(LoggingClass.ENTRY_START, null, null, null, null, null);
     ChangeClientMode(TechniqueClientController.ModeType.Entering);
 }
Exemplo n.º 2
0
 private static void CheckHtml()
 {
     if (HtmlParts.Length != 2)
     {
         Logmsg = "Exeption: Wrong html, something wrong with <body> tag" + "\n\n";
         Console.WriteLine(Logmsg);
         LoggingClass.Log(Logmsg);
         throw new Exception();
     }
 }
 void CmdOnButtonPress(string text)
 {
     if (text == ExperimentServerController.START)
     {
         data.experimentServerController.ClientStart();
         return;
     }
     if (text == ExperimentServerController.CONTINUE)
     {
         data.experimentServerController.ClientContinue();
         return;
     }
     LoggingClass.AppendToLog(LoggingClass.BUTTON_PRESS, null, null, null, text, null);
     serverController.OnButtonPress(text);
     // TODO: remove commented line once experiment server controller knows
     // when EnteredNumbers changes
     //data.experimentServerController.DigitEntered(text);
 }
Exemplo n.º 4
0
    private static (string, int) ParseRequest(string data)
    {
        Logmsg = "REQUEST: " + data + "\n\n";
        Console.Write(Logmsg);
        LoggingClass.Log(Logmsg);
        string address   = DefaultDir;
        int    ErrorCode = 0;

        if (data.Length > 0)
        {
            string ParamsLine   = data.Split('\n')[0];
            string ParamsString = ParamsLine.Split(" ")[1];

            if (ParamsString != "/") // in case "/" address = DefaultDir
            {
                address = ParamsString.Replace("/?adress=", "");
                address = Uri.UnescapeDataString(address);
            }
        }
        Logmsg = "ADDRESS: " + address + "\n\n";
        Console.Write(Logmsg);
        LoggingClass.Log(Logmsg);
        return(address, ErrorCode);
    }
    void Update()
    {
        if (!Enabled)
        {
            return;
        }


        LoggingClass.AppendToLog(
            LoggingClass.VICON,
            localCoordThing.posn.x, localCoordThing.posn.y, localCoordThing.posn.z,
            null, null);

        //
        // Calculate cursor position
        //
        var viconPos3D        = localCoordThing.posn;
        var viconPos2D        = new Vector2(viconPos3D.x, viconPos3D.y);
        var depthOffsetScalar = (viconPos3D.z - Pattern3DSharedData.minScreenZ) / Pattern3DSharedData.spacingZ;
        var depthOffsetVector = depthOffsetScalar * Pattern3DSharedData.spacingProjDepth * new Vector2(1, -1);
        var viconPosProj      = viconPos2D + depthOffsetVector;

        // FIXME TODO need new event for cursor size/color
        //textThing.text = pk.ToString();

        InvokeOnCursorPositionChanged(Util.PixelToCanvas(viconPosProj));

        // 0.5 offset to account for fact that depth offset marks
        // *boundary* of depths.
        var   depthOffsetRounded = (int)(depthOffsetScalar + 0.5f);
        Depth depth;

        switch (depthOffsetRounded)
        {
        case 0: depth = Depth.Close; break;

        case 1: depth = Depth.Middle; break;

        case 2: depth = Depth.Far; break;

        default: depth = Depth.Inactive; break;
        }

        InvokeOnCursorDepthChanged(depth);

        //
        // Calculate pin
        //
        var cellOrNull = NearestGridCell3D(localCoordThing.posn);

        if (cellOrNull == null)
        {
            return;
        }

        var gc = (int)cellOrNull;

        if (!EnteredNumbers.Contains(gc))
        {
            EnteredNumbers.Add(gc);
            InvokeOnEnteredNumbersChanged();
        }
    }
Exemplo n.º 6
0
 public void StartListening()
 {
     try
     {
         IPHostEntry ipHost     = Dns.GetHostEntry(Host);
         IPAddress   ipAddr     = ipHost.AddressList[0];
         IPEndPoint  ipEndPoint = new IPEndPoint(ipAddr, Port);
         Socket      sListener  = new Socket(ipAddr.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
         sListener.Bind(ipEndPoint);
         sListener.Listen(ClientLimit);
         while (true)
         {
             Logmsg = "Waiting for connection at " + ipEndPoint.ToString();
             Console.WriteLine(Logmsg);
             LoggingClass.Log(Logmsg);
             Socket handler = sListener.Accept();
             try // Now, after connection with client, we can catch errors and send answer about specific type of errors to client
             {
                 string data  = null;
                 byte[] bytes = new byte[BufferSize];
                 while (handler.Connected)
                 {
                     int bytesRec = handler.Receive(bytes);
                     //Enable this for debug
                     //Logmsg = "Reading " + bytesRec + " bytes \n\n";
                     //Console.WriteLine(Logmsg);
                     //LoggingClass.Log(Logmsg);
                     data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                     if (Regex.IsMatch(@data, @EndOfRequestPattern) || bytesRec < 1)
                     {
                         break;
                     }
                 }
                 (string address, int Error) = ParseRequest(data);
                 BackButton = GetBackButton(address);
                 ErrorCode  = Error;
                 if (address == "/favicon.ico" || address == "/style.css" || address == "/scripts.js")
                 {
                     SendLocalResoures(handler, address);
                 }
                 else
                 {
                     CheckHtml();
                     (FileInfo[] Files, DirectoryInfo[] Dirs) = GetFilesAndDirs(address);
                     SendAnswer(handler, Files, Dirs, BackButton);
                 }
             }
             catch (System.UnauthorizedAccessException ex)
             {
                 ErrorCode = 1;
                 Logmsg    = "Exeption: " + ex.ToString() + "\n\n";
                 Console.WriteLine(Logmsg);
                 LoggingClass.Log(Logmsg);
             }
             catch (System.IO.DirectoryNotFoundException ex)
             {
                 ErrorCode = 2;
                 Logmsg    = "Exeption: " + ex.ToString() + "\n\n";
                 Console.WriteLine(Logmsg);
                 LoggingClass.Log(Logmsg);
             }
             catch (Exception ex)
             {
                 ErrorCode = 3; //there we can also just answer with 500 code.
                 Logmsg    = "Exeption: " + ex.ToString() + "\n\n";
                 Console.WriteLine(Logmsg);
                 LoggingClass.Log(Logmsg);
             }
             if (ErrorCode > 0)
             {
                 SendWarnAnswer(handler, ErrorCode, BackButton);
             }                                                                   //make and send html with error message to client
             CloseConnection(handler);
         }
     }
     catch (Exception ex)
     {
         Logmsg = "Exeption: " + ex.ToString() + "\n\n";
         Console.WriteLine(Logmsg);
         LoggingClass.Log(Logmsg);
     }
 }
 public void ClientStart()
 {
     LoggingClass.AppendToLog(LoggingClass.ENTRY_START, null, null, null, null, null);
     ChangeClientMode(TechniqueClientController.ModeType.Entering);
 }
    private void DigitEntered()
    {
        var enteredPinString = string.Join(",", _controller.EnteredNumbers);

        SetLoggerCurrentEnteredPin(enteredPinString);
        LoggingClass.AppendToLog(LoggingClass.ENTERED_PIN_CHANGE, null, null, null, null, null);
        if (_controller.EnteredNumberCount == 4)
        {
            // TODO only in the case that feedback is enabled do we show correct or incorrect
            if (enteredPinString == CurrentCorrectPinString)
            {
                if (currentTrialForPin >= PRACTICE_TRIALS)
                {
                    ChangeClientMode(TechniqueClientController.ModeType.ContinueNoFeedback);
                }
                else
                {
                    ChangeClientMode(TechniqueClientController.ModeType.ContinueCorrect);
                }
                LoggingClass.AppendToLog(LoggingClass.ENTRY_END, null, null, null, null, true);
            }
            else
            {
                if (currentTrialForPin >= PRACTICE_TRIALS)
                {
                    ChangeClientMode(TechniqueClientController.ModeType.ContinueNoFeedback);
                }
                else
                {
                    ChangeClientMode(TechniqueClientController.ModeType.ContinueIncorrect);
                }
                LoggingClass.AppendToLog(LoggingClass.ENTRY_END, null, null, null, null, false);
            }

            // TODO use somewhere: (in the case that feedback is disabled, regardless of correctness)
            // ChangeClientMode(TechniqueClientController.ModeType.ContinueNoFeedback);

            _controller.ResetEnteredNumbers();

            currentTrialForPin++;
            SetCurrentPinTrial(currentTrialForPin);

            if (currentTrialForPin >= PRACTICE_TRIALS)
            {
                if (currentPinTested == 0)
                {
                    OnClientRoundNotification?.Invoke(TechniqueClientController.NotificationType.Round1Normal);
                }
                else
                {
                    OnClientRoundNotification?.Invoke(TechniqueClientController.NotificationType.Round2Normal);
                }
                OnClientFeedbackEnabledChanged?.Invoke(false);
            }

            // TODO when past trial rounds do this:
            // OnClientFeedbackEnabledChanged?.Invoke(false);

            if (currentTrialForPin == TOTAL_TRIALS)   //changing the current pin tested.
            {
                currentPinTested++;
                SetCurrentPin(currentPinTested);
                currentTrialForPin = 0;
                SetCurrentPinTrial(currentTrialForPin);
                if (currentPinTested == (PINS_PER_PARTICIPANT - 1))
                {
                    OnClientFeedbackEnabledChanged?.Invoke(true);
                    OnClientRoundNotification?.Invoke(TechniqueClientController.NotificationType.Round2Practice);
                }
                if (currentPinTested == PINS_PER_PARTICIPANT)
                {
                    OnClientRoundNotification?.Invoke(TechniqueClientController.NotificationType.Finished);
                }
            }

            /*
             * //Check if we want this to be the last trial for the technique
             * if (currentPinTested == (PINS_PER_PARTICIPANT - 1) && currentTrialForPin == 8)
             * {
             *  // TODO: make sure this is called when pin changes
             *  OnClientFeedbackEnabledChanged?.Invoke(true);
             *  OnClientRoundNotification?.Invoke(TechniqueClientController.NotificationType.Round2);
             *  return;
             * }
             */
        }
    }
 void CmdOnDrag(Vector2 pos)
 {
     LoggingClass.AppendToLog(LoggingClass.DRAG_MOVE, pos.x, pos.y, null, null, null);
     serverController.OnDrag(pos);
 }
 void CmdEndDrag()
 {
     LoggingClass.AppendToLog(LoggingClass.DRAG_END, null, null, null, null, null);
     serverController.OnEndDrag();
 }
 void CmdBeginDrag()
 {
     LoggingClass.AppendToLog(LoggingClass.DRAG_START, null, null, null, null, null);
     serverController.OnBeginDrag();
 }