Пример #1
0
        // Loop while program is running and ping trusted nodes to determine whether they are online or offline
        // When a node comes online, distribute indexes to that node
        public void BeginIndexDistribution()
        {
            DistributionDatabase ddb = new DistributionDatabase();
            List<string> guidList = new List<string>();
            NodeDatabase ndb = new NodeDatabase();
            string online = "online";
            string offline = "offline";

            ddb.ResetStatus();

            while (distribute)
            {
                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID))
                    {
                        Thread.Sleep(1000);
                        ddb.InsertNode(currentGUID, offline);
                        if (ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                        {
                            Ping pingSender = new Ping();
                            int timeout = 100;
                            try
                            {
                                IPAddress ip = ndb.SelectNodeIp(Guid.Parse(currentGUID));
                                PingReply reply = pingSender.Send(ip, timeout);

                                if (reply.Status == IPStatus.Success)
                                {
                                    if (ddb.GetStatus(currentGUID) == offline)
                                    {
                                        sendIndexes(currentGUID);
                                        ddb.UpdateStatus(currentGUID, online);
                                    }
                                }
                                else
                                {
                                    ddb.UpdateStatus(currentGUID, offline);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.Print(ex.Message);
                            }
                        }
                        else
                        {
                            ddb.UpdateStatus(currentGUID, offline);
                        }
                    }
                }
            }
        }