示例#1
0
 public void Start()
 {
     this.mySelf = SocketLibrary.Utils.CreateServer(port);
     ServerToolsEvent sta = null;
     if (!this.mySelf.Start())
         sta = new ServerToolsEvent(-1, ServerToolsEvent.typeEvent.INFORMATION, null, null);
     else
         sta = new ServerToolsEvent(0, ServerToolsEvent.typeEvent.INFORMATION, null, null);
     serverToolsReceiveEvent(this, sta);
     this.mySelf.Subscribe(HandleServerEvent);
 }
示例#2
0
        public void Start()
        {
            this.mySelf = SocketLibrary.Utils.CreateServer(port);
            ServerToolsEvent sta = null;

            if (!this.mySelf.Start())
            {
                sta = new ServerToolsEvent(-1, ServerToolsEvent.typeEvent.INFORMATION, null, null);
            }
            else
            {
                sta = new ServerToolsEvent(0, ServerToolsEvent.typeEvent.INFORMATION, null, null);
            }
            serverToolsReceiveEvent(this, sta);
            this.mySelf.Subscribe(HandleServerEvent);
        }
示例#3
0
        /// <summary>
        /// Démarrer le serveur
        /// </summary>
        public bool Start()
        {
            this.mySelf = SocketLibrary.Utils.CreateServer(port);
            ServerToolsEvent sta = null;
            bool             ret;

            if (!this.mySelf.Start())
            {
                sta = new ServerToolsEvent(-1, ServerToolsEvent.typeEvent.INFORMATION, null, null, null, -1);
                ret = false;
            }
            else
            {
                sta = new ServerToolsEvent(0, ServerToolsEvent.typeEvent.INFORMATION, null, null, null, -1);
                ret = true;
            }
            serverToolsReceiveEvent(this, sta);
            this.mySelf.Subscribe(HandleServerEvent);
            return(ret);
        }
示例#4
0
        /// <summary>
        /// Intercepter un évenement, puis créer un ServerToolsEvent correspondant à son type.
        /// </summary>
        private void HandleServerEvent(object sender, ServerEventArgs e)
        {
            ServerToolsEvent sta = null;

            switch (e.Type)
            {
            case ServerEventArgs.typeEvent.CONNEXION:
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.CONNEXION, null, null, null, -1);
                break;

            case ServerEventArgs.typeEvent.DECONNEXION:
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.DECONNEXION, null, null, null, -1);
                break;

            case ServerEventArgs.typeEvent.MESSAGE:
                Message msg = MessageUtil.decoder(e.Msg);
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.MESSAGE, msg.Operation, msg.ListParams, msg.Source, int.Parse(msg.Stamp));
                break;
            }
            serverToolsReceiveEvent(this, sta);
        }
示例#5
0
 /// <summary>
 /// Exécuter l'opération demandée, puis envoyer le résultat au client
 /// </summary>
 public void handleRequest(ServerToolsEvent e, Type type, string name)
 {
     try {
         MethodInfo mi = LibraryInterfaceServer.Utils.getMethod(e.Operation, type, OperationInfo.VisibilityType.GLOBAL);
         if (mi.GetCustomAttributes(typeof(OperationInfo), false).Count() != 0)
         {
             if (mi.GetCustomAttributes(typeof(OperationInfo), false)[0].GetType() == typeof(OperationInfo))
             {
                 OperationInfo oi = (OperationInfo)mi.GetCustomAttributes(typeof(OperationInfo), false)[0];
                 if (oi.Visibility == OperationInfo.VisibilityType.GLOBAL)
                 {
                     try {
                         e.Param.Add(e.Id.ToString());
                         MethodInfo    mib    = LibraryInterfaceServer.Utils.getMethod(oi.Func, type, OperationInfo.VisibilityType.PRIVATE);
                         List <string> result = (List <string>)mib.Invoke(null, new object[] { e.Param });
                         if (result != null)
                         {
                             Send(name, e.Source, e.Operation, e.Stamp.ToString(), result, e.Id);
                         }
                         return;
                     }
                     catch {
                         Send(name, e.Source, e.Operation, e.Stamp.ToString(), new List <string>()
                         {
                             DataUtils.BAD_PARAMETERS_CODE
                         }, e.Id);
                         return;
                     }
                 }
             }
         }
     }
     catch {
         Send(name, e.Source, e.Operation, e.Stamp.ToString(), new List <string>()
         {
             DataUtils.UNKOWN_OPERATION
         }, e.Id);
     }
 }
