Ignore:
Timestamp:
May 26, 2011, 5:45:42 AM (13 years ago)
Author:
Sam Habiel
Message:

BMXNetEhrSessionConnection.cs implements ConnectionEncoding so that the project can compile.
BMXNetEhrSessionConnection.cs: ReceiveString TCP code refactored, AGAIN!

Updated dlls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs

    r1180 r1193  
    1010using System.Threading;
    1111using System.Timers;
     12using System.Linq;
    1213
    1314namespace IndianHealthService.BMXNet.Net
     
    115116     Port = "All",
    116117     Transport = "All")]
    117                 protected virtual void OpenConnectionCommon()
     118        protected virtual void OpenConnectionCommon()
    118119                {
    119120                        try
     
    346347#endif
    347348
     349            /******************INIT*****************/
    348350            NetworkStream ns = tcpClient.GetStream();
    349351            ns.ReadTimeout = this.ReceiveTimeout; //Timeout; throw exception automatically if we time out.
    350352
     353            /*************SECURITY S-PACKET READ***********************/
     354            int secPackLen = ns.ReadByte();  //Read S-Pack Length Byte
     355            byte[] secPackContents = new byte[secPackLen];;
     356            if (secPackLen > 0)
     357            {
     358                ns.Read(secPackContents, 0, secPackLen);
     359            }
     360
     361            /****************ERROR S-PACKET READ******************/
     362            int errPackLen = ns.ReadByte(); //Read S-Pack Length Byte
     363            byte[] errPackConents = new byte[errPackLen];;
     364            if (errPackLen > 0)
     365            {
     366                ns.Read(errPackConents, 0, errPackLen);
     367            }
     368
     369            //If either one of these exists, then we have an error on the Mumps Database
     370            if (secPackLen > 0 || errPackLen > 0)
     371            {
     372                //We still have to read the Data to empty the tcp OS buffers even if we have security/errors in the DB
     373                while (ns.DataAvailable) ns.ReadByte() ;  //while loop to empty the buffer -- this is theoretically slow, but that's not important here
     374
     375                //Now decode them.
     376                string secString = ConnectionEncoding.GetString(secPackContents);
     377                string errString = ConnectionEncoding.GetString(errPackConents);
     378                throw new BMXNetException("Mumps Database Security/Error: " + secString + " | " + errString);
     379            }
     380
     381            /*****************DATA STREAM READ*******************/
     382            //Data stream from VISTA ends when we find the EOT (ASCII 4) character
    351383            MemoryStream mStream = new MemoryStream(1500); // Auto expanding memory storage for what we receive
    352             int numberOfBytesRead = 0; 
     384            int numberOfBytesRead = 0;
    353385            bool bFinished = false;  // Have we found the End of Transmission (ASCII 4) yet?
    354386
     
    362394                else mStream.Write(bReadBuffer, 0, numberOfBytesRead - 1);           //otherwise, number of bytes minus the $C(4) at the end
    363395            }
     396
     397            //At this point, we are done reading from the Network Stream. Now we have to decode the data.
    364398           
    365             //Read Security S-Packet
    366             mStream.Seek(0, SeekOrigin.Begin);
    367             int secLength = mStream.ReadByte();
    368             byte[] secBytes = new byte[secLength];
    369             if (secLength > 0)
    370             {
    371                 mStream.Read(secBytes, 0, secLength);
    372             }
    373 
    374             //Read Error S-Packet
    375             mStream.Seek(secLength + 1, SeekOrigin.Begin);
    376             int errLength = mStream.ReadByte();
    377             byte[] errBytes = new byte[errLength];
    378             if (errLength > 0)
    379             {
    380                 mStream.Read(errBytes, 0, errLength);
    381             }
    382 
    383             //If either one of these exists, then we have an error on the Mumps Database
    384             if (secLength > 0 || errLength > 0)
    385             {
    386                 string errString = ConnectionEncoding.GetString(secBytes);
    387                 string appString = ConnectionEncoding.GetString(errBytes);
    388                 throw new BMXNetException("Mumps Database Security/Error: " + errString + " | " + appString);
    389             }
    390 
    391             //No Errors. Decode the entire message starting from after the S packets above
    392             string sReadBuffer = ConnectionEncoding.GetString(mStream.ToArray(), secLength + errLength + 2, mStream.ToArray().Length - (secLength + errLength + 2)); //decode
     399            //Decode the entire message.
     400            string sReadBuffer = ConnectionEncoding.GetString(mStream.ToArray()); //decode
    393401
    394402            String decodedReceiveString = this.DecodeReceiveString(sReadBuffer);
     
    636644                this.SendString(this.Socket, ADEBLDMsg(m_cHDR, "BMXGetFac", aDuz));
    637645                return this.ReceiveString(this.Socket);
    638 #if DEBUG
    639                 _watch = new Stopwatch();
    640                 _watch.Start();
    641 #endif
    642 
    643646                        }
    644647                        catch (BMXNetException bmxEx)
Note: See TracChangeset for help on using the changeset viewer.