Exemplo n.º 1
0
        public static bool TryGetPCS(string clientOrServerId, out PCSServices.PCSServicesClient pcs)
        {
            string pcsPort = TryGetClientOrServer(clientOrServerId);

            if (pcsPort != null)
            {
                return(gRPCpuppetMasterToPCSconnetionsDictionary.TryGetValue(pcsPort, out pcs));
            }
            else
            {
                return(TryGetFirstFreePCS(clientOrServerId, out pcs));
            }
        }
Exemplo n.º 2
0
        public static bool EstablishPCSConnection(string port)
        {
            string url = "http://localhost:" + port;

            Console.WriteLine(">>> Initializing Grpc Connection for url: " + url);
            try
            {
                GrpcChannel channel = GrpcChannel.ForAddress(url);
                PCSServices.PCSServicesClient pcsClient = new PCSServices.PCSServicesClient(channel);
                gRPCpuppetMasterToPCSconnetionsDictionary.Add(port, pcsClient);

                Console.WriteLine(">>> Connections: " + gRPCpuppetMasterToPCSconnetionsDictionary.Count);
                return(true);
            }
            catch (UriFormatException)
            {
                Console.WriteLine(">>> Exception. URI format is incorrect");
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool TryGetFirstFreePCS(string clientOrServerId, out PCSServices.PCSServicesClient pcs)
        {
            string[] arrayOfPorts = gRPCpuppetMasterToPCSconnetionsDictionary.Keys.ToArray();

            if (pcsPortToServerOrClientIdDictionary.Count != 0)
            {
                foreach (string port in arrayOfPorts)
                {
                    bool portIsFree = true;
                    foreach (string pcsPort in pcsPortToServerOrClientIdDictionary.Values)
                    {
                        // PCS on 'port' is busy
                        if (port == pcsPort)
                        {
                            portIsFree = false;
                            break;
                        }
                    }

                    if (portIsFree)
                    {
                        AddNewPcsPortToServerOrClientUrlDictionary(port, clientOrServerId);
                        return(gRPCpuppetMasterToPCSconnetionsDictionary.TryGetValue(port, out pcs));
                    }
                }
            }
            else
            {
                // First Port
                AddNewPcsPortToServerOrClientUrlDictionary(arrayOfPorts.First(), clientOrServerId);
                return(gRPCpuppetMasterToPCSconnetionsDictionary.TryGetValue(arrayOfPorts.First(), out pcs));
            }

            pcs = null;
            return(false);
        }
Exemplo n.º 4
0
 public PupFrontendPCS(string URL)
 {
     channel = GrpcChannel.ForAddress(URL);
     stub    = new PCSServices.PCSServicesClient(channel);
 }