示例#6
0
        private void HandleServerEvent(object sender, ServerEventArgs e)
        {
            ServerToolsEvent sta = null;

            switch (e.Type)
            {
            case ServerEventArgs.typeEvent.CONNEXION:
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.CONNEXION, null, null);
                break;

            case ServerEventArgs.typeEvent.DECONNEXION:
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.DECONNEXION, null, null);
                break;

            case ServerEventArgs.typeEvent.MESSAGE:
                //Décoder opération demandée
                sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.MESSAGE, "operation", new List <byte[]>()
                {
                    new byte[] { }
                });
                break;
            }
            serverToolsReceiveEvent(this, sta);
        }
 private void handleIntefaceEvents(object sender, ServerToolsEvent e)
 {
     switch (e.Type) {
         case ServerToolsEvent.typeEvent.MESSAGE:
             appendTextToLog("Message from client number " + e.Id + " received!" + Environment.NewLine);
             appendTextToLog("Operation asked : " + e.Operation + Environment.NewLine);
             //TODO: décoder les paramètres + faire la réponse et l'envoyer
             break;
         case ServerToolsEvent.typeEvent.INFORMATION:
             if (e.Id == -1) {
                 appendTextToLog("Error! The server cannot start!" + Environment.NewLine);
                 btn_start.Enabled = true;
                 btn_stop.Enabled = false;
             }
             else
                 appendTextToLog("Server successfully started on port " + port_local + " !" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.DECONNEXION:
             appendTextToLog("Client number " + e.Id + " disconnected!" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.CONNEXION:
             appendTextToLog("Client number " + e.Id + " connected!" + Environment.NewLine);
             break;
     }
 }
示例#8
0
 private void handleInterfaceEvents(object sender, ServerToolsEvent e)
 {
     switch (e.Type) {
         case ServerToolsEvent.typeEvent.MESSAGE:
             AppendTextToLog("Message from client number " + e.Id + " received!" + Environment.NewLine);
             if (e.Operation != "") {
                 AppendTextToLog("Operation asked : " + e.Operation + Environment.NewLine);
                 mySelf.handleRequest(e, typeof(ServiceCatalogue), catalogue_name);
             }
             else if (e.Param[0] == DataUtils.ACKNOWLEDGE_PRESENCE_CODE) {
                 AppendTextToLog("Client number " + e.Id + " still here!" + Environment.NewLine);
             }
             else AppendTextToLog("Client number " + e.Id + " sent an empty message!" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.INFORMATION:
             if (e.Id == -1) {
                 AppendTextToLog("Error! The server cannot connect!" + Environment.NewLine);
                 btn_start.Enabled = true;
                 btn_stop.Enabled = false;
             }
             else
                 AppendTextToLog("Server successfully started on port " + port_catalogue + " !" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.DECONNEXION:
             AppendTextToLog("Client number " + e.Id + " disconnected!" + Environment.NewLine);
             UnregisterById(e.Id);
             break;
         case ServerToolsEvent.typeEvent.CONNEXION:
             AppendTextToLog("Client number " + e.Id + " connected!" + Environment.NewLine);
             break;
     }
 }
示例#9
0
 /// <summary>
 /// Intercepter un évenement, puis créer un ServerToolsEvent correspondant à son type. 
 /// </summary>
 private void HandleServerEvent(object sender, ServerEventArgs e)
 {
     ServerToolsEvent sta = null;
     switch (e.Type) {
         case ServerEventArgs.typeEvent.CONNEXION:
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.CONNEXION, null, null, null, -1);
             break;
         case ServerEventArgs.typeEvent.DECONNEXION:
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.DECONNEXION, null, null, null, -1);
             break;
         case ServerEventArgs.typeEvent.MESSAGE:
             Message msg = MessageUtil.decoder(e.Msg);
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.MESSAGE, msg.Operation, msg.ListParams, msg.Source, int.Parse(msg.Stamp));
             break;
     }
     serverToolsReceiveEvent(this, sta);
 }
示例#10
0
 /// <summary>
 /// Démarrer le serveur
 /// </summary>
 public bool Start()
 {
     this.mySelf = SocketLibrary.Utils.CreateServer(port);
     ServerToolsEvent sta = null;
     bool ret;
     if (!this.mySelf.Start()) {
         sta = new ServerToolsEvent(-1, ServerToolsEvent.typeEvent.INFORMATION, null, null, null, -1);
         ret = false;
     }
     else {
         sta = new ServerToolsEvent(0, ServerToolsEvent.typeEvent.INFORMATION, null, null, null, -1);
         ret = true;
     }
     serverToolsReceiveEvent(this, sta);
     this.mySelf.Subscribe(HandleServerEvent);
     return ret;
 }
示例#11
0
        /// <summary>
        /// Exécuter l'opération demandée, puis envoyer le résultat au client
        /// </summary>
        public void handleRequest(ServerToolsEvent e, Type type, string name)
        {
            try {
                MethodInfo mi = LibraryInterfaceServer.Utils.getMethod(e.Operation, type, OperationInfo.VisibilityType.GLOBAL);
                if (mi.GetCustomAttributes(typeof(OperationInfo), false).Count() != 0) {
                    if (mi.GetCustomAttributes(typeof(OperationInfo), false)[0].GetType() == typeof(OperationInfo)) {
                        OperationInfo oi = (OperationInfo)mi.GetCustomAttributes(typeof(OperationInfo), false)[0];
                        if (oi.Visibility == OperationInfo.VisibilityType.GLOBAL) {
                            try {
                                e.Param.Add(e.Id.ToString());
                                MethodInfo mib = LibraryInterfaceServer.Utils.getMethod(oi.Func, type, OperationInfo.VisibilityType.PRIVATE);
                                List<string> result = (List<string>)mib.Invoke(null, new object[] { e.Param });
                                if (result != null)
                                    Send(name, e.Source, e.Operation, e.Stamp.ToString(), result, e.Id);
                                return;
                            }
                            catch {
                                Send(name, e.Source, e.Operation, e.Stamp.ToString(), new List<string>() { DataUtils.BAD_PARAMETERS_CODE }, e.Id);
                                return;
                            }

                        }
                    }
                }

            }
            catch {
                Send(name, e.Source, e.Operation, e.Stamp.ToString(), new List<string>() { DataUtils.UNKOWN_OPERATION }, e.Id);
            }
        }
示例#12
0
 private void handleIntefaceEvents(object sender, ServerToolsEvent e)
 {
     switch (e.Type) {
         case ServerToolsEvent.typeEvent.MESSAGE:
             appendTextToLog("Message from client number " + e.Id + " received!" + Environment.NewLine);
             appendTextToLog("Operation asked : " + e.Operation + Environment.NewLine);
             mySelfServer.handleRequest(e, typeof(ServiceEcho), service);
             break;
         case ServerToolsEvent.typeEvent.INFORMATION:
             if (e.Id == -1) {
                 appendTextToLog("Error! The server cannot start!" + Environment.NewLine);
                 btn_start.Enabled = true;
                 btn_stop.Enabled = false;
             }
             else
                 appendTextToLog("Server successfully started on port " + port_local + " !" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.DECONNEXION:
             appendTextToLog("Client number " + e.Id + " disconnected!" + Environment.NewLine);
             break;
         case ServerToolsEvent.typeEvent.CONNEXION:
             appendTextToLog("Client number " + e.Id + " connected!" + Environment.NewLine);
             break;
     }
 }
示例#13
0
 private void HandleServerEvent(object sender, ServerEventArgs e)
 {
     ServerToolsEvent sta = null;
     switch (e.Type) {
         case ServerEventArgs.typeEvent.CONNEXION:
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.CONNEXION, null, null);
             break;
         case ServerEventArgs.typeEvent.DECONNEXION:
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.DECONNEXION, null, null);
             break;
         case ServerEventArgs.typeEvent.MESSAGE:
             //Décoder opération demandée
             sta = new ServerToolsEvent(e.Id, ServerToolsEvent.typeEvent.MESSAGE, "operation", new List<byte[]>() { new byte[] { } });
             break;
     }
     serverToolsReceiveEvent(this, sta);
 }