Exemplo n.º 1
0
        /// <summary>
        /// recieve a HelloRequest from the client
        /// </summary>
        /// <param name="pHro">the HRO</param>
        public void recieveHelloRequest(HelloRequestObject pHro)
        {
            Log.LogManager.writeLogDebug("[RegistrationService:RegistrationService] Hello request recieved from " + pHro.Name + " with the ID " + pHro.ID);
            ClientConfigObject cco = _DBManager.recieveHelloRequest(pHro);

            Log.LogManager.writeLogDebug("[RegistrationService:RegistrationService] Hello: CCO generated, isConnected: " + cco.clientRequestObject.isConnected);
            OnConfigRequestSendingEvent(cco);
        }
Exemplo n.º 2
0
        /// <summary>
        /// initializes the RegistrationServer
        /// </summary>
        internal void initialize()
        {
            _ConfigManager = new ConfigManager();

            //timer registration
            _timeoutTimer           = new Timer(ConfigManager._ClientConfigObject.clientConnectionConfig.keepAliveInterval + 1000);
            _timeoutTimer.Elapsed  += intervalTimer_Elapsed;
            _timeoutTimer.AutoReset = true;
            _timeoutTimer.Start();

            LogManager.updateClientStatus(Post_KNV_Client.MainWindow.ClientStatus.disconnected);
            RequestHelloEvent(HelloRequestObject.createHelloFromClientConfig(ConfigManager._ClientConfigObject));
        }
