public void Write(MotSocket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException($"motQueue Null Socket Argument");
            }

            try
            {
                // Push it to the port
                foreach (var record in Records)
                {
                    socket.Write(record.Value);

                    if (DebugMode)
                    {
                        _eventLogger.Debug(record);
                    }
                }

                // Flush
                Records.Clear();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to write queue to Socket: " + ex.Message);
            }
        }
        /// <summary>
        /// Write the specified socket and doLogging.
        /// </summary>
        /// <param name="socket">Socket.</param>
        /// <param name="doLogging">If set to <c>true</c> do logging.</param>
        public void Write(MotSocket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            try
            {
                if (QueueWrites)
                {
                    AddToQueue();
                }
                else
                {
                    Write(socket, _fieldList);
                }
            }
            catch (Exception ex)
            {
                var errorString = $"Failed to write Prescription record: {ex.Message}";
                EventLogger.Error(errorString);
                throw new Exception(errorString);
            }
        }
        /// <summary>
        ///     <c>Commit</c>
        ///     Wrapper for WriteQueue that takes a motSocket parameter
        /// </summary>
        /// <param name="socket"></param>
        public void Commit(MotSocket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            WriteQueue(socket);
        }
 /// <summary>
 ///     <c>Commit</c>
 ///     Commits the queueud items to the database over ta socket
 /// </summary>
 /// <param name="socket"></param>
 // ReSharper disable once UnusedMember.Global
 public void Commit(MotSocket socket)
 {
     try
     {
         _writeQueue.Write(socket);
     }
     catch (Exception ex)
     {
         _eventLogger.Error("Commit Bundle: {0}", ex.Message);
         throw new Exception("Commit: " + ex.Message);
     }
 }
        /// <summary>
        ///     <cr>Write</cr>
        ///     Write string data directly to the socket
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="data"></caparam>
        public void Write(MotSocket socket, string data)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (IsEmpty)
            {
                return;
            }

            try
            {
                if (logRecords)
                {
                    LogTaggedRecord(data);
                }

                if (UseAscii)
                {
                    if (!socket.Write(Encoding.ASCII.GetBytes(data)))
                    {
                        throw new InvalidOperationException();
                    }
                }
                else
                {
                    if (!socket.Write(Encoding.UTF8.GetBytes(data)))
                    {
                        throw new InvalidOperationException();
                    }
                }

                if (SendEof)
                {
                    socket.Write("<EOF/>");
                }
            }
            catch (Exception ex)
            {
                EventLogger.Error("Failed to write {0} to port.  Error {1}", data, ex.Message);
                throw;
            }
        }
        public void WriteEof(MotSocket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException($"motQueue Null Socket Argument");
            }

            if (SendEof)
            {
                try
                {
                    socket.WriteReturn("<EOF/>");
                }
                catch (Exception ex)
                {
                    throw new Exception($"Failed to write queue <EOF/>: {ex.Message}");
                }
            }
        }
コード例 #7
0
 public void Write(MotSocket socket)
 {
     try
     {
         if (QueueWrites)
         {
             AddToQueue();
         }
         else
         {
             Write(socket, _fieldList);
         }
     }
     catch (Exception ex)
     {
         var errorString = $"Failed to write Patient record: {ex.Message}";
         EventLogger.Error(errorString);
         throw new Exception(errorString);
     }
 }
コード例 #8
0
 /// <summary>
 /// Write
 /// </summary>
 /// <param name="socket"></param>
 /// <param name="doLogging"></param>
 /// <exception cref="Exception"></exception>
 public void Write(MotSocket socket)
 {
     try
     {
         if (QueueWrites)
         {
             AddToQueue();
         }
         else
         {
             Write(socket, _fieldList);
         }
     }
     catch (Exception ex)
     {
         var errorString = string.Format("Failed to write Store record: {0}", ex.Message);
         EventLogger.Error(errorString);
         throw new Exception(errorString);
     }
 }
        /// <summary>
        ///     <c>WriteQueue</c>
        ///     Pushes everything in the queue to the passed socket
        /// </summary>
        /// <param name="socket"></param>
        public void WriteQueue(MotSocket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            try
            {
                if (LocalWriteQueue == null)
                {
                    throw new ArgumentNullException($"Invalid Queue");
                }

                LocalWriteQueue.Write(socket);
                LocalWriteQueue.Clear();
            }
            catch (Exception ex)
            {
                EventLogger.Error($"WriteQueue: {ex.Message}");
                throw;
            }
        }
        /// <summary>
        ///     <c>Write</c>
        ///     Pushes the current set of fields to the passed socket after formatting
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="fieldSet"></param>
        protected void Write(MotSocket socket, List <Field> fieldSet)
        {
            if (DontSend)
            {
                return;
            }

            var record  = "<Record>";
            var dataLen = 0;

            if (IsEmpty)
            {
                return;
            }

            if (socket == null || fieldSet == null)
            {
                EventLogger.Error("Null parameters to base.Write()");
                throw new ArgumentNullException($"Null Arguments");
            }

            try
            {
                CheckDependencies(fieldSet);

                foreach (var tag in fieldSet)
                {
                    if (tag.TagName.ToUpper().Contains("DATE") && tag.TagData.Contains("0001"))
                    {
                        tag.TagData = "";
                    }

                    record += "<" + tag.TagName + ">" + tag.TagData + "</" + tag.TagName + ">";

                    // If there's no data other than Table and Action we should ignore it.
                    if (tag.TagName.ToUpper() != "TABLE" && tag.TagName.ToUpper() != "ACTION")
                    {
                        dataLen += tag.TagData.Length;
                    }

                    if (tag.TagName.ToUpper().Contains("DATE") && tag.TagData.Contains("0001"))
                    {
                        tag.TagData = "";
                    }
                }

                record += "</Record>";

                if (dataLen > 0)
                {
                    if (logRecords)
                    {
                        LogTaggedRecord(record);
                    }

                    if (!UseAscii)
                    {
                        if (!socket.Write(Encoding.ASCII.GetBytes(record)))
                        {
                            throw new InvalidOperationException();
                        }
                    }
                    else
                    {
                        // Push it to the port
                        if (!socket.Write(Encoding.UTF8.GetBytes(record)))
                        {
                            throw new InvalidOperationException();
                        }
                    }

                    if (SendEof)
                    {
                        socket.Write("<EOF/>");
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogger.Error("{0)\n{1}", ex.Message, record);
                throw;
            }
        }