本文整理汇总了C#中OpenSource.UPnP.UPnPDevice.AddService方法的典型用法代码示例。如果您正苦于以下问题:C# UPnPDevice.AddService方法的具体用法?C# UPnPDevice.AddService怎么用?C# UPnPDevice.AddService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenSource.UPnP.UPnPDevice
的用法示例。
在下文中一共展示了UPnPDevice.AddService方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SampleDevice
public SampleDevice()
{
device = UPnPDevice.CreateRootDevice(1800,1.0,"\\");
device.FriendlyName = "Media Server (CASPER-LAPTOP)";
device.Manufacturer = "OpenSource";
device.ManufacturerURL = "";
device.ModelName = "Media Server";
device.ModelDescription = "Provides content through UPnP ContentDirectory service";
device.ModelNumber = "0.765";
device.HasPresentation = false;
device.DeviceURN = "urn:schemas-upnp-org:device:MediaServer:1";
DvConnectionManager ConnectionManager = new DvConnectionManager();
ConnectionManager.External_GetCurrentConnectionIDs = ConnectionManager_GetCurrentConnectionIDs;
ConnectionManager.External_GetCurrentConnectionInfo = ConnectionManager_GetCurrentConnectionInfo;
//ConnectionManager.External_GetProtocolInfo = ConnectionManager_GetProtocolInfo;
device.AddService(ConnectionManager);
DvContentDirectory ContentDirectory = new DvContentDirectory();
ContentDirectory.External_Browse = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_Browse(ContentDirectory_Browse);
ContentDirectory.External_CreateObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_CreateObject(ContentDirectory_CreateObject);
ContentDirectory.External_CreateReference = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_CreateReference(ContentDirectory_CreateReference);
ContentDirectory.External_DeleteResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_DeleteResource(ContentDirectory_DeleteResource);
ContentDirectory.External_DestroyObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_DestroyObject(ContentDirectory_DestroyObject);
ContentDirectory.External_ExportResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_ExportResource(ContentDirectory_ExportResource);
ContentDirectory.External_GetSearchCapabilities = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSearchCapabilities(ContentDirectory_GetSearchCapabilities);
ContentDirectory.External_GetSortCapabilities = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSortCapabilities(ContentDirectory_GetSortCapabilities);
ContentDirectory.External_GetSystemUpdateID = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetSystemUpdateID(ContentDirectory_GetSystemUpdateID);
ContentDirectory.External_GetTransferProgress = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_GetTransferProgress(ContentDirectory_GetTransferProgress);
ContentDirectory.External_ImportResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_ImportResource(ContentDirectory_ImportResource);
ContentDirectory.External_Search = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_Search(ContentDirectory_Search);
ContentDirectory.External_StopTransferResource = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_StopTransferResource(ContentDirectory_StopTransferResource);
ContentDirectory.External_UpdateObject = new OpenSource.DeviceBuilder.DvContentDirectory.Delegate_UpdateObject(ContentDirectory_UpdateObject);
device.AddService(ContentDirectory);
// Setting the initial value of evented variables
ConnectionManager.Evented_SourceProtocolInfo = "Sample String";
ConnectionManager.Evented_SinkProtocolInfo = "Sample String";
ConnectionManager.Evented_CurrentConnectionIDs = "Sample String";
ContentDirectory.Evented_ContainerUpdateIDs = "Sample String";
ContentDirectory.Evented_SystemUpdateID = 0;
ContentDirectory.Evented_TransferIDs = "Sample String";
}
示例2: Gatekeeper
public Gatekeeper(int PortNumber)
{
A_ICB = new UPnPService.UPnPServiceInvokeHandler(A_InvokeSink);
A_IECB = new UPnPService.UPnPServiceInvokeErrorHandler(A_InvokeErrorSink);
Port = PortNumber;
Root = UPnPDevice.CreateRootDevice(1000,1,"");
Root.FriendlyName = "UPnPShare";
Root.StandardDeviceType = "UPnPGateKeeper";
DV = new DvGateKeeper();
Root.AddService(DV);
DV.External_Register = new DvGateKeeper.Delegate_Register(RegisterSink);
DV.External_UnRegister = new DvGateKeeper.Delegate_UnRegister(UnRegisterSink);
DV.External_GetDocument = new DvGateKeeper.Delegate_GetDocument(GetDocumentSink);
DV.External_AddDevice = new DvGateKeeper.Delegate_AddDevice(AddDeviceSink);
DV.External_RemoveDevice = new DvGateKeeper.Delegate_RemoveDevice(RemovedDeviceSink);
DV.External_FireEvent = new DvGateKeeper.Delegate_FireEvent(FireEventSink);
DV.External_GetStateTable = new DvGateKeeper.Delegate_GetStateTable(GetStateTableSink);
DV.External_Invoke = new DvGateKeeper.Delegate_Invoke(InvokeSink);
DV.External_InvokeAsync = new DvGateKeeper.Delegate_InvokeAsync(InvokeAsyncSink);
DV.External_InvokeAsyncResponse = new DvGateKeeper.Delegate_InvokeAsyncResponse(InvokeAsyncResponseSink);
(new UPnPDebugObject(Root)).SetField("NoSSDP",true);
Root.StartDevice(PortNumber);
}
示例3: UPnPDeviceHostServiceProxy
public UPnPDeviceHostServiceProxy(Assembly assembly)
{
this.Name = Environment.MachineName + ":" + assembly.FullName.Split(',').First();
this.Namespace = assembly.FullName;
var regex = new Regex("Version=(.\\..)");
var version = regex.Match(this.Namespace).Groups[1].Value;
this.Version = double.Parse(version);
_device = UPnPDevice.CreateRootDevice(int.MaxValue, this.Version, "\\");
_device.FriendlyName = this.Name;
_device.DeviceURN = this.Namespace;
_device.HasPresentation = false;
var types = (from type in assembly.GetTypes()
let ifs = type.GetInterfaces().Where(t => t.GetCustomAttributes<ServiceContractAttribute>().Count() > 0).First()
select new { Type = type, Interface = ifs }).ToList();
List<IUPnPService> services = new List<IUPnPService>();
foreach (var tc in types)
{
var service = new UPnPServiceProxy(tc.Type, tc.Interface);
services.Add(service);
_device.AddService(service);
}
this.Services = services.ToList();
_device = this.GetUPnPDevice();
}
示例4: SinkDevice
public SinkDevice()
{
//Creates root device
device = UPnPDevice.CreateRootDevice(1800, 1.0 , "\\");
//Device information:
device.FriendlyName = "Caspers homemade Renderer";
device.Manufacturer = "Awesome Casper";
device.DeviceURN = "urn:schemas-upnp-org:device:MediaRenderer:1";
//Create stacks
DvAVTransport AVTransport = new DvAVTransport();
DvConnectionManager connectionManager = new DvConnectionManager();
DvRenderingControl renderingControl = new DvRenderingControl();
//Add stacks to device (and network visibility)
device.AddService(AVTransport);
device.AddService(connectionManager);
device.AddService(renderingControl);
AVTransport.Evented_LastChange = "Sample string";
}
示例5: UPnPRelayDevice
public UPnPRelayDevice(UPnPDevice device, CpGateKeeper _CP)
{
OpenSource.Utilities.InstanceTracker.Add(this);
ILCB = new InvokeResponseHandler(InvokeResponseSink);
CP = _CP;
ProxyDevice = UPnPDevice.CreateRootDevice(750, double.Parse(device.Version), "");
ProxyDevice.UniqueDeviceName = Guid.NewGuid().ToString();
ProxyDevice.HasPresentation = false;
ProxyDevice.FriendlyName = "*" + device.FriendlyName;
ProxyDevice.Manufacturer = device.Manufacturer;
ProxyDevice.ManufacturerURL = device.ManufacturerURL;
ProxyDevice.ModelName = device.ModelName;
ProxyDevice.DeviceURN = device.DeviceURN;
foreach (UPnPService S in device.Services)
{
UPnPService S2 = (UPnPService)S.Clone();
foreach (UPnPAction A in S2.Actions)
{
A.ParentService = S2;
A.SpecialCase += new UPnPAction.SpecialInvokeCase(InvokeSink);
}
UPnPDebugObject dbg = new UPnPDebugObject(S2);
dbg.SetField("SCPDURL", "_" + S2.ServiceID + "_scpd.xml");
dbg.SetProperty("ControlURL", "_" + S2.ServiceID + "_control");
dbg.SetProperty("EventURL", "_" + S2.ServiceID + "_event");
ProxyDevice.AddService(S2);
}
UDNTable[device.UniqueDeviceName] = ProxyDevice;
ReverseUDNTable[ProxyDevice.UniqueDeviceName] = device.UniqueDeviceName;
foreach (UPnPDevice _ed in device.EmbeddedDevices)
{
ProcessDevice(_ed);
}
}
示例6: SampleDevice
public SampleDevice()
{
device = UPnPDevice.CreateRootDevice(1800, 1.0, "\\");
device.FriendlyName = "Aquarium";
device.Manufacturer = "Aquarium";
device.ManufacturerURL = "http://polytech.unice.fr";
device.ModelName = "Aquarium";
device.ModelDescription = "Aquarium";
device.ModelNumber = "AQUA1";
device.HasPresentation = false;
device.DeviceURN = "urn:schemas-upnp-org:device:Aquarium:1";
Aquarium.DvaquariumService aquariumService = new Aquarium.DvaquariumService();
aquariumService.External_getBrightness = new Aquarium.DvaquariumService.Delegate_getBrightness(aquariumService_getBrightness);
aquariumService.External_getTemperature = new Aquarium.DvaquariumService.Delegate_getTemperature(aquariumService_getTemperature);
aquariumService.External_setBrightness = new Aquarium.DvaquariumService.Delegate_setBrightness(aquariumService_setBrightness);
aquariumService.External_setTemperature = new Aquarium.DvaquariumService.Delegate_setTemperature(aquariumService_setTemperature);
device.AddService(aquariumService);
// Setting the initial value of evented variables
aquariumService.Evented_brightness = 0;
aquariumService.Evented_temperature = 0;
}
示例7: startMenuItem_Click
private void startMenuItem_Click(object sender, System.EventArgs e)
{
startMenuItem.Enabled = false;
foreach (MenuItem i in pfcMenuItem.MenuItems) {i.Enabled = false;}
foreach (MenuItem i in menuItem3.MenuItems) {i.Enabled = false;}
InfoStringBox.Enabled = false;
device = UPnPDevice.CreateRootDevice(900,1,"");
device.UniqueDeviceName = Guid.NewGuid().ToString();
device.StandardDeviceType = "MediaRenderer";
device.FriendlyName = "Media Renderer (" + System.Net.Dns.GetHostName() + ")";
device.HasPresentation = false;
device.Manufacturer = "OpenSource";
device.ManufacturerURL = "http://opentools.homeip.net/";
device.PresentationURL = "/";
device.HasPresentation = true;
device.ModelName = "AV Renderer";
device.ModelDescription = "Media Renderer Device";
device.ModelURL = new Uri("http://opentools.homeip.net/");
UPnPService ts = new UPnPService(1, "EmptyService", "EmptyService", true, this);
ts.AddMethod("NullMethod");
//device.AddService(ts);
DText p = new DText();
p.ATTRMARK = "\r\n";
p[0] = this.InfoStringBox.Text;
int len = p.DCOUNT();
ProtocolInfoString[] istring = new ProtocolInfoString[len];
for(int i=1;i<=len;++i)
{
istring[i-1] = new ProtocolInfoString(p[i]);
}
r = new AVRenderer(MaxConnections, istring, new AVRenderer.ConnectionHandler(NewConnectionSink));
r.OnClosedConnection += new AVRenderer.ConnectionHandler(ClosedConnectionSink);
if (supportRecordMenuItem.Checked == false)
{
r.AVT.RemoveAction_Record();
}
if (supportRecordQualityMenuItem.Checked == false)
{
r.AVT.RemoveAction_SetRecordQualityMode();
}
if (supportNextContentUriMenuItem.Checked == false)
{
r.AVT.RemoveAction_SetNextAVTransportURI();
}
if (MaxConnections == 0)
{
r.Manager.RemoveAction_PrepareForConnection();
r.Manager.RemoveAction_ConnectionComplete();
}
r.AVT.GetUPnPService().GetStateVariableObject("CurrentPlayMode").AllowedStringValues = new String[3]{"NORMAL","REPEAT_ALL","INTRO"};
r.Control.GetUPnPService().GetStateVariableObject("A_ARG_TYPE_Channel").AllowedStringValues = new String[3]{"Master","LF","RF"};
r.Control.GetUPnPService().GetStateVariableObject("RedVideoBlackLevel").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("GreenVideoBlackLevel").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("BlueVideoBlackLevel").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("RedVideoGain").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("GreenVideoGain").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("BlueVideoGain").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("Brightness").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("Contrast").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("Sharpness").SetRange((ushort)0,(ushort)100,(ushort)1);
r.Control.GetUPnPService().GetStateVariableObject("Volume").SetRange((UInt16)0,(UInt16)100,(ushort)1);
device.AddService(r.Control);
device.AddService(r.AVT);
device.AddService(r.Manager);
//device.AddDevice(r);
device.StartDevice();
//r.Start();
}
示例8: AVRenderer
//.........这里部分代码省略.........
Manager.External_GetCurrentConnectionInfo = new DvConnectionManager.Delegate_GetCurrentConnectionInfo(GetCurrentConnectionInfoSink);
Manager.Evented_CurrentConnectionIDs = "";
//Manager.Evented_PhysicalConnections = "";
string Sink = "";
foreach(ProtocolInfoString s in InfoStrings)
{
if(Sink=="")
{
Sink = s.ToString();
}
else
{
Sink = Sink + "," + s.ToString();
}
}
Manager.Evented_SinkProtocolInfo = Sink;
Manager.Evented_SourceProtocolInfo = "";
AVT.Accumulator_LastChange = new InstanceID_LastChangeAccumulator("AVT");
AVT.ModerationDuration_LastChange = 0.5;
AVT.Evented_LastChange = "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/AVT/"/>";
AVT.External_GetMediaInfo = new DvAVTransport.Delegate_GetMediaInfo(GetMediaInfoSink);
AVT.External_GetPositionInfo = new DvAVTransport.Delegate_GetPositionInfo(GetPositionInfoSink);
AVT.External_GetTransportInfo = new DvAVTransport.Delegate_GetTransportInfo(GetTransportInfoSink);
AVT.External_GetTransportSettings = new DvAVTransport.Delegate_GetTransportSettings(GetTransportSettingsSink);
AVT.External_GetDeviceCapabilities = new DvAVTransport.Delegate_GetDeviceCapabilities(GetDeviceCapabilitiesSink);
AVT.External_GetCurrentTransportActions = new DvAVTransport.Delegate_GetCurrentTransportActions(GetCurrentTransportActionsSink);
AVT.External_Play = new DvAVTransport.Delegate_Play(PlaySink);
AVT.External_Stop = new DvAVTransport.Delegate_Stop(StopSink);
AVT.External_Pause = new DvAVTransport.Delegate_Pause(PauseSink);
AVT.External_Record = new DvAVTransport.Delegate_Record(RecordSink);
AVT.External_Previous = new DvAVTransport.Delegate_Previous(PreviousSink);
AVT.External_Next = new DvAVTransport.Delegate_Next(NextSink);
AVT.External_Seek = new DvAVTransport.Delegate_Seek(SeekSink);
AVT.External_SetAVTransportURI = new DvAVTransport.Delegate_SetAVTransportURI(SetAVTransportURISink);
AVT.External_SetNextAVTransportURI = new DvAVTransport.Delegate_SetNextAVTransportURI(SetNextAVTransportURISink);
AVT.External_SetPlayMode = new DvAVTransport.Delegate_SetPlayMode(SetPlayModeSink);
AVT.External_SetRecordQualityMode = new DvAVTransport.Delegate_SetRecordQualityMode(SetRecordQualityModeSink);
AVT.External_Record = new DvAVTransport.Delegate_Record(RecordSink);
Control.Evented_LastChange = "<Event xmlns = "urn:schemas-upnp-org:metadata-1-0/RCS/"/>";
Control.Accumulator_LastChange = new InstanceID_LastChangeAccumulator("RCS");
Control.ModerationDuration_LastChange = 1;
Control.External_GetMute = new DvRenderingControl.Delegate_GetMute(GetMuteSink);
Control.External_SetMute = new DvRenderingControl.Delegate_SetMute(SetMuteSink);
Control.External_GetVolume = new DvRenderingControl.Delegate_GetVolume(GetVolumeSink);
Control.External_SetVolume = new DvRenderingControl.Delegate_SetVolume(SetVolumeSink);
Control.External_GetBlueVideoBlackLevel = new DvRenderingControl.Delegate_GetBlueVideoBlackLevel(GetBlueVideoBlackSink);
Control.External_GetBlueVideoGain = new DvRenderingControl.Delegate_GetBlueVideoGain(GetBlueVideoGainSink);
Control.External_SetBlueVideoBlackLevel = new DvRenderingControl.Delegate_SetBlueVideoBlackLevel(SetBlueVideoBlackSink);
Control.External_SetBlueVideoGain = new DvRenderingControl.Delegate_SetBlueVideoGain(SetBlueVideoGainSink);
Control.External_GetGreenVideoBlackLevel = new DvRenderingControl.Delegate_GetGreenVideoBlackLevel(GetGreenVideoBlackSink);
Control.External_GetGreenVideoGain = new DvRenderingControl.Delegate_GetGreenVideoGain(GetGreenVideoGainSink);
Control.External_SetGreenVideoBlackLevel = new DvRenderingControl.Delegate_SetGreenVideoBlackLevel(SetGreenVideoBlackSink);
Control.External_SetGreenVideoGain = new DvRenderingControl.Delegate_SetGreenVideoGain(SetGreenVideoGainSink);
Control.External_GetRedVideoBlackLevel = new DvRenderingControl.Delegate_GetRedVideoBlackLevel(GetRedVideoBlackSink);
Control.External_GetRedVideoGain = new DvRenderingControl.Delegate_GetRedVideoGain(GetRedVideoGainSink);
Control.External_SetRedVideoBlackLevel = new DvRenderingControl.Delegate_SetRedVideoBlackLevel(SetRedVideoBlackSink);
Control.External_SetRedVideoGain = new DvRenderingControl.Delegate_SetRedVideoGain(SetRedVideoGainSink);
Control.External_GetBrightness = new DvRenderingControl.Delegate_GetBrightness(GetBrightnessSink);
Control.External_SetBrightness = new DvRenderingControl.Delegate_SetBrightness(SetBrightnessSink);
Control.External_GetContrast = new DvRenderingControl.Delegate_GetContrast(GetContrastSink);
Control.External_SetContrast = new DvRenderingControl.Delegate_SetContrast(SetContrastSink);
Control.External_GetSharpness = new DvRenderingControl.Delegate_GetSharpness(GetSharpnessSink);
Control.External_SetSharpness = new DvRenderingControl.Delegate_SetSharpness(SetSharpnessSink);
Control.External_ListPresets = new DvRenderingControl.Delegate_ListPresets(ListPresetsSink);
Control.External_SelectPreset = new DvRenderingControl.Delegate_SelectPreset(SelectPresetSink);
device.Manufacturer = "OpenSource";
device.ManufacturerURL = "";
device.PresentationURL = "/";
device.HasPresentation = false;
device.ModelName = "Renderer";
device.ModelDescription = "AV Media Renderer Device";
device.ModelURL = new Uri("http://www.sourceforge.org");
device.StandardDeviceType = "MediaRenderer";
device.AddService(Manager);
device.AddService(Control);
device.AddService(AVT);
if(ConnectionMax == 0)
{
Manager.Evented_CurrentConnectionIDs = "0";
CurrentConnections = 1;
AVConnection c = new AVConnection(this, "", "/", -1, DvConnectionManager.Enum_A_ARG_TYPE_Direction.INPUT, 0, 0, 0);
c.Parent = this;
c._WhoCreatedMe = new IPEndPoint(IPAddress.Parse("127.0.0.1"),0);
ID_Table[(UInt32)0] = c;
if(h!=null) h(this,c);
}
}
示例9: ParseDevice
//.........这里部分代码省略.........
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();
break;
case "serviceList":
if (XMLDoc.IsEmptyElement)
break;
XMLDoc.Read();
XMLDoc.MoveToContent();
while (XMLDoc.LocalName != "serviceList")
{
if (XMLDoc.LocalName == "service")
{
embeddedLine = XMLDoc.LineNumber;
service = UPnPService.Parse(XMLDoc.ReadOuterXml(), embeddedLine - 1 + startLine);
RetVal.AddService(service);
}
if (!XMLDoc.IsStartElement())
{
if (XMLDoc.LocalName != "serviceList")
{
XMLDoc.Read();
XMLDoc.MoveToContent();
}
}
}
break;
/*
case "iconList":
bool finishedIconList = false;
while (!finishedIconList && XMLDoc.Read())
{
switch (XMLDoc.NodeType)
{
case XmlNodeType.Element:
if (XMLDoc.LocalName == "icon")
{
embeddedLine = XMLDoc.LineNumber;
ParseIconXML(RetVal, startLine + embeddedLine-1, XMLDoc.ReadOuterXml());
if (XMLDoc.NodeType == XmlNodeType.EndElement && XMLDoc.LocalName == "iconList") { finishedIconList = true; }
}
break;
case XmlNodeType.EndElement:
if (XMLDoc.LocalName == "iconList") { finishedIconList = true; }
break;
}
}
break;
*/
default:
if (XMLDoc.LocalName != "")
{
string customPrefix = XMLDoc.Prefix;
string customFieldName = XMLDoc.LocalName;
string customFieldNamespace = XMLDoc.LookupNamespace(customPrefix);
string customFieldVal = XMLDoc.ReadInnerXml();
RetVal.AddCustomFieldInDescription(customFieldName, customFieldVal, customFieldNamespace);
}
else
{
XMLDoc.Skip();
}
continue;
}
XMLDoc.Read();
//XMLDoc.MoveToContent();
}
}
}
catch (XMLParsingException ex)
{
throw ex;
}
catch (Exception ex)
{
throw new XMLParsingException("Invalid Device XML", startLine + XMLDoc.LineNumber, XMLDoc.LinePosition, ex);
}
}
示例10: MainForm
public MainForm(string[] args)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
foreach (string parm in args)
{
if (parm.ToUpper().StartsWith("/CACHE:"))
{
DText p = new DText();
p.ATTRMARK = ":";
p[0] = parm;
try
{
CacheTime = int.Parse(p[2]);
}
catch (Exception)
{
}
}
else if (parm.ToUpper() == "/DEBUG")
{
OpenSource.Utilities.EventLogger.Enabled = true;
OpenSource.Utilities.EventLogger.ShowAll = true;
OpenSource.Utilities.InstanceTracker.Display();
}
else if (parm.ToUpper().StartsWith("/PORT:"))
{
DText p = new DText();
p.ATTRMARK = ":";
p[0] = parm;
try
{
PortNum = int.Parse(p[2]);
}
catch (Exception)
{
}
}
}
upnpLightDevice = UPnPDevice.CreateRootDevice(CacheTime, 1, "web\\");
upnpLightDevice.Icon = iconImageList.Images[0];
upnpLightDevice.HasPresentation = true;
upnpLightDevice.PresentationURL = "/";
upnpLightDevice.FriendlyName = this.Text + " (" + System.Windows.Forms.SystemInformation.ComputerName + ")";
upnpLightDevice.Manufacturer = "OpenSource";
upnpLightDevice.ManufacturerURL = "http://opentools.homeip.net";
upnpLightDevice.ModelName = "Network Light Bulb";
upnpLightDevice.ModelDescription = "Software Emulated Light Bulb";
upnpLightDevice.ModelURL = new Uri("http://opentools.homeip.net");
upnpLightDevice.ModelNumber = "XPC-L1";
upnpLightDevice.StandardDeviceType = "DimmableLight";
upnpLightDevice.UniqueDeviceName = System.Guid.NewGuid().ToString();
// Switch Power
upnpLightService = new UPnPService(1, "SwitchPower.0001", "SwitchPower", true, this);
upnpLightService.AddMethod("SetTarget");
upnpLightService.AddMethod("GetTarget");
upnpLightService.AddMethod("GetStatus");
UPnPStateVariable upnpStatusVar = new UPnPStateVariable("Status", typeof(bool), true);
upnpStatusVar.AddAssociation("GetStatus", "ResultStatus");
upnpStatusVar.Value = false;
upnpLightService.AddStateVariable(upnpStatusVar);
UPnPStateVariable upnpTargetVar = new UPnPStateVariable("Target", typeof(bool), false);
upnpTargetVar.AddAssociation("SetTarget", "newTargetValue");
upnpTargetVar.AddAssociation("GetTarget", "newTargetValue");
upnpTargetVar.Value = false;
upnpLightService.AddStateVariable(upnpTargetVar);
// Dimmable device
upnpDimmerService = new UPnPService(1, "Dimming.0001", "Dimming", true, this);
upnpDimmerService.AddMethod("SetLoadLevelTarget");
upnpDimmerService.AddMethod("GetLoadLevelTarget");
upnpDimmerService.AddMethod("GetLoadLevelStatus");
upnpDimmerService.AddMethod("GetMinLevel");
UPnPStateVariable upnpLevelTargetVar = new UPnPStateVariable("LoadLevelTarget", typeof(byte), false);
upnpLevelTargetVar.AddAssociation("SetLoadLevelTarget", "NewLoadLevelTarget");
upnpLevelTargetVar.AddAssociation("GetLoadLevelTarget", "NewLoadLevelTarget");
upnpLevelTargetVar.Value = (byte)100;
upnpLevelTargetVar.SetRange((byte)0, (byte)100, null);
upnpDimmerService.AddStateVariable(upnpLevelTargetVar);
UPnPStateVariable upnpLevelStatusVar = new UPnPStateVariable("LoadLevelStatus", typeof(byte), true);
upnpLevelStatusVar.AddAssociation("GetLoadLevelStatus", "RetLoadLevelStatus");
upnpLevelStatusVar.Value = (byte)100;
upnpLevelStatusVar.SetRange((byte)0, (byte)100, null);
upnpDimmerService.AddStateVariable(upnpLevelStatusVar);
UPnPStateVariable upnpMinLevelVar = new UPnPStateVariable("MinLevel", typeof(byte), false);
upnpMinLevelVar.AddAssociation("GetMinLevel", "MinLevel");
upnpMinLevelVar.Value = (byte)0;
upnpDimmerService.AddStateVariable(upnpMinLevelVar);
// Add Services
upnpLightDevice.AddService(upnpLightService);
upnpLightDevice.AddService(upnpDimmerService);
}
示例11: ParseDevice
//.........这里部分代码省略.........
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 { }
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();
break;
case "serviceList":
if (XMLDoc.IsEmptyElement) break;
XMLDoc.Read();
XMLDoc.MoveToContent();
while (XMLDoc.LocalName != "serviceList")
{
if (XMLDoc.LocalName == "service")
{
// TODO: DONE Resilience case 5a - wrap in try/catch block
string servicexml = "Failed to read service xml element from device xml";
try
{
servicexml = XMLDoc.ReadOuterXml();
service = UPnPService.Parse(servicexml);
RetVal.AddService(service);
}
catch (Exception e)
{
OpenSource.Utilities.EventLogger.Log(null, System.Diagnostics.EventLogEntryType.Error, "Invalid Service element within Device XML");
OpenSource.Utilities.EventLogger.Log(e, "XML content: \r\n" + servicexml);
OpenSource.Utilities.EventLogger.Log(null, System.Diagnostics.EventLogEntryType.Warning, "Dropping failed Service and commencing parsing remainder of device");
}
}
if (!XMLDoc.IsStartElement())
{
if (XMLDoc.LocalName != "serviceList")
{
XMLDoc.Read();
XMLDoc.MoveToContent();
}
}
}
break;
case "iconList":
bool finishedIconList = false;
while (!finishedIconList && XMLDoc.Read())
{
switch (XMLDoc.NodeType)
{
case XmlNodeType.Element:
if (XMLDoc.LocalName == "icon")
{
ParseIconXML(RetVal, XMLDoc.ReadOuterXml());
if (XMLDoc.NodeType == XmlNodeType.EndElement && XMLDoc.LocalName == "iconList") { finishedIconList = true; }
}
break;
case XmlNodeType.EndElement:
if (XMLDoc.LocalName == "iconList") { finishedIconList = true; }
break;
}
}
break;
default:
if (XMLDoc.LocalName != "")
{
string customPrefix = XMLDoc.Prefix;
string customFieldName = XMLDoc.LocalName;
string customFieldNamespace = XMLDoc.LookupNamespace(customPrefix);
string customFieldVal = XMLDoc.ReadInnerXml();
RetVal.AddCustomFieldInDescription(customFieldName, customFieldVal, customFieldNamespace);
}
else
{
XMLDoc.Skip();
}
continue;
}
XMLDoc.Read();
//XMLDoc.MoveToContent();
}
}
}