/// <summary> /// 投屏 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void proj_Click(object sender, RoutedEventArgs e) { string uri = this.resourceUri.Text; if (string.IsNullOrEmpty(uri) || ResourceIsDefault()) { MessageBox.Show("请填入正确的资源URI"); return; } var device = this.deviceList.SelectedItem as UPnPDevice; if (device == null) { MessageBox.Show("请选择要投的设备"); return; } try { UPnPService service = device.GetService("AVTransport"); if (service == null) { MessageBox.Show("设备无投屏功能"); return; } this.instanceID++; UPnPAction transportAction = service.GetAction("SetAVTransportURI"); UPnPArgument instanceID = transportAction.GetArg("InstanceID"); instanceID.DataValue = this.instanceID; UPnPArgument currentURI = transportAction.GetArg("CurrentURI"); currentURI.DataValue = uri; UPnPArgument current = transportAction.GetArg("CurrentURIMetaData"); current.DataValue = string.Empty; service.InvokeAsync(transportAction.Name, new[] { instanceID, currentURI, current }); UPnPAction playAction = service.GetAction("Play"); UPnPArgument speed = playAction.GetArg("Speed"); service.InvokeAsync(playAction.Name, new[] { instanceID, speed }); } catch (Exception ex) { MessageBox.Show("投屏失败," + ex.Message); } }
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 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); }
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 Invoke(UPnPService S, string Action, byte[] InArgs, out byte[] OutArgs) { 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); object RetVal = null; try { RetVal = S.InvokeSync(Action, Arguments); } catch (UPnPInvokeException ie) { if (ie.UPNP != null) { throw(ie.UPNP); } else { throw(ie); } } ArrayList RetList = new ArrayList(); if (A.HasReturnValue == true) { UPnPArgument RA = (UPnPArgument)A.GetRetArg().Clone(); RA.DataValue = RetVal; RetList.Add(RA); } foreach (UPnPArgument OA in Arguments) { if (OA.Direction == "out") { RetList.Add(OA); } } OutArgs = BuildArguments((UPnPArgument[])RetList.ToArray(typeof(UPnPArgument))); }