public void ReportAsync(QueueCmdReport command, string host, Action <IQueueItem> action) { using ( Task <IQueueItem> task = Task <IQueueItem> .Factory.StartNew(() => Report(command, host) , canceller.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default)) { task.Wait(); if (task.IsCompleted) { IQueueItem item = task.Result; if (item != null) { if (action != null) { Task.Factory.StartNew(() => action(item)); } } } else if (task.IsCanceled) { } else if (task.IsFaulted) { } } }
//public void ReportAsync(QueueCmdReport cmd, Action<string> onFault, Action<TransStream> onCompleted, DuplexTypes DuplexType, AutoResetEvent resetEvent) //{ // QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.Dequeue, null); // { // Host = _QueueName, // QCommand = (QueueCmd)(int)cmd, // DuplexType = DuplexType // }; // base.SendDuplexStreamAsync(request, onFault, onCompleted, resetEvent); //} public T Report <T>(QueueCmdReport cmd) { var res = Report(cmd); if (res == null) { return(default(T)); } return(res.ReadValue <T>()); }
public TransStream Report(QueueCmdReport cmd) { QueueRequest request = new QueueRequest() { Host = _QueueName, QCommand = (QueueCmd)(int)cmd //Command = (QueueCmd)(int)cmd }; var response = ExecDuplexStream(request, ConnectTimeout); return(response); }
public IQueueItem Report(QueueCmdReport cmd) { QueueRequest request = new QueueRequest() { Host = _QueueName, QCommand = (QueueCmd)(int)cmd, //Command = (QueueCmd)(int)cmd }; var response = ConsumItem(request, ConnectTimeout); return(response);// == null ? null : response.ToMessage(); //ReportApi client = new ReportApi(QueueDefaults.QueueManagerPipeName, true); //return (Message)client.Exec(message, (QueueCmd)(int)cmd); }
public T Report <T>(QueueCmdReport cmd) { QueueRequest request = new QueueRequest() { Host = _QueueName, QCommand = (QueueCmd)(int)cmd, //Command = (QueueCmd)(int)cmd }; var res = ConsumItem(request, ConnectTimeout); //var res= response == null ? null : response.ToMessage(); //ReportApi client = new ReportApi(QueueDefaults.QueueManagerPipeName, true); //var res = client.Exec(message, (QueueCmd)(int)cmd); if (res == null) { return(default(T)); } return(res.GetBody <T>()); }
/* * * //bool KeepAlive = false; * //public void ListenerStart() * //{ * // KeepAlive = true; * //} * //public void ListenerStop() * //{ * // KeepAlive = false; * //} * //public void Listener(int connectTimeout, Action<IQueueItem> action) * //{ * // KeepAlive = true; * // ConnectTimeout = connectTimeout; * // while (KeepAlive) * // { * // var message = Receive();// connectTimeout); * // if (message != null) * // action(message); * // Thread.Sleep(100); * // } * //} * * //public void ReceiveAsync(Action<string> onFault, Action<QueueItem> onCompleted,DuplexTypes DuplexType, AutoResetEvent resetEvent)// = DuplexTypes.WaitOne) * //{ * // QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.Dequeue, null); * // { * // Host = _QueueName, * // QCommand = QueueCmd.Dequeue, * // DuplexType = DuplexType * // }; * * // base.SendDuplexAsync(request, onFault, onCompleted, resetEvent); * * * // //var response = base.SendDuplexAsync(request, OnFault); * // //Assists.SetDuration(response); * // //return response;// == null ? null : response.ToMessage(); * * // //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * // //return client.Exec(request, QueueCmd.Dequeue); * //} * * public IQueueItem Receive(DuplexTypes DuplexType= DuplexTypes.WaitOne) * { * QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.Dequeue, null); * { * Host = _QueueName, * QCommand = QueueCmd.Dequeue, * DuplexType= DuplexType * }; * * * var response = base.SendDuplex(request,OnFault); * Assists.SetReceived(response, MessageState.Received); * return response;// == null ? null : response.ToMessage(); * * //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * //return client.Exec(request, QueueCmd.Dequeue); * } * public IQueueItem Receive(QueueRequest request) * { * var response = base.SendDuplex(request, OnFault); * Assists.SetReceived(response, MessageState.Received); * return response;// == null ? null : response.ToMessage(); * //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * //return client.Exec(request, QueueCmd.Dequeue, _ServerName, connectTimeout); * } * //public IQueueItem Receive(int connectTimeout) * //{ * // QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.Dequeue, null); * // { * // Host = _QueueName, * // QCommand = QueueCmd.Dequeue, * // DuplexType = DuplexTypes.NoWaite * // }; * // var response = base.SendDuplex(request, OnFault); * // Assists.SetReceived(response, MessageState.Received); * // return response;// == null ? null : response.ToMessage(); * // //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * // //return client.Exec(request, QueueCmd.Dequeue, _ServerName, connectTimeout); * //} * * public IQueueItem Receive(Priority priority) * { * QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.DequeuePriority, null); * { * Host = _QueueName, * QCommand = QueueCmd.DequeuePriority * }; * request.Priority = priority; * var response = base.SendDuplex(request, OnFault); * Assists.SetReceived(response, MessageState.Received); * return response;// == null ? null : response.ToMessage(); * //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * //return client.Exec(request, QueueCmd.DequeuePriority); * } * * public int Receive(int connectTimeout, Action<IQueueItem> action) * { * ConnectTimeout = connectTimeout; * var message = Receive(); * if (message == null) * return 0; * action(message); * return 1; * } * * public IQueueItem Peek() * { * QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.Peek, null); * { * Host = _QueueName, * QCommand = QueueCmd.Peek * }; * var response = base.SendDuplex(request, OnFault); * Assists.SetReceived(response, MessageState.Peeked); * return response;// == null ? null : response.ToMessage(); * //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * //return client.Exec(request, QueueCmd.Peek); * } * * public IQueueItem Peek(Priority priority) * { * QueueRequest request = new QueueRequest()//_QueueName, QueueCmd.PeekPriority, null); * { * Host = _QueueName, * QCommand = QueueCmd.PeekPriority * }; * request.Priority = priority; * var response = base.SendDuplex(request, OnFault); * Assists.SetReceived(response, MessageState.Peeked); * return response;// == null ? null : response.ToMessage(); * //DequeueApi client = new DequeueApi(QueueDefaults.DequeuePipeName, true); * //return client.Exec(request, QueueCmd.PeekPriority); * } */ #endregion #region Recieve async /* * public void ReceiveAsync(int connectTimeout, Action<IQueueItem> action) * { * if (action == null) * { * throw new ArgumentNullException("ReceiveAsync.action"); * } * * ConnectTimeout = connectTimeout; * using ( * * Task<IQueueItem> task = Task<IQueueItem>.Factory.StartNew(()=> * Receive() * , * canceller.Token, * TaskCreationOptions.LongRunning, * TaskScheduler.Default)) * { * task.Wait(); * if (task.IsCompleted) * { * IQueueItem item = task.Result; * if (item != null) * { * Task.Factory.StartNew(() => action(item)); * } * } * else if (task.IsCanceled) * { * * } * else if (task.IsFaulted) * { * * } * } * } * * public bool ReceiveAsync(int connectTimeout, out IQueueItem message) * { * ConnectTimeout = connectTimeout; * using ( * * Task<IQueueItem> task = Task<IQueueItem>.Factory.StartNew(() => * Receive() * , * canceller.Token, * TaskCreationOptions.LongRunning, * TaskScheduler.Default)) * { * task.Wait(); * if (task.IsCompleted) * { * message = task.Result; * return true; * } * message = null; * return false; * } * } */ #endregion #region Report public IQueueItem Report(QueueCmdReport command, string host) { QueueRequest request = new QueueRequest() { QCommand = (QueueCmd)(int)command, Host = host }; var ack = ConsumItem(request, ConnectTimeout); if (ack == null) { ack = new QueueItem()//MessageState.UnExpectedError, "Server was not responsed for this message", command.ToString(), host); { MessageState = MessageState.UnExpectedError, Label = "Server was not responsed for this message", Host = host }; } return(ack); }