Ignore:
Timestamp:
May 11, 2011, 9:17:45 AM (13 years ago)
Author:
Sam Habiel
Message:

RemoteSession.cs Interface: Added:

  • Lock method to lock glvns on M db.
  • Encoding ConnectionEncoding to set the connection encoding on the DB

BMXNetSessionConnection: Added:

  • Abstract ConnectionEncoding property
  • Clarified error message that gets called. It now says that you don't have TransmitRPC writer lock??? When the error could be any BMXNetException.

BMXNetSessionSocketConnection:

  • Added ConnectionEncoding property
  • ReceiveString completely refactored: now we get much better performance
  • Timers and Debug Writes are all over the place now.

BMXNetRemoteSession:

  • Implemented the 2 new 'stuff' in Interface RemoteSesssion: -- Lock glvn -- Encoding Property
  • TableFromSQL with Dataset has an honest to god bug in it: The passed dataset and table name are not used even though they are passed.

BMXNetSessionConnectionOverAnotherSessionConnection:

  • Implemented the Encoding Property in Interface RemoteSession to have the project compile.

Updated dlls. Have fun.

Location:
BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework
Files:
9 edited

Legend:

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

    r1146 r1180  
    441441        public abstract int ReceiveTimeout { get; set; }
    442442        public abstract int SendTimeout { get; set; }
     443        public abstract Encoding ConnectionEncoding { get; set; }
    443444
    444445
     
    469470                // The writer lock request timed out.
    470471                //TODO: Remark: to writer lock for Transmit RPC
    471                 Debug.Write("TransmitRPC writer lock request timed out.\n");
     472                //SMH: Wrong error message. We do have an exception, but nothing to do with a lock.
     473                //Debug.Write("TransmitRPC writer lock request timed out.\n");
     474                Debug.Write("Exception: " + exception.Message);
    472475                throw exception;
    473476            }
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Net/BMXNetSessionSocketConnection.cs

    r1146 r1180  
    2424        public static int DefaultReceiveTimeout = 40000;
    2525       
     26       
    2627        private int _sendTimeout = 0;
    2728
     
    6364        }
    6465
     66        public override Encoding ConnectionEncoding // Default Encoding determined by Windows; typically a Windows Code Page
     67        {
     68            get;
     69            set;
     70        }
     71           
     72
    6573                public BMXNetSessionSocketConnection(BMXNetBroker aBroker):base(aBroker)
    6674                {
     
    7078                        m_sWISH = "";
    7179                        m_cHDR = ADEBHDR(m_sWKID,m_sWINH,m_sPRCH,m_sWISH);
     80
     81            ConnectionEncoding = Encoding.Default;
    7282
    7383                }
     
    218228        }
    219229
    220 
    221 
    222 
    223230        bool m_bLogging = false;
    224231
     
    239246            {
    240247                String cMSG = ADEBLDMsg(m_cHDR, "BMX CONNECT STATUS", "");
    241 
     248#if DEBUG
     249                _watch = new Stopwatch();
     250                _watch.Start();
     251#endif
    242252                this.SendString(this.Socket, cMSG);
    243253                String strReceive = ReceiveString(this.Socket);
     254#if DEBUG
     255                _watch.Stop();
     256
     257                Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms");
     258                Debug.WriteLine("---");
     259                _watch = null;
     260#endif
     261
    244262                String port = BMXNetBroker.Piece(strReceive, "|", 1);
    245263                String message = BMXNetBroker.Piece(strReceive, "|", 2);
     
    275293        }
    276294
    277      
     295        Stopwatch _watch = new Stopwatch();
     296
    278297        protected override String SendReceiveString(string cSendString, string cMult)
    279298        {
    280299#if DEBUG
    281             Stopwatch _watch = new Stopwatch();
     300            _watch = new Stopwatch();
    282301            _watch.Start();
    283             Debug.WriteLine("Sending (T:" + Thread.CurrentThread.ManagedThreadId + "): " + cSendString);
    284302#endif
    285303            this.SendString(this.m_pCommSocket, cSendString, cMult);
     304            Debug.WriteLine("Time After Send: " + _watch.ElapsedMilliseconds + " ms");
    286305            string _received = this.ReceiveString(this.m_pCommSocket);
    287306#if DEBUG
    288             Debug.WriteLine("Received(T:" + Thread.CurrentThread.ManagedThreadId + "): " + _received.Replace((char) 30, (char) 10));
     307            _watch.Stop();
     308
    289309            Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms");
    290310            Debug.WriteLine("---");
     
    303323        protected virtual void SendString(TcpClient tcpClient, string cSendString, string cMult)
    304324                {
     325#if DEBUG
     326            Debug.WriteLine("Sending (T:" + Thread.CurrentThread.ManagedThreadId + "): " + cSendString);
     327#endif
    305328            String encodedString = this.EncodeSendString(cSendString, cMult);
    306329               
    307330                        NetworkStream ns = tcpClient.GetStream();
    308331            ns.WriteTimeout = this.SendTimeout;
    309                         byte[] sendBytes = Encoding.ASCII.GetBytes(encodedString);
     332                        byte[] sendBytes = ConnectionEncoding.GetBytes(encodedString);
    310333                        ns.Write(sendBytes,0,sendBytes.Length);
    311334            if (this.m_bLogging == true)
     
    319342                private string ReceiveString(TcpClient tcpClient)
    320343                {
    321                         NetworkStream ns = tcpClient.GetStream();
     344#if DEBUG
     345            Debug.WriteLine("Time At Start of Receive: " + _watch.ElapsedMilliseconds + " ms");
     346#endif
     347
     348            NetworkStream ns = tcpClient.GetStream();
     349            ns.ReadTimeout = this.ReceiveTimeout; //Timeout; throw exception automatically if we time out.
     350
     351            MemoryStream mStream = new MemoryStream(1500); // Auto expanding memory storage for what we receive
     352            int numberOfBytesRead = 0; 
     353            bool bFinished = false;  // Have we found the End of Transmission (ASCII 4) yet?
     354
     355            // Main Read Loop
     356            while (!bFinished) //while we are not done
     357            {
     358                byte[] bReadBuffer = new byte[1500];        //buffer size = MTU. Message MUST be smaller.
     359                numberOfBytesRead = ns.Read(bReadBuffer, 0, bReadBuffer.Length);    //read data
     360                bFinished = FindChar(bReadBuffer, (char)4) > -1;                    //look for the EOT (ASCII 4) character
     361                if (!bFinished) mStream.Write(bReadBuffer, 0, numberOfBytesRead);  //if we are not done, put the whole stream in
     362                else mStream.Write(bReadBuffer, 0, numberOfBytesRead - 1);           //otherwise, number of bytes minus the $C(4) at the end
     363            }
     364           
     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
     393
     394            String decodedReceiveString = this.DecodeReceiveString(sReadBuffer);
     395
     396            if (this.m_bLogging)
     397            {
     398                Log("Received: " + decodedReceiveString, this.m_LogWriter);
     399            }
     400#if DEBUG
     401            Debug.WriteLine("Time At End of Receive: " + _watch.ElapsedMilliseconds + " ms");
     402            Debug.WriteLine("Received(T:" + Thread.CurrentThread.ManagedThreadId + "): " + decodedReceiveString.Replace((char)30, (char)10));
     403#endif
     404            return decodedReceiveString;
     405           
     406
     407            /* OLD CODE
     408            NetworkStream ns = tcpClient.GetStream();
    322409            ns.ReadTimeout = this.ReceiveTimeout;
    323410
     
    409496                Log("Received: " + decodedReceiveString, this.m_LogWriter);
    410497            }
     498#if DEBUG
     499            Debug.WriteLine("Time At End of Receive: " + _watch.ElapsedMilliseconds + " ms");
     500#endif
    411501            return decodedReceiveString;
    412                        
     502                        */
    413503                }
    414504
     
    422512                        //Build AV Call
    423513                        cMSG = ADEBLDMsg(m_cHDR, "BMX AV CODE", winIdentity.Name);
     514#if DEBUG
     515            _watch = new Stopwatch();
     516            _watch.Start();
     517#endif
    424518            SendString(this.Socket, cMSG);
    425 
    426519            strReceive = ReceiveString(this.Socket);
     520#if DEBUG
     521            _watch.Stop();
     522
     523            Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms");
     524            Debug.WriteLine("---");
     525            _watch = null;
     526#endif
     527
    427528                        sTest = strReceive.Substring(0,3);
    428529
     
    453554               
    454555                        cMSG = ADEBLDMsg(m_cHDR, "XUS AV CODE", encryptedAccessVerifyCode);
     556#if DEBUG
     557            _watch = new Stopwatch();
     558            _watch.Start();
     559#endif     
    455560            SendString(this.Socket, cMSG);
    456 
    457561            strReceive = ReceiveString(this.Socket);
     562#if DEBUG
     563            _watch.Stop();
     564
     565            Debug.WriteLine("Time: " + _watch.ElapsedMilliseconds + " ms");
     566            Debug.WriteLine("---");
     567            _watch = null;
     568#endif
    458569
    459570            if (strReceive.StartsWith("M ERROR="))
     
    519630                                        throw new BMXNetException("BMXNetBroker is not connected to RPMS");
    520631                                }
    521 
     632#if DEBUG
     633                _watch = new Stopwatch();
     634                _watch.Start();
     635#endif     
    522636                this.SendString(this.Socket, ADEBLDMsg(m_cHDR, "BMXGetFac", aDuz));
    523637                return this.ReceiveString(this.Socket);
     638#if DEBUG
     639                _watch = new Stopwatch();
     640                _watch.Start();
     641#endif
     642
    524643                        }
    525644                        catch (BMXNetException bmxEx)
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/RemoteSession.cs

    r1146 r1180  
    4747        /// </example>
    4848        String AppContext { get; set; }
     49
     50        Encoding ConnectionEncoding { get; set; }
    4951
    5052        #endregion
     
    680682        /// <param name="aString">The command to be examined</param>
    681683        /// <returns>True if it complied, otherwise false</returns>
    682         bool IsBmxAdoCommand(String aString);
     684        bool IsBmxAdoCommand(String aString);
     685
     686        /// <summary>
     687        /// Locks a Name on the Mumps Database
     688        /// </summary>
     689        /// <param name="g/lvnToLock">Global or Local Name to Lock</param>
     690        /// <param name="addOrSubstract">+ or - to increment or decrement the lock</param>
     691        /// <returns>true for success; false for failure</returns>
     692        bool Lock(string lvnToLock, string addOrSubstract);
     693
    683694        #endregion
    684695
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Sevices/BMXNetRemoteSession.cs

    r1146 r1180  
    11using System;
    22using System.Data;
     3using System.Text;
    34using System.Windows.Forms;
    45using IndianHealthService.BMXNet.Model;
     
    7677        }
    7778
     79        public Encoding ConnectionEncoding
     80        {
     81            get
     82            {
     83                return SessionConnection.ConnectionEncoding;
     84            }
     85            set
     86            {
     87                SessionConnection.ConnectionEncoding = value;
     88            }
     89        }
     90
    7891        public bool IsEventPollingEnabled
    7992        {
     
    509522        }
    510523
     524        //smh: THIS IS WRONG. If you pass the data set, why make a new dataset...
    511525        public DataTable TableFromSQL(string sql, DataSet aDataSet, string aTableName)
    512526        {
    513             return this.TableFromSQL(sql, new DataSet(), this.DefaultTableName, this.AppContext);
     527            return this.TableFromSQL(sql, aDataSet, aTableName, this.AppContext);
    514528        }
    515529
     
    10701084            }                   
    10711085        }
     1086
     1087        public bool Lock(string lvnToLock, string addOrSubstract)
     1088        {
     1089            return SessionConnection.Lock(lvnToLock, addOrSubstract);
     1090        }
    10721091    }
    10731092}
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/Sevices/BMXNetSessionConnectionOverAnotherSessionConnection.cs

    r1146 r1180  
    3535        }
    3636
     37        public override Encoding ConnectionEncoding
     38        {
     39            get;
     40            set;
     41        }
     42
    3743        public override void Close()
    3844        {
  • BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/IndianHealthService.BMXNet/bmxnet.xml

    r1146 r1180  
    10511051            <param name="aString">The command to be examined</param>
    10521052            <returns>True if it complied, otherwise false</returns>
     1053        </member>
     1054        <member name="M:IndianHealthService.BMXNet.RemoteSession.Lock(System.String,System.String)">
     1055            <summary>
     1056            Locks a Name on the Mumps Database
     1057            </summary>
     1058            <param name="g/lvnToLock">Global or Local Name to Lock</param>
     1059            <param name="addOrSubstract">+ or - to increment or decrement the lock</param>
     1060            <returns>true for success; false for failure</returns>
    10531061        </member>
    10541062        <member name="M:IndianHealthService.BMXNet.RemoteSession.Close">
Note: See TracChangeset for help on using the changeset viewer.