Exemplo n.º 1
0
        }// end MessageFromClient

        private void ProcessGenericOperation(BibliotecaClient.Operatie op)
        {
            switch (op.Denumire)
            {
            case BibliotecaClient.Operatie.DenumireOperatie.OP_SERVER:
                //Operatii client - conectare deconectare
                BibliotecaClient.OperatieServer os = op as BibliotecaClient.OperatieServer;
                ProcessServerOperation(os);
                break;

            case BibliotecaClient.Operatie.DenumireOperatie.OP_INSERARE:
                OperatieInserare oi = op as OperatieInserare;
                ProcessInsertOperation(oi);
                System.Console.WriteLine("Operatie primită: " + op.Denumire.ToString());
                break;

            case BibliotecaClient.Operatie.DenumireOperatie.OP_DEPLASARE:
                System.Console.WriteLine("Operatie primită: " + op.Denumire.ToString());
                break;

            default:
                System.Console.WriteLine("Mesaj invalid receptionat - Operatie necunoscuta");
                break;
            } // end switch
        }
Exemplo n.º 2
0
        private void OnServerMessage(IAsyncResult ar)
        {
            MessageQueue mq = (MessageQueue)ar.AsyncState;

            System.Messaging.Message msg = null;
            try
            {
                msg = mq.EndReceive(ar);
            }
            catch
            {
                SafeUpdateControl(tbLog, tbLog.Text + "Server Timeout\n");
            }
            mq.BeginReceive(TimeSpan.FromSeconds(10), mq, new AsyncCallback(OnServerMessage));

            //Procesare mesaj
            BibliotecaClient.Operatie op = (Operatie)msg.Body;
            ParseServerMessage(op);
        }
Exemplo n.º 3
0
        public void MessageFromClient(IAsyncResult ar)
        {
            //Am primit un mesaj pe coada principala
            Message msg = null;

            try
            {
                msg = ((MessageQueue)ar.AsyncState).EndReceive(ar);
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    Console.WriteLine("Timeout! Nothing new happened.");
                    mainQ.BeginReceive(
                        TimeSpan.FromSeconds(10),
                        mainQ,
                        new AsyncCallback(MessageFromClient)
                        );
                    return;
                }
            }
            mainQ.BeginReceive(
                TimeSpan.FromSeconds(1),
                mainQ,
                new AsyncCallback(MessageFromClient)
                );

            BibliotecaClient.Operatie op = (BibliotecaClient.Operatie)msg.Body;
            if (op == null)
            {
                System.Console.WriteLine("Mesaj invalid receptionat - Nu e o operatie");
                return;
            }
            //Procesare
            ProcessGenericOperation(op);
        }// end MessageFromClient