/// <summary>
 /// Register a computer
 /// </summary>
 /// <param name="serverInfos">The information of the computer.</param>
 /// <param name="ip">The IP address of the computer.</param>
 /// <param name="port">The port number.</param>
 /// <returns>True if success or False if fail</returns>
 public static bool Register(ServiceInfos serverInfos, string ip, int port, int id)
 {
     try
     {
         IPEndPoint ipEnd = new IPEndPoint(IPAddress.Parse(ip),port);
         subscribers.Add(new Tuple<Tuple<ServiceInfos, IPEndPoint>, int> (new Tuple<ServiceInfos, IPEndPoint>(serverInfos, ipEnd), id));
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 2
0
 public Echo()
 {
     InitializeComponent();
     config = new Configuration(new setCatalogueInfo(setCataloguePortAndAdress));
     Dictionary<string, List<Type>>  param = new Dictionary<string, List<Type>>() {
         {"echo",
             new List<Type>() {
                 typeof(string), //prend une chaîne en entrée
                 typeof(string) }} //retourne une chaîne
     };
     myInfos = new ServiceInfos(param, service);
     port_local = port_local_default;
     port_catalogue = port_catalogue_default;
     adresse_catalogue = adresse_catalogue_default;
 }
Exemplo n.º 3
0
 //Retourner tous les services disponibles dans le catalogue
 private void loadServerList(List<string> serviceNames, 
     List<List<string>> operationNames,
     List<List<List<Type>>> typeForOperations,
     List<string> ipAdresses,
     List<string> portValues)
 {
     clearList();
     initKnownServices();
     for (int i = 0; i < serviceNames.Count; i++) {
         Dictionary<string, List<Type>> operations = new Dictionary<string, List<Type>>();
         int noOperation = 0;
         foreach (string operationName in operationNames[i]) {
             List<Type> typeForOperation = typeForOperations[i][noOperation];
             operations.Add(operationName, typeForOperation);
             noOperation++;
         }
         ServiceInfos si = new ServiceInfos(operations, serviceNames[i]);
         knownServices.Add(si);
         addRowToList(new object[] { false, ipAdresses[i], portValues[i], serviceNames[i] });
     }
 }
Exemplo n.º 4
0
 internal static void send(string service, string operation, List<string> param)
 {
     int iStamp= queryNumber++;
     string stamp = iStamp.ToString();
     ServiceInfos ks = null;
     foreach (ServiceInfos ks_ in knownServices) {
         if(ks_.Service == service) {
             ks = new ServiceInfos(new Dictionary<string, List<Type>>() { { operation, ks_.Operation[operation] } }, service);
             break;
         }
     }
     queries.Add(iStamp, ks);
     string address = DataUtils.GetIPaddresses(System.Net.Dns.GetHostName())[0];
     if (!mySelf.Send(address, service, operation, stamp, param)) {
         mySelf.Disconnect();
         MessageBox.Show("Le serveur sur lequel vous étiez connecté s'est arrêté.",
                         "Attention",
                         MessageBoxButtons.OK);
         if (request != null)
             if (request.Visible)
                 request.Close();
     }
 }
Exemplo n.º 5
0
 internal static void send(string service, string operation, List<string> param)
 {
     //convertir param en byte[][]
     int iStamp;
     if (emptyQueryNumbers.Count > 0)
         iStamp = emptyQueryNumbers[0];
     else
         iStamp = queryNumber++;
     string stamp = iStamp.ToString();
     ServiceInfos ks = null;
     foreach (ServiceInfos ks_ in knownServices) {
         if(ks_.Service == service) {
             ks = new ServiceInfos(new Dictionary<string, List<Type>>() { { operation, ks_.Operation[operation] } }, service);
             break;
         }
     }
     queries.Add(iStamp, ks);
     mySelf.Send(service, operation, stamp, new byte[][] {});
 }
        public static List<string> IRegister(List<string> param)
        {
            Dictionary<string, List<Type>> dico = new Dictionary<string, List<Type>>();

            string title = param[1];

            List<string> operationNames = new List<string>();
            List<List<Type>> typeForOperations = new List<List<Type>>();

            string[] operations = title.Split('_');

            int noOperation = 0;
            foreach (string operation in operations) {
                string operationName = "";
                int charAt = 0;
                do {
                    operationName += operation[charAt++];
                }
                while (operation[charAt] != '(');
                charAt++;
                operationNames.Add(operationName);

                typeForOperations.Add(new List<Type>());
                do {
                    string typeParamIn = "";
                    do {
                        typeParamIn += operation[charAt];
                        charAt++;
                        if (operation[charAt] == ')')
                            break;
                    }
                    while (operation[charAt] != ',');

                    typeForOperations[noOperation].Add(DataUtils.GetType(typeParamIn));
                }
                while (operation[charAt] != ')');
                charAt++;
                //on est sur le type de retour
                string typeRetour = "";
                do {
                    typeRetour += operation[charAt++];
                }
                while (charAt < operation.Length);
                typeForOperations[noOperation].Add(DataUtils.GetType(typeRetour));
                noOperation++;
            }

            for (int i = 0; i < operationNames.Count; i++) {
                dico.Add(operationNames[i], typeForOperations[i]);
            }
            string service = param[0];
            string address = param[2];
            string port = param[3];
            ServiceInfos si = new ServiceInfos(dico, service);

            Register(si, address, int.Parse(port), int.Parse(param[4]));
            return null;
        }