예제 #1
0
        private static void ___AddOrUpdate_PeerProfile(PeerDataMessage pdm)
        {
            try
            {
                PeerProfile pp = JsonConvert.DeserializeObject <PeerProfile>((string)pdm.hData[KW.Params]);
                pp.IpAddress = pdm.packet.IpAddress;    // Get Real IP Address
                PeerProfile pp_now = null;

                lock (hPeerProfile.SyncRoot)
                {
                    if (hPeerProfile.Contains(pp.PeerID))
                    {
                        pp_now = (PeerProfile)hPeerProfile[pp.PeerID];

                        pp_now.TotalProfile = pp.TotalProfile;
                        pp_now.Version      = pp.Version;
                        pp_now.UpdateTime   = pp.UpdateTime;

                        that.DebugAndLog("Update Existing PeerProfile ID=" + pp.PeerID);
                        pp = null;      // Dispose Memory
                    }
                    else
                    {
                        hPeerProfile[pp.PeerID] = pp;   // Link this memory to hPeerProfile
                        that.DebugAndLog("Add New PeerProfile ID=" + pp.PeerID);
                    }
                }
            }
            catch (Exception ex)
            {
                that.DebugAndLog("Invalid JSON->PeerProfile: " + ex.Message);
            }
        }
예제 #2
0
        private void RefreshPeerProfile()
        {
            lvwPeerProfile.SuspendLayout();

            lvwPeerProfile.GridLines = true;
            lvwPeerProfile.Columns.Clear();
            lvwPeerProfile.Columns.Add("colHost", "Host Name", 50);
            lvwPeerProfile.Columns.Add("colIpAddress", "IP Address", 50);
            lvwPeerProfile.Columns.Add("colVersion", "Software Version", 50);
            lvwPeerProfile.Columns.Add("colTotalMovieProfile", "Total Movie Profile", 50);
            lvwPeerProfile.Columns.Add("colRemark", "Remark", 50);

            string[] k = new string[P2P.hPeerProfile.Keys.Count];
            P2P.hPeerProfile.Keys.CopyTo(k, 0);
            PeerProfile pp = null;

            for (int i = 0; i < k.Length; i++)
            {
                string PeerID = k[i];
                lock (P2P.hPeerProfile.SyncRoot)
                {
                    if (P2P.hPeerProfile.Contains(PeerID))
                    {
                        pp = (PeerProfile)P2P.hPeerProfile[PeerID];
                    }
                    else
                    {
                        continue;
                    }
                }
                ListViewItem itm = new ListViewItem(new string[] {
                    pp.HostName,
                    pp.IpAddress,
                    pp.Version,
                    pp.TotalProfile.ToString(),
                    ""
                });
                lvwPeerProfile.Items.Add(itm);
            }

            lvwPeerProfile.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

            lvwPeerProfile.ResumeLayout();
        }
예제 #3
0
        //--------------------------------------- Public Method
        public static bool Initialize()
        {
            zLog.Write("P2P->Initialize(): Create UdpService on Port=" + P2P_PORT.ToString());
            P2P.UDP = new ptkUdpService(P2P_PORT);
            zLog.Write("Create UdpService: " + ((P2P.UDP.IsReady)?("Success"):("Fail!!!")));

            if (P2P.UDP.IsReady)
            {
                P2P.UDP.OnPacketUdpArrival += new WhenPacketUdpArrival(_OnPacketUdpAttrival);

                P2P.thrProcessDataMessage              = new Thread(new ThreadStart(_ThreadProcess_DataMessage));
                P2P.thrProcessDataMessage.Name         = "P2P.ProcessDataMessage";
                P2P.thrProcessDataMessage.IsBackground = true;
                P2P.thrProcessDataMessage.Priority     = ThreadPriority.AboveNormal;
                P2P.thrProcessDataMessage.Start();

                P2P.myProfile = new PeerProfile(
                    System.Environment.MachineName,
                    "255.255.255.255",
                    that.VersionOnly(),
                    0
                    );

                P2P.thrSendPeerProfile              = new Thread(new ThreadStart(_ThreadSendPeerProfile));
                P2P.thrSendPeerProfile.Name         = "P2P.SendPeerProfile";
                P2P.thrSendPeerProfile.IsBackground = true;
                P2P.thrSendPeerProfile.Priority     = ThreadPriority.BelowNormal;
                P2P.thrSendPeerProfile.Start();

                return(true);
            }
            else
            {
                return(false);
            }
        }