Esempio n. 1
0
        internal void ClientConnected(BluetoothClient client)
        {
            Stream stream = null;
            try
            {
                Log.BtServer("MScanner med navn " + client.RemoteMachineName + " kobler til..");
                this.clientName = client.RemoteMachineName;
                this.clientAccepted = false;
                this.clientAppName = "Unknown";
                this.clientAppVersion = 0;
                stream = client.GetStream();
                stream.ReadTimeout = 10 * 1000;

                if (main.appConfig.blueServerDatabaseUpdated.Date != DateTime.Now.Date)
                {
                    Log.BtServer("App-databasene trenger oppdatering. Sist oppdatert: " + main.appConfig.blueServerDatabaseUpdated.ToShortDateString());
                    if (FormMain.appManagerIsBusy)
                        Log.BtServer("AppManager er opptatt: App-databasene er iferd med å bli oppdatert");
                    else
                    {
                        AppManager app = new AppManager(main);
                        app.UpdateAllAsync();
                        return;
                    }
                }

                while (true)
                {
                    try
                    {
                        if (!client.Connected || !serverStarted)
                            break;

                        if (!clientAccepted) // Client is not initialized, run init routine..
                            this.clientAccepted = serverInitConnectionRoutine(stream);

                        string strServerMsg = waitForMessage(stream);
                        if (strServerMsg.StartsWith(CMD_UPDATE_PRODUCT))
                        {
                            if (!serverUpdateRoutine(stream, strServerMsg, dataFilename))
                                break;
                        }
                        if (strServerMsg.StartsWith(CMD_UPDATE_INVENTORY))
                        {
                            if (!serverUpdateRoutine(stream, strServerMsg, inventoryFilename))
                                break;
                        }
                        if (strServerMsg.StartsWith(CMD_GOODBYE))
                        {
                            Log.BtServer("(" + this.clientName + ") Goodbye!");
                            break;
                        }

                        Thread.Sleep(300); // Used to limit the number of loops per second
                    }
                    catch (Exception ex)
                    {
                        Log.BtServer("Kommunikasjons feil med " + this.clientName + ". Kobler fra..", true);
                        Log.Unhandled(ex);
                        break;
                    }
                }

                if (stream != null)
                {
                    stream.Flush();
                    stream.Close();
                }

                if (client != null)
                    client.Close();

                Log.BtServer("(" + this.clientName + ") Koblet fra.");
            }
            catch (Exception ex)
            {
                Log.BtServer("Generell feil: " + ex.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Flush();
                    stream.Close();
                    stream = null;
                }
                if (client != null)
                {
                    client.Close();
                    client = null;
                }
            }
        }
Esempio n. 2
0
 private void oppdaterAppDatabaserToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!IsBusy())
     {
         AppManager appMng = new AppManager(this);
         appMng.UpdateAllAsync();
     }
 }