Пример #1
0
        public TypeCheckTask(TcpClient client, List <TcpTask> currentTasks, ServerData serverData)
        {
            this.client       = client;
            this.serverData   = serverData;
            this.currentTasks = currentTasks;
            TcpHelper helper = new TcpHelper(client);

            helper.ReadJsonData(OnAuthorizeConnection);
        }
Пример #2
0
        public void OnHandleNextRequest()
        {
            TcpHelper helper = new TcpHelper(client);

            helper.ReadJsonData(OnReceivedNextRequest);
        }
Пример #3
0
        public void OnAuthorizeConnection(Datagram received)
        {
            TcpTask currentTask = null;

            if (received.DataType == DataType.Login)
            {
                var loginRequest = TcpHelper.ToConcreteType <JsonLogin>(received.Data);
                if (loginRequest.IsDoctorProgram)
                {
                    DoctorData currentUser = FindDoctorWithPassword(loginRequest.Id, loginRequest.Password);
                    if (currentUser != null)
                    {
                        DoctorTask doctorTask = new DoctorTask(client, serverData, currentUser, currentTasks);
                        currentTask = doctorTask;
                        lock (OnlineListSyncRoot)
                        {
                            currentTasks.Add(doctorTask);
                        }
                    }
                }
                else
                {
                    //moet voor client lists in server data want we voegen data toe maar lezen ook.
                    serverData.ClientListLock.EnterReadLock();
                    PatientData currentUser = FindClientWithPassword(loginRequest.Id, loginRequest.Password);
                    serverData.ClientListLock.ExitReadLock();
                    if (currentUser != null)
                    {
                        // ZORGT VOOR DEADLOCK!!!
                        PatientTask clientTask = new PatientTask(client, serverData, currentUser, currentTasks);
                        currentTask = clientTask;
                        lock (OnlineListSyncRoot)
                        {
                            currentTasks.Add(clientTask);
                        }
                    }
                }
            }

            //TcpHelper writerHelper = new TcpHelper(client);
            //dynamic response = new ExpandoObject();
            //response.DataType = DataType.Login;
            //response.Data = new ExpandoObject();

            TcpHelper writerHelper = new TcpHelper(client);
            var       response     = new Datagram();

            response.DataType = DataType.Login;
            if (currentTask != null)
            {
                response.Data = new JsonResponse
                {
                    Error   = "200",
                    Message = "LoginOK"
                };
                writerHelper.WriteJsonData(response);
                currentTask.Run();
            }
            else
            {
                response.Data = new JsonResponse
                {
                    Error   = "500",
                    Message = "LoginWrong"
                };
                writerHelper.WriteJsonData(response);
                //lets try that again
                TcpHelper helper = new TcpHelper(client);
                helper.ReadJsonData(OnAuthorizeConnection);
            }
        }