Exemplo n.º 1
0
        /// <summary>
        /// Constructs an instance of ManagerResponse based on a map of attributes.
        /// </summary>
        /// <param name="attributes">the attributes and their values. The keys of this map must be all lower case.</param>
        /// <returns>the response with the given attributes.</returns>
        internal static ManagerResponse BuildResponse(Dictionary <string, string> attributes)
        {
            ManagerResponse response;

            string responseType = ((string)attributes["response"]).ToLower(Helper.CultureInfo);

            // Determine type
            if (responseType == "error")
            {
                response = new ManagerError();
            }
            else if (attributes.ContainsKey("challenge"))
            {
                response = new ChallengeResponse();
            }
            else if (attributes.ContainsKey("mailbox") && attributes.ContainsKey("waiting"))
            {
                response = new MailboxStatusResponse();
            }
            else if (attributes.ContainsKey("mailbox") && attributes.ContainsKey("newmessages") && attributes.ContainsKey("oldmessages"))
            {
                response = new MailboxCountResponse();
            }
            else if (attributes.ContainsKey("exten") && attributes.ContainsKey("context") && attributes.ContainsKey("hint") && attributes.ContainsKey("status"))
            {
                response = new ExtensionStateResponse();
            }
            else
            {
                response = new ManagerResponse();
            }

            Helper.SetAttributes(response, attributes);
            return(response);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Generate a collection of parking data
 /// </summary>
 public static IEnumerable <ParkingSpot> PullParkingData(ManagerConnection ami)
 {
     for (int i = 701; i < 706; i++)
     {
         ExtensionStateAction action = new ExtensionStateAction()
         {
             Exten    = i.ToString(),
             Context  = "blf",
             ActionId = "1"
         };
         ExtensionStateResponse res = null;
         try
         {
             res = (ExtensionStateResponse)ami.SendAction(action);
         }
         catch (Exception e)
         {
             e.Warn();
         }
         if (res != null)
         {
             yield return new ParkingSpot(i.ToString())
                    {
                        InUse = res.Status == 1
                    }
         }
         ;
     }
 }
Exemplo n.º 3
0
        public Int32 StatusExtension(String Extension)
        {
            ExtensionStateAction Ext = new ExtensionStateAction();

            Ext.Exten   = Extension;
            Ext.Context = "from-internal";
            ExtensionStateResponse Resp = (ExtensionStateResponse)Conn.SendAction(Ext, 30000);

            return(Resp.Status);
        }
Exemplo n.º 4
0
        public static int GetExtensionStatus(ManagerConnection ami, int number)
        {
            ExtensionStateAction a = new ExtensionStateAction()
            {
                Exten    = number.ToString(),
                Context  = "blf",
                ActionId = "1"
            };
            int res = 4;
            ExtensionStateResponse response = null;

            try
            {
                response = (ExtensionStateResponse)ami.SendAction(a);
                res      = response.Status;
            }
            catch // if the response is invalid due to a broken extension, set the value to 0
            {
                Console.WriteLine("Bad cast, " + a.Exten);
            }
            return(res);
        }