/// <summary> /// Execute remote command from client to cache using <see cref="QueueMessage"/>. /// </summary> /// <param name="message"></param> /// <returns></returns> public NetStream ExecRemote(QueueMessage message) { QueueState state = QueueState.Ok; DateTime requestTime = DateTime.Now; try { switch (message.Command) { case QueueCmd.Reply: return(QueueEntry.GetAckStream(QueueState.Ok, QueueCmd.Reply, message.Key)); case QueueCmd.AddItem: return(message.AsyncAckTask(() => AddItemWithAck(message), message.Command)); case QueueCmd.GetValue: return(message.AsyncAckTask(() => GetValueStream(message.Key), message.Command)); case QueueCmd.FetchValue: return(message.AsyncAckTask(() => FetchValueStream(message.Key), message.Command)); case QueueCmd.GetItem: return(message.AsyncAckTask(() => GetItemStream(message.Key), message.Command)); case QueueCmd.FetchItem: return(message.AsyncAckTask(() => FetchItemStream(message.Key), message.Command)); case QueueCmd.ViewItem: return(message.AsyncAckTask(() => ViewItemStream(message.Key), message.Command)); case QueueCmd.RemoveItem: return(message.AsyncAckTask(() => RemoveItem(message), message.Command)); case QueueCmd.RemoveItemAsync: message.AsyncTask(() => RemoveItemAsync(message.Key)); break; case QueueCmd.CopyItem: { var args = message.GetArgs(); return(message.AsyncAckTask(() => CopyItemInternal(args.Get <string>(KnowsArgs.Source), args.Get <string>(KnowsArgs.Destination), message.Expiration), message.Command)); } case QueueCmd.CutItem: { var args = message.GetArgs(); return(message.AsyncAckTask(() => CutItemInternal(args.Get <string>(KnowsArgs.Source), args.Get <string>(KnowsArgs.Destination), message.Expiration), message.Command)); } case QueueCmd.KeepAliveItem: message.AsyncTask(() => KeepAliveItem(message.Key)); break; case QueueCmd.RemoveQueueSessionItems: return(message.AsyncAckTask(() => RemoveQueueSessionItemsAsync(message), message.Command)); case QueueCmd.LoadData: return(message.AsyncAckTask(() => LoadData(message), message.Command)); } } catch (QueueException ce) { state = ce.State; LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote QueueException error: " + ce.Message); } catch (System.Runtime.Serialization.SerializationException se) { state = QueueState.SerializationError; LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote SerializationException error: " + se.Message); } catch (ArgumentException aex) { state = QueueState.ArgumentsError; QueueLogger.Logger.LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote ArgumentException: " + aex.Message); } catch (Exception ex) { state = QueueState.UnexpectedError; LogAction(QueueAction.QueueException, QueueActionState.Error, "QueueAgent.ExecRemote error: " + ex.Message); } finally { if (QueueSettings.EnablePerformanceCounter) { if (QueueSettings.EnableAsyncTask) { AgentManager.PerformanceTasker.Add(new Nistec.Threading.TaskItem(() => PerformanceCounter.AddResponse(requestTime, state, true), QueueDefaults.DefaultTaskTimeout)); } else { Task.Factory.StartNew(() => PerformanceCounter.AddResponse(requestTime, state, true)); } } } return(QueueEntry.GetAckStream(state, message.Command)); }