Example #1
0
        public static Student GetStudentPersonalInfo()
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.studentGetPersonalInfo);

            sw.WriteLine(ClientJsonConverter.GetStudentPersonalInfoRequestJson(
                             connectionInfo));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(null);
            }
            Student student = ClientJsonConverter.GetStudentPersonalInfo(
                jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(student);
        }
Example #2
0
        public static IList <Score> GetTeacherCourseGrades(Course course)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.teacherGetCourseGrades);

            sw.WriteLine(ClientJsonConverter.GetCourseGradesRequestJson(
                             connectionInfo, course));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(null);
            }
            IList <Score> grades = ClientJsonConverter.
                                   GetCourseGradesFromResponse(jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(grades);
        }
Example #3
0
        public static bool GetTeacherCourseGrades(IList <Score> grades)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.teacherUpdateCourseGrades);

            sw.WriteLine(ClientJsonConverter.GetCourseGradesUpdateRequestJson(
                             connectionInfo, grades));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(false);
            }
            ServerResponse serverResponse = ClientJsonConverter.GetServerResponse(
                jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(serverResponse.Result == ServerResponse.success);
        }
Example #4
0
        public static IList <Course> GetCoursesToChoose()
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.studentGetCourseToChoose);

            sw.WriteLine(ClientJsonConverter.GetCoursesToChooseRequestJson(
                             connectionInfo));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(null);
            }
            IList <Course> courses = ClientJsonConverter.
                                     GetCoursesToChooseFromResponse(jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(courses);
        }
Example #5
0
        public static RoomInfo GetRoomInfo(Room room)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.getRoomInfo);

            sw.WriteLine(ClientJsonConverter.GetRoomInfoRequestJson(
                             connectionInfo, room));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(null);
            }
            RoomInfo resultRoom = ClientJsonConverter.GetRoomInfoFromResponse(
                jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(resultRoom);
        }
Example #6
0
        public static bool Login(UserAccount userAccount)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            string s = ClientJsonConverter.GetLoginRequestJson(userAccount);

            sw.WriteLine(ClientJsonConverter.GetLoginRequestJson(userAccount));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(false);
            }
            ConnectionInfo connectionInfo = ClientJsonConverter.GetLoginFromResponse(
                jsonResponse);

            if (connectionInfo != null)
            {
                GlobalSession = connectionInfo.Session;
            }

            ns.Close();
            tcpClient.Close();
            return(connectionInfo != null);
        }
Example #7
0
        public static bool UpdatePassword(UserAccount userAccount)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.updatePassword);

            sw.WriteLine(ClientJsonConverter.GetPasswordUpdateRequestJson(
                             connectionInfo, userAccount));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(false);
            }
            ServerResponse serverResponse = ClientJsonConverter.GetServerResponse(jsonResponse);

            ns.Close();
            tcpClient.Close();
            return(serverResponse.Result == ServerResponse.success);
        }
Example #8
0
        public static bool IsRequestSuccessful(string jsonResponse)
        {
            ServerResponse serverResponse = ClientJsonConverter.
                                            GetServerResponse(jsonResponse);

            return(serverResponse.Result == ServerResponse.success);
        }
Example #9
0
        public static bool InsertStudentCourse(Score score)
        {
            TcpClient     tcpClient = new TcpClient("127.0.0.1", 6666);
            NetworkStream ns        = tcpClient.GetStream();
            StreamReader  sr        = new StreamReader(ns);
            StreamWriter  sw        = new StreamWriter(ns);

            ConnectionInfo connectionInfo = new ConnectionInfo(GlobalSession,
                                                               ConnectionInfo.studentInsertCourse);

            sw.WriteLine(ClientJsonConverter.GetStudentInsertCourseRequestJson(
                             connectionInfo, score));
            sw.Flush();
            string jsonResponse = sr.ReadLine();

            if (!IsRequestSuccessful(jsonResponse))
            {
                return(false);
            }

            ns.Close();
            tcpClient.Close();
            return(true);
        }