コード例 #1
0
ファイル: Server.cs プロジェクト: xicocana/DIDA-TUPLE
        private bool BroadcastAdd(DIDATuple didaAdd)
        {
            int numberOfActiveServers = 1;
            int numberOfAcknowledge   = 1;

            string mypath     = System.Reflection.Assembly.GetEntryAssembly().Location;
            string finalpath  = mypath.Substring(0, mypath.Length - 13);
            string newpath    = Path.GetFullPath(Path.Combine(finalpath, @"..\..\"));
            string pathToList = newpath + "ListaServers.txt";

            string[] lines = System.IO.File.ReadAllLines(pathToList);

            foreach (string line in lines)
            {
                //port : name : priority
                string[] args        = line.Split(':');
                int      server_port = Int32.Parse(args[0]);
                string   server_name = args[1];

                if (didaAdd.getName() != server_name)
                {
                    try
                    {
                        string           url         = "tcp://localhost:" + server_port + "/" + server_name;
                        TcpClientChannel channelnovo = new TcpClientChannel(server_name, null);
                        ChannelServices.RegisterChannel(channelnovo, false);
                        IServerInterface servernovo = (IServerInterface)Activator.GetObject(typeof(IServerInterface), url);

                        if (servernovo.XLBroadcastAdd(didaAdd))
                        {
                            numberOfAcknowledge++;
                        }

                        ChannelServices.UnregisterChannel(channelnovo);

                        numberOfActiveServers++;
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            return(numberOfAcknowledge >= (numberOfActiveServers / 2) + 1);
        }