예제 #1
0
파일: Assists.cs 프로젝트: nistec/MQueue
        internal static void SetReceived(QueueItem item, QueueCmd cmd)
        {
            if (item == null)
            {
                return;
            }
            switch (cmd)
            {
            case QueueCmd.Peek:
            case QueueCmd.PeekItem:
            case QueueCmd.PeekPriority:
                item.SetReceived(MessageState.Peeked);
                break;

            case QueueCmd.Dequeue:
            case QueueCmd.DequeueItem:
            case QueueCmd.DequeuePriority:
                item.SetReceived(MessageState.Received);
                break;

            default:
                item.SetReceived(MessageState.None);
                break;
            }
        }
예제 #2
0
파일: Message.cs 프로젝트: nistec/MQueue
 public static QueueItem Ack(MessageState state, QueueCmd cmd, Exception ex)
 {
     return(new QueueItem()
     {
         Command = cmd,
         Label = ex == null?state.ToString() : ex.Message,
                     MessageState = state
     });
 }
예제 #3
0
파일: Message.cs 프로젝트: nistec/MQueue
 public static QueueItem Ack(MessageState state, QueueCmd cmd)
 {
     return(new QueueItem()
     {
         Command = cmd,
         Label = state.ToString(),
         MessageState = state
     });
 }
예제 #4
0
파일: Message.cs 프로젝트: nistec/MQueue
 public static QueueItem Ack(MessageState state, QueueCmd cmd, string label, string identifier)
 {
     return(new QueueItem()
     {
         Command = cmd,
         Label = label,
         Identifier = identifier,
         MessageState = state
     });
 }
예제 #5
0
        public TransStream Command(QueueCmd command)
        {
            QueueRequest request = new QueueRequest()
            {
                QCommand = (QueueCmd)(int)command,
                Host     = _QueueName
            };

            var result = ExecDuplexStream(request, ConnectTimeout);

            return(result);
        }
예제 #6
0
 public static QueueRequest GetQRequest(QueueCmd command, int version, Priority priority, TransformType transformType, string host, NetStream bodyStream)
 {
     return(new QueueRequest()
     {
         //Version = version,
         //MessageType = messageType,
         QCommand = command,
         Priority = priority,
         TransformType = transformType,
         Host = host,
         //Creation = DateTime.Now,
         //Modified = DateTime.Now,
         //ArrivedTime = Assists.NullDate,
         BodyStream = bodyStream
     });
 }
예제 #7
0
파일: Message.cs 프로젝트: nistec/MQueue
        public Message(QueueCmd command, TransformTypes transformType, Priority priority, string destination, string json)
        {
            MessageType   = MQTypes.MessageRequest;
            Command       = command;
            Priority      = priority;
            TransformType = transformType;
            Destination   = destination;
            if (json != null)
            {
                m_BodyStream = new NetStream(Encoding.UTF8.GetBytes(json));
            }
            //ArrivedTime = DateTime.Now;
            SetArrived();

            ItemBinary = Encoding.UTF8.GetBytes(json);
            //m_BodyStream = new NetStream(Body);
        }
예제 #8
0
        public static void WriteAck(Stream pipeStream, MessageState state, QueueCmd cmd, string label)
        {
            if (pipeStream == null)
            {
                throw new MessageException(MessageState.PipeError, "Invalid stream to write ack");
            }
            string lbl = label == null?state.ToString() : label;

            QueueItem response = QueueItem.Ack(state, cmd, lbl, null);

            using (NetStream stream = new NetStream())
            {
                response.EntityWrite(stream, null);
                WriteReponse(pipeStream, stream.ToArray());
            }

            QLogger.Debug("Server Ack State:{0}, Label: {1}", state, label);
        }
예제 #9
0
 public static void WriteError(Stream pipeStream, MessageState state, QueueCmd cmd, Exception ex)
 {
     if (pipeStream == null)
     {
         return;
     }
     try
     {
         string    lbl      = ex.Message;
         QueueItem response = QueueItem.Ack(state, cmd, ex);
         using (NetStream stream = new NetStream())
         {
             response.EntityWrite(stream, null);
             WriteReponse(pipeStream, stream.ToArray());
         }
     }
     catch (Exception x)
     {
         QLogger.Error("QueueResponse WriteError Exception: " + x.Message);
     }
 }
예제 #10
0
        public static TransStream DoReport(object item, QueueCmd cmd, MessageState state, string lbl)
        {
            if (item == null)
            {
                throw new MessageException(MessageState.PipeError, "Invalid item to write response");
            }
            if (item != null)
            {
                var message = QueueItem.Ack(state, cmd, lbl, null);

                message.SetBody(item);
                return(message.ToTransStream());
            }
            else
            {
                QueueItem response = QueueItem.Ack(MessageState.UnExpectedError, cmd, new MessageException(MessageState.UnExpectedError, "WriteReport error: there is no item stream to write reponse"));
                return(response.ToTransStream());
            }

            // QLogger.DebugFormat("Server WriteReport State:{0}, MessageType: {1}", state, msgType);
        }
예제 #11
0
        //public static void WriteResponse(Stream pipeStream, IQueueItem item, MessageState state)
        //{
        //    if (pipeStream == null)
        //    {
        //        throw new MessageException(MessageState.PipeError, "Invalid stream to write response");
        //    }
        //    if (item != null)
        //    {
        //        ((QueueItem)item).SetState(state);
        //        WriteReponse(pipeStream, item.Serilaize());

        //        //using (NetStream stream = new NetStream())
        //        //{
        //        //    //response.EntityWrite(stream, null);
        //        //    WriteReponse(pipeStream, ((QueueItem)item).ItemBinary);
        //        //}
        //    }
        //    else
        //    {
        //        QueueItem response = QueueItem.Ack(MessageState.UnExpectedError,item.QCommand, new MessageException(MessageState.UnExpectedError, "WriteResponse error: there is no item stream to write reponse"));
        //        using (NetStream stream = new NetStream())
        //        {
        //            response.EntityWrite(stream, null);
        //            WriteReponse(pipeStream, stream.ToArray());
        //        }
        //    }

        //    QLogger.DebugFormat("Server WriteResponse State:{0}, Identifier: {1}", item.MessageState, item.Identifier);
        //}

        public static void WriteReport(Stream pipeStream, object item, QueueCmd cmd, MessageState state, string lbl)
        {
            if (pipeStream == null)
            {
                throw new MessageException(MessageState.PipeError, "Invalid stream to write report");
            }
            if (item != null)
            {
                var message = QueueItem.Ack(state, cmd, lbl, null);

                message.SetBody(item);
                WriteReponse(pipeStream, message.ToStream().ToArray());
            }
            else
            {
                QueueItem response = QueueItem.Ack(MessageState.UnExpectedError, cmd, new MessageException(MessageState.UnExpectedError, "WriteReport error: there is no item stream to write reponse"));
                WriteReponse(pipeStream, response.ToStream().ToArray());
            }

            QLogger.Debug("Server WriteReport State:{0}, Command: {1}", state, cmd);
        }
예제 #12
0
파일: QueueItem.cs 프로젝트: nistec/MQueue
        /// <summary>
        /// Initialize a new instance of QueueItem
        /// </summary>
        /// <param name="stream"></param>
        private QueueItem(Message message, QueueCmd command)
        {
            if (message == null)
            {
                throw new ArgumentNullException("QueueItem.ctor message");
            }

            message.Command = command;
            if (message.Command == QueueCmd.Enqueue)
            {
                message.ArrivedTime  = DateTime.Now;
                message.MessageState = Messaging.MessageState.Arrived;
                message.ItemId       = UUID.NewUuid();
            }

            message.Modified = DateTime.Now;
            NetStream stream = new NetStream();

            message.EntityWrite(stream, null);
            stream.Position = 0;
            m_stream        = stream.Copy();
            ValidateStream();

            Body         = stream.ToArray();
            MessageState = message.MessageState;
            Command      = message.Command;
            //Priority = message.Priority;
            ItemId      = message.ItemId;
            Retry       = message.Retry;
            ArrivedTime = message.ArrivedTime;
            //SentTime = message.SentTime;
            Modified      = message.Modified;
            Expiration    = message.Expiration;
            TransformType = message.TransformType;
            QueueName     = message.Destination;
            Sender        = message.Sender;
        }
예제 #13
0
 /// <summary>
 /// Добавляем состояние к отчету
 /// </summary>
 /// <param name="rptUID"></param>
 /// <param name="cmd"></param>
 protected override void doOnMarkRQCmdState(String rptUID, QueueCmd cmd) {
   //throw new NotImplementedException();
   const string sql = "begin xlr.mark_cmd_done(:p_rpt_uid, :p_cmd); end;";
   var v_prms = new Params();
   v_prms.Add("p_rpt_uid", rptUID);
   v_prms.Add("p_cmd", (int)cmd);
   SQLCmd.ExecuteScript(this.cfg.dbSession, sql, v_prms, 120);
 }
예제 #14
0
 public static void WriteAck(Stream stream, bool state, QueueCmd cmd, string label)
 {
     WriteAck(stream, state ? MessageState.Ok : MessageState.None, cmd, label);
 }
예제 #15
0
 protected abstract void doOnMarkRQCmdState(String rptUID, QueueCmd cmd);