Beispiel #1
0
        public static void Start()
        {
            if (_started)
            {
                return;
            }
            _started = true;

            NetworkComms.DisableLogging();

            var serializer = DPSManager.GetDataSerializer <ProtobufSerializer>();

            NetworkComms.DefaultSendReceiveOptions = new SendReceiveOptions(serializer,
                                                                            NetworkComms.DefaultSendReceiveOptions.DataProcessors, NetworkComms.DefaultSendReceiveOptions.Options);

            PeerDiscovery.EnableDiscoverable(PeerDiscovery.DiscoveryMethod.UDPBroadcast);

            NetworkComms.AppendGlobalIncomingPacketHandler <AndroidInfo>(AndroidInfo.GetHeader(), AndroidHandler.HandShakeHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StudentInfoRequest>(StudentInfoRequest.GetHeader(), AndroidHandler.StudentInfoRequested);
            NetworkComms.AppendGlobalIncomingPacketHandler <EndPointInfo>(EndPointInfo.GetHeader(), HandShakeHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetWork>(GetWork.GetHeader(), GetWorkHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Login>(Login.GetHeader(), LoginHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Logout>(Logout.GetHeader(), LogoutHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <SchedulesRequest>(SchedulesRequest.GetHeader(), AndroidHandler.ScheduleRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <EnrollRequest>(EnrollRequest.GetHeader(), AndroidHandler.EnrollRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <RegisterStudent>(RegisterStudent.GetHeader(), AndroidHandler.RegisterStudentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <SaveWork>(SaveWork.GetHeader(), SaveWorkHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetCourses>(GetCourses.GetHeader(), AndroidHandler.GetCoursesHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <GetCoursesDesktop>(GetCoursesDesktop.GetHeader(), GetCoursesHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <Pong>(Pong.GetHeader(), PongHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <EnrollStudent>(EnrollStudent.GetHeader(), EnrollStudentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StartEnrollment>(StartEnrollment.GetHeader(), AndroidHandler.StartEnrollmentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <AddSchedule>(AddSchedule.GetHeader(), AndroidHandler.AddScheduleHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <CommitEnrollment>(CommitEnrollment.GetHeader(), AndroidHandler.CommitEnrollmentHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <StatusRequest>(StatusRequest.GetHeader(), AndroidHandler.StatusRequestHandler);
            NetworkComms.AppendGlobalIncomingPacketHandler <CancelEnrollment>(CancelEnrollment.GetHeader(), AndroidHandler.CancelEnrollmentHandler);
            //  try
            // {
            Connection.StartListening(ConnectionType.UDP, new IPEndPoint(IPAddress.Any, 0), true);
            // }
            // catch (Exception e)
            // {
            //
            // }
        }
Beispiel #2
0
        public static async void StartEnrollmentHandler(PacketHeader packetheader, Connection connection, StartEnrollment req)
        {
            var dev = AndroidDevice.Cache.FirstOrDefault(
                d => d.IP == ((IPEndPoint)connection.ConnectionInfo.RemoteEndPoint).Address.ToString());

            //Maybe do not ignore this on production
            if (dev == null)
            {
                return;
            }

            var request = Models.Request.Cache.FirstOrDefault(x => x.ReceiptNumber?.ToLower() == req.Receipt.ToLower());

            if (request == null)
            {
                request = new Request()
                {
                    StudentId     = req.StudentId,
                    ReceiptNumber = req.Receipt,
                };
                await request.SaveAsync();
            }

            if (request.StudentId == req.StudentId)
            {
                var result = new StartEnrollmentResult()
                {
                    Success       = true,
                    TransactionId = request.Id,
                    Submitted     = request.Submitted,
                };

                foreach (var item in request.Details)
                {
                    result.ClassSchedules.Add(new ClassSchedule()
                    {
                        ClassId     = item.ScheduleId,
                        Enrolled    = Models.ClassSchedule.GetEnrolled(item.ScheduleId),
                        Instructor  = item.Schedule.Instructor,
                        Schedule    = item.Schedule.Description,
                        Room        = item.Schedule.Room,
                        Slots       = item.Schedule.Slots,
                        SubjectCode = item.Schedule.Subject.Code
                    });
                }

                await result.Send(new IPEndPoint(IPAddress.Parse(dev.IP), dev.Port));
            }
            else
            {
                await new StartEnrollmentResult()
                {
                    Success      = false,
                    ErrorMessage = "OR Number is already used"
                }.Send(new IPEndPoint(IPAddress.Parse(dev.IP), dev.Port));
            }
        }