本文整理汇总了C#中OpenSource.UPnP.HTTPMessage.AddTag方法的典型用法代码示例。如果您正苦于以下问题:C# HTTPMessage.AddTag方法的具体用法?C# HTTPMessage.AddTag怎么用?C# HTTPMessage.AddTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenSource.UPnP.HTTPMessage
的用法示例。
在下文中一共展示了HTTPMessage.AddTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MSEARCH
private HTTPMessage[] MSEARCH(UPnPDevice device)
{
ArrayList PacketList = new ArrayList();
foreach (UPnPDevice d in device.EmbeddedDevices)
{
foreach (HTTPMessage m in MSEARCH(d))
{
PacketList.Add(m);
}
}
HTTPMessage rq;
rq = new HTTPMessage();
rq.Directive = "M-SEARCH";
rq.DirectiveObj = "*";
rq.AddTag("MX", "5");
rq.AddTag("ST", "uuid:" + device.UniqueDeviceName);
rq.AddTag("Host", "239.255.255.250:1900");
rq.AddTag("MAN", "\"ssdp:discover\"");
PacketList.Add(rq);
rq = new HTTPMessage();
rq.Directive = "M-SEARCH";
rq.DirectiveObj = "*";
rq.AddTag("MX", "5");
rq.AddTag("ST", device.DeviceURN);
rq.AddTag("Host", "239.255.255.250:1900");
rq.AddTag("MAN", "\"ssdp:discover\"");
PacketList.Add(rq);
foreach (UPnPService s in device.Services)
{
rq = new HTTPMessage();
rq.Directive = "M-SEARCH";
rq.DirectiveObj = "*";
rq.AddTag("MX", "5");
rq.AddTag("ST", s.ServiceURN);
rq.AddTag("Host", "239.255.255.250:1900");
rq.AddTag("MAN", "\"ssdp:discover\"");
PacketList.Add(rq);
}
return ((HTTPMessage[])PacketList.ToArray(typeof(HTTPMessage)));
}
示例2: Validate_DISCOVERY
private void Validate_DISCOVERY()
{
//Test all types of M-SEARCH, both valid and invalid
MSEARCHTable.Clear();
ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(ReceiveSink);
ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(MSEARCHSink);
HTTPMessage rq = new HTTPMessage();
byte[] rbuf;
IPEndPoint d = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
rq.Directive = "M-SEARCH";
rq.DirectiveObj = "*";
rq.AddTag("MX", "5");
rq.AddTag("Host", "239.255.255.250:1900");
rq.AddTag("MAN", "\"ssdp:discover\"");
rq.AddTag("ST", "ssdp:all");
rbuf = rq.RawPacket;
ASocket.Send(rbuf, 0, rbuf.Length, d);
MRE.Reset();
StartCountDown(0, 91);
MRE.WaitOne(8000, false);
AbortCountDown();
if (MSEARCHTable.ContainsKey("upnp:rootdevice"))
{
AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> OK");
}
else
{
DISCOVERY = UPnPTestStates.Failed;
AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> MISSING");
}
foreach (HTTPMessage m in MSEARCH(TestDevice))
{
if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim()))
{
AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> OK");
}
else
{
DISCOVERY = UPnPTestStates.Failed;
AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> MISSING");
}
}
// Test MSEARCH upnp:rootdevice, and others
MSEARCHTable.Clear();
rq.AddTag("ST", "upnp:rootdevice");
rbuf = rq.RawPacket;
ASocket.Send(rbuf, 0, rbuf.Length, d);
foreach (HTTPMessage m in MSEARCH(TestDevice))
{
this.sample2 += "\r\n\r\n" + m.StringPacket;
ASocket.Send(m.RawPacket, 0, m.RawPacket.Length, d);
}
MRE.Reset();
StartCountDown(8, 91);
MRE.WaitOne(8000, false);
AbortCountDown();
ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(MSEARCHSink);
if (MSEARCHTable.ContainsKey("upnp:rootdevice"))
{
AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<upnp:rootdevice>> OK");
}
else
{
DISCOVERY = UPnPTestStates.Failed;
AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<upnp:rootdevice>> MISSING");
}
foreach (HTTPMessage m in MSEARCH(TestDevice))
{
if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim()))
{
AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> OK");
}
else
{
DISCOVERY = UPnPTestStates.Failed;
AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> MISSING");
}
}
// Test Invalid MSEARCHes
string ST = "";
MSEARCHTable.Clear();
ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(BadMSEARCHSink);
rq = new HTTPMessage();
rq.Directive = "M-SEARCH";
rq.DirectiveObj = "*";
rq.AddTag("MX", "2");
rq.AddTag("Host", "239.255.255.250:1900");
rq.AddTag("MAN", "\"ssdp:discover\"");
rq.AddTag("ST", "uuid:___" + TestDevice.UniqueDeviceName + "___");
rbuf = rq.RawPacket;
ASocket.Send(rbuf, 0, rbuf.Length, d);
MRE.Reset();
StartCountDown(16, 91);
//.........这里部分代码省略.........
示例3: FindDeviceAsync
/// <summary>
/// Searches for a SearchTarget Asynchronously
/// </summary>
/// <param name="SearchTarget">The Target</param>
public void FindDeviceAsync(String SearchTarget, IPEndPoint RemoteEP)
{
HTTPMessage request = new HTTPMessage();
request.Directive = "M-SEARCH";
request.DirectiveObj = "*";
request.AddTag("ST", SearchTarget);
request.AddTag("MX", MX.ToString());
request.AddTag("MAN", "\"ssdp:discover\"");
if (RemoteEP.AddressFamily == AddressFamily.InterNetwork) request.AddTag("HOST", RemoteEP.ToString()); // "239.255.255.250:1900"
if (RemoteEP.AddressFamily == AddressFamily.InterNetworkV6) request.AddTag("HOST", string.Format("[{0}]:{1}", RemoteEP.Address.ToString(), RemoteEP.Port)); // "[FF05::C]:1900"
byte[] buffer = UTF8Encoding.UTF8.GetBytes(request.StringPacket);
IPAddress[] LocalAddresses = NetInfo.GetLocalAddresses();
foreach (IPAddress localaddr in LocalAddresses)
{
try
{
UdpClient session = (UdpClient)SSDPSessions[localaddr];
if (session == null)
{
session = new UdpClient(new IPEndPoint(localaddr, 0));
session.EnableBroadcast = true;
session.BeginReceive(new AsyncCallback(OnReceiveSink), session);
SSDPSessions[localaddr] = session;
}
if (RemoteEP.AddressFamily != session.Client.AddressFamily) continue;
if ((RemoteEP.AddressFamily == AddressFamily.InterNetworkV6) && ((IPEndPoint)session.Client.LocalEndPoint).Address.IsIPv6LinkLocal == true && RemoteEP != Utils.UpnpMulticastV6EndPoint2) continue;
if ((RemoteEP.AddressFamily == AddressFamily.InterNetworkV6) && ((IPEndPoint)session.Client.LocalEndPoint).Address.IsIPv6LinkLocal == false && RemoteEP != Utils.UpnpMulticastV6EndPoint1) continue;
IPEndPoint lep = (IPEndPoint)session.Client.LocalEndPoint;
if (session.Client.AddressFamily == AddressFamily.InterNetwork)
{
session.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, localaddr.GetAddressBytes());
}
else if (session.Client.AddressFamily == AddressFamily.InterNetworkV6)
{
session.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface, BitConverter.GetBytes((int)localaddr.ScopeId));
}
session.Send(buffer, buffer.Length, RemoteEP);
session.Send(buffer, buffer.Length, RemoteEP);
}
catch (Exception ex)
{
OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "CP Failure: " + localaddr.ToString());
OpenSource.Utilities.EventLogger.Log(ex);
}
}
}
示例4: HandleGetOrHeadRequest
//.........这里部分代码省略.........
{
lock (session)
{
// get the intended length, if known
long expectedLength = -1;
if (mapping.OverrideRedirectedStreamLength)
{
expectedLength = mapping.ExpectedStreamLength;
}
else
{
expectedLength = mapping.RedirectedStream.Length;
}
if (String.Compare(msg.Directive, "HEAD", true) == 0)
{
// must be a head request - reply with 200/OK, content type, content length
HTTPMessage head = new HTTPMessage();
head.StatusCode = 200;
head.StatusData = "OK";
head.ContentType = type;
if (expectedLength >= 0)
{
// if we can calculate the length,
// then we provide a content-length and
// also indicate that range requests can be
// handled.
head.OverrideContentLength = true;
string rangeStr = msg.GetTag("RANGE");
if ((rangeStr == null) || (rangeStr == ""))
{
head.AddTag("CONTENT-LENGTH", expectedLength.ToString());
head.AddTag("ACCEPT-RANGES", "bytes");
}
else
{
ArrayList rangeSets = new ArrayList();
head.StatusCode = 206;
AddRangeSets(rangeSets, rangeStr.Trim().ToLower(), expectedLength);
if (rangeSets.Count == 1)
{
head.AddTag("Content-Range", "bytes " + ((HTTPSession.Range)(rangeSets[0])).Position.ToString() + "-" + ((int)(((HTTPSession.Range)(rangeSets[0])).Position+((HTTPSession.Range)(rangeSets[0])).Length-1)).ToString() + "/" + expectedLength.ToString());
head.AddTag("Content-Length", ((HTTPSession.Range)(rangeSets[0])).Length.ToString());
}
}
}
else
{
// can't calculate length => can't do range
head.AddTag("ACCEPT-RANGES", "none");
}
session.Send(head);
is404 = false;
}
else
{
ArrayList rangeSets = new ArrayList();
string rangeStr = msg.GetTag("RANGE");
// Only allow range requests for content where we have the
// entire length and also only for requests that have
// also provided an allowed range.
if ((rangeStr == null) || (rangeStr != ""))
{
示例5: UnSubscribe
/// <summary>
/// Unsubscribe to UPnPEvent
/// </summary>
/// <param name="cb"></param>
public void UnSubscribe(UPnPEventHandler cb)
{
bool processUnSubscribe = false;
lock (SubscribeLock)
{
--SubscribeCounter;
if (SubscribeCounter <= 0)
{
SubscribeCounter = 0;
processUnSubscribe = true;
}
if (cb == null)
{
processUnSubscribe = true;
OnUPnPEvent = null;
}
else
{
OnUPnPEvent -= cb;
}
}
if (processUnSubscribe == false) return;
HTTPMessage request = new HTTPMessage();
String WebIP;
int WebPort;
String Tag;
SSDP.ParseURL(this.__eventurl, out WebIP, out WebPort, out Tag);
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(WebIP), WebPort);
request.Directive = "UNSUBSCRIBE";
request.DirectiveObj = Tag;
request.AddTag("Host", WebIP + ":" + WebPort.ToString()); // WebIP is already formatted for IPv6
request.AddTag("SID", CurrentSID);
HTTPRequest UR = new HTTPRequest();
SubscribeRequestTable[UR] = UR;
UR.OnResponse += new HTTPRequest.RequestHandler(HandleUnsubscribeResponse);
CurrentSID = "";
UR.PipelineRequest(dest, request, null);
}
示例6: _SubscribeEvent
internal HTTPMessage _SubscribeEvent(out String SID, String CallbackURL, String Timeout)
{
SubscriberInfo sinfo = new SubscriberInfo();
sinfo.SID = GetNewSID();
sinfo.CallbackURL = CallbackURL;
sinfo.SEQ = 1;
int to = int.Parse(Timeout);
if (to == 0)
{
sinfo.Expires = -1;
}
else
{
sinfo.Expires = DateTime.Now.AddSeconds(to).Ticks;
}
SubscriberTable[sinfo.SID] = sinfo;
// Send an inital Event
//SSDP.ParseURL(CallbackURL,out WebIP, out WebPort, out Tag);
HTTPMessage Packet = new HTTPMessage();
Packet.Directive = "NOTIFY";
Packet.AddTag("Content-Type", "text/xml");
Packet.AddTag("NT", "upnp:event");
Packet.AddTag("NTS", "upnp:propchange");
Packet.AddTag("SID", sinfo.SID);
Packet.AddTag("SEQ", "0");
Packet.AddTag("CONNECTION", "close");
Packet.BodyBuffer = BuildEventXML();
SID = sinfo.SID;
SubscriptionAddedEvent.Fire(this); // Trigger event saying that a subscription was added
return (Packet);
}
示例7: BuildNotifyPacket
private HTTPMessage[] BuildNotifyPacket(IPAddress local)
{
ArrayList NotifyList = new ArrayList();
IPEndPoint localep = null;
HTTPMessage msg;
try
{
localep = ((MiniWebServer)WebServerTable[local.ToString()]).LocalIPEndPoint;
}
catch (Exception ex)
{
OpenSource.Utilities.EventLogger.Log(ex);
return (new HTTPMessage[0]);
}
String BaseURL;
if (localep.AddressFamily == AddressFamily.InterNetworkV6)
{
string ipaddr = localep.Address.ToString();
int i = ipaddr.IndexOf("%");
if (i > 0)
ipaddr = ipaddr.Substring(0, i);
BaseURL = "http://[" + ipaddr + "]:" + localep.Port.ToString() + "/";
}
else
{
BaseURL = "http://" + localep.Address.ToString() + ":" + localep.Port.ToString() + "/";
}
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", "upnp:rootdevice");
msg.AddTag("NTS", "ssdp:alive");
msg.AddTag("Location", BaseURL);
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::upnp:rootdevice");
msg.AddTag("Server", "Windows NT/5.0, UPnP/1.0");
msg.AddTag("Cache-Control", "max-age=" + ExpirationTimeout.ToString());
NotifyList.Add(msg);
BuildNotifyPacket2(BaseURL, NotifyList, local);
foreach (UPnPDevice d in this.EmbeddedDevices)
{
d.BuildNotifyPacket2(BaseURL, NotifyList, local);
}
return ((HTTPMessage[])NotifyList.ToArray(typeof(HTTPMessage)));
}
示例8: InvokeAsync
/// <summary>
/// Invokes a method on this service with specific callbacks
/// </summary>
/// <param name="MethodName">Name of Method</param>
/// <param name="InVarArr">Array of UPnPArguments</param>
/// <param name="InvokeCallback">Callback for Success</param>
/// <param name="ErrorCallback">Callback for Failed</param>
/// <returns>Unique Handle identifier</returns>
public void InvokeAsync(String MethodName, UPnPArgument[] InVarArr,
object Tag,
UPnPService.UPnPServiceInvokeHandler InvokeCallback,
UPnPService.UPnPServiceInvokeErrorHandler ErrorCallback)
{
HTTPMessage request = new HTTPMessage();
if (InVarArr == null)
{
InVarArr = new UPnPArgument[0];
}
UPnPAction action = (UPnPAction)RemoteMethods[MethodName];
if (action == null)
{
throw (new UPnPInvokeException(MethodName, InVarArr, MethodName + " is not currently defined in this object"));
}
else
{
action.ValidateArgs(InVarArr);
}
String WebIP;
String sName;
int WebPort;
SSDP.ParseURL(__controlurl, out WebIP, out WebPort, out sName);
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(WebIP), WebPort);
request.Directive = "POST";
request.DirectiveObj = sName;
request.AddTag("Host", WebIP + ":" + WebPort);
request.AddTag("Content-Type", "text/xml; charset=\"utf-8\"");
request.AddTag("SoapAction", "\"" + ServiceURN + "#" + MethodName + "\"");
MemoryStream mstream = new MemoryStream(4096);
XmlTextWriter W = new XmlTextWriter(mstream, System.Text.Encoding.UTF8);
W.Formatting = Formatting.Indented;
W.Indentation = 3;
W.WriteStartDocument();
String S = "http://schemas.xmlsoap.org/soap/envelope/";
W.WriteStartElement("s", "Envelope", S);
W.WriteAttributeString("s", "encodingStyle", S, "http://schemas.xmlsoap.org/soap/encoding/");
W.WriteStartElement("s", "Body", S);
W.WriteStartElement("u", MethodName, ServiceURN);
for (int ID = 0; ID < InVarArr.Length; ++ID)
{
if (action.GetArg(InVarArr[ID].Name).Direction == "in")
{
W.WriteElementString(InVarArr[ID].Name, UPnPService.SerializeObjectInstance(InVarArr[ID].DataValue));
}
}
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndDocument();
W.Flush();
byte[] wbuf = new Byte[mstream.Length - 3];
mstream.Seek(3, SeekOrigin.Begin);
mstream.Read(wbuf, 0, wbuf.Length);
W.Close();
request.BodyBuffer = wbuf;
AsyncInvokeInfo state = new AsyncInvokeInfo();
state.Args = InVarArr;
state.MethodName = MethodName;
state.Packet = request;
state.Tag = Tag;
state.InvokeCB = InvokeCallback;
state.ErrorCB = ErrorCallback;
InvocationPipeline.PipelineRequest(dest, request, state);
}
示例9: BuildByePacket
private HTTPMessage[] BuildByePacket(IPAddress local)
{
HTTPMessage msg;
ArrayList ByeList = new ArrayList();
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", "upnp:rootdevice");
msg.AddTag("NTS", "ssdp:byebye");
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::upnp:rootdevice");
ByeList.Add(msg);
BuildByePacket2(ByeList, local);
foreach (UPnPDevice d in this.EmbeddedDevices)
{
d.BuildByePacket2(ByeList, local);
}
return ((HTTPMessage[])ByeList.ToArray(typeof(HTTPMessage)));
}
示例10: BuildByePacket2
private void BuildByePacket2(ArrayList ByeList, IPAddress local)
{
HTTPMessage msg;
for (int id = 0; id < Services.Length; ++id)
{
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", Services[id].ServiceURN);
msg.AddTag("NTS", "ssdp:byebye");
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::" + Services[id].ServiceURN);
ByeList.Add(msg);
}
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", DeviceURN);
msg.AddTag("NTS", "ssdp:byebye");
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::" + DeviceURN);
ByeList.Add(msg);
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", "uuid:" + UniqueDeviceName);
msg.AddTag("NTS", "ssdp:byebye");
msg.AddTag("USN", "uuid:" + UniqueDeviceName);
ByeList.Add(msg);
}
示例11: ParseInvokeResponse
internal HTTPMessage ParseInvokeResponse(string MethodTag, string SOAPACTION, string urn, object RetVal, UPnPArgument[] OutArgs)
{
HTTPMessage response = new HTTPMessage();
MemoryStream mstream = new MemoryStream(4096);
XmlTextWriter W = new XmlTextWriter(mstream, System.Text.Encoding.UTF8);
W.Formatting = Formatting.Indented;
W.Indentation = 3;
W.WriteStartDocument();
String S = "http://schemas.xmlsoap.org/soap/envelope/";
W.WriteStartElement("s", "Envelope", S);
W.WriteAttributeString("s", "encodingStyle", S, "http://schemas.xmlsoap.org/soap/encoding/");
W.WriteStartElement("s", "Body", S);
if (SOAPACTION.EndsWith("#QueryStateVariable\"") == false)
{
W.WriteStartElement("u", MethodTag + "Response", urn);
if (RetVal != null)
{
W.WriteElementString(((UPnPArgument)RetVal).Name, UPnPService.SerializeObjectInstance(((UPnPArgument)RetVal).DataValue));
}
foreach (UPnPArgument arg in OutArgs)
{
W.WriteElementString(arg.Name, UPnPService.SerializeObjectInstance(arg.DataValue));
}
}
else
{
//QueryStateVariableResponse
String QSV = "urn:schemas-upnp-org:control-1-0";
W.WriteStartElement("u", MethodTag + "Response", QSV);
W.WriteElementString("return", UPnPStringFormatter.EscapeString(UPnPService.SerializeObjectInstance(RetVal)));
}
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndElement();
W.WriteEndDocument();
W.Flush();
byte[] wbuf = new Byte[mstream.Length - 3];
mstream.Seek(3, SeekOrigin.Begin);
mstream.Read(wbuf, 0, wbuf.Length);
W.Close();
response.StatusCode = 200;
response.StatusData = "OK";
response.AddTag("Content-Type", "text/xml; charset=\"utf-8\"");
response.AddTag("EXT", "");
response.AddTag("Server", "Windows NT/5.0, UPnP/1.0");
response.BodyBuffer = wbuf;
return (response);
}
示例12: Start
public override void Start(UPnPDevice device)
{
if(!Enabled) return;
UPnPDevice dv = device;
while(dv.ParentDevice!=null)
{
dv = dv.ParentDevice;
}
state = UPnPTestStates.Running;
UPnPService[] _S = device.GetServices("urn:");
foreach(UPnPService s in _S)
{
bool ok = false;
foreach(UPnPStateVariable v in s.GetStateVariables())
{
if(v.SendEvent)
{
ok = true;
break;
}
}
if(ok)
{
UPnPDebugObject d = new UPnPDebugObject(s);
Uri EventUri = new Uri((string)d.GetField("__eventurl"));
IPEndPoint dest = new IPEndPoint(IPAddress.Parse(EventUri.Host),EventUri.Port);
HTTPMessage R = new HTTPMessage();
R.Directive = "SUBSCRIBE";
R.DirectiveObj = HTTPMessage.UnEscapeString(EventUri.PathAndQuery);
R.AddTag("Host",dest.ToString());
R.AddTag("Callback","<http://" + dv.InterfaceToHost.ToString()+ ":" + NetworkInfo.GetFreePort(10000,50000,dv.InterfaceToHost).ToString() + ">");
//R.AddTag("Callback","<http://127.0.0.1:55555>");
R.AddTag("NT","upnp:event");
R.AddTag("Timeout","Second-15");
System.Console.WriteLine(R.GetTag("Callback"));
MRE.Reset();
SID = "";
StartCountDown(30);
HTTPRequest rq = new HTTPRequest();
rq.OnResponse += new HTTPRequest.RequestHandler(SubscribeSink);
AddHTTPMessage(R);
rq.PipelineRequest(dest,R,s);
MRE.WaitOne(30000,false);
AbortCountDown();
if (SID=="")
{
AddEvent(LogImportance.Critical,"Subscribe","SUBSCRIBE: " + s.ServiceURN + " << FAILED >>");
AddEvent(LogImportance.Remark,"Subscribe","Aborting tests");
result = "Subscription test failed."; // TODO
state = UPnPTestStates.Failed;
return;
}
else
{
AddEvent(LogImportance.Remark,"Subscribe","SUBSCRIBE: " + s.ServiceURN + " << OK >>");
// Renew Test
R = new HTTPMessage();
R.Directive = "SUBSCRIBE";
R.DirectiveObj = HTTPMessage.UnEscapeString(EventUri.PathAndQuery);
R.AddTag("Host",dest.ToString());
R.AddTag("SID",SID);
R.AddTag("Timeout","Second-15");
StartCountDown(30);
SID = "";
MRE.Reset();
AddHTTPMessage(R);
rq = new HTTPRequest();
rq.OnResponse += new HTTPRequest.RequestHandler(SubscribeSink);
rq.PipelineRequest(dest,R,s);
MRE.WaitOne(30000,false);
AbortCountDown();
if (SID=="")
{
AddEvent(LogImportance.Critical,"Subscribe","SUBSCRIBE (Renew): " + s.ServiceURN + " << FAILED >>");
AddEvent(LogImportance.Remark,"Subscribe","Aborting tests");
result = "Subscription test failed."; // TODO
state = UPnPTestStates.Failed;
return;
}
else
{
AddEvent(LogImportance.Remark,"Subscribe","SUBSCRIBE (Renew): " + s.ServiceURN + " << OK >>");
//.........这里部分代码省略.........
示例13: SinkCd_ImportResource
//.........这里部分代码省略.........
throw new Error_InvalidServerConfiguration("ImportResource() cannot be supported until the vendor configures the server correctly.");
}
//
// Grab the file through http-get
//
IPAddress addr = null;
IPHostEntry ihe = null;
IPEndPoint dest = null;
// Attempt to get a routeable IP address for the request
try
{
if(SourceURI.HostNameType == UriHostNameType.Dns)
{
ihe = Dns.GetHostByName(SourceURI.Host);
addr = new IPAddress(ihe.AddressList[0].Address);
}
else
{
addr = IPAddress.Parse(SourceURI.Host);
}
}
catch
{
throw new Error_ConnectionProblem("Could parse or resolve the SourceURI IP address represented by" +SourceURI.ToString());
}
dest = new IPEndPoint(addr, SourceURI.Port);
// Open a socket and connect to the remote IP address and port
System.Net.Sockets.Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
s.Connect(dest);
}
catch
{
throw new Error_ConnectionProblem("Could not connect to the remote URI " + DestinationURI.ToString());
}
// Do a check to make sure we're not dumping to a directory.
string filename = res.ContentUri.Substring(MediaResource.AUTOMAPFILE.Length);
if (Directory.Exists(filename))
{
throw new Error_ImportError("System error. Resource has been mapped incorrectly. Cannot overwrite a directory with a binary.");
}
// Create an HTTP session for this socket.
// Set things up so that the HTTP-GET will automatically dump
// the body of the message into a binary file that has
// been automatically mapped.
HTTPSession session = new HTTPSession(s, null, null);
this.SetupSessionForTransfer(session);
session.OnHeader += new HTTPSession.ReceiveHeaderHandler(this.GetRequest_OnHeaderReceiveSink);
try
{
session.UserStream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None);
}
catch
{
throw new Error_ImportError("System busy. Could not open file from local system for writing.");
}
if (session.UserStream == null)
{
throw new Error_ImportError("System error. Cannot write to a null stream.");
}
SessionData sd = (SessionData) session.StateObject;
sd.HttpVer1_1 = false;
// Create the HTTP message that will request the binary.
HTTPMessage msg = new HTTPMessage();
msg.Directive = "GET";
msg.DirectiveObj = HTTPMessage.UnEscapeString(SourceURI.PathAndQuery);
msg.AddTag("HOST", dest.ToString());
msg.Version = "1.0";
// Create an HttpTransfer object that will represent the progress
// of this file transfer and add it to the media server's current
// transfers list.
long expectedLength = 0;
HttpTransfer transferInfo = new HttpTransfer(true, true, session, res, session.UserStream, expectedLength);
this.AddTransfer(session, transferInfo);
TransferID = transferInfo.m_TransferId;
// Go make the request for the file.
session.Send(msg);
this.m_Stats.ImportResource++;
this.FireStatsChange();
}
示例14: Validate_MSEARCH_RESPONSETIME
private void Validate_MSEARCH_RESPONSETIME()
{
AddMessage(0, "Testing Notifications");
HTTPMessage r = new HTTPMessage();
r.Directive = "M-SEARCH";
r.DirectiveObj = "*";
r.AddTag("MX", "10");
r.AddTag("ST", "uuid:" + TestDevice.UniqueDeviceName);
r.AddTag("Host", "239.255.255.250:1900");
r.AddTag("MAN", "\"ssdp:discover\"");
byte[] buf = r.RawPacket;
IPEndPoint dest = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900);
Cache = -1;
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(0, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(15, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(30, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(45, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(60, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
MRE.Reset();
StartTime = DateTime.Now;
ASocket.Send(buf, 0, buf.Length, dest);
StartCountDown(75, 90);
MRE.WaitOne(15000, false);
AbortCountDown();
double s = 0;
try
{
s = DPA.StandardDeviation.TotalSeconds;
}
catch (DivideByZeroException) {}
if (s < (double)1.50)
{
AddEvent(LogImportance.Medium, "M-SEARCH, MX Value",
"WARNING: Device not choosing Random interval based on MX value <<Standard Deviation: " + s.ToString() + ">>");
Results.Add("M-SEARCH Response time not choosing Random interval based on MX value");
MX = UPnPTestStates.Warn;
SetState("MX Value", UPnPTestStates.Warn);
}
else
{
MX = UPnPTestStates.Pass;
AddEvent(LogImportance.Remark, "M-SEARCH, MX Value",
"Random MX interval: <<Standard Deviation: " + s.ToString() + ">> OK");
Results.Add("M-SEARCH Response time OK");
SetState("MX Value", UPnPTestStates.Pass);
}
}
示例15: BuildNotifyPacket2
private void BuildNotifyPacket2(string BaseURL, ArrayList NotifyList, IPAddress local)
{
HTTPMessage msg;
for (int id = 0; id < Services.Length; ++id)
{
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", Services[id].ServiceURN);
msg.AddTag("NTS", "ssdp:alive");
msg.AddTag("Location", BaseURL);
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::" + Services[id].ServiceURN);
msg.AddTag("Server", "Windows NT/5.0, UPnP/1.0");
msg.AddTag("Cache-Control", "max-age=" + ExpirationTimeout.ToString());
NotifyList.Add(msg);
}
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", DeviceURN);
msg.AddTag("NTS", "ssdp:alive");
msg.AddTag("Location", BaseURL);
msg.AddTag("USN", "uuid:" + UniqueDeviceName + "::" + DeviceURN);
msg.AddTag("Server", "Windows NT/5.0, UPnP/1.0");
msg.AddTag("Cache-Control", "max-age=" + ExpirationTimeout.ToString());
NotifyList.Add(msg);
msg = new HTTPMessage();
msg.Directive = "NOTIFY";
msg.DirectiveObj = "*";
msg.AddTag("Host", Utils.GetMulticastAddrBraketPort(local));
msg.AddTag("NT", "uuid:" + UniqueDeviceName);
msg.AddTag("NTS", "ssdp:alive");
msg.AddTag("Location", BaseURL);
msg.AddTag("USN", "uuid:" + UniqueDeviceName);
msg.AddTag("Server", "Windows NT/5.0, UPnP/1.0");
msg.AddTag("Cache-Control", "max-age=" + ExpirationTimeout.ToString());
NotifyList.Add(msg);
}