コード例 #1
0
        public async Task <IEnumerable <CourseDto> > HandleAsync(GetCourses query)
        {
            var list = await _repository.GetAllAsync();

            return(list.Select(course => new CourseDto
            {
                Title = course.Title, Description = course.Description, Id = course.Id, Tags = course.Tags
            })
                   .ToList());
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: marktabz/EncodeMe
        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)
            // {
            //
            // }
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: marktabz/EncodeMe
        private async Task <Courses> _GetCourses()
        {
            if (_courses != null)
            {
                return(_courses);
            }
            if (Server == null)
            {
                await FindServer();
            }
            if (Server == null)
            {
                return(null);
            }

            var request = new GetCourses();

            Courses result = null;

            NetworkComms.AppendGlobalIncomingPacketHandler <Courses>(Courses.GetHeader(),
                                                                     (h, c, r) =>
            {
                NetworkComms.RemoveGlobalIncomingPacketHandler(Courses.GetHeader());
                result   = r;
                _courses = r;
            });

            await request.Send(new IPEndPoint(IPAddress.Parse(Server.IP), Server.Port));

            var start = DateTime.Now;

            while ((DateTime.Now - start).TotalSeconds < 17)
            {
                if (result != null)
                {
                    return(result);
                }
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
            Server = null;
            NetworkComms.RemoveGlobalIncomingPacketHandler(Courses.GetHeader());
            return(null);
        }
コード例 #4
0
        public static void GetCoursesHandler(PacketHeader packetheader, Connection connection, GetCourses incomingobject)
        {
            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 result = new Courses();

            foreach (var course in Models.Course.Cache.ToList())
            {
                result.Items.Add(new Course()
                {
                    Id   = course.Id,
                    Name = course.Acronym,
                });
            }

            result.Send(new IPEndPoint(IPAddress.Parse(dev.IP), dev.Port));
        }
コード例 #5
0
 public async Task <IActionResult> Get([FromRoute] GetCourses query)
 => Select(await Dispatcher.QueryAsync(query));