コード例 #1
0
ファイル: EncoderHandler.cs プロジェクト: marktabz/EncodeMe
        private static void GetCoursesHandler(PacketHeader packetheader, Connection connection, GetCoursesDesktop incomingobject)
        {
            var ip     = ((IPEndPoint)connection.ConnectionInfo.RemoteEndPoint).Address.ToString();
            var client = Client.Cache.FirstOrDefault(x => x.IP == ip);

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

            var result = new GetCoursesResult();

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

            result.Send(new IPEndPoint(IPAddress.Parse(client.IP), client.Port));
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: marktabz/EncodeMe
        public static async Task <GetCoursesResult> GetCoursesDesktop()
        {
            await FindServer();

            if (Server == null)
            {
                return(null);
            }

            GetCoursesResult result = null;

            NetworkComms.AppendGlobalIncomingPacketHandler <GetCoursesResult>(GetCoursesResult.GetHeader(),
                                                                              (h, c, i) =>
            {
                NetworkComms.RemoveGlobalIncomingPacketHandler(GetCoursesResult.GetHeader());
                result = i;
            });

            await new GetCoursesDesktop().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 TaskEx.Delay(TimeSpan.FromSeconds(1));
            }

            Server = null;
            NetworkComms.RemoveGlobalIncomingPacketHandler(GetCoursesResult.GetHeader());
            return(null);
        }