/// <summary> /// Occurs when an event enabled state variable changes. /// </summary> /// <param name="service">The service for which the state variable changed.</param> /// <param name="stateVarName">The state variable name.</param> /// <param name="stateVarValue">The new value of the state variable.</param> void IUPnPServiceCallback.StateVariableChanged(UPnPService service, string stateVarName, object stateVarValue) { if (Service != null) { Service.OnStateVariableChanged(new StateVariableChangedEventArgs(stateVarName, stateVarValue)); } }
/// <summary> /// Occurs when a service instance is no longer available. /// </summary> /// <param name="service">The service instance which is no longer available.</param> void IUPnPServiceCallback.ServiceInstanceDied(UPnPService service) { if (Service != null) { Service.OnServiceInstanceDied(new ServiceInstanceDiedEventArgs()); } }
public void Play(string deviceId, int httpPort, string objectID, ItemManager manager, TimeSpan startTime) { IUPnPDeviceDocumentAccess deviceAccess; UPnPService service = GetServiceSync(deviceId, "urn:schemas-upnp-org:service:AVTransport:1", out deviceAccess); IPAddress deviceIP = IPAddress.Parse(new Uri(deviceAccess.GetDocumentURL()).Host); //Najdenie adresy servera podla adresy zariadenia kde sa ma prehravanie spustit IPAddress[] addresses = Dns.GetHostAddresses(Dns.GetHostName()).Where(a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray(); int byteIndex = 0; while (addresses.Length > 1) { addresses = addresses.Where(a => a.GetAddressBytes()[byteIndex] == deviceIP.GetAddressBytes()[byteIndex]).ToArray(); byteIndex++; } //Ak ostane jedna adresa - zapise sa if (addresses.Length == 1) { deviceIP = addresses[0]; } string result, firstResource; manager.BrowseMetadata("http://" + deviceIP + ":" + httpPort, objectID, startTime, out result, out firstResource); object[] inArgs = new object[] { 0, firstResource, result }; object outArgs = null; service.InvokeAction("SetAVTransportURI", inArgs, ref outArgs); inArgs = new object[] { 0, 1 }; outArgs = null; service.InvokeAction("Play", inArgs, ref outArgs); }
public void ServiceAdded(UPnPService service) { comboBoxTV.Items.Add(service); foreach (UPnPService item in comboBoxTV.Items) { if (item.ParentDevice.UDN == _device.UDN) { comboBoxTV.SelectedItem = item; break; } } if (comboBoxTV.SelectedIndex == -1) { comboBoxTV.SelectedItem = service; } listBoxCompatibleModels.Items.Clear(); foreach (String model in _device.SelectedDeviceModel.CompatibleModels) { listBoxCompatibleModels.Items.Add(" " + model); } }
/// <summary> /// This method sets the Action List URL found in the DLNA Device Action List XML. /// </summary> /// <param name="devName">This is the Name of the Device to get the infromation for</param> /// private void getActionlist_URL(UPnPService service) { Log.Debug("Auto3D: Retrieving Action List URL from device description file: " + service.ParentDevice.FriendlyName); try { XElement xDeviceInfo = service.ParentDevice.DeviceXML.Elements().First(e => e.Name.LocalName == "X_UNR_DeviceInfo"); if (xDeviceInfo != null) { XElement xActionList = xDeviceInfo.Elements().First(e => e.Name.LocalName == "X_CERS_ActionList_URL"); if (xActionList != null) { actionListURL = xActionList.Value; Log.Debug("Auto3D: Action List URL found for device: " + service.ParentDevice.FriendlyName); return; } } } catch (Exception ex) { Log.Error("Auto3D: " + ex.Message); } Log.Error("Auto3D: Action List URL was NOT found for device: " + service.ParentDevice.FriendlyName); actionListURL = ""; }
private void Error_Sink_PrepareForConnection(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, object _Tag) { for (int i = 0; i < Args.Length; ++i) { switch (Args[i].Name) { case "Direction": switch ((string)Args[i].DataValue) { case "Input": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.INPUT; break; case "Output": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.OUTPUT; break; } break; } } object[] StateInfo = (object[])_Tag; if (StateInfo[1] != null) { ((Delegate_OnResult_PrepareForConnection)StateInfo[1])(this, (System.String)Args[0].DataValue, (System.String)Args[1].DataValue, (System.Int32)Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), e, StateInfo[0]); } else { OnResult_PrepareForConnection_Event.Fire(this, (System.String)Args[0].DataValue, (System.String)Args[1].DataValue, (System.Int32)Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32), null), e, StateInfo[0]); } }
private void Sink_PrepareForConnection(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, object _Tag) { for (int i = 0; i < Args.Length; ++i) { switch (Args[i].Name) { case "Direction": switch ((string)Args[i].DataValue) { case "Input": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.INPUT; break; case "Output": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.OUTPUT; break; default: SetUnspecifiedValue("Enum_A_ARG_TYPE_Direction", (string)Args[i].DataValue); Args[i].DataValue = Enum_A_ARG_TYPE_Direction._UNSPECIFIED_; break; } break; } } object[] StateInfo = (object[])_Tag; if (StateInfo[1] != null) { ((Delegate_OnResult_PrepareForConnection)StateInfo[1])(this, (System.String)Args[0].DataValue, (System.String)Args[1].DataValue, (System.Int32)Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)Args[4].DataValue, (System.Int32)Args[5].DataValue, (System.Int32)Args[6].DataValue, null, StateInfo[0]); } else { OnResult_PrepareForConnection_Event.Fire(this, (System.String)Args[0].DataValue, (System.String)Args[1].DataValue, (System.Int32)Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)Args[4].DataValue, (System.Int32)Args[5].DataValue, (System.Int32)Args[6].DataValue, null, StateInfo[0]); } }
public SwitchPowerServiceControl(UPnPService service) : base(service, x => new SwitchPowerEvent(x)) { if (service.Id != "urn:upnp-org:serviceId:SwitchPower.0001") { throw new ArgumentException("Service does not have correct id, is " + service.Id + ", should be urn:upnp-org:serviceId:SwitchPower.0001"); } }
/// <summary> /// Generates a UPnPService object from an SCPD XML /// </summary> /// <param name="SCPD_XML">XML String</param> /// <returns>UPnPService</returns> public static UPnPService GenerateServiceFromSCPD(string SCPD_XML) { UPnPService s = new UPnPService(1); s.ParseSCPD(SCPD_XML); return(s); }
public override void StateVariableChanged(UPnPService pus, string pcwszStateVarName, object vaValue) { try { IUPnPServiceCallback callback = (IUPnPServiceCallback)connection.Target; if (callback == null) { return; } XPathDocument doc = new XPathDocument(new StringReader((string)vaValue)); XPathNavigator nav = doc.CreateNavigator(); foreach (XPathNavigator node in nav.Select(XPath.Expressions.EventElements)) { XPathNavigator val = node.SelectSingleNode(XPath.Expressions.ValueAttributes); if (String.CompareOrdinal(val.Value, "NOT_IMPLEMENTED") != 0) { callback.StateVariableChanged(pus, node.LocalName, val.Value); } } } finally { Marshal.ReleaseComObject(pus); } }
protected UPnPService BuildUPnPService() { UPnPStateVariable[] RetVal = new UPnPStateVariable[8]; RetVal[0] = new UPnPModeratedStateVariable("AuthorizationDeniedUpdateID", typeof(System.UInt32), true); RetVal[1] = new UPnPModeratedStateVariable("A_ARG_TYPE_DeviceID", typeof(System.String), false); RetVal[1].AddAssociation("IsAuthorized", "DeviceID"); RetVal[1].AddAssociation("IsValidated", "DeviceID"); RetVal[2] = new UPnPModeratedStateVariable("A_ARG_TYPE_RegistrationRespMsg", typeof(System.Byte[]), false); RetVal[2].AddAssociation("RegisterDevice", "RegistrationRespMsg"); RetVal[3] = new UPnPModeratedStateVariable("ValidationRevokedUpdateID", typeof(System.UInt32), true); RetVal[4] = new UPnPModeratedStateVariable("ValidationSucceededUpdateID", typeof(System.UInt32), true); RetVal[5] = new UPnPModeratedStateVariable("A_ARG_TYPE_Result", typeof(System.Int32), false); RetVal[5].AddAssociation("IsAuthorized", "Result"); RetVal[5].AddAssociation("IsValidated", "Result"); RetVal[6] = new UPnPModeratedStateVariable("AuthorizationGrantedUpdateID", typeof(System.UInt32), true); RetVal[7] = new UPnPModeratedStateVariable("A_ARG_TYPE_RegistrationReqMsg", typeof(System.Byte[]), false); RetVal[7].AddAssociation("RegisterDevice", "RegistrationReqMsg"); UPnPService S = new UPnPService(1, "urn:microsoft.com:serviceId:X_MS_MediaReceiverRegistrar", "urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1", true, this); for (int i = 0; i < RetVal.Length; ++i) { S.AddStateVariable(RetVal[i]); } S.AddMethod("IsAuthorized"); S.AddMethod("IsValidated"); S.AddMethod("RegisterDevice"); return(S); }
protected void HandleInvokeError(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, object Handle) { if (sender != service) { return; } if (MethodName != action.Name) { return; } TimeSpan invokeSpan = DateTime.Now.Subtract(invokeTime); string timeStr; if (invokeSpan.TotalMilliseconds >= 1000) { timeStr = invokeSpan.Seconds + "." + invokeSpan.Milliseconds + "sec"; } else { timeStr = invokeSpan.Milliseconds + "ms"; } if (e.UPNP == null) { statusBar.Text = "Invocation error (" + timeStr + "): " + e.ToString(); } else { statusBar.Text = "Invocation Error Code " + e.UPNP.ErrorCode.ToString() + " (" + timeStr + "): " + e.UPNP.ErrorDescription; } }
public AVTransport(UPnPService service) : base(service) { _service.AddCallback(new AVTransportCallback(this)); PropertyChanged += new PropertyChangedEventHandler(AVTransport_PropertyChanged); PropertyChanged += new PropertyChangedEventHandler(TransportStateChanged); _timer = new Timer(new TimerCallback(this.OnTimerFired), null, 1000, 1000); }
protected void InvokeSink(UPnPAction sender, UPnPArgument[] InArgs, out object RetVal, out UPnPArgument[] OutArgs) { UPnPService S = (UPnPService)ServiceTable[sender.ParentService]; UPnPAction A = S.GetAction(sender.Name); ArrayList TempList = new ArrayList(); foreach (UPnPArgument arg in A.Arguments) { if ((arg.IsReturnValue == false) && (arg.Direction == "out")) { TempList.Add(arg.Clone()); } } foreach (UPnPArgument arg in InArgs) { TempList.Add(arg); } lock (CallQueue) { ++InvokeID; CallQueue.Enqueue(InvokeID); S.InvokeAsync(sender.Name, (UPnPArgument[])TempList.ToArray(typeof(UPnPArgument)), InvokeID, new UPnPService.UPnPServiceInvokeHandler(RealInvokeSink), null); InvokeTable[InvokeID] = sender.ParentService; } UPnPArgument[] OtherArgs; sender.ParentService.DelayInvokeRespose(InvokeID, out OtherArgs); throw(new DelayedResponseException()); }
public void InvokeAsync(UPnPService S, string Action, byte[] InArgs, string Caller, int Handle) { UPnPAction A = S.GetAction(Action); ArrayList AList = new ArrayList(); foreach (UPnPArgument arg in A.ArgumentList) { if (arg.IsReturnValue == false && arg.Direction == "out") { UPnPArgument _arg = (UPnPArgument)arg.Clone(); _arg.DataValue = UPnPService.CreateObjectInstance(arg.RelatedStateVar.GetNetType(), null); AList.Add(_arg); } } UPnPArgument[] Temp = ParseArguments(InArgs); foreach (UPnPArgument _arg in Temp) { _arg.DataType = A.GetArg(_arg.Name).RelatedStateVar.ValueType; _arg.Direction = "in"; AList.Add(_arg); } UPnPArgument[] Arguments = (UPnPArgument[])AList.ToArray(typeof(UPnPArgument)); (new UPnPDebugObject(S)).SetProperty("ValidationMode", false); S.InvokeAsync(Action, Arguments, new Object[2] { Caller, Handle }, A_ICB, A_IECB); }
private void GetDocumentSink(System.String DeviceUDN, System.String ServiceID, out System.Byte[] Document) { if (ServiceID != "") { foreach (UPnPDevice d in ShareList) { UPnPDevice _D = d.GetDevice(DeviceUDN); if (_D != null) { UPnPService s = _D.GetService(ServiceID); if (s != null) { Document = s.GetSCPDXml(); return; } } } } else { foreach (UPnPDevice d in ShareList) { if (d.UniqueDeviceName == DeviceUDN) { Document = d.GetRootDeviceXML(DV.GetReceiver()); return; } } } throw(new UPnPCustomException(800, "No Match")); }
public RenderingControlServiceControl(UPnPService service) : base(service, x => new RenderingControlEvent(x)) { if (service.Id != UPnPServiceIds.RenderingControl) { throw new ArgumentException("Service does not have correct id, is " + service.Id + ", should be " + UPnPServiceIds.AvTransport); } }
private void A_InvokeSink(UPnPService sender, String MethodName, UPnPArgument[] Args, Object ReturnValue, object Tag) { object[] state = (object[])Tag; string Caller = (string)state[0]; int Handle = (int)state[1]; ArrayList RetList = new ArrayList(); UPnPAction A = sender.GetAction(MethodName); if (A.HasReturnValue == true) { UPnPArgument RA = (UPnPArgument)A.GetRetArg().Clone(); RA.DataValue = ReturnValue; RetList.Add(RA); } foreach (UPnPArgument OA in Args) { if (OA.Direction == "out") { RetList.Add(OA); } } byte[] OutArgs = BuildArguments((UPnPArgument[])RetList.ToArray(typeof(UPnPArgument))); CpGateKeeper C = (CpGateKeeper)RegisteredTable[Caller]; C.InvokeAsyncResponse(Handle, OutArgs, 0, ""); }
public UPnPAction() { this.SpecialCase = null; this.ParentService = null; this.MethodPointer = null; this.ArgList = new ArrayList(); }
/// <summary> /// when device is found add to tree view /// </summary> /// <param name="lFindData"></param> /// <param name="pDevice"></param> public void DeviceAdded(int lFindData, UPnPDevice pDevice) { var enumerate = pDevice.Services.GetEnumerator(); TreeNode parent = new TreeNode(); parent.Text = pDevice.FriendlyName; UPnPServerBrowserDialog.tvwServerList.Nodes.Add(parent); try { while (enumerate.MoveNext()) { try { UPnPService current = enumerate.Current as UPnPService; XDocument content = UPnPData.Browser(current, "0"); object[,] structure = UPnPData.buildStructure(current, content); UPnPData.buildTreeView(structure, parent); } catch { //Do nothing } } } catch (Exception e) { MessageBox.Show(e.Message); } UPnPServerBrowserDialog.lblSearching.Text = "Finished: " + pDevice.FriendlyName; }
private ArrayList BasicControlTest_BuildActionArgs(UPnPAction A) { ArrayList ArgList = new ArrayList(); foreach (UPnPArgument arg in A.ArgumentList) { if (arg.IsReturnValue == false) { UPnPArgument NArg; // if(arg.RelatedStateVar.GetNetType().FullName=="System.String") // { // NArg = new UPnPArgument(arg.Name,"Sample String"); // } // else // { NArg = new UPnPArgument(arg.Name, UPnPService.CreateObjectInstance(arg.RelatedStateVar.GetNetType(), null)); // } if (arg.RelatedStateVar.AllowedStringValues != null) { NArg.DataValue = arg.RelatedStateVar.AllowedStringValues[0]; } if (arg.RelatedStateVar.Minimum != null) { NArg.DataValue = arg.RelatedStateVar.Minimum; } if (arg.RelatedStateVar.Maximum != null) { NArg.DataValue = arg.RelatedStateVar.Maximum; } ArgList.Add(NArg); } } return(ArgList); }
private void GetStateTableSink(System.String DeviceUDN, System.String ServiceID, out System.Byte[] Variables) { foreach (UPnPDevice d in ShareList) { UPnPDevice _D = d.GetDevice(DeviceUDN); if (_D != null) { UPnPService s = _D.GetService(ServiceID); if (s != null) { ArrayList t = new ArrayList(); foreach (UPnPStateVariable V in s.GetStateVariables()) { if (V.SendEvent) { t.Add(new UPnPArgument(V.Name, UPnPService.SerializeObjectInstance(V.Value))); } } Variables = Gatekeeper.BuildArguments((UPnPArgument[])t.ToArray(typeof(UPnPArgument))); return; } } } throw(new UPnPCustomException(800, "No Match")); }
public static byte[] BuildArguments(UPnPArgument[] Args) { MemoryStream ms = new MemoryStream(); UTF8Encoding U = new UTF8Encoding(); byte[] Name; byte[] Val; byte[] LofA; byte[] LofN; byte[] LofV; foreach (UPnPArgument A in Args) { Name = U.GetBytes(A.Name); Val = U.GetBytes(UPnPService.SerializeObjectInstance(A.DataValue)); LofV = BitConverter.GetBytes(Val.Length); LofN = BitConverter.GetBytes(Name.Length); LofA = BitConverter.GetBytes(Val.Length + 4 + Name.Length + 4 + 4); ms.Write(LofA, 0, LofA.Length); ms.Write(LofN, 0, LofN.Length); ms.Write(Name, 0, Name.Length); ms.Write(LofV, 0, LofV.Length); ms.Write(Val, 0, Val.Length); } ms.Flush(); return(ms.ToArray()); }
public override void ServiceAdded(UPnPService service) { base.ServiceAdded(service); Log.Info("Auto3D: Sony service found -> " + service.ParentDevice.Manufacturer + ", " + service.ParentDevice.WebAddress.Host); if (service.ParentDevice.UDN == UDN) { MAC = Auto3DHelpers.RequestMACAddress(service.ParentDevice.WebAddress.Host); Log.Info("Auto3D: Sony service connected"); } try { sonyDevice.initialize(service); } catch (Exception ex) { Log.Error("Auto3D: Initialize failed: " + ex.Message); } // show on GUI that device is not registered!) if (!sonyDevice.Registered) { Log.Error("Auto3D: Device " + service.ParentDevice.FriendlyName + " is not registered"); } else { String CmdList = sonyDevice.get_remote_command_list(); Log.Debug("Auto3D: Device " + service.ParentDevice.FriendlyName + " CmdList = " + CmdList); } ((SonyTVSetup)GetSetupControl()).SetRegisterButtonState(!sonyDevice.Registered); }
private void deviceTree_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { TreeNode node = deviceTree.GetNodeAt(e.X, e.Y); if (node == null) { return; } deviceTree.SelectedNode = node; object infoObject = node.Tag; if (infoObject == null) { service = null; okButton.Enabled = false; return; } if (infoObject.GetType() == typeof(UPnPService)) { service = (UPnPService)infoObject; okButton.Enabled = true; } else { service = null; okButton.Enabled = false; } }
private void RenderingControl_OnUPnPEvent(UPnPService sender, long SEQ) { Match match; string lastChange = (string)sender.GetStateVariable("LastChange"); // Volume change // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"><InstanceID val="0"><Volume Channel="Master" val="61"/><VolumeDB Channel="Master" val="-1829"/></InstanceID></Event> if ((match = rcVolumeRegex.Match(lastChange)).Success) { string volume = match.Groups["volume"].Value; Console.WriteLine("Volume Change: " + volume); if (OnVolumeChanged != null) { OnVolumeChanged(this, int.Parse(volume)); } } // Mute change // <Event xmlns="urn:schemas-upnp-org:metadata-1-0/RCS/"><InstanceID val="0"><Mute Channel="Master" val="1"/></InstanceID></Event> else if ((match = rcMuteRegex.Match(lastChange)).Success) { string mute = match.Groups["mute"].Value; Console.WriteLine("Mute Change: " + mute); if (OnMuteChanged != null) { OnMuteChanged(this, int.Parse(mute) == 1); } } // other events... else { Console.WriteLine("RenderingControl Event " + SEQ + " " + sender.ServiceID + " " + lastChange); } }
private void EventSink(UPnPStateVariable sender, object val) { lock (RegisteredTable) { IDictionaryEnumerator en = RegisteredTable.GetEnumerator(); while (en.MoveNext()) { CpGateKeeper cp = (CpGateKeeper)en.Value; cp.FireEvent(sender.OwningService.ParentDevice.UniqueDeviceName, sender.OwningService.ServiceID, sender.Name, UPnPService.SerializeObjectInstance(val)); } } if (this.OnEvent != null) { UPnPDevice _d = sender.OwningService.ParentDevice; while (_d.ParentDevice != null) { _d = _d.ParentDevice; } OnEvent(_d, sender.Name); } }
/// <summary> /// Creates a programmer-friendly object for using a device /// that happens implement a MediaServer. /// </summary> /// <param name="device"></param> public CpMediaServer(UPnPDevice device) { UPnPService sCM = device.GetServices(CpConnectionManager.SERVICE_NAME)[0]; UPnPService sCD = device.GetServices(CpContentDirectory.SERVICE_NAME)[0]; CpConnectionManager cpCM = new CpConnectionManager(sCM); CpContentDirectory cpCD = new CpContentDirectory(sCD); UDN = device.UniqueDeviceName; if ( (cpCD.HasAction_GetSearchCapabilities == false) || (cpCD.HasAction_GetSortCapabilities == false) || (cpCD.HasAction_GetSystemUpdateID == false) || (cpCD.HasAction_Browse == false) ) { throw new UPnPCustomException(0, "MediaServer does not implement minimum features."); } this.m_ConnectionManager = cpCM; this.m_ContentDirectory = cpCD; //create a virtualized root container with the desired settings m_Root = new CpRootContainer(this); m_Root.UDN = device.UniqueDeviceName; }
protected void _subscribe_sink(UPnPService sender, bool OK) { if (OnSubscribe != null) { OnSubscribe(this, OK); } }
private void DeviceRetrieved(object Sender, DeviceDescriptionEventArgs e) { try { if (!(e.DeviceDescriptionDocument is null)) { UPnPService Service = e.DeviceDescriptionDocument.GetService("urn:schemas-upnp-org:service:WANIPConnection:1"); if (Service is null) { Service = e.DeviceDescriptionDocument.GetService("urn:schemas-upnp-org:service:WANIPConnection:2"); if (Service is null) { return; } } Service.StartGetService(this.ServiceRetrieved, e.State); } } catch (Exception ex) { this.exception = ex; this.State = PeerToPeerNetworkState.Error; } }
protected void SniffPacketSink(UPnPService sender, HTTPMessage MSG) { if (this.OnSniffPacket != null) { this.OnSniffPacket(this, MSG); } }
protected void EventSink(UPnPService sender, long seq) { UPnPService S = (UPnPService)RealServiceTable[sender]; foreach(UPnPStateVariable v in sender.GetStateVariables()) { UPnPStateVariable sv = S.GetStateVariableObject(v.Name); sv.Value = v.Value; } }
internal RenderingControl(UPnPService service) : base(service) { _Loudness[Channel.Master] = false; foreach (Channel c in Enum.GetValues(typeof(Channel))) { _Mute[c] = false; _Volume[c] = 0; } this.PropertyChanged += new PropertyChangedEventHandler(RenderingControl_PropertyChanged); }
/// <summary> /// Browses through UPnPService object with id objectId and adds it to a TreeView /// </summary> /// <param name="service"></param> /// <param name="objectId"></param> /// <param name="parent"></param> /// <returns></returns> public static XDocument Browser(UPnPService service, string objectId) { object output = new object(); object[] input = new object[6] {objectId, "BrowseDirectChildren", "", 0, 0, "0",}; object response; Array o; response = service.InvokeAction("Browse", input, ref output); o = (Array) output; XDocument content = XDocument.Parse(o.GetValue(0).ToString()); return content; }
void IUPnPServiceCallback.ServiceInstanceDied(UPnPService pus) { try { IUPnPServiceCallback callback = (IUPnPServiceCallback)connection.Target; if (callback == null) { return; } callback.ServiceInstanceDied(pus); } finally { Marshal.ReleaseComObject(pus); } }
public virtual void StateVariableChanged(UPnPService pus, string pcwszStateVarName, object vaValue) { try { IUPnPServiceCallback callback = (IUPnPServiceCallback)connection.Target; if (callback == null) { return; } callback.StateVariableChanged(pus, pcwszStateVarName, vaValue); } finally { Marshal.ReleaseComObject(pus); } }
private void Error_Sink_SetPlayMode(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "NewPlayMode": switch((string)Args[i].DataValue) { case "NORMAL": Args[i].DataValue = Enum_CurrentPlayMode.NORMAL; break; case "SHUFFLE": Args[i].DataValue = Enum_CurrentPlayMode.SHUFFLE; break; case "REPEAT_ONE": Args[i].DataValue = Enum_CurrentPlayMode.REPEAT_ONE; break; case "REPEAT_ALL": Args[i].DataValue = Enum_CurrentPlayMode.REPEAT_ALL; break; case "RANDOM": Args[i].DataValue = Enum_CurrentPlayMode.RANDOM; break; case "DIRECT_1": Args[i].DataValue = Enum_CurrentPlayMode.DIRECT_1; break; case "INTRO": Args[i].DataValue = Enum_CurrentPlayMode.INTRO; break; } break; } } if(OnResult_SetPlayMode != null) { OnResult_SetPlayMode((System.UInt32 )Args[0].DataValue, (Enum_CurrentPlayMode )Args[1].DataValue, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_SetPlayMode.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_SetPlayMode)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_CurrentPlayMode )Args[1].DataValue, e, Handle); } else { WeakList_SetPlayMode.Remove(wr); } } }
private void Sink_GetTransportInfo(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "CurrentTransportState": switch((string)Args[i].DataValue) { case "STOPPED": Args[i].DataValue = Enum_TransportState.STOPPED; break; case "PAUSED_PLAYBACK": Args[i].DataValue = Enum_TransportState.PAUSED_PLAYBACK; break; case "PAUSED_RECORDING": Args[i].DataValue = Enum_TransportState.PAUSED_RECORDING; break; case "PLAYING": Args[i].DataValue = Enum_TransportState.PLAYING; break; case "RECORDING": Args[i].DataValue = Enum_TransportState.RECORDING; break; case "TRANSITIONING": Args[i].DataValue = Enum_TransportState.TRANSITIONING; break; case "NO_MEDIA_PRESENT": Args[i].DataValue = Enum_TransportState.NO_MEDIA_PRESENT; break; default: SetUnspecifiedValue("Enum_TransportState", (string)Args[i].DataValue); Args[i].DataValue = Enum_TransportState._UNSPECIFIED_; break; } break; case "CurrentTransportStatus": switch((string)Args[i].DataValue) { case "OK": Args[i].DataValue = Enum_TransportStatus.OK; break; case "ERROR_OCCURRED": Args[i].DataValue = Enum_TransportStatus.ERROR_OCCURRED; break; case " vendor-defined ": Args[i].DataValue = Enum_TransportStatus._VENDOR_DEFINED_; break; default: SetUnspecifiedValue("Enum_TransportStatus", (string)Args[i].DataValue); Args[i].DataValue = Enum_TransportStatus._UNSPECIFIED_; break; } break; case "CurrentSpeed": switch((string)Args[i].DataValue) { case "1": Args[i].DataValue = Enum_TransportPlaySpeed._1; break; case " vendor-defined ": Args[i].DataValue = Enum_TransportPlaySpeed._VENDOR_DEFINED_; break; default: SetUnspecifiedValue("Enum_TransportPlaySpeed", (string)Args[i].DataValue); Args[i].DataValue = Enum_TransportPlaySpeed._UNSPECIFIED_; break; } break; } } if(OnResult_GetTransportInfo != null) { OnResult_GetTransportInfo((System.UInt32 )Args[0].DataValue, (Enum_TransportState )Args[1].DataValue, (Enum_TransportStatus )Args[2].DataValue, (Enum_TransportPlaySpeed )Args[3].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetTransportInfo.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetTransportInfo)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_TransportState )Args[1].DataValue, (Enum_TransportStatus )Args[2].DataValue, (Enum_TransportPlaySpeed )Args[3].DataValue, null, Handle); } else { WeakList_GetTransportInfo.Remove(wr); } } }
private void Sink_GetTransportSettings(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "PlayMode": switch((string)Args[i].DataValue) { case "NORMAL": Args[i].DataValue = Enum_CurrentPlayMode.NORMAL; break; case "SHUFFLE": Args[i].DataValue = Enum_CurrentPlayMode.SHUFFLE; break; case "REPEAT_ONE": Args[i].DataValue = Enum_CurrentPlayMode.REPEAT_ONE; break; case "REPEAT_ALL": Args[i].DataValue = Enum_CurrentPlayMode.REPEAT_ALL; break; case "RANDOM": Args[i].DataValue = Enum_CurrentPlayMode.RANDOM; break; case "DIRECT_1": Args[i].DataValue = Enum_CurrentPlayMode.DIRECT_1; break; case "INTRO": Args[i].DataValue = Enum_CurrentPlayMode.INTRO; break; default: SetUnspecifiedValue("Enum_CurrentPlayMode", (string)Args[i].DataValue); Args[i].DataValue = Enum_CurrentPlayMode._UNSPECIFIED_; break; } break; case "RecQualityMode": switch((string)Args[i].DataValue) { case "0:EP": Args[i].DataValue = Enum_CurrentRecordQualityMode._0_EP; break; case "1:LP": Args[i].DataValue = Enum_CurrentRecordQualityMode._1_LP; break; case "2:SP": Args[i].DataValue = Enum_CurrentRecordQualityMode._2_SP; break; case "0:BASIC": Args[i].DataValue = Enum_CurrentRecordQualityMode._0_BASIC; break; case "1:MEDIUM": Args[i].DataValue = Enum_CurrentRecordQualityMode._1_MEDIUM; break; case "2:HIGH": Args[i].DataValue = Enum_CurrentRecordQualityMode._2_HIGH; break; case "NOT_IMPLEMENTED": Args[i].DataValue = Enum_CurrentRecordQualityMode.NOT_IMPLEMENTED; break; case " vendor-defined ": Args[i].DataValue = Enum_CurrentRecordQualityMode._VENDOR_DEFINED_; break; default: SetUnspecifiedValue("Enum_CurrentRecordQualityMode", (string)Args[i].DataValue); Args[i].DataValue = Enum_CurrentRecordQualityMode._UNSPECIFIED_; break; } break; } } if(OnResult_GetTransportSettings != null) { OnResult_GetTransportSettings((System.UInt32 )Args[0].DataValue, (Enum_CurrentPlayMode )Args[1].DataValue, (Enum_CurrentRecordQualityMode )Args[2].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetTransportSettings.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetTransportSettings)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_CurrentPlayMode )Args[1].DataValue, (Enum_CurrentRecordQualityMode )Args[2].DataValue, null, Handle); } else { WeakList_GetTransportSettings.Remove(wr); } } }
private void Sink_GetPositionInfo(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { if(OnResult_GetPositionInfo != null) { OnResult_GetPositionInfo((System.UInt32 )Args[0].DataValue, (System.UInt32 )Args[1].DataValue, (System.String )Args[2].DataValue, (System.String )Args[3].DataValue, (System.String )Args[4].DataValue, (System.String )Args[5].DataValue, (System.String )Args[6].DataValue, (System.Int32 )Args[7].DataValue, (System.Int32 )Args[8].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetPositionInfo.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetPositionInfo)wr.Target)((System.UInt32 )Args[0].DataValue, (System.UInt32 )Args[1].DataValue, (System.String )Args[2].DataValue, (System.String )Args[3].DataValue, (System.String )Args[4].DataValue, (System.String )Args[5].DataValue, (System.String )Args[6].DataValue, (System.Int32 )Args[7].DataValue, (System.Int32 )Args[8].DataValue, null, Handle); } else { WeakList_GetPositionInfo.Remove(wr); } } }
private void Error_Sink_GetTransportInfo(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { if(OnResult_GetTransportInfo != null) { OnResult_GetTransportInfo((System.UInt32 )Args[0].DataValue, (Enum_TransportState)0, (Enum_TransportStatus)0, (Enum_TransportPlaySpeed)0, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetTransportInfo.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetTransportInfo)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_TransportState)0, (Enum_TransportStatus)0, (Enum_TransportPlaySpeed)0, e, Handle); } else { WeakList_GetTransportInfo.Remove(wr); } } }
internal DeviceProperties(UPnPService service) : base(service) { }
public ConnectionManager(UPnPService service) : base(service) { }
private void Error_Sink_GetCurrentConnectionIDs(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { if(OnResult_GetCurrentConnectionIDs != null) { OnResult_GetCurrentConnectionIDs((System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), e, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetCurrentConnectionIDs.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetCurrentConnectionIDs)wr.Target)((System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), e, Handle); } else { WeakList_GetCurrentConnectionIDs.Remove(wr); } } }
private void Sink_GetCurrentConnectionInfo(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "Direction": switch((string)Args[i].DataValue) { case "Input": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.INPUT; break; case "Output": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.OUTPUT; break; default: SetUnspecifiedValue("Enum_A_ARG_TYPE_Direction", (string)Args[i].DataValue); Args[i].DataValue = Enum_A_ARG_TYPE_Direction._UNSPECIFIED_; break; } break; case "Status": switch((string)Args[i].DataValue) { case "OK": Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus.OK; break; case "ContentFormatMismatch": Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus.CONTENTFORMATMISMATCH; break; case "InsufficientBandwidth": Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus.INSUFFICIENTBANDWIDTH; break; case "UnreliableChannel": Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus.UNRELIABLECHANNEL; break; case "Unknown": Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus.UNKNOWN; break; default: SetUnspecifiedValue("Enum_A_ARG_TYPE_ConnectionStatus", (string)Args[i].DataValue); Args[i].DataValue = Enum_A_ARG_TYPE_ConnectionStatus._UNSPECIFIED_; break; } break; } } if(OnResult_GetCurrentConnectionInfo != null) { OnResult_GetCurrentConnectionInfo((System.Int32 )Args[0].DataValue, (System.Int32 )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (System.String )Args[3].DataValue, (System.String )Args[4].DataValue, (System.Int32 )Args[5].DataValue, (Enum_A_ARG_TYPE_Direction )Args[6].DataValue, (Enum_A_ARG_TYPE_ConnectionStatus )Args[7].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetCurrentConnectionInfo.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetCurrentConnectionInfo)wr.Target)((System.Int32 )Args[0].DataValue, (System.Int32 )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (System.String )Args[3].DataValue, (System.String )Args[4].DataValue, (System.Int32 )Args[5].DataValue, (Enum_A_ARG_TYPE_Direction )Args[6].DataValue, (Enum_A_ARG_TYPE_ConnectionStatus )Args[7].DataValue, null, Handle); } else { WeakList_GetCurrentConnectionInfo.Remove(wr); } } }
private void Sink_GetCurrentConnectionIDs(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { if(OnResult_GetCurrentConnectionIDs != null) { OnResult_GetCurrentConnectionIDs((System.String )Args[0].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetCurrentConnectionIDs.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetCurrentConnectionIDs)wr.Target)((System.String )Args[0].DataValue, null, Handle); } else { WeakList_GetCurrentConnectionIDs.Remove(wr); } } }
private void Error_Sink_ConnectionComplete(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { if(OnResult_ConnectionComplete != null) { OnResult_ConnectionComplete((System.Int32 )Args[0].DataValue, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_ConnectionComplete.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_ConnectionComplete)wr.Target)((System.Int32 )Args[0].DataValue, e, Handle); } else { WeakList_ConnectionComplete.Remove(wr); } } }
private void Error_Sink_PrepareForConnection(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "Direction": switch((string)Args[i].DataValue) { case "Input": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.INPUT; break; case "Output": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.OUTPUT; break; } break; } } if(OnResult_PrepareForConnection != null) { OnResult_PrepareForConnection((System.String )Args[0].DataValue, (System.String )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), e, Handle); } WeakReference[] w = (WeakReference[])WeakList_PrepareForConnection.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_PrepareForConnection)wr.Target)((System.String )Args[0].DataValue, (System.String )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), e, Handle); } else { WeakList_PrepareForConnection.Remove(wr); } } }
private void Sink_PrepareForConnection(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "Direction": switch((string)Args[i].DataValue) { case "Input": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.INPUT; break; case "Output": Args[i].DataValue = Enum_A_ARG_TYPE_Direction.OUTPUT; break; default: SetUnspecifiedValue("Enum_A_ARG_TYPE_Direction", (string)Args[i].DataValue); Args[i].DataValue = Enum_A_ARG_TYPE_Direction._UNSPECIFIED_; break; } break; } } if(OnResult_PrepareForConnection != null) { OnResult_PrepareForConnection((System.String )Args[0].DataValue, (System.String )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32 )Args[4].DataValue, (System.Int32 )Args[5].DataValue, (System.Int32 )Args[6].DataValue, null, Handle); } WeakReference[] w = (WeakReference[])WeakList_PrepareForConnection.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_PrepareForConnection)wr.Target)((System.String )Args[0].DataValue, (System.String )Args[1].DataValue, (System.Int32 )Args[2].DataValue, (Enum_A_ARG_TYPE_Direction )Args[3].DataValue, (System.Int32 )Args[4].DataValue, (System.Int32 )Args[5].DataValue, (System.Int32 )Args[6].DataValue, null, Handle); } else { WeakList_PrepareForConnection.Remove(wr); } } }
private void Error_Sink_GetCurrentConnectionInfo(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { if(OnResult_GetCurrentConnectionInfo != null) { OnResult_GetCurrentConnectionInfo((System.Int32 )Args[0].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), (System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (Enum_A_ARG_TYPE_Direction)0, (Enum_A_ARG_TYPE_ConnectionStatus)0, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_GetCurrentConnectionInfo.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_GetCurrentConnectionInfo)wr.Target)((System.Int32 )Args[0].DataValue, (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), (System.String)UPnPService.CreateObjectInstance(typeof(System.String),null), (System.Int32)UPnPService.CreateObjectInstance(typeof(System.Int32),null), (Enum_A_ARG_TYPE_Direction)0, (Enum_A_ARG_TYPE_ConnectionStatus)0, e, Handle); } else { WeakList_GetCurrentConnectionInfo.Remove(wr); } } }
private void Error_Sink_SetRecordQualityMode(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "NewRecordQualityMode": switch((string)Args[i].DataValue) { case "0:EP": Args[i].DataValue = Enum_CurrentRecordQualityMode._0_EP; break; case "1:LP": Args[i].DataValue = Enum_CurrentRecordQualityMode._1_LP; break; case "2:SP": Args[i].DataValue = Enum_CurrentRecordQualityMode._2_SP; break; case "0:BASIC": Args[i].DataValue = Enum_CurrentRecordQualityMode._0_BASIC; break; case "1:MEDIUM": Args[i].DataValue = Enum_CurrentRecordQualityMode._1_MEDIUM; break; case "2:HIGH": Args[i].DataValue = Enum_CurrentRecordQualityMode._2_HIGH; break; case "NOT_IMPLEMENTED": Args[i].DataValue = Enum_CurrentRecordQualityMode.NOT_IMPLEMENTED; break; case " vendor-defined ": Args[i].DataValue = Enum_CurrentRecordQualityMode._VENDOR_DEFINED_; break; } break; } } if(OnResult_SetRecordQualityMode != null) { OnResult_SetRecordQualityMode((System.UInt32 )Args[0].DataValue, (Enum_CurrentRecordQualityMode )Args[1].DataValue, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_SetRecordQualityMode.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_SetRecordQualityMode)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_CurrentRecordQualityMode )Args[1].DataValue, e, Handle); } else { WeakList_SetRecordQualityMode.Remove(wr); } } }
/// <summary> /// Generates Device side implementation from SCPD XML /// </summary> /// <param name="ClassName">Class Name to build</param> /// <param name="ns">Namespace to use</param> /// <param name="SavePath">Path to save source</param> /// <param name="ServiceID">Service ID to use</param> /// <param name="ServiceURN">Service URN to use</param> /// <param name="SCPD_XML">SCPD XML String</param> public static void Generate(String ClassName, String ns, String SavePath, String ServiceID, String ServiceURN, String SCPD_XML) { UPnPService s = new UPnPService(1); DText p = new DText(); p.ATTRMARK = ":"; p[0] = ServiceURN; string v = p[p.DCOUNT()]; s.SetVersion(v); s.ParseSCPD(SCPD_XML); String cl = "\r\n"; StringBuilder cs = new StringBuilder(); UPnPArgument[] Args; UPnPArgument arg; UPnPStateVariable[] SV = s.GetStateVariables(); cs.Append("using Intel.UPNP;" + cl + cl); cs.Append("namespace " + ns + cl); cs.Append("{\r\n"); cs.Append(" /// <summary>" + cl); cs.Append(" /// Transparent DeviceSide UPnP Service" + cl); cs.Append(" /// </summary>" + cl); cs.Append(" public class " + ClassName + " : IUPnPService" + cl); cs.Append(" {" + cl + cl); cs.Append(" // Place your declarations above this line\r\n"); cs.Append("\r\n"); cs.Append(" #region AutoGenerated Code Section [Do NOT Modify, unless you know what you're doing]\r\n"); cs.Append(" //{{{{{ Begin Code Block\r\n"); cs.Append("\r\n"); cs.Append(" private _" + ClassName + " _S;\r\n"); cs.Append(" public static string URN = \"" + ServiceURN + "\";\r\n"); cs.Append(" public double VERSION\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(double.Parse(_S.GetUPnPService().Version));\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n\r\n"); // Build Enumerations Hashtable elist = BuildEnumerations(SV); IDictionaryEnumerator el = elist.GetEnumerator(); VarData vd; while(el.MoveNext()) { vd = (VarData)el.Value; cs.Append(" public enum Enum_" + vd.VariableName + "\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" " + vs.EnumName + ",\r\n"); } cs.Append(" }\r\n"); cs.Append(" public Enum_" + vd.VariableName + " "); if(s.GetStateVariableObject(vd.VariableName).SendEvent==true) { cs.Append("Evented_"); } cs.Append(vd.VariableName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" set\r\n"); cs.Append(" {\r\n"); cs.Append(" string v = \"\";\r\n"); cs.Append(" switch(value)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" case Enum_" + vd.VariableName + "." + vs.EnumName + ":\r\n"); cs.Append(" v = \"" + vs.EnumValue + "\";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" }\r\n"); cs.Append(" _S.SetStateVariable(\"" + vd.VariableName + "\",v);\r\n"); cs.Append(" }\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" Enum_" + vd.VariableName + " RetVal = 0;\r\n"); cs.Append(" string v = (string)_S.GetStateVariable(\"" + vd.VariableName + "\");\r\n"); cs.Append(" switch(v)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" case \"" + vs.EnumValue + "\":\r\n"); cs.Append(" RetVal = Enum_" + vd.VariableName + "." + vs.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" }\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } el.Reset(); while(el.MoveNext()) { vd = (VarData)el.Value; cs.Append(" static public string Enum_" + vd.VariableName + "_ToString(Enum_" + vd.VariableName + " en)\r\n"); cs.Append(" {\r\n"); cs.Append(" string RetVal = \"\";\r\n"); cs.Append(" switch(en)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" case Enum_" + vd.VariableName + "." + vs.EnumName + ":\r\n"); cs.Append(" RetVal = \"" + vs.EnumValue + "\";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" }\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); // Build Easy Way to get All Values cs.Append(" static public string[] Values_" + vd.VariableName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" string[] RetVal = new string[" + vd.Enumerations.Count.ToString() + "]{"); string EasyStrings = ""; foreach(EnumStruct vs in vd.Enumerations) { if(EasyStrings == "") { EasyStrings = "\"" + vs.EnumValue + "\""; } else { EasyStrings = "\"" + vs.EnumValue + "\"," + EasyStrings; } } cs.Append(EasyStrings + "};\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } cs.Append(" public delegate void OnStateVariableModifiedHandler(" + ClassName + " sender);\r\n"); foreach(UPnPStateVariable V in SV) { cs.Append(" public event OnStateVariableModifiedHandler OnStateVariableModified_" + V.Name + ";\r\n"); } foreach(UPnPStateVariable V in SV) { if(elist.ContainsKey(V.Name)==false) { // Build Accessors cs.Append(" public " + V.GetNetType().FullName + " "); if(V.SendEvent==true) { cs.Append("Evented_"); } cs.Append(V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return((" + V.GetNetType().FullName + ")_S.GetStateVariable(\"" + V.Name + "\"));\r\n"); cs.Append(" }\r\n"); cs.Append(" set\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.SetStateVariable(\"" + V.Name + "\", value);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } } foreach(UPnPStateVariable V in SV) { cs.Append(" public UPnPModeratedStateVariable.IAccumulator Accumulator_"); cs.Append(V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(((UPnPModeratedStateVariable)_S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\")).Accumulator);\r\n"); cs.Append(" }\r\n"); cs.Append(" set\r\n"); cs.Append(" {\r\n"); cs.Append(" ((UPnPModeratedStateVariable)_S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\")).Accumulator = value;\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" public double ModerationDuration_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(((UPnPModeratedStateVariable)_S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\")).ModerationPeriod);\r\n"); cs.Append(" }\r\n"); cs.Append(" set\r\n"); cs.Append(" {\r\n"); cs.Append(" ((UPnPModeratedStateVariable)_S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\")).ModerationPeriod = value;\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } // Build MethodDelegates foreach(UPnPAction A in s.Actions) { cs.Append(" public delegate "); if(A.HasReturnValue==false) { cs.Append("void "); } else { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName + " "); } cs.Append("Delegate_" + A.Name + "("); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { if(arg.Direction=="out") { cs.Append("out "); } if(arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append(ClassName + ".Enum_" + arg.RelatedStateVar.Name + " "); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } } cs.Append(");\r\n"); } // Build Overriding Delegates cs.Append("\r\n"); foreach(UPnPAction A in s.Actions) { cs.Append(" public Delegate_" + A.Name + " External_" + A.Name + " = null;\r\n"); } cs.Append("\r\n"); // Build Ability to remove Optional State Variables foreach(UPnPStateVariable V in s.GetStateVariables()) { cs.Append(" public void RemoveStateVariable_" + V.Name + "()\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.GetUPnPService().RemoveStateVariable(_S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\"));\r\n"); cs.Append(" }\r\n"); } // Build Ability to remove Optional Actions foreach(UPnPAction A in s.Actions) { cs.Append(" public void RemoveAction_" + A.Name + "()\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.GetUPnPService().RemoveMethod(\"" + A.Name + "\");\r\n"); cs.Append(" }\r\n"); } // Add Helper Methods cs.Append(" public System.Net.IPEndPoint GetCaller()\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S.GetUPnPService().GetCaller());\r\n"); cs.Append(" }\r\n"); cs.Append(" public System.Net.IPEndPoint GetReceiver()\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S.GetUPnPService().GetReceiver());\r\n"); cs.Append(" }\r\n"); cs.Append("\r\n"); // Build Private Class cs.Append(" private class _" + ClassName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" private " + ClassName + " Outer = null;\r\n"); cs.Append(" private UPnPService S;\r\n"); cs.Append(" internal _" + ClassName + "(" + ClassName + " n)\r\n"); cs.Append(" {\r\n"); cs.Append(" Outer = n;\r\n"); cs.Append(" S = BuildUPnPService();\r\n"); cs.Append(" }\r\n"); cs.Append(" public UPnPService GetUPnPService()\r\n"); cs.Append(" {\r\n"); cs.Append(" return(S);\r\n"); cs.Append(" }\r\n"); cs.Append(" public void SetStateVariable(string VarName, object VarValue)\r\n"); cs.Append(" {\r\n"); cs.Append(" S.SetStateVariable(VarName,VarValue);\r\n"); cs.Append(" }\r\n"); cs.Append(" public object GetStateVariable(string VarName)\r\n"); cs.Append(" {\r\n"); cs.Append(" return(S.GetStateVariable(VarName));\r\n"); cs.Append(" }\r\n"); cs.Append(" protected UPnPService BuildUPnPService()\r\n"); cs.Append(" {\r\n"); cs.Append(" UPnPStateVariable[] RetVal = new UPnPStateVariable[" + SV.Length.ToString() + "];\r\n"); for(int i=0;i<SV.Length;++i) { cs.Append(" RetVal[" + i.ToString() +"] = new UPnPModeratedStateVariable(\"" + SV[i].Name + "\", typeof(" + SV[i].GetNetType().FullName + "), " + SV[i].SendEvent.ToString().ToLower() + ");\r\n"); if((SV[i].Maximum!=null)|| (SV[i].Minimum!=null)|| (SV[i].Step!=null)) { cs.Append(" RetVal[" + i.ToString() +"].SetRange("); if(SV[i].Minimum==null) { cs.Append("null"); } else { cs.Append("(" + SV[i].Minimum.GetType().FullName + ")(" + SV[i].Minimum.ToString() + ")"); } cs.Append(","); if(SV[i].Maximum==null) { cs.Append("null"); } else { cs.Append("(" + SV[i].Maximum.GetType().FullName + ")(" + SV[i].Maximum.ToString() + ")"); } cs.Append(","); if(SV[i].Step==null) { cs.Append("null"); } else { cs.Append("(" + SV[i].Step.GetType().FullName + ")" + SV[i].Step.ToString()); } cs.Append(");\r\n"); } if(SV[i].DefaultValue!=null) { cs.Append(" RetVal[" + i.ToString() + "].DefaultValue = UPnPService.CreateObjectInstance(typeof(" + SV[i].GetNetType().FullName + "),\"" + UPnPService.SerializeObjectInstance(SV[i].DefaultValue) + "\");\r\n"); //cs.Append(" RetVal[" + i.ToString() + "].DefaultValue = (" + SV[i].GetNetType().FullName + ")(\"" + UPnPService.SerializeObjectInstance(SV[i].DefaultValue) + "\";\r\n"); } if(SV[i].AllowedStringValues!=null) { cs.Append(" RetVal[" + i.ToString() + "].AllowedStringValues = new string[" + SV[i].AllowedStringValues.Length.ToString() + "]{"); for(int ai=0;ai<SV[i].AllowedStringValues.Length;++ai) { cs.Append("\"" + SV[i].AllowedStringValues[ai] + "\""); if(ai<SV[i].AllowedStringValues.Length-1) { cs.Append(", "); } } cs.Append("};\r\n"); } System.Collections.IList e = s.Actions; foreach(UPnPAction A in e) { foreach(UPnPArgument ag in A.ArgumentList) { if(ag.RelatedStateVar.Name==SV[i].Name) { cs.Append(" RetVal[" + i.ToString() + "].AddAssociation(\"" + A.Name + "\", \"" + ag.Name + "\");\r\n"); } } } } // Build UPnPService cs.Append("\r\n"); cs.Append(" UPnPService S = new UPnPService(" + s.Version + ", \"" + ServiceID + "\", \"" + ServiceURN + "\", true, this);\r\n"); cs.Append(" for(int i=0;i<RetVal.Length;++i)\r\n"); cs.Append(" {\r\n"); cs.Append(" S.AddStateVariable(RetVal[i]);\r\n"); cs.Append(" }\r\n"); foreach(UPnPAction A in s.Actions) { cs.Append(" S.AddMethod(\"" + A.Name + "\");\r\n"); } cs.Append(" return(S);\r\n"); cs.Append(" }\r\n\r\n"); System.Collections.IList ee = s.Actions; foreach(UPnPAction A in ee) { if(A.HasReturnValue) { cs.Append(" [Intel.UPNP.ReturnArgument(\""+A.GetRetArg().Name+"\")]"+cl); } cs.Append(" public "); if(A.HasReturnValue==false) { cs.Append("void "); } else { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName + " "); } cs.Append(A.Name+"("); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { if(arg.Direction=="out") { cs.Append("out "); } cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } } cs.Append(")" + cl); cs.Append(" {\r\n"); // Convert to Enum if neccessary Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if((arg.IsReturnValue==false)&& (arg.RelatedStateVar.AllowedStringValues!=null)) { cs.Append(" Enum_" + arg.RelatedStateVar.Name + " e_" + arg.Name + ";\r\n"); if(arg.Direction=="in") { cs.Append(" switch(" + arg.Name + ")\r\n"); cs.Append(" {\r\n"); vd = (VarData)elist[arg.RelatedStateVar.Name]; foreach(EnumStruct ss in vd.Enumerations) { cs.Append(" case \"" + ss.EnumValue + "\":\r\n"); cs.Append(" e_" + arg.Name + " = Enum_" + arg.RelatedStateVar.Name + "." + ss.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" e_" + arg.Name + " = 0;\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } } } // Make Method Call if(A.HasReturnValue==true) { cs.Append(" object RetObj = null;\r\n"); } cs.Append(" if(Outer.External_" + A.Name + " != null)\r\n"); cs.Append(" {\r\n"); cs.Append(" "); if(A.HasReturnValue==true) { cs.Append("RetObj = "); } cs.Append("Outer.External_" + A.Name + "("); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { if(arg.Direction=="out") { cs.Append("out "); } if(arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append("e_"); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } } cs.Append(");\r\n"); cs.Append(" }\r\n"); cs.Append(" else\r\n"); cs.Append(" {\r\n"); cs.Append(" "); if(A.HasReturnValue==true) { cs.Append("RetObj = "); } cs.Append("Sink_" + A.Name + "("); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { if(arg.Direction=="out") { cs.Append("out "); } if(arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append("e_"); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } } cs.Append(");\r\n"); cs.Append(" }\r\n"); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if((arg.IsReturnValue==false)&& (arg.RelatedStateVar.AllowedStringValues!=null)) { if(arg.Direction=="out") { cs.Append(" switch(e_" + arg.Name + ")\r\n"); cs.Append(" {\r\n"); vd = (VarData)elist[arg.RelatedStateVar.Name]; foreach(EnumStruct ss in vd.Enumerations) { cs.Append(" case Enum_" + arg.RelatedStateVar.Name + "." + ss.EnumName + ":\r\n"); cs.Append(" " + arg.Name + " = \"" + ss.EnumValue + "\";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" " + arg.Name + " = \"\";\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } } } if(A.HasReturnValue==true) { cs.Append(" return((" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + ")RetObj);\r\n"); } cs.Append(" }\r\n"); } cs.Append("\r\n"); foreach(UPnPAction A in s.Actions) { cs.Append(" public Delegate_" + A.Name + " Sink_" + A.Name + ";\r\n"); } cs.Append(" }\r\n"); // End of Private Class // Build Constructor cs.Append(" public " + ClassName + "()\r\n"); cs.Append(" {\r\n"); cs.Append(" _S = new _" + ClassName + "(this);\r\n"); foreach(UPnPStateVariable V in SV) { cs.Append(" _S.GetUPnPService().GetStateVariableObject(\"" + V.Name + "\").OnModified += new UPnPStateVariable.ModifiedHandler(OnModifiedSink_" + V.Name + ");\r\n"); } foreach(UPnPAction A in s.Actions) { cs.Append(" _S.Sink_" + A.Name + " = new Delegate_" + A.Name + "(" + A.Name + ");\r\n"); } cs.Append(" }\r\n"); cs.Append(" public " + ClassName + "(string ID):this()\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.GetUPnPService().ServiceID = ID;\r\n"); cs.Append(" }\r\n"); cs.Append(" public UPnPService GetUPnPService()\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S.GetUPnPService());\r\n"); cs.Append(" }\r\n"); foreach(UPnPStateVariable V in SV) { cs.Append(" private void OnModifiedSink_" + V.Name + "(UPnPStateVariable sender, object NewValue)\r\n"); cs.Append(" {\r\n"); cs.Append(" if(OnStateVariableModified_" + V.Name + " != null) OnStateVariableModified_" + V.Name + "(this);\r\n"); cs.Append(" }\r\n"); } cs.Append(" //}}}}} End of Code Block\r\n\r\n"); cs.Append(" #endregion\r\n"); cs.Append("\r\n"); foreach(UPnPAction A in s.Actions) { cs.Append(" /// <summary>\r\n"); cs.Append(" /// Action: " + A.Name + "\r\n"); cs.Append(" /// </summary>\r\n"); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { cs.Append(" /// <param name=\"" + arg.Name + "\">Associated State Variable: " + arg.RelatedStateVar.Name + "</param>\r\n"); } } if(A.HasReturnValue==true) { cs.Append(" /// <returns>Associated StateVariable: " + A.GetRetArg().RelatedStateVar.Name + "</returns>\r\n"); } cs.Append(" public "); if(A.HasReturnValue==false) { cs.Append("void "); } else { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName + " "); } cs.Append(A.Name+"("); Args = A.ArgumentList; for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.IsReturnValue==false) { if(arg.Direction=="out") { cs.Append("out "); } if(arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append("Enum_" + arg.RelatedStateVar.Name + " "); } else { cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } } cs.Append(")" + cl); cs.Append(" {\r\n"); cs.Append(" //ToDo: Add Your implementation here, and remove exception\r\n"); cs.Append(" throw(new UPnPCustomException(800,\"This method has not been completely implemented...\"));\r\n"); cs.Append(" }\r\n"); } cs.Append(" }\r\n"); cs.Append("}"); UTF8Encoding UTF8 = new UTF8Encoding(); FileStream ws = new FileStream(SavePath, FileMode.Create, FileAccess.Write); byte[] buffer = UTF8.GetBytes(cs.ToString()); ws.Write(buffer,0,buffer.Length); ws.Close(); }
internal ZoneGroupTopology(UPnPService service) : base(service) { }
public CpConnectionManager(UPnPService s) { _S = s; _S.OnSubscribe += new UPnPService.UPnPEventSubscribeHandler(_subscribe_sink); if(HasStateVariable_SourceProtocolInfo) _S.GetStateVariableObject("SourceProtocolInfo").OnModified += new UPnPStateVariable.ModifiedHandler(SourceProtocolInfo_ModifiedSink); if(HasStateVariable_SinkProtocolInfo) _S.GetStateVariableObject("SinkProtocolInfo").OnModified += new UPnPStateVariable.ModifiedHandler(SinkProtocolInfo_ModifiedSink); if(HasStateVariable_CurrentConnectionIDs) _S.GetStateVariableObject("CurrentConnectionIDs").OnModified += new UPnPStateVariable.ModifiedHandler(CurrentConnectionIDs_ModifiedSink); }
/// <summary> /// Generates Control Point Implementation /// </summary> /// <param name="ClassName">Class Name to generate</param> /// <param name="ns">Namespace to use</param> /// <param name="SavePath">Path to save source</param> /// <param name="ServiceURN">Service URN to use</param> /// <param name="SCPD_XML">SCPD XML</param> public static void GenerateCP(String ClassName, String ns, String SavePath, String ServiceURN, String SCPD_XML) { string urn = ServiceURN.Substring(0, ServiceURN.LastIndexOf(":")) + ":"; UPnPService s = new UPnPService(1); DText p = new DText(); ArrayList tlist = new ArrayList(); s.ParseSCPD(SCPD_XML); String cl = "\r\n"; StringBuilder cs = new StringBuilder(); UPnPArgument[] Args; UPnPArgument arg; UPnPStateVariable[] SV = s.GetStateVariables(); Hashtable elist = BuildEnumerations(SV); cs.Append("using System;\r\n"); cs.Append("using System.Collections;\r\n"); cs.Append("using System.Threading;\r\n"); cs.Append("using Intel.Utilities;\r\n"); cs.Append("using Intel.UPNP;" + cl + cl); cs.Append("namespace " + ns + cl); cs.Append("{\r\n"); cs.Append(" /// <summary>" + cl); cs.Append(" /// Transparent ClientSide UPnP Service" + cl); cs.Append(" /// </summary>" + cl); cs.Append(" public class " + ClassName + "\r\n"); cs.Append(" {" + cl); cs.Append(" private Hashtable UnspecifiedTable = Hashtable.Synchronized(new Hashtable());\r\n"); cs.Append(" internal UPnPService _S;\r\n\r\n"); cs.Append(" public UPnPService GetUPnPService()\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S);\r\n"); cs.Append(" }\r\n"); cs.Append(" public static string SERVICE_NAME = \"" + urn + "\";\r\n"); cs.Append(" public double VERSION\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(double.Parse(_S.Version));\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n\r\n"); foreach(UPnPStateVariable v in SV) { if(v.SendEvent==true) { cs.Append(" public delegate void StateVariableModifiedHandler_" + v.Name + "(" + ClassName + " sender, "); if(elist.ContainsKey(v.Name)==true) { cs.Append("Enum_" + v.Name + " NewValue"); } else { cs.Append(v.GetNetType().FullName + " NewValue"); } cs.Append(");\r\n"); cs.Append(" private WeakEvent OnStateVariable_"+v.Name+"_Event = new WeakEvent();"+cl); cs.Append(" public event StateVariableModifiedHandler_" + v.Name + " OnStateVariable_" + v.Name + "\r\n"); cs.Append(" {"+cl); cs.Append(" add{OnStateVariable_"+v.Name+"_Event.Register(value);}"+cl); cs.Append(" remove{OnStateVariable_"+v.Name+"_Event.UnRegister(value);}"+cl); cs.Append(" }"+cl); cs.Append(" protected void " + v.Name + "_ModifiedSink(UPnPStateVariable Var, object NewValue)\r\n"); cs.Append(" {\r\n"); cs.Append(" OnStateVariable_" + v.Name + "_Event.Fire(this, "+v.Name+");"+cl); cs.Append(" }\r\n"); } } cs.Append(" public delegate void SubscribeHandler(" + ClassName + " sender, bool Success);\r\n"); cs.Append(" public event SubscribeHandler OnSubscribe;\r\n"); // Build Events/Delegates foreach(UPnPAction A in s.Actions) { cs.Append(" public delegate void Delegate_OnResult_" + A.Name + "(" + ClassName + " sender, "); foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name + " "); } cs.Append(_arg.Name + ", "); } } if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name + " "); } cs.Append("ReturnValue, "); } cs.Append("UPnPInvokeException e, object _Tag);\r\n"); cs.Append(" private WeakEvent OnResult_"+A.Name+"_Event = new WeakEvent();"+cl); cs.Append(" public event Delegate_OnResult_" + A.Name + " OnResult_" + A.Name + "\r\n"); cs.Append(" {"+cl); cs.Append(" add{OnResult_"+A.Name+"_Event.Register(value);}"+cl); cs.Append(" remove{OnResult_"+A.Name+"_Event.UnRegister(value);}"+cl); cs.Append(" }"+cl); } // Build Constructor cs.Append("\r\n"); cs.Append(" public " + ClassName + "(UPnPService s)\r\n"); cs.Append(" {\r\n"); cs.Append(" _S = s;\r\n"); cs.Append(" _S.OnSubscribe += new UPnPService.UPnPEventSubscribeHandler(_subscribe_sink);\r\n"); foreach(UPnPStateVariable v in SV) { if(v.SendEvent==true) { cs.Append(" if(HasStateVariable_" + v.Name + ") _S.GetStateVariableObject(\"" + v.Name + "\").OnModified += new UPnPStateVariable.ModifiedHandler(" + v.Name + "_ModifiedSink);\r\n"); } } cs.Append(" }\r\n"); // Build Dispose cs.Append(" public void Dispose()\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.OnSubscribe -= new UPnPService.UPnPEventSubscribeHandler(_subscribe_sink);\r\n"); cs.Append(" OnSubscribe = null;\r\n"); foreach(UPnPStateVariable v in SV) { if(v.SendEvent==true) { cs.Append(" if(HasStateVariable_" + v.Name + ") _S.GetStateVariableObject(\"" + v.Name + "\").OnModified -= new UPnPStateVariable.ModifiedHandler(" + v.Name + "_ModifiedSink);\r\n"); } } cs.Append(" }\r\n"); cs.Append(" public void _subscribe(int Timeout)\r\n"); cs.Append(" {\r\n"); cs.Append(" _S.Subscribe(Timeout, null);\r\n"); cs.Append(" }\r\n"); cs.Append(" protected void _subscribe_sink(UPnPService sender, bool OK)\r\n"); cs.Append(" {\r\n"); cs.Append(" if(OnSubscribe!=null)\r\n"); cs.Append(" {\r\n"); cs.Append(" OnSubscribe(this, OK);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); // Build Enumerations cs.Append(" public void SetUnspecifiedValue(string EnumType, string val)\r\n"); cs.Append(" {\r\n"); cs.Append(" string hash = Thread.CurrentThread.GetHashCode().ToString() + \":\" + EnumType;\r\n"); cs.Append(" UnspecifiedTable[hash] = val;\r\n"); cs.Append(" }\r\n"); cs.Append(" public string GetUnspecifiedValue(string EnumType)\r\n"); cs.Append(" {\r\n"); cs.Append(" string hash = Thread.CurrentThread.GetHashCode().ToString() + \":\" + EnumType;\r\n"); cs.Append(" if(UnspecifiedTable.ContainsKey(hash)==false)\r\n"); cs.Append(" {\r\n"); cs.Append(" return(\"\");\r\n"); cs.Append(" }\r\n"); cs.Append(" string RetVal = (string)UnspecifiedTable[hash];\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); IDictionaryEnumerator el = elist.GetEnumerator(); VarData vd; while(el.MoveNext()) { vd = (VarData)el.Value; cs.Append(" public string[] Values_" + vd.VariableName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" UPnPStateVariable sv = _S.GetStateVariableObject(\"" + vd.VariableName + "\");\r\n"); cs.Append(" return(sv.AllowedStringValues);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" public string Enum_" + vd.VariableName + "_ToString(Enum_" + vd.VariableName + " en)\r\n"); cs.Append(" {\r\n"); cs.Append(" string RetVal = \"\";\r\n"); cs.Append(" switch(en)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" case Enum_" + vd.VariableName + "." + vs.EnumName + ":\r\n"); cs.Append(" RetVal = \"" + vs.EnumValue + "\";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" case Enum_" + vd.VariableName + "._UNSPECIFIED_:\r\n"); cs.Append(" RetVal = GetUnspecifiedValue(\"Enum_" + vd.VariableName + "\");\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); cs.Append(" public enum Enum_" + vd.VariableName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" _UNSPECIFIED_,\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" " + vs.EnumName + ",\r\n"); } cs.Append(" }\r\n"); cs.Append(" public Enum_" + vd.VariableName + " " + vd.VariableName + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" Enum_" + vd.VariableName + " RetVal = 0;\r\n"); cs.Append(" string v = (string)_S.GetStateVariable(\"" + vd.VariableName + "\");\r\n"); cs.Append(" switch(v)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct vs in vd.Enumerations) { cs.Append(" case \"" + vs.EnumValue + "\":\r\n"); cs.Append(" RetVal = Enum_" + vd.VariableName + "." + vs.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" RetVal = Enum_" + vd.VariableName + "._UNSPECIFIED_;\r\n"); cs.Append(" SetUnspecifiedValue(\"Enum_" + vd.VariableName + "\", v);\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); cs.Append(" return(RetVal);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } foreach(UPnPStateVariable V in SV) { if(elist.ContainsKey(V.Name)==false) { // Build Accessors cs.Append(" public " + V.GetNetType().FullName + " " + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return((" + V.GetNetType().FullName + ")_S.GetStateVariable(\"" + V.Name + "\"));\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } } foreach(UPnPStateVariable V in SV) { // Range Stuff if((V.Maximum!=null)||(V.Minimum!=null)) { cs.Append(" public bool HasMaximum_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S.GetStateVariableObject(\"" + V.Name + "\").Maximum!=null);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" public bool HasMinimum_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return(_S.GetStateVariableObject(\"" + V.Name + "\").Minimum!=null);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" public " + V.GetNetType().FullName + " Maximum_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return((" + V.GetNetType().FullName +")_S.GetStateVariableObject(\"" + V.Name + "\").Maximum);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" public " + V.GetNetType().FullName + " Minimum_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" return((" + V.GetNetType().FullName +")_S.GetStateVariableObject(\"" + V.Name + "\").Minimum);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } // Has Stuff cs.Append(" public bool HasStateVariable_" + V.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" if(_S.GetStateVariableObject(\"" + V.Name + "\")==null)\r\n"); cs.Append(" {\r\n"); cs.Append(" return(false);\r\n"); cs.Append(" }\r\n"); cs.Append(" else\r\n"); cs.Append(" {\r\n"); cs.Append(" return(true);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } foreach(UPnPAction A in s.Actions) { cs.Append(" public bool HasAction_" + A.Name + "\r\n"); cs.Append(" {\r\n"); cs.Append(" get\r\n"); cs.Append(" {\r\n"); cs.Append(" if(_S.GetAction(\"" + A.Name + "\")==null)\r\n"); cs.Append(" {\r\n"); cs.Append(" return(false);\r\n"); cs.Append(" }\r\n"); cs.Append(" else\r\n"); cs.Append(" {\r\n"); cs.Append(" return(true);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); } foreach(UPnPAction A in s.Actions) { // Build Sync Version cs.Append(" public "); if(A.HasReturnValue==false) { cs.Append("void "); } else { if(elist.ContainsKey(A.GetRetArg().RelatedStateVar.Name)==true) { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name + " "); } else { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName + " "); } } cs.Append("Sync_" + A.Name + "("); tlist.Clear(); foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { tlist.Add(_arg); } } Args = (UPnPArgument[])tlist.ToArray(typeof(UPnPArgument)); for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(arg.Direction=="out") { cs.Append("out "); } if(elist.ContainsKey(arg.RelatedStateVar.Name)) { cs.Append("Enum_" + arg.RelatedStateVar.Name + " "); } else { cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } cs.Append(")\r\n"); cs.Append(" {\r\n"); cs.Append(" UPnPArgument[] args = new UPnPArgument["); if(A.HasReturnValue==false) { cs.Append(A.ArgumentList.Length.ToString()); } else { cs.Append((A.ArgumentList.Length-1).ToString()); } cs.Append("];\r\n"); int ia=0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.Direction=="in") { if(elist.ContainsKey(_arg.RelatedStateVar.Name)==true) { cs.Append(" switch(" + _arg.Name + ")\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[_arg.RelatedStateVar.Name]).Enumerations) { cs.Append(" case Enum_" + _arg.RelatedStateVar.Name + "." + ess.EnumName + ":\r\n"); cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", \"" + ess.EnumValue + "\");\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", GetUnspecifiedValue(\"Enum_" + _arg.RelatedStateVar.Name + "\"));\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } else { cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", " + _arg.Name + ");\r\n"); } } else { cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", \"\");\r\n"); } ++ia; } } if(A.HasReturnValue==true) { cs.Append(" object RetVal = null;\r\n"); cs.Append(" RetVal = "); } else { cs.Append(" "); } cs.Append("_S.InvokeSync(\"" + A.Name + "\", args);\r\n"); if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues!=null) { cs.Append(" Enum_" + A.GetRetArg().RelatedStateVar.Name + " RetEnum = 0;\r\n"); cs.Append(" switch((string)RetVal)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[A.GetRetArg().RelatedStateVar.Name]).Enumerations) { cs.Append(" case \"" + ess.EnumValue + "\":\r\n"); cs.Append(" RetEnum = Enum_" + A.GetRetArg().RelatedStateVar.Name + "." + ess.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" RetEnum = Enum_" + A.GetRetArg().RelatedStateVar.Name + "._UNSPECIFIED_;\r\n"); cs.Append(" SetUnspecifiedValue(\"Enum_" + A.GetRetArg().RelatedStateVar.Name + "\",(string)RetVal);\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } } // Check if this is necessary bool IsNeccessary = false; foreach(UPnPArgument _arg in A.ArgumentList) { if((_arg.RelatedStateVar.AllowedStringValues!=null)&& (_arg.IsReturnValue==false)) { IsNeccessary = true; break; } } if(IsNeccessary==true) { cs.Append(" for(int i=0;i<args.Length;++i)\r\n"); cs.Append(" {\r\n"); cs.Append(" switch(args[i].Name)\r\n"); cs.Append(" {\r\n"); tlist.Clear(); foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { tlist.Add(_arg); } } Args = (UPnPArgument[])tlist.ToArray(typeof(UPnPArgument)); foreach(UPnPArgument _arg in Args) { if(_arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append(" case \"" + _arg.Name + "\":\r\n"); cs.Append(" switch((string)args[i].DataValue)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[_arg.RelatedStateVar.Name]).Enumerations) { cs.Append(" case \"" + ess.EnumValue + "\":\r\n"); cs.Append(" args[i].DataValue = Enum_" + _arg.RelatedStateVar.Name + "." + ess.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" SetUnspecifiedValue(\"Enum_" + _arg.RelatedStateVar.Name + "\", (string)args[i].DataValue);\r\n"); cs.Append(" args[i].DataValue = Enum_" + _arg.RelatedStateVar.Name + "._UNSPECIFIED_;\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); cs.Append(" break;\r\n"); } } cs.Append(" }\r\n"); // End of Switch cs.Append(" }\r\n"); // End of For Loop } int argid = 0; foreach(UPnPArgument _arg in A.Arguments) { if(_arg.IsReturnValue==false) { cs.Append(" " + _arg.Name + " = ("); if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name); } cs.Append(") args[" + argid.ToString() + "].DataValue;\r\n"); } ++argid; } if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append(" return((" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + ")RetVal);\r\n"); } else { cs.Append(" return(RetEnum);\r\n"); } } else { cs.Append(" return;\r\n"); } cs.Append(" }\r\n"); // End of SyncAction Class // Build Async Version [Overload] cs.Append(" public "); cs.Append("void "); cs.Append(A.Name + "("); tlist.Clear(); foreach(UPnPArgument _arg in A.ArgumentList) { if((_arg.IsReturnValue==false)&& (_arg.Direction=="in")) { tlist.Add(_arg); } } Args = (UPnPArgument[])tlist.ToArray(typeof(UPnPArgument)); for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(elist.ContainsKey(arg.RelatedStateVar.Name)) { cs.Append("Enum_" + arg.RelatedStateVar.Name + " "); } else { cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); } cs.Append(arg.Name); if(i<Args.Length-1) { cs.Append(", "); } } cs.Append(")\r\n"); cs.Append(" {\r\n"); cs.Append(" " + A.Name + "("); for(int i=0;i<Args.Length;++i) { arg = Args[i]; cs.Append(arg.Name); cs.Append(", "); } cs.Append("null, null);\r\n"); cs.Append(" }\r\n"); // Build Async Version cs.Append(" public "); cs.Append("void "); cs.Append(A.Name + "("); tlist.Clear(); foreach(UPnPArgument _arg in A.ArgumentList) { if((_arg.IsReturnValue==false)&& (_arg.Direction=="in")) { tlist.Add(_arg); } } Args = (UPnPArgument[])tlist.ToArray(typeof(UPnPArgument)); for(int i=0;i<Args.Length;++i) { arg = Args[i]; if(elist.ContainsKey(arg.RelatedStateVar.Name)) { cs.Append("Enum_" + arg.RelatedStateVar.Name + " "); } else { cs.Append(arg.RelatedStateVar.GetNetType().FullName + " "); } cs.Append(arg.Name); cs.Append(", "); } cs.Append("object _Tag, Delegate_OnResult_" + A.Name + " _Callback"); cs.Append(")\r\n"); cs.Append(" {\r\n"); cs.Append(" UPnPArgument[] args = new UPnPArgument["); if(A.HasReturnValue==false) { cs.Append(A.ArgumentList.Length.ToString()); } else { cs.Append((A.ArgumentList.Length-1).ToString()); } cs.Append("];\r\n"); ia=0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.Direction=="in") { if(elist.ContainsKey(_arg.RelatedStateVar.Name)==true) { cs.Append(" switch(" + _arg.Name + ")\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[_arg.RelatedStateVar.Name]).Enumerations) { cs.Append(" case Enum_" + _arg.RelatedStateVar.Name + "." + ess.EnumName + ":\r\n"); cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", \"" + ess.EnumValue + "\");\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", GetUnspecifiedValue(\"Enum_" + _arg.RelatedStateVar.Name + "\"));\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } else { cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", " + _arg.Name + ");\r\n"); } } else { cs.Append(" args[" + ia.ToString() + "] = new UPnPArgument(\"" + _arg.Name + "\", \"\");\r\n"); } ++ia; } } cs.Append(" _S.InvokeAsync(\"" + A.Name + "\", args, new object[2]{_Tag,_Callback},new UPnPService.UPnPServiceInvokeHandler(Sink_" + A.Name + "), new UPnPService.UPnPServiceInvokeErrorHandler(Error_Sink_" + A.Name + "));\r\n"); cs.Append(" }\r\n"); // End of Action Class // Build Async Sink cs.Append(" private void Sink_" + A.Name + "(UPnPService sender, string MethodName, UPnPArgument[] Args, object RetVal, object _Tag)\r\n"); cs.Append(" {\r\n"); if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues!=null) { cs.Append(" Enum_" + A.GetRetArg().RelatedStateVar.Name + " RetEnum = 0;\r\n"); cs.Append(" switch((string)RetVal)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[A.GetRetArg().RelatedStateVar.Name]).Enumerations) { cs.Append(" case \"" + ess.EnumValue + "\":\r\n"); cs.Append(" RetEnum = Enum_" + A.GetRetArg().RelatedStateVar.Name + "." + ess.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" RetEnum = Enum_" + A.GetRetArg().RelatedStateVar.Name + "._UNSPECIFIED_;\r\n"); cs.Append(" SetUnspecifiedValue(\"Enum_" + A.GetRetArg().RelatedStateVar.Name + "\",(string)RetVal);\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); } } // Check if this is necessary IsNeccessary = false; foreach(UPnPArgument _arg in A.ArgumentList) { if((_arg.RelatedStateVar.AllowedStringValues!=null)&& (_arg.IsReturnValue==false)) { IsNeccessary = true; break; } } if(IsNeccessary==true) { cs.Append(" for(int i=0;i<Args.Length;++i)\r\n"); cs.Append(" {\r\n"); cs.Append(" switch(Args[i].Name)\r\n"); cs.Append(" {\r\n"); tlist.Clear(); foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { tlist.Add(_arg); } } Args = (UPnPArgument[])tlist.ToArray(typeof(UPnPArgument)); foreach(UPnPArgument _arg in Args) { if(_arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append(" case \"" + _arg.Name + "\":\r\n"); cs.Append(" switch((string)Args[i].DataValue)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[_arg.RelatedStateVar.Name]).Enumerations) { cs.Append(" case \"" + ess.EnumValue + "\":\r\n"); cs.Append(" Args[i].DataValue = Enum_" + _arg.RelatedStateVar.Name + "." + ess.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" default:\r\n"); cs.Append(" SetUnspecifiedValue(\"Enum_" + _arg.RelatedStateVar.Name + "\", (string)Args[i].DataValue);\r\n"); cs.Append(" Args[i].DataValue = Enum_" + _arg.RelatedStateVar.Name + "._UNSPECIFIED_;\r\n"); cs.Append(" break;\r\n"); cs.Append(" }\r\n"); cs.Append(" break;\r\n"); } } cs.Append(" }\r\n"); // End of Switch cs.Append(" }\r\n"); // End of For Loop } cs.Append(" object[] StateInfo = (object[])_Tag;\r\n"); cs.Append(" if(StateInfo[1]!=null)\r\n"); cs.Append(" {\r\n"); cs.Append(" ((Delegate_OnResult_" + A.Name + ")StateInfo[1])(this, "); argid = 0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { cs.Append("("); if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name + " "); } cs.Append(")"); cs.Append("Args[" + argid.ToString() + "].DataValue, "); ++argid; } } if(A.HasReturnValue==true) { cs.Append("("); if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName); cs.Append(")"); cs.Append("RetVal, "); } else { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name); cs.Append(")"); cs.Append("RetEnum, "); } } cs.Append("null, StateInfo[0]);\r\n"); cs.Append(" }\r\n"); cs.Append(" else\r\n"); cs.Append(" {\r\n"); cs.Append(" OnResult_" + A.Name + "_Event.Fire(this, "); argid = 0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { cs.Append("("); if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name + " "); } cs.Append(")"); cs.Append("Args[" + argid.ToString() + "].DataValue, "); ++argid; } } if(A.HasReturnValue==true) { cs.Append("("); if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append(A.GetRetArg().RelatedStateVar.GetNetType().FullName); cs.Append(")"); cs.Append("RetVal, "); } else { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name); cs.Append(")"); cs.Append("RetEnum, "); } } cs.Append("null, StateInfo[0]);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); //Build Error Sink cs.Append(" private void Error_Sink_" + A.Name + "(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, object _Tag)\r\n"); cs.Append(" {\r\n"); // Check if this is necessary IsNeccessary = false; foreach(UPnPArgument _arg in A.ArgumentList) { if((_arg.RelatedStateVar.AllowedStringValues!=null)&& (_arg.Direction=="in")) { IsNeccessary = true; break; } } if(IsNeccessary==true) { cs.Append(" for(int i=0;i<Args.Length;++i)\r\n"); cs.Append(" {\r\n"); cs.Append(" switch(Args[i].Name)\r\n"); cs.Append(" {\r\n"); foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append(" case \"" + _arg.Name + "\":\r\n"); cs.Append(" switch((string)Args[i].DataValue)\r\n"); cs.Append(" {\r\n"); foreach(EnumStruct ess in ((VarData)elist[_arg.RelatedStateVar.Name]).Enumerations) { cs.Append(" case \"" + ess.EnumValue + "\":\r\n"); cs.Append(" Args[i].DataValue = Enum_" + _arg.RelatedStateVar.Name + "." + ess.EnumName + ";\r\n"); cs.Append(" break;\r\n"); } cs.Append(" }\r\n"); cs.Append(" break;\r\n"); } } } cs.Append(" }\r\n"); // End of Switch cs.Append(" }\r\n"); // End of For Loop } if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues!=null) { cs.Append(" SetUnspecifiedValue(\"Enum_" + A.GetRetArg().RelatedStateVar.Name + "\",\"* error *\");\r\n"); } } cs.Append(" object[] StateInfo = (object[])_Tag;\r\n"); cs.Append(" if(StateInfo[1]!=null)\r\n"); cs.Append(" {\r\n"); cs.Append(" ((Delegate_OnResult_" + A.Name + ")StateInfo[1])(this, "); argid = 0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.Direction=="in") { cs.Append("("); if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name + " "); } cs.Append(")"); cs.Append("Args[" + argid.ToString() + "].DataValue, "); } else { if(_arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append("(Enum_" + _arg.RelatedStateVar.Name + ")0, "); } else { cs.Append("(" + _arg.RelatedStateVar.GetNetType().FullName + ")UPnPService.CreateObjectInstance(typeof(" + _arg.RelatedStateVar.GetNetType().FullName + "),null), "); } } ++argid; } } if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append("(" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + ")UPnPService.CreateObjectInstance(typeof(" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + "),null), "); } else { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name + "._UNSPECIFIED_, "); } } cs.Append("e, StateInfo[0]);\r\n"); cs.Append(" }\r\n"); cs.Append(" else\r\n"); cs.Append(" {\r\n"); cs.Append(" OnResult_" + A.Name + "_Event.Fire(this, "); argid = 0; foreach(UPnPArgument _arg in A.ArgumentList) { if(_arg.IsReturnValue==false) { if(_arg.Direction=="in") { cs.Append("("); if(_arg.RelatedStateVar.AllowedStringValues==null) { cs.Append(_arg.RelatedStateVar.GetNetType().FullName + " "); } else { cs.Append("Enum_" + _arg.RelatedStateVar.Name + " "); } cs.Append(")"); cs.Append("Args[" + argid.ToString() + "].DataValue, "); } else { if(_arg.RelatedStateVar.AllowedStringValues!=null) { cs.Append("(Enum_" + _arg.RelatedStateVar.Name + ")0, "); } else { cs.Append("(" + _arg.RelatedStateVar.GetNetType().FullName + ")UPnPService.CreateObjectInstance(typeof(" + _arg.RelatedStateVar.GetNetType().FullName + "),null), "); } } ++argid; } } if(A.HasReturnValue==true) { if(A.GetRetArg().RelatedStateVar.AllowedStringValues==null) { cs.Append("(" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + ")UPnPService.CreateObjectInstance(typeof(" + A.GetRetArg().RelatedStateVar.GetNetType().FullName + "),null), "); } else { cs.Append("Enum_" + A.GetRetArg().RelatedStateVar.Name + "._UNSPECIFIED_, "); } } cs.Append("e, StateInfo[0]);\r\n"); cs.Append(" }\r\n"); cs.Append(" }\r\n"); // End of Error Sink } cs.Append(" }\r\n"); cs.Append("}"); UTF8Encoding UTF8 = new UTF8Encoding(); FileStream ws = new FileStream(SavePath, FileMode.Create, FileAccess.Write); byte[] buffer = UTF8.GetBytes(cs.ToString()); ws.Write(buffer,0,buffer.Length); ws.Close(); }
public void _subscribe(int Timeout, UPnPService.UPnPEventHandler UPnPEventCallback) { _S.Subscribe(Timeout, UPnPEventCallback); }
private void Error_Sink_Seek(UPnPService sender, string MethodName, UPnPArgument[] Args, UPnPInvokeException e, int Handle) { for(int i=0;i<Args.Length;++i) { switch(Args[i].Name) { case "Unit": switch((string)Args[i].DataValue) { case "ABS_TIME": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.ABS_TIME; break; case "REL_TIME": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.REL_TIME; break; case "ABS_COUNT": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.ABS_COUNT; break; case "REL_COUNT": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.REL_COUNT; break; case "TRACK_NR": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.TRACK_NR; break; case "CHANNEL_FREQ": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.CHANNEL_FREQ; break; case "TAPE-INDEX": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.TAPE_INDEX; break; case "FRAME": Args[i].DataValue = Enum_A_ARG_TYPE_SeekMode.FRAME; break; } break; } } if(OnResult_Seek != null) { OnResult_Seek((System.UInt32 )Args[0].DataValue, (Enum_A_ARG_TYPE_SeekMode )Args[1].DataValue, (System.String )Args[2].DataValue, e, Handle); } WeakReference[] w = (WeakReference[])WeakList_Seek.ToArray(typeof(WeakReference)); foreach(WeakReference wr in w) { if(wr.IsAlive==true) { ((Delegate_OnResult_Seek)wr.Target)((System.UInt32 )Args[0].DataValue, (Enum_A_ARG_TYPE_SeekMode )Args[1].DataValue, (System.String )Args[2].DataValue, e, Handle); } else { WeakList_Seek.Remove(wr); } } }
protected void _subscribe_sink(UPnPService sender, bool OK) { if(OnSubscribe!=null) { OnSubscribe(OK); } }