示例#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)
            // {
            //
            // }
        }
示例#2
0
        public static void ScheduleRequestHandler(PacketHeader packetheader, Connection con, SchedulesRequest incomingobject)
        {
            var dev = AndroidDevice.Cache.FirstOrDefault(
                d => d.IP == ((IPEndPoint)con.ConnectionInfo.RemoteEndPoint).Address.ToString());

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

            var result = new SchedulesResult()
            {
                Serial = incomingobject.Serial, Subject = incomingobject.SubjectCode
            };

            var student = Models.Student.Cache.FirstOrDefault(x => x.Id == incomingobject.StudentId);
            var subject = Models.Subject.Cache
                          .FirstOrDefault(x => x.Code.ToLower() == incomingobject.SubjectCode.ToLower());

            if (student == null || subject == null)
            {
                result.Success      = false;
                result.ErrorMessage = $"{incomingobject.SubjectCode.ToUpper()} not found!";
            }
            else
            {
                if (!(Models.CourseSubject.Cache
                      .Any(x => x.CourseId == student?.CourseId &&
                           x.SubjectId == subject.Id)))
                {
                    result.Success      = false;
                    result.ErrorMessage = $"{incomingobject.SubjectCode.ToUpper()} is not in your course.";
                }
                else
                {
                    var schedules = Models.ClassSchedule.Cache.Where(x => x.Subject.Code == subject.Code);
                    result.Success   = true;
                    result.Schedules = new List <ClassSchedule>();
                    foreach (var sched in schedules)
                    {
                        result.Schedules.Add(new ClassSchedule()
                        {
                            ClassId     = sched.Id,
                            Instructor  = sched.Instructor,
                            Schedule    = sched.Description,
                            SubjectCode = sched.Subject.Code,
                            Room        = sched.Room,
                            Slots       = sched.Slots,
                            Enrolled    = GetEnrolled(sched.Id)
                        });
                    }
                }
            }
            result.Send(new IPEndPoint(IPAddress.Parse(dev.IP), dev.Port));
        }