本文整理汇总了C#中OpenSource.UPnP.DText类的典型用法代码示例。如果您正苦于以下问题:C# DText类的具体用法?C# DText怎么用?C# DText使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DText类属于OpenSource.UPnP命名空间,在下文中一共展示了DText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetURNPrefix
public static string GetURNPrefix(string urn)
{
int len;
DText p = new DText();
p.ATTRMARK = ":";
p[0] = urn;
len = p[p.DCOUNT()].Length;
return(urn.Substring(0, urn.Length - len));
}
示例2: PopulateMetaData
public static MediaItem PopulateMetaData(MediaResource R, FileInfo F)
{
MediaItem RetVal;
MediaBuilder.item Item = null;
DText parser = new DText();
parser.ATTRMARK = "-";
parser.MULTMARK = ".";
switch(F.Extension.ToUpper())
{
case ".MP3":
Item = ParseMP3_V1(F);
if(Item==null)
{
parser[0] = F.Name;
if(parser.DCOUNT()==2)
{
Item = new MediaBuilder.musicTrack(parser[2,1].Trim());
Item.creator = parser[1].Trim();
((MediaBuilder.musicTrack)Item).artist = new PersonWithRole[1]{new PersonWithRole()};
((MediaBuilder.musicTrack)Item).artist[0].Name = Item.creator;
((MediaBuilder.musicTrack)Item).artist[0].Role = null;
}
}
break;
}
if(Item!=null)
{
RetVal = MediaBuilder.CreateItem(Item);
RetVal.AddResource(R);
return(RetVal);
}
else
{
// Create a Generic Item
string fname = F.Name;
int fnameidx = fname.IndexOf(".");
if(fnameidx!=-1) fname=fname.Substring(0,fnameidx);
MediaBuilder.item genericItem = new MediaBuilder.item(fname);
RetVal = MediaBuilder.CreateItem(genericItem);
RetVal.AddResource(R);
return(RetVal);
}
}
示例3: GenerateControlSchemas
//.........这里部分代码省略.........
if (!cleanSchema)
{
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // any
}
X.WriteEndElement(); // sequence
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // complexType
// ActionResponse
X.WriteStartElement("xsd","complexType",null);
X.WriteAttributeString("name",a.Name+"ResponseType");
X.WriteStartElement("xsd","sequence",null);
foreach(UPnPArgument arg in a.Arguments)
{
if (arg.Direction=="out" || arg.IsReturnValue)
{
X.WriteStartElement("xsd","element",null);
X.WriteAttributeString("name",arg.Name);
if (arg.RelatedStateVar.ComplexType==null)
{
// Simple
X.WriteStartElement("xsd","complexType",null);
X.WriteStartElement("xsd","simpleContent",null);
X.WriteStartElement("xsd","extension",null);
X.WriteAttributeString("base","upnp:"+arg.RelatedStateVar.ValueType);
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // extension
X.WriteEndElement(); // simpleContent
X.WriteEndElement(); // complexType
}
else
{
// Complex
X.WriteAttributeString("type",h[arg.RelatedStateVar.ComplexType.Name_NAMESPACE].ToString()+":"+arg.RelatedStateVar.ComplexType.Name_LOCAL);
}
X.WriteEndElement(); // Element
}
}
// After all arguments
if (!cleanSchema)
{
X.WriteStartElement("xsd","any",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("minOccurs","0");
X.WriteAttributeString("maxOccurs","unbounded");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // any
}
X.WriteEndElement(); // sequence
if (!cleanSchema)
{
X.WriteStartElement("xsd","anyAttribute",null);
X.WriteAttributeString("namespace","##other");
X.WriteAttributeString("processContents","lax");
X.WriteEndElement(); // anyAttribute
}
X.WriteEndElement(); // complexType
}
X.WriteEndElement(); //schema
X.WriteEndDocument();
StreamWriter writer3;
DText PP = new DText();
PP.ATTRMARK = ":";
PP[0] = s.ServiceURN;
writer3 = File.CreateText(dirInfo.FullName + "\\"+PP[PP.DCOUNT()-1]+".xsd");
System.Text.UTF8Encoding U = new System.Text.UTF8Encoding();
X.Flush();
ms.Flush();
writer3.Write(U.GetString(ms.ToArray(),2,ms.ToArray().Length-2));
writer3.Close();
ms = new MemoryStream();
X = new System.Xml.XmlTextWriter(ms,System.Text.Encoding.UTF8);
X.Formatting = System.Xml.Formatting.Indented;
}
}
示例4: BuildCertToolFiles
private void BuildCertToolFiles(UPnPDevice device, DirectoryInfo outputDir)
{
StringBuilder sb = new StringBuilder();
ServiceGenerator.Configuration DeviceConf = (ServiceGenerator.Configuration)device.User;
sb.Append("<device>");
if (device.Services.Length>0)
{
sb.Append("<serviceList>");
foreach(UPnPService s in device.Services)
{
sb.Append("<service>");
sb.Append("<serviceType>"+s.ServiceURN+"</serviceType>");
sb.Append("<serviceId>"+s.ServiceID+"</serviceId>");
sb.Append("</service>");
BuildCertToolFiles_Service(s,outputDir);
}
sb.Append("</serviceList>");
}
sb.Append("</device>");
StreamWriter W;
DText d = new DText();
d.ATTRMARK = ":";
d[0] = device.DeviceURN;
W = File.CreateText(outputDir.FullName + "\\"+d[4]+device.Version.ToString()+".xml");
W.Write(sb.ToString());
W.Close();
}
示例5: SSniffer_OnPacket
void SSniffer_OnPacket(object sender, string Packet, IPEndPoint Local, IPEndPoint From)
{
//System.Console.WriteLine(Local.ToString() + " / " + From.ToString());
//if (From.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) return;
//if (From.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) return;
//Console.WriteLine(Packet);
DText p = new DText();
UTF8Encoding U = new UTF8Encoding();
string PType = "Unknown";
int i = Packet.IndexOf(" ");
if (i > 0) PType = Packet.Substring(0, i);
string NT = "Unknown";
string USN="";
string UUID="";
string Location = "";
if (PType == "NOTIFY")
{
int pos1 = Packet.IndexOf("\r\nNT:");
if (pos1 == -1) pos1 = Packet.IndexOf("\r\nnt:");
if (pos1 > 0)
{
int pos2 = Packet.IndexOf("\r\n", pos1 + 5);
NT = Packet.Substring(pos1 + 5, pos2 - (pos1 + 5));
}
NT = NT.Trim();
USN = "";
pos1 = Packet.IndexOf("\r\nUSN:");
if (pos1 == -1) pos1 = Packet.IndexOf("\r\nusn:");
if (pos1 > 0)
{
int pos2 = Packet.IndexOf("\r\n", pos1 + 6);
USN = Packet.Substring(pos1 + 6, pos2 - (pos1 + 6));
}
USN = USN.Trim();
int UsnEndPos = USN.IndexOf("::");
if (USN.StartsWith("uuid:") == true && UsnEndPos != -1)
{
UUID = USN.Substring(5, UsnEndPos - 5);
}
}
if (PType == "HTTP/1.1")
{
int pos1 = Packet.IndexOf("\r\nST:");
if (pos1 == -1) pos1 = Packet.IndexOf("\r\nst:");
if (pos1 > 0)
{
int pos2 = Packet.IndexOf("\r\n", pos1 + 5);
NT = Packet.Substring(pos1 + 5, pos2 - (pos1 + 5));
}
NT = NT.Trim();
USN = "";
pos1 = Packet.IndexOf("\r\nUSN:");
if (pos1 == -1) pos1 = Packet.IndexOf("\r\nusn:");
if (pos1 > 0)
{
int pos2 = Packet.IndexOf("\r\n", pos1 + 6);
USN = Packet.Substring(pos1 + 6, pos2 - (pos1 + 6));
}
USN = USN.Trim();
string packetLower = Packet.ToLowerInvariant();
Location = "";
pos1 = packetLower.IndexOf("\r\nlocation:");
if (pos1 > 0)
{
int pos2 = Packet.IndexOf("\r\n", pos1 + 11);
Location = Packet.Substring(pos1 + 11, pos2 - (pos1 + 11));
}
Location = Location.Trim();
int UsnEndPos = USN.IndexOf("::");
if (USN.StartsWith("uuid:") == true && UsnEndPos != -1)
{
UUID = USN.Substring(5, UsnEndPos - 5);
}
}
string FromHostName = From.Address.ToString();
try
{
FromHostName = System.Net.Dns.Resolve(From.Address.ToString()).HostName;
}
catch (Exception) { }
if (OnUPnPDeviceFound != null) OnUPnPDeviceFound(sender, Packet, Local, From, PType, NT, USN, UUID, Location, FromHostName);
}
示例6: GenerateEx
protected bool GenerateEx(UPnPDevice device, DirectoryInfo outputDirectory, Hashtable serviceNames)
{
string sampleService = "Sample";
StreamWriter writer;
ServiceNames = serviceNames;
DText dt = new DText();
dt.ATTRMARK = ":";
dt[0] = device.DeviceURN;
// *** Generate Main Code
Log("Writing main stack module...");
IDictionaryEnumerator en = serviceNames.GetEnumerator();
while (en.MoveNext())
{
string servicename = (string)en.Value;
sampleService = servicename;
UPnPService service = (UPnPService)en.Key;
string servicexml = new UTF8Encoding().GetString(service.GetSCPDXml());
Log("Generating service class for " + servicename);
OpenSource.UPnP.ServiceGenerator.GenerateCP("Cp" + servicename, nspace, outputDirectory.FullName + "\\Cp" + servicename + ".cs", service.ServiceURN, servicexml);
}
CodeProcessor cs = new CodeProcessor(new StringBuilder(), true);
StringBuilder cs2;
cs.Comment("UPnP .NET Framework Control Point Stack, Discovery Module");
cs.Comment(VersionString);
cs.Append(cl);
cs.Append("using System;" + cl);
cs.Append("using System.Net;" + cl);
cs.Append("using OpenSource.UPnP;" + cl);
cs.Append("using OpenSource.Utilities;" + cl);
cs.Append("using " + nspace + ";" + cl);
cs.Append(cl);
cs.Append("namespace " + nspace + cl);
cs.Append("{" + cl);
cs.Append(" /// <summary>" + cl);
cs.Append(" /// Summary description for " + dt[4] + "Discovery." + cl);
cs.Append(" /// </summary>" + cl);
cs.Append(" class " + dt[4] + "Discovery" + cl);
cs.Append(" {" + cl);
cs.Append(" private UPnPSmartControlPoint scp;" + cl);
cs.Append(" private WeakEvent AddEvent = new WeakEvent();" + cl);
cs.Append(" private WeakEvent RemoveEvent = new WeakEvent();" + cl);
cs.Append(cl);
cs.Append(" public delegate void DiscoveryHandler(" + dt[4] + "Discovery sender, UPnPDevice dev);" + cl);
cs.Append(" public event DiscoveryHandler OnAddedDevice" + cl);
cs.Append(" {" + cl);
cs.Append(" add" + cl);
cs.Append(" {" + cl);
cs.Append(" AddEvent.Register(value);" + cl);
cs.Append(" }" + cl);
cs.Append(" remove" + cl);
cs.Append(" {" + cl);
cs.Append(" AddEvent.UnRegister(value);" + cl);
cs.Append(" }" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public event DiscoveryHandler OnRemovedDevice" + cl);
cs.Append(" {" + cl);
cs.Append(" add" + cl);
cs.Append(" {" + cl);
cs.Append(" RemoveEvent.Register(value);" + cl);
cs.Append(" }" + cl);
cs.Append(" remove" + cl);
cs.Append(" {" + cl);
cs.Append(" RemoveEvent.UnRegister(value);" + cl);
cs.Append(" }" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public " + dt[4] + "Discovery()" + cl);
cs.Append(" {" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void Start()" + cl);
cs.Append(" {" + cl);
cs.Append(" scp = new UPnPSmartControlPoint(new UPnPSmartControlPoint.DeviceHandler(OnAddSink), null ,\"" + device.DeviceURN + "\");" + cl);
cs.Append(" scp.OnRemovedDevice += new UPnPSmartControlPoint.DeviceHandler(OnRemoveSink);" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void ReScan()" + cl);
cs.Append(" {" + cl);
cs.Append(" scp.Rescan();" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void UnicastSearch(IPAddress address)" + cl);
cs.Append(" {" + cl);
cs.Append(" scp.UnicastSearch(address);" + cl);
cs.Append(" }" + cl);
cs.Append(cl);
cs.Append(" public void ForceDisposeDevice(UPnPDevice dev)" + cl);
cs.Append(" {" + cl);
cs.Append(" if (dev.ParentDevice != null)" + cl);
cs.Append(" {" + cl);
cs.Append(" ForceDisposeDevice(dev.ParentDevice);" + cl);
cs.Append(" }" + cl);
cs.Append(" else" + cl);
cs.Append(" {" + cl);
cs.Append(" scp.ForceDisposeDevice(dev);" + cl);
//.........这里部分代码省略.........
示例7: UPnPService
internal UPnPService(double version)
{
OpenSource.Utilities.InstanceTracker.Add(this);
InvocationPipeline.OnResponse += new HTTPRequest.RequestHandler(HandleInvokeRequest);
this.SubscribeCycleCallback = new LifeTimeMonitor.LifeTimeHandler(SubscribeCycleSink);
SubscribeCycle.OnExpired += this.SubscribeCycleCallback;
VarAssociation = new Hashtable();
LocalMethodList = new Hashtable();
RemoteMethods = new SortedList();
SIDLock = new object();
EventSID = 0;
StateVariables = Hashtable.Synchronized(new Hashtable());
SubscriberTable = Hashtable.Synchronized(new Hashtable());
CurrentSID = "";
if (version == 0)
{
Major = 1;
Minor = 0;
}
else
{
DText TempNum = new DText();
TempNum.ATTRMARK = ".";
TempNum[0] = version.ToString();
Major = int.Parse(TempNum[1]);
Minor = 0;
if (TempNum.DCOUNT() == 2) int.TryParse(TempNum[2], out Minor);
}
}
示例8: ParseEventURL
private Uri[] ParseEventURL(String URLList)
{
DText parser = new DText();
String temp;
ArrayList TList = new ArrayList();
parser.ATTRMARK = ">";
parser[0] = URLList;
int cnt = parser.DCOUNT();
for (int x = 1; x <= cnt; ++x)
{
temp = parser[x];
try
{
temp = temp.Substring(temp.IndexOf("<") + 1);
TList.Add(new Uri(temp));
}
catch (Exception) { }
}
Uri[] RetVal = new Uri[TList.Count];
for (int x = 0; x < RetVal.Length; ++x) RetVal[x] = (Uri)TList[x];
return RetVal;
}
示例9: UPnPDevice
internal UPnPDevice(int DeviceExpiration, double version, String RootDir)
{
//OpenSource.Utilities.InstanceTracker.Add(this);
// Full Device
IsRoot = true;
parent = null;
HasPresentation = true;
ControlPointOnly = false;
RootPath = RootDir;
ExpirationTimeout = DeviceExpiration;
WebServerTable = Hashtable.Synchronized(new Hashtable());
VirtualDir_Table = new Hashtable();
VirtualDir_Header_Table = new Hashtable();
if (version == 0)
{
Major = 1;
Minor = 0;
}
else
{
DText TempNum = new DText();
TempNum.ATTRMARK = ".";
TempNum[0] = version.ToString();
Major = int.Parse(TempNum[1]);
if (TempNum.DCOUNT() == 2)
{
Minor = int.Parse(TempNum[2]);
}
else
{
Minor = 0;
}
}
Services = new UPnPService[0];
UniqueDeviceName = Guid.NewGuid().ToString();
SSDPServer = new SSDP(ExpirationTimeout);
SSDPServer.OnRefresh += SendNotify;
SSDPServer.OnSearch += HandleSearch;
}
示例10: HandleHeaderRequest
private void HandleHeaderRequest(HTTPMessage msg, HTTPSession WebSession)
{
DText parser = new DText();
HTTPMessage Response = new HTTPMessage();
String Method = msg.Directive;
String MethodData = msg.DirectiveObj;
VirtualDirectoryHandler H_cb = null;
VirtualDirectoryHandler P_cb = null;
String vd = "";
String vdobj = "";
// Check VirtualDirTable
int vdi;
try
{
vdi = MethodData.IndexOf("/", 1);
if (vdi != -1)
{
vdobj = MethodData.Substring(vdi);
vd = MethodData.Substring(0, vdi);
if (VirtualDir_Header_Table.ContainsKey(vd))
{
if (VirtualDir_Header_Table[vd] != null)
H_cb = (VirtualDirectoryHandler)VirtualDir_Header_Table[vd];
}
if (VirtualDir_Table.ContainsKey(vd))
{
if (VirtualDir_Table[vd] != null)
P_cb = (VirtualDirectoryHandler)VirtualDir_Table[vd];
}
}
}
catch (Exception ex)
{
OpenSource.Utilities.EventLogger.Log(ex);
}
if ((H_cb != null) || (P_cb != null))
{
HTTPMessage _msg = (HTTPMessage)msg.Clone();
_msg.DirectiveObj = vdobj;
WebSession.InternalStateObject = new Object[3] { vd, vdobj, P_cb };
if (H_cb != null)
H_cb(this, _msg, WebSession, vd);
return;
}
}
示例11: GetNonRootDeviceXML
private void GetNonRootDeviceXML(IPEndPoint local, XmlTextWriter XDoc)
{
IDictionaryEnumerator de = CustomField.GetEnumerator();
DText pp = new DText();
;
pp.ATTRMARK = ":";
XDoc.WriteStartElement("device");
//
// Always advertise version :1
//
XDoc.WriteElementString("deviceType", DeviceURN);
if (HasPresentation == true)
{
XDoc.WriteElementString("presentationURL", PresentationURL);
}
while (de.MoveNext())
{
IDictionaryEnumerator ede = ((Hashtable)de.Value).GetEnumerator();
while (ede.MoveNext())
{
string localName = (string)ede.Key;
string elementValue = (string)ede.Value;
string ns = (string)de.Key;
pp[0] = localName;
if (pp.DCOUNT() == 2)
{
XDoc.WriteStartElement(pp[1], pp[2], ns);
XDoc.WriteString(elementValue);
XDoc.WriteEndElement();
}
else
{
if (ns != "")
{
XDoc.WriteElementString(localName, ns, elementValue);
}
else
{
XDoc.WriteElementString(localName, elementValue);
}
}
}
}
XDoc.WriteElementString("friendlyName", FriendlyName);
if (Manufacturer != null)
XDoc.WriteElementString("manufacturer", Manufacturer);
if (ManufacturerURL != null)
XDoc.WriteElementString("manufacturerURL", ManufacturerURL);
if (ModelDescription != null)
XDoc.WriteElementString("modelDescription", ModelDescription);
if (ModelName != null)
XDoc.WriteElementString("modelName", ModelName);
if (ModelNumber != null)
XDoc.WriteElementString("modelNumber", ModelNumber);
if (ModelURL != null)
XDoc.WriteElementString("modelURL", HTTPMessage.UnEscapeString(ModelURL.AbsoluteUri));
if (SerialNumber != null)
XDoc.WriteElementString("serialNumber", SerialNumber);
XDoc.WriteElementString("UDN", "uuid:" + UniqueDeviceName);
/*
if (_icon != null)
{
lock (_icon)
{
XDoc.WriteStartElement("iconList");
XDoc.WriteStartElement("icon");
XDoc.WriteElementString("mimetype", "image/png");
XDoc.WriteElementString("width", _icon.Width.ToString());
XDoc.WriteElementString("height", _icon.Height.ToString());
XDoc.WriteElementString("depth", System.Drawing.Image.GetPixelFormatSize(_icon.PixelFormat).ToString());
XDoc.WriteElementString("url", "/icon.png");
XDoc.WriteEndElement();
XDoc.WriteStartElement("icon");
XDoc.WriteElementString("mimetype", "image/jpg");
XDoc.WriteElementString("width", _icon.Width.ToString());
XDoc.WriteElementString("height", _icon.Height.ToString());
XDoc.WriteElementString("depth", System.Drawing.Image.GetPixelFormatSize(_icon.PixelFormat).ToString());
XDoc.WriteElementString("url", "/icon.jpg");
XDoc.WriteEndElement();
if (_icon2 != null)
{
XDoc.WriteStartElement("icon");
XDoc.WriteElementString("mimetype", "image/png");
XDoc.WriteElementString("width", _icon2.Width.ToString());
XDoc.WriteElementString("height", _icon2.Height.ToString());
XDoc.WriteElementString("depth", System.Drawing.Image.GetPixelFormatSize(_icon.PixelFormat).ToString());
XDoc.WriteElementString("url", "/icon2.png");
XDoc.WriteEndElement();
XDoc.WriteStartElement("icon");
XDoc.WriteElementString("mimetype", "image/jpg");
//.........这里部分代码省略.........
示例12: ParseDevice
private static void ParseDevice(String XML, int startLine, ref UPnPDevice RetVal)
{
string TempString;
UPnPService service;
int embeddedLine;
DText p = new DText();
TextReader MyString = new StringReader(XML);
XmlTextReader XMLDoc = new XmlTextReader(MyString);
try
{
XMLDoc.Read();
XMLDoc.MoveToContent();
if (XMLDoc.LocalName == "device")
{
if (XMLDoc.AttributeCount > 0)
{
for (int ax = 0; ax < XMLDoc.AttributeCount; ++ax)
{
XMLDoc.MoveToAttribute(ax);
if (XMLDoc.LocalName == "MaxVersion")
{
RetVal.SetVersion(XMLDoc.Value);
}
}
XMLDoc.MoveToContent();
XMLDoc.Read();
}
else
{
XMLDoc.Read();
XMLDoc.MoveToContent();
}
while (XMLDoc.LocalName != "device" && !XMLDoc.EOF)
{
switch (XMLDoc.LocalName)
{
case "deviceList":
embeddedLine = XMLDoc.LineNumber;
ParseDeviceList(XMLDoc.ReadOuterXml(), startLine + embeddedLine - 1, ref RetVal);
break;
case "URLBase":
// Here, tport is a hack to make Windows Home Server visible. WHS does no set the port in the BaseURL and so, you need to keep it from the SSDP message.
int tport = 80;
if (RetVal.BaseURL != null)
tport = RetVal.BaseURL.Port;
RetVal.BaseURL = new Uri(XMLDoc.ReadString());
if (RetVal.BaseURL.Port == 80 && RetVal.BaseURL.Port != tport)
RetVal.BaseURL = new Uri(RetVal.BaseURL.Scheme + "://" + RetVal.BaseURL.Host + ":" + tport + RetVal.BaseURL.AbsolutePath);
break;
case "deviceType":
RetVal.DeviceURN = XMLDoc.ReadString();
break;
case "friendlyName":
RetVal.FriendlyName = XMLDoc.ReadString();
break;
case "manufacturer":
RetVal.Manufacturer = XMLDoc.ReadString();
break;
case "manufacturerURL":
RetVal.ManufacturerURL = XMLDoc.ReadString();
break;
case "modelDescription":
RetVal.ModelDescription = XMLDoc.ReadString();
break;
case "modelName":
RetVal.ModelName = XMLDoc.ReadString();
break;
case "modelNumber":
RetVal.ModelNumber = XMLDoc.ReadString();
break;
case "modelURL":
try
{
string u = XMLDoc.ReadString();
if (Uri.TryCreate(u, UriKind.Absolute, out RetVal.ModelURL) == false)
{
Uri.TryCreate("http://" + u, UriKind.Absolute, out RetVal.ModelURL);
}
}
catch (Exception ex)
{
OpenSource.Utilities.EventLogger.Log(ex);
}
break;
case "serialNumber":
RetVal.SerialNumber = XMLDoc.ReadString();
break;
case "UDN":
TempString = XMLDoc.ReadString();
RetVal.UniqueDeviceName = TempString.Substring(5);
break;
case "UPC":
RetVal.ProductCode = XMLDoc.ReadString();
break;
case "presentationURL":
RetVal.HasPresentation = true;
RetVal.PresentationURL = XMLDoc.ReadString();
//.........这里部分代码省略.........
示例13: ProtocolInfoString
/// <summary>
/// Constructs a ProtocolInfoString using string.
/// </summary>
/// <param name="protocolInfo">proposed value of the protocolInfo string</param>
public ProtocolInfoString(string protocolInfo)
{
DText parser = new DText();
parser.ATTRMARK = ":";
parser[0] = protocolInfo;
_Protocol = parser[1];
_Network = parser[2];
_MimeType = parser[3];
_Info = parser[4];
StringBuilder sb = new StringBuilder(100);
sb.AppendFormat("{0}:{1}:{2}:{3}", _Protocol, _Network, _MimeType, _Info);
_value = sb.ToString();
}
示例14: ProcessPacket
private void ProcessPacket(HTTPMessage msg, IPEndPoint src, IPEndPoint local)
{
if (OnSniffPacket != null) OnSniffPacket(src, null, msg);
DText parser = new DText();
parser.ATTRMARK = "::";
bool Alive = false;
String UDN = msg.GetTag("USN");
parser[0] = UDN;
String USN = parser[1];
USN = USN.Substring(USN.IndexOf(":") + 1);
String ST = parser[2];
int MaxAge = 0;
String NTS = msg.GetTag("NTS").ToUpper();
if (NTS == "SSDP:ALIVE")
{
Alive = true;
String ma = msg.GetTag("Cache-Control").Trim();
if (ma != "")
{
parser.ATTRMARK = ",";
parser.MULTMARK = "=";
parser[0] = ma;
for (int i = 1; i <= parser.DCOUNT(); ++i)
{
if (parser[i, 1].Trim().ToUpper() == "MAX-AGE")
{
MaxAge = int.Parse(parser[i, 2].Trim());
break;
}
}
}
}
if (msg.Directive == "NOTIFY" && OnNotify != null)
{
Uri locuri = null;
string location = msg.GetTag("Location");
if (location != null && location.Length > 0) { try { locuri = new Uri(location); } catch (Exception) { } }
OnNotify(src, msg.LocalEndPoint, locuri, Alive, USN, ST, MaxAge, msg);
}
else if (msg.Directive == "M-SEARCH" && OnSearch != null)
{
if (ValidateSearchPacket(msg) == false) return;
int MaxTimer = int.Parse(msg.GetTag("MX"));
SearchStruct SearchData = new SearchStruct();
SearchData.ST = msg.GetTag("ST");
SearchData.Source = src;
SearchData.Local = local;
SearchTimer.Add(SearchData, RandomGenerator.Next(0, MaxTimer));
}
}
示例15: UPnPDevice
internal UPnPDevice(double version, String UDN)
{
// Full Device
IsRoot = false;
VirtualDir_Table = new Hashtable();
VirtualDir_Header_Table = new Hashtable();
parent = null;
HasPresentation = true;
ControlPointOnly = false;
RootPath = "";
if (version == 0)
{
Major = 1;
Minor = 0;
}
else
{
DText TempNum = new DText();
TempNum.ATTRMARK = ".";
TempNum[0] = version.ToString();
Major = int.Parse(TempNum[1]);
if (TempNum.DCOUNT() == 2)
{
Minor = int.Parse(TempNum[2]);
}
else
{
Minor = 0;
}
}
Services = new UPnPService[0];
if (UDN == "")
{
UniqueDeviceName = Guid.NewGuid().ToString();
}
else
{
UniqueDeviceName = UDN;
}
SSDPServer = new SSDP(ExpirationTimeout);
SSDPServer.OnRefresh += new SSDP.RefreshHandler(SendNotify);
SSDPServer.OnSearch += new SSDP.SearchHandler(HandleSearch);
}