public Stream QueueMemberList(IpccQueue ipccQueue)
        {
            InvokeResult <string> result = new InvokeResult <string> {
                Success = true
            };

            if (!string.IsNullOrEmpty(ipccQueue.RemoteUrl))
            {
                IList <StringObjectDictionary> queueMembers = new List <StringObjectDictionary>();

                if (ipccQueue.QueueNames != null && ipccQueue.QueueNames.Count > 0)
                {
                    try
                    {
                        foreach (string item in ipccQueue.QueueNames)
                        {
                            HttpAdapter.getSyncTo(ipccQueue.RemoteUrl + item, (ret, res) =>
                            {
                                dynamic agent = JsonConvert.DeserializeObject(ret);
                                if (agent.success == "true" && agent.data != null)
                                {
                                    foreach (var key in agent.data)
                                    {
                                        queueMembers.Add(new { queueName = item, uuid = key.uuid, cid_number = key.cid_number, cid_name = key.cid_name, join_time = key.join_time }.ToStringObjectDictionary());
                                    }
                                }
                            });
                        }

                        if (queueMembers.Count > 0)
                        {
                            result.ret = JsonConvert.SerializeObject(queueMembers);
                        }
                        else
                        {
                            result.ret = "";
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Success      = false;
                        result.ErrorMessage = ex.ToString();
                    }
                }
            }

            byte[] resultBytes = Encoding.UTF8.GetBytes(result.ToJson());
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            return(new MemoryStream(resultBytes));
        }
        public Stream QueueAgentList(IpccQueue ipccQueue)
        {
            InvokeResult <string> result = new InvokeResult <string> {
                Success = true
            };

            if (!string.IsNullOrEmpty(ipccQueue.RemoteUrl))
            {
                IList <StringObjectDictionary> queueAgents = new List <StringObjectDictionary>();

                if (ipccQueue.QueueNames != null && ipccQueue.QueueNames.Count > 0)
                {
                    try {
                        string agent_no = "";
                        foreach (string item in ipccQueue.QueueNames)
                        {
                            HttpAdapter.getSyncTo(ipccQueue.RemoteUrl + item, (ret, res) =>
                            {
                                dynamic agent = JsonConvert.DeserializeObject(ret);
                                if (agent.success == "true" && agent.data != null)
                                {
                                    StringObjectDictionary sod;
                                    foreach (var key in agent.data)
                                    {
                                        agent_no = (string)key.agent_no;

                                        sod = queueAgents.FirstOrDefault(s => s["agent_no"].Equals(agent_no));
                                        if (sod == null)
                                        {
                                            sod = new StringObjectDictionary();
                                            sod.Add("agent_no", agent_no);
                                            sod.Add("uuid", key.uuid);
                                            sod.Add("status", key.status);
                                            sod.Add("cause", key.cause);
                                            sod.Add("state", key.state);
                                            sod.Add("last_offered_call", key.last_offered_call);
                                            sod.Add("last_status_change", key.last_status_change);
                                            sod.Add("no_answer_count", key.no_answer_count);
                                            sod.Add("answer_count", key.answer_count);
                                            sod.Add("ext", (item.IndexOf("999") > -1 ? 1 : 0));
                                            sod.Add("queueName", new List <string>()
                                            {
                                                item
                                            });
                                            queueAgents.Add(sod);
                                        }
                                        else
                                        {
                                            List <string> queueNames = (List <string>)sod.First(s => s.Key == "queueName").Value;
                                            if (queueNames != null)
                                            {
                                                queueNames.Add(item);
                                            }
                                        }
                                    }
                                }
                            });
                        }

                        if (queueAgents.Count > 0)
                        {
                            result.ret = JsonConvert.SerializeObject(queueAgents);
                        }
                        else
                        {
                            result.ret = "";
                        }
                    }
                    catch (Exception ex) {
                        result.Success      = false;
                        result.ErrorMessage = ex.ToString();
                    }
                }
            }

            byte[] resultBytes = Encoding.UTF8.GetBytes(result.ToJson());
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            return(new MemoryStream(resultBytes));
        }