예제 #1
0
        /*
         * Возвращает партисипанта с id =
         * -1 при проблемах с соединением с сервером,
         * -2 при отсутствии доступа,
         * -3 при неправильном адресе запроса,
         * -4 при другой ошибке сервера
         */
        public Participant Register(ParticipantRegistrationRequest registrationInfo)
        {
            string registration_json     = JsonConvert.SerializeObject(registrationInfo);
            HttpResponseMessage response = netManager.SendRegistrationRequestAsync(registration_json);

            if (response == null)
            {
                UnityEngine.Debug.Log("Unseccessfull http GetParticipant request. Troubles with connection");
                return(new Participant(-1));
            }

            if (response.IsSuccessStatusCode)
            {
                string responseBody = response.Content.ReadAsStringAsync().Result;
                UnityEngine.Debug.Log("Get Participant from server (after registration): \n" + responseBody);
                var         jpart = JObject.Parse(responseBody);
                Participant part  = jpart.ToObject <Participant>();
                return(part);
            }
            else
            {
                UnityEngine.Debug.Log("Unseccessfull http registration request. StatusCode : " + response.StatusCode);
                switch (response.StatusCode)
                {
                case System.Net.HttpStatusCode.Unauthorized:
                    return(new Participant(-2));

                case System.Net.HttpStatusCode.NotFound:
                    return(new Participant(-3));

                default:
                    return(new Participant(-4));
                }
            }
        }
예제 #2
0
        public ParticipantRegistrationRequest GetRegistrationInfo()
        {
            DateTime birth_date = GetBirthDate();

            ParticipantRegistrationRequest res = new ParticipantRegistrationRequest(birth_date, GenderDropdown.GetComponent <TMP_Dropdown>().captionText.text,
                                                                                    NationalityInputField.text, AdditionInformationInputField.text);

            return(res);
        }
예제 #3
0
        public void OnRegistrationSend()
        {
            ParticipantRegistrationCanvasController registrationCanvasController = canvasManager.GetParticipantRegistrationCanvasController();
            ParticipantRegistrationRequest          registrationInfo             = registrationCanvasController.GetRegistrationInfo();
            Participant res = dataManager.Register(registrationInfo);

            switch (res.ParticipantId)
            {
            case -1:
                applicationView.ShowNotificationMessage("Неудачная попытка регистрации испытуемого. Отсутствует соединение с сервером. Обращайтесь к администратору системы.");
                break;

            case -2:
                applicationView.ShowNotificationMessage("Неудачная попытка регистрации испытуемого. Недостаточно прав. Обращайтесь к администратору системы.");
                break;

            case -3:
            case -4:
                applicationView.ShowNotificationMessage("Неудачная попытка регистрации испытуемого. Внутренняя ошибка сервера. Обращайтесь к администратору системы.");
                break;

            default:
                if (!res.IsFemale())
                {
                    canvasManager.GetParticipantInExperimentCanvasController().HidePeriod();
                }
                else
                {
                    canvasManager.GetParticipantInExperimentCanvasController().ShowPeriod();
                }

                canvasManager.GetParticipantInExperimentCanvasController().SetParticipantId(res.ParticipantId);
                applicationView.ShowNotificationMessage("Ваш ID : " + res.ParticipantId + ". Запишите его, чтобы, при повторной работе с системой, авторизоваться с его помощью.");
                experimentManager.SetParticipantId(curr_identifying_participant, res.ParticipantId);
                applicationView.OpenScreen(ScreenType.ParticipantInExperimentMenu);
                break;
            }
        }