Exemplo n.º 3
0
 /// <summary>
 /// gets fired when the registration service requests a HELLO to the server (e.g. after a timeout)
 /// </summary>
 /// <param name="pHello"></param>
 void _RegistrationService_RequestHelloEvent(HelloRequestObject pHello)
 {
     //send hello
     if (Config.ConfigManager._ClientConfigObject.clientConnectionConfig.targetGateway != String.Empty)
     {
         LogManager.writeLog("[Webservice] Sending HELLO to " + ConfigManager._ClientConfigObject.clientConnectionConfig.targetGateway);
         _WebserviceSender.startHelloRequest(ConfigManager._ClientConfigObject.clientConnectionConfig.targetGateway, pHello);
     }
     else
     {
         LogManager.writeLog("[Webservice] Sending HELLO to " + ConfigManager._ClientConfigObject.clientConnectionConfig.targetIP);
         _WebserviceSender.startHelloRequest(ConfigManager._ClientConfigObject.clientConnectionConfig.targetIP, pHello);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// response function from a hello.
        /// </summary>
        /// <param name="message">the stream recieved from the client</param>
        /// <returns>a status message</returns>
        public String responseHello(Stream message)
        {
            // deserialize
            BinaryFormatter    formatter = new BinaryFormatter();
            HelloRequestObject hro       = (HelloRequestObject)formatter.Deserialize(message);

            // give info in the Log
            LogManager.writeLog("[Webservice:ServerDefinition] Client " + hro.Name.ToString() + " " + hro.ownIP.ToString() + " has connected.");

            // fire the event
            OnHelloRequestEvent(hro);

            // feedback for the client
            return("HELLOREQUEST RECIEVED");
        }
Exemplo n.º 5
0
        /// <summary>
        /// starts a hello request to the target IP with the HRO object
        /// </summary>
        /// <param name="pTargetIP">the target server</param>
        /// <param name="pHelloObject">data package containing the necessary information</param>
        public void startHelloRequest(String pTargetIP, HelloRequestObject pHelloObject)
        {
            //send data
            if (helloWorking)
            {
                return;
            }
            helloWorking = true;
            Task <String> t = new Task <String>(() => sendRequestThread(@"http://" + pTargetIP + @"/HELLO", pHelloObject, 10000));

            t.ContinueWith(TaskFaultedHandler, TaskContinuationOptions.OnlyOnFaulted);
            t.ContinueWith(HelloRequestSuccessfulHandler, TaskContinuationOptions.OnlyOnRanToCompletion);
            t.ContinueWith(delegate { helloWorking = false; });
            t.Start();
        }
Exemplo n.º 6
0
        /// <summary>
        /// gets thrown every time the keepAliveInterval hits
        /// </summary>
        void intervalTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (ConfigManager._ClientConfigObject.clientRequestObject.isConnected)
            {
                LogManager.updateClientStatus(Post_KNV_Client.MainWindow.ClientStatus.waiting_for_ping);
            }
            if (timerRounds < 2)
            {
                timerRounds++;
                return;
            }

            timerRounds = 0;
            LogManager.writeLog("[RegistrationService] TIMEOUT: Requesting new HELLO");
            ConfigManager._ClientConfigObject.clientRequestObject.isConnected = false;
            LogManager.updateClientStatus(Post_KNV_Client.MainWindow.ClientStatus.disconnected);
            RequestHelloEvent(HelloRequestObject.createHelloFromClientConfig(ConfigManager._ClientConfigObject));
        }
Exemplo n.º 7
0
        /// <summary>
        /// the task the dbMamager has to do if a client sends a HelloRequest
        /// </summary>
        /// <param name="pHbo">the HBO</param>
        /// <returns>returns the CCO</returns>
        public ClientConfigObject recieveHelloRequest(HelloRequestObject pHbo)
        {
            try
            {
                //check if client already exists
                DataTable    currentDataTable = getClientDataTable();
                DataColumn[] primaryKeyArray  = new DataColumn[1];
                primaryKeyArray[0]          = currentDataTable.Columns["ClientId"];
                currentDataTable.PrimaryKey = primaryKeyArray;

                //if exists, do
                if (currentDataTable.Rows.Contains(pHbo.ID))
                {
                    DataRow targetRow = currentDataTable.Rows.Find(pHbo.ID);

                    targetRow[2] = pHbo.ownIP;

                    //get object from DB
                    ClientConfigObject cco;
                    using (MemoryStream memStream = new MemoryStream((byte[])targetRow[3]))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        cco = (ClientConfigObject)formatter.Deserialize(memStream);
                        memStream.Close();
                    }

                    //change object
                    cco.ownIP = pHbo.ownIP;

                    //check if gateway is defined, if yes, send gateway info as target IP instead of server IP
                    if (Config.ServerConfigManager._ServerConfigObject.gatewayAddress == string.Empty)
                    {
                        cco.clientConnectionConfig.targetIP = Config.ServerConfigManager._ServerConfigObject.ownIP + ":" +
                                                              Config.ServerConfigManager._ServerConfigObject.listeningPort;
                    }
                    else
                    {
                        cco.clientConnectionConfig.targetIP = Config.ServerConfigManager._ServerConfigObject.gatewayAddress;
                    }
                    cco.clientRequestObject.isConnected = true;

                    //write object
                    using (MemoryStream wrStream = new MemoryStream())
                    {
                        BinaryFormatter formatterTwo = new BinaryFormatter();
                        formatterTwo.Serialize(wrStream, cco);
                        byte[] serInput = wrStream.ToArray();
                        targetRow[3] = (Object)serInput;
                        wrStream.Close();
                    }

                    //update
                    updateKinectObjectInDB(currentDataTable);
                    return(cco);
                }
                else
                {
                    //create new cco
                    ClientConfigObject cco = ClientConfigObject.createDefaultConfig();
                    cco.clientConnectionConfig.keepAliveInterval = Config.ServerConfigManager._ServerConfigObject.keepAliveInterval;
                    cco.ownIP = pHbo.ownIP;
                    cco.name  = pHbo.Name;
                    cco.clientRequestObject.isConnected = true;

                    //check if gateway is defined, if yes, send gateway info as target IP instead of server IP
                    if (Config.ServerConfigManager._ServerConfigObject.gatewayAddress == string.Empty)
                    {
                        cco.clientConnectionConfig.targetIP = Config.ServerConfigManager._ServerConfigObject.ownIP + ":" +
                                                              Config.ServerConfigManager._ServerConfigObject.listeningPort;
                    }
                    else
                    {
                        cco.clientConnectionConfig.targetIP = Config.ServerConfigManager._ServerConfigObject.gatewayAddress;
                    }
                    cco.ID = getNewPrimaryID(currentDataTable);

                    //write object
                    BinaryFormatter formatter = new BinaryFormatter();
                    MemoryStream    wrStream  = new MemoryStream();
                    formatter.Serialize(wrStream, cco);
                    byte[] serInput = wrStream.ToArray();
                    wrStream.Close();
                    wrStream.Dispose();

                    Object[] values = new Object[4];
                    values[0] = cco.ID;
                    values[1] = cco.name;
                    values[2] = cco.ownIP;
                    values[3] = (Object)serInput;
                    currentDataTable.Rows.Add(values);

                    //update the database
                    updateKinectObjectInDB(currentDataTable);
                    return(cco);
                }
            }
            catch (Exception ex) { LogManager.writeLog("[DataManager:DBManager] ERROR: " + ex.Message); throw; }
        }