Exemplo n.º 1
0
        /// <summary>
        /// Read from the object server, value of the ServerPadInt.
        /// </summary>
        /// <returns></returns>
        public int Read()
        {
            int value;

            try
            {
                if (PADI_Client.TransactionId != 0)
                {
                    if (worker.IsThisServerFreezed)
                    {
                        AsyncReadPadInt read         = new AsyncReadPadInt(worker.Read);
                        AsyncCallback   readCallback = new AsyncCallback(AsyncReadCallBack);
                        IAsyncResult    RemAr        = read.BeginInvoke(this.UID, PADI_Client.TransactionId, readCallback, null);
                        Console.WriteLine("Read will be delayed due to server freeze, this is a junk value");
                        value = Int32.MinValue;
                    }
                    else
                    {
                        value = worker.Read(this.UID, PADI_Client.TransactionId);
                    }
                }
                else
                {
                    throw new TxException("Transaction is required to be started before read operation");
                }
            }
            catch (TxException ex)
            {
                Common.Logger().LogError(ex.Message, ex.StackTrace, ex.Source);
                Console.WriteLine(ex.Message);
                throw ex;
            }
            return(value);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Read request will be replied here
 /// </summary>
 /// <param name="ar"></param>
 public void AsyncReadCallBack(IAsyncResult ar)
 {
     try
     {
         AsyncReadPadInt del = (AsyncReadPadInt)((AsyncResult)ar).AsyncDelegate;
         Console.WriteLine("Read the value " + del.EndInvoke(ar));
     }
     catch (TxException ex)
     {
         Console.WriteLine(ex.Message);
         throw ex;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex;
     }
 }