Example #1
0
        // Send indexes to a specific node
        // Use after a node comes online
        public void sendIndexes(string guid)
        {
            NodeDatabase ndb = new NodeDatabase();
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                Guid myGuid = Node.GetGuid();
                TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(guid))).ToString(), 7890);
                ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                ct.EnqueueWork(pir);
                NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                while (ct.IsWorking())
                {
                    Thread.Sleep(1000);
                }
                ct.RequestStop();
                while (ct.IsAlive())
                {
                    Thread.Sleep(1000);
                }
            }
        }
Example #2
0
        // Send indexes to all trusted nodes that are online
        // For use after a backup and associated index insertion have occurred
        public void sendIndexes()
        {
            IndexDatabase idd = new IndexDatabase();
            if (!idd.TablesEmpty()) //if there are indexes to send
            {
                DistributionDatabase ddb = new DistributionDatabase();
                List<string> guidList = new List<string>();
                NodeDatabase ndb = new NodeDatabase();

                string online = "online";
                string indexDBCopy = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\indexes_" + (Properties.Settings.Default.guid).ToString() + ".s3db";

                if (System.IO.File.Exists(idd.GetPathFileName()))
                {
                    try
                    {
                        System.IO.File.Copy(idd.GetPathFileName(), indexDBCopy, true);
                    }
                    catch (System.IO.IOException e)
                    {
                        Debug.Print(e.Message);
                    }
                }

                guidList = ndb.SelectGUID();

                foreach (string currentGUID in guidList)
                {
                    if (Node.GetGuid() != Guid.Parse(currentGUID) && ddb.GetStatus(currentGUID) == online && ndb.SelectNodeTrusted(Guid.Parse(currentGUID)) == "yes")
                    {
                        Guid myGuid = Node.GetGuid();
                        TcpClient tcpClient = new TcpClient((ndb.SelectNodeIp(Guid.Parse(currentGUID))).ToString(), 7890);
                        ClientThread ct = new ClientThread(tcpClient, false, myGuid);
                        PushIndexRequest pir = new PushIndexRequest(indexDBCopy, new FileInfo(indexDBCopy).Length);
                        ct.EnqueueWork(pir);
                        NetworkResponse response = (NetworkResponse)ct.DequeueEvent();
                        while (ct.IsWorking())
                        {
                            Thread.Sleep(1000);
                        }
                        ct.RequestStop();
                        while (ct.IsAlive())
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
        }