Exemple #1
0
 void FeedbackServer_IncomingCallEvent(CiscoCodec codec, CodecIncomingCallEventArgs args)
 {
     if (IncomingCall != null)
     {
         IncomingCall(this, args);
     }
 }
Exemple #2
0
        object ProcessData(object a)
        {
            OnHttpRequestArgs args = (OnHttpRequestArgs)a;

            try
            {
                args.Response.KeepAlive = true;
#if DEBUG
                CrestronConsole.PrintLine("\r\n>>> CODEC EVENT to {0} from {1}", server.ServerName, args.Connection.RemoteEndPointAddress);
#endif

                if (args.Request.Header.RequestType == "POST")
                {
                    XDocument xml = XDocument.Load(new XmlReader(args.Request.ContentString));

                    XElement identification;
                    string   productID;

                    if (xml.Root.HasAttributes)
                    {
                        XNamespace ns = xml.Root.Attribute("xmlns").Value;
                        identification = xml.Root.Element(ns + "Identification");
                        productID      = identification.Element(ns + "ProductID").Value;
                    }
                    else
                    {
                        identification = xml.Root.Element("Identification");
                        productID      = identification.Element("ProductID").Value;
                    }

                    identification.Remove();
                    XElement element = xml.Root;

#if DEBUG
                    //CrestronConsole.PrintLine(element.ToString());
#endif

                    if (Codec.LoggingEnabled)
                    {
                        Codec.Logger.Log("New Post from {0} at {1}{2}{3}", productID, args.Connection.RemoteEndPointAddress,
                                         CrestronEnvironment.NewLine, element.ToString());
                    }

                    if (element.XName.LocalName == "Event" && element.HasElements)
                    {
                        foreach (XElement eventElement in element.Elements())
                        {
                            switch (eventElement.XName.LocalName)
                            {
                            case "IncomingCallIndication":
                                CodecIncomingCallEventArgs incomingCallArgs = new CodecIncomingCallEventArgs();
                                foreach (XElement e in eventElement.Elements())
                                {
                                    switch (e.XName.LocalName)
                                    {
                                    case "RemoteURI":
                                        incomingCallArgs.RemoteURI = e.Value;
                                        break;

                                    case "DisplayNameValue":
                                        incomingCallArgs.DisplayNameValue = e.Value;
                                        break;

                                    case "CallId":
                                        incomingCallArgs.Call = Codec.Calls.GetOrInsert(int.Parse(e.Value));
                                        break;
                                    }
                                }

                                try
                                {
                                    foreach (XElement e in this.Codec.RequestPath("Configuration/Conference/AutoAnswer").Elements())
                                    {
                                        switch (e.XName.LocalName)
                                        {
                                        case "Delay": incomingCallArgs.AutoAnswerDelay = int.Parse(e.Value); break;

                                        case "Mode": incomingCallArgs.AutoAnswerMode = (e.Value == "On"); break;

                                        case "Mute": incomingCallArgs.AutoAnswerMute = (e.Value == "On"); break;
                                        }
                                    }
                                }
                                catch
                                {
                                    ErrorLog.Error("Error getting auto answer config in Incoming Call event notification handler");
                                }

                                try
                                {
                                    if (IncomingCallEvent != null)
                                    {
                                        IncomingCallEvent(Codec, incomingCallArgs);
                                    }
                                }
                                catch (Exception e)
                                {
                                    ErrorLog.Exception("Error calling IncomingCallEvent in codec", e);
                                }

                                break;

                            case "UserInterface":
                                try
                                {
                                    foreach (XElement widget in eventElement.Element("Extensions").Elements("Widget"))
                                    {
                                        foreach (XElement action in widget.Elements("Action"))
                                        {
#if DEBUG
                                            CrestronConsole.PrintLine(action.ToString());
#endif
                                            if (WidgetActionEvent != null)
                                            {
                                                WidgetActionEvent(this.Codec,
                                                                  new CodecUserInterfaceWidgetActionEventArgs(
                                                                      action.Element("WidgetId").Value,
                                                                      action.Element("Value").Value,
                                                                      (UserInterfaceActionType)Enum.Parse(typeof(UserInterfaceActionType),
                                                                                                          action.Element("Type").Value, true)));
                                            }
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    ErrorLog.Exception("Error in codec event handler for UserInterface Widgets", e);
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        string path = element.XName.LocalName;
                        while (element.Elements().Count() == 1 && element.Elements().FirstOrDefault().HasElements)
                        {
                            element = element.Elements().FirstOrDefault();
                            path    = string.Format("{0}/{1}", path, element.XName.LocalName);

                            if (path == @"Status/Conference/Site")
                            {
                                break;
                            }
                            if (path == @"Status/Conference/Call")
                            {
                                break;
                            }
                            if (path == @"Status/Call")
                            {
                                break;
                            }
                        }

                        if (element == xml.Root && element.Elements().FirstOrDefault() != null)
                        {
                            element = element.Elements().FirstOrDefault();
                            path    = string.Format("{0}/{1}", path, element.XName.LocalName);
                        }

#if DEBUG
                        CrestronConsole.PrintLine("Received {0} Update from {1} for path /{2}", xml.Root.XName.LocalName, productID, path);
                        //ErrorLog.Notice("Received {0} Update from {1} for path /{2}", xml.Root.XName.LocalName, productID, path);
                        //CrestronConsole.PrintLine("{0}\r\n", element.ToString());
#endif
                        if (ReceivedData != null)
                        {
                            try
                            {
                                ReceivedData(this, new CodecFeedbackServerReceiveEventArgs(path, element));
                            }
                            catch (Exception e)
                            {
                                ErrorLog.Exception("Error calling ReceivedData event in CodecFeedbackServer", e);
                            }
                        }
                    }
                }
                else if (args.Request.Header.RequestType == "GET")
                {
                    args.Response.SendError(405, "Method not allowed");
                    return(null);
                }
                return(null);
            }
            catch (Exception e)
            {
                ErrorLog.Exception("Exception on codec http feedback server", e);

                if (Codec.LoggingEnabled)
                {
                    Codec.Logger.Log("ERROR processing post from {0}{1}Content:{1}{2}{1}StackTrace:{1}{3}", args.Connection.RemoteEndPointAddress,
                                     CrestronEnvironment.NewLine, args.Request.ContentString, e.StackTrace);
                }

                args.Response.SendError(500, "Internal server error");
                return(null);
            }
        }