コード例 #1
0
ファイル: Server.cs プロジェクト: xicocana/DIDA-TUPLE
        private DIDATuple BroadcastRead(DIDATuple didaAdd)
        {
            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";
            DIDATuple didaRead   = null;

            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);

                        didaRead = (DIDATuple)servernovo.XLBroadcastRead(didaAdd);
                        if (didaRead != null)
                        {
                            break;
                        }

                        ChannelServices.UnregisterChannel(channelnovo);
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            return(didaRead);
        }