Exemplo n.º 1
0
        internal void Publish(string sipUri, string basic, string note, int expires)
        {
            UserAgent pua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(sipUri) };
            Useragents.Add(pua);
            Message request = pua.CreateRequest("PUBLISH");
            request.InsertHeader(new Header("presence", "Event"));
            request.InsertHeader(new Header(pua.LocalParty.ToString(), "P-Preferred-Identity"));
            request.InsertHeader(new Header("application/pidf+xml", "Content-Type"));

            StringBuilder sb = new StringBuilder();
            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            sb.Append("<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" xmlns:im=\"urn:ietf:params:xml:ns:pidf:im\" entity=\"" + sipUri + "\">\n");
            sb.Append("<tuple id=\"Sharp_IMS_Client\">\n");
            sb.Append("<status>\n");
            sb.Append("<basic>" + basic + "</basic>\n");
            sb.Append("</status>\n");
            sb.Append("<note>" + note + "</note>\n");
            sb.Append("</tuple>\n");
            sb.Append("</presence>\n");
            request.Body = sb.ToString();
            pua.SendRequest(request);
        }
Exemplo n.º 2
0
 public void SendInvite(string uri, SDP sdp)
 {
     uri = checkURI(uri);
     UserAgent cua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) };
     Useragents.Add(cua);
     Message invite = cua.CreateRequest("INVITE");
     invite.InsertHeader(new Header("application/sdp", "Content-Type"));
     invite.Body = sdp.ToString();
     cua.SendRequest(invite);
 }
Exemplo n.º 3
0
 public void SendMessage(string uri, string message, string contentType = "text/plain")
 {
     uri = checkURI(uri);
     UserAgent mua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) };
     Useragents.Add(mua);
     Message m = mua.CreateRequest("MESSAGE", message);
     m.InsertHeader(new Header(contentType, "Content-Type"));
     mua.SendRequest(m);
 }
Exemplo n.º 4
0
        private static void UpdateServiceMetrics(Dictionary<string, float> metrics)
        {
            UserAgent pua = new UserAgent(_app.Stack)
            {
                RemoteParty = new Address("<sip:" + ServerURI + ">"),
                LocalParty = _localParty
            };
            Message request = pua.CreateRequest("PUBLISH");
            request.InsertHeader(new Header("service-description", "Event"));
            request.InsertHeader(new Header("application/SERV_DESC+xml", "Content-Type"));
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("Resources/ServiceDescription.xml");
            XmlNode node = xmlDoc.SelectSingleNode("Service/Metrics/TotalCPU");
            node.InnerText = String.Format("{0:0.##}", metrics["totalCPU"]);

            node = xmlDoc.SelectSingleNode("Service/Metrics/CPU");
            node.InnerText = String.Format("{0:0.##}", metrics["cpu"]);

            node = xmlDoc.SelectSingleNode("Service/Metrics/TotalMemory");
            node.InnerText = String.Format("{0:0.##}", metrics["memAvailable"]) + " MB";

            node = xmlDoc.SelectSingleNode("Service/Metrics/Memory");
            node.InnerText = String.Format("{0:0.##}", ((metrics["memUsed"] / 1024) / 1024)) + " MB";

            request.Body = xmlDoc.OuterXml;
            pua.SendRequest(request);
        }
Exemplo n.º 5
0
 public void SendInvite(string uri)
 {
     uri = checkURI(uri);
     UserAgent cua = new UserAgent(Stack) { LocalParty = PublicServiceIdentity, RemoteParty = new Address(uri) };
     Useragents.Add(cua);
     Message invite = cua.CreateRequest("INVITE");
     cua.SendRequest(invite);
 }
Exemplo n.º 6
0
        public void SendIM(string uri, string message,string contentType = "text/plain")
        {
            uri = checkURI(uri);
            if (IsRegistered())
            {

                UserAgent mua = new UserAgent(Stack) {LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri)};
                Useragents.Add(mua);
                Message m = mua.CreateRequest("MESSAGE", message);
                m.InsertHeader(new Header(contentType, "Content-Type"));
                mua.SendRequest(m);
            }
        }
Exemplo n.º 7
0
 private static void PublishService(bool determineIP, int port)
 {
     UserAgent pua = new UserAgent(_app.Stack) { RemoteParty = new Address("<sip:" + ServerURI + ">"), LocalParty = _localParty };
     Message request = pua.CreateRequest("PUBLISH");
     request.InsertHeader(new Header("service-description", "Event"));
     request.InsertHeader(new Header("application/SERV_DESC+xml", "Content-Type"));
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load("Resources/ServiceDescription.xml");
     if (determineIP)
     {
         XmlNode IPnode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_IP");
         IPnode.InnerText = _localIP;
     }
     XmlNode Portnode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_Port");
     Portnode.InnerText = Convert.ToString(port);
     xmlDoc.Save("Resources/ServiceDescription.xml");
     request.Body = xmlDoc.OuterXml;
     pua.SendRequest(request);
     ConsoleLog.Info("Sent service information to SRS");
 }
Exemplo n.º 8
0
 public void Invite(string uri, SDP sdp)
 {
     uri = checkURI(uri);
     if (IsRegistered())
     {
         UserAgent cua = new UserAgent(Stack) { LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri) };
         Useragents.Add(cua);
         Message invite = cua.CreateRequest("INVITE");
         invite.InsertHeader(new Header("application/sdp", "Content-Type"));
         invite.Body= sdp.ToString();
         cua.SendRequest(invite);
     }
     else
     {
         Log.Error("isRegistered failed in invite message");
     }
 }
Exemplo n.º 9
0
 public void Invite(string uri)
 {
     uri = checkURI(uri);
     if (IsRegistered())
     {
         UserAgent cua = new UserAgent(Stack) {LocalParty = RegisterUA.LocalParty, RemoteParty = new Address(uri)};
         Useragents.Add(cua);
         Message invite = cua.CreateRequest("INVITE");
         cua.SendRequest(invite);
     }
     else
     {
         Log.Error("isRegistered failed in invite message");
     }
 }
 public void Subscribe(string sipUri)
 {
     UserAgent pua = new UserAgent(_app.Stack)
                         {RemoteParty = new Address(sipUri), LocalParty = _app.RegisterUA.LocalParty};
     Message request = pua.CreateRequest("SUBSCRIBE");
     request.InsertHeader(new Header("presence", "Event"));
     pua.SendRequest(request);
 }
Exemplo n.º 11
0
 private static void PublishService(bool determineIP, int port)
 {
     UserAgent pua = new UserAgent(_app.Stack)
         {
             RemoteParty = new Address("<sip:[email protected]>"),
             LocalParty = _localparty
         };
     Message request = pua.CreateRequest("PUBLISH");
     request.InsertHeader(new Header("service-description", "Event"));
     request.InsertHeader(new Header("application/SERV_DESC+xml", "Content-Type"));
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load("Resources/ServiceDescription.xml");
     if (determineIP)
     {
         XmlNode ipNode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_IP");
         if (ipNode == null)
         {
             Log.Error("Service XML does not contain Server IP node");
             return;
         }
         ipNode.InnerText = _localIP;
     }
     XmlNode portNode = xmlDoc.SelectSingleNode("Service/Service_Config/Server_Port");
     if (portNode == null)
     {
         Log.Error("Service XML does not contain Server Port node");
         return;
     }
     portNode.InnerText = Convert.ToString(port);
     xmlDoc.Save("Resources/ServiceDescription.xml");
     request.Body = xmlDoc.OuterXml;
     pua.SendRequest(request);
 }
Exemplo n.º 12
0
 private void SendServicesChains(object sender, ElapsedEventArgs e)
 {
     DataTable serviceFlows = ReadServiceFlowDB();
     bool updateNeeded = false;
     if (serviceFlows == null) return;
     Dictionary<string, List<ServiceFlow>> changedFlows = new Dictionary<string, List<ServiceFlow>>();
     foreach (DataRow r in serviceFlows.Rows)
     {
         DateTime t2 = Convert.ToDateTime(r["LastUpdatedDate"].ToString());
         if (_lastupdate >= t2) continue;
         changedFlows[r["email"].ToString()] =
             r["PropertyValuesString"].ToString().UnzipAndDeserialize<List<ServiceFlow>>();
         updateNeeded = true;
     }
     if (updateNeeded)
     {
         UserAgent serviceChainUA = new UserAgent(_app.Stack)
             {
                 RemoteParty = new Address("<sip:[email protected]>"),
                 LocalParty = _localparty
             };
         _app.Useragents.Add(serviceChainUA);
         Message m = serviceChainUA.CreateRequest("MESSAGE", changedFlows.SerializeAndZip());
         m.InsertHeader(new Header("APPLICATION/SERV_DESC+XML", "Content-Type"));
         serviceChainUA.SendRequest(m);
         _lastupdate = DateTime.Now;
         //request.InsertHeader(new Header("service.description", "Event"));
     }
 }