/// <summary> /// Creates a device from a URL. [Depracated] use UPnPDeviceFactory /// </summary> /// <param name="DescriptionURL"></param> /// <param name="LifeTime"></param> public void CreateDeviceAsync(Uri DescriptionURL, int LifeTime) { //ToDo: Replace the failed callback UPnPDeviceFactory fac = new UPnPDeviceFactory(DescriptionURL, LifeTime, new UPnPDeviceFactory.UPnPDeviceHandler(HandleDeviceCreation), null, null, null); CreateTable[fac] = fac; Lifetime.Add(fac, 30); }
private void HandleDeviceCreation(UPnPDeviceFactory Factory, UPnPDevice device, Uri URL) { Factory.Shutdown(); if (OnCreateDevice != null) { OnCreateDevice(device, URL); } }
private void HandleFactory(UPnPDeviceFactory Factory, UPnPDevice device, Uri URL) { lock (CreateTable) { CreateTable.Remove(Factory); } Factory.Shutdown(); if (OnDevice != null) { OnDevice(this, device, URL); } }
private void DeviceFactoryFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { lock (deviceTableLock) { if (deviceTable.ContainsKey(urn)) { deviceTable.Remove(urn); } } }
/// <summary> /// Create a UPnPDevice from a Uri /// </summary> /// <param name="DescLocation">XML Description Uri</param> /// <param name="MaxSeconds">Device refresh Cycle</param> public void CreateDevice(Uri DescLocation, int MaxSeconds, IPAddress localaddr, string usn) { OpenSource.Utilities.EventLogger.Log(this, EventLogEntryType.Information, "Creating Device: " + usn); lock (CreateTable) { // TODO: Fix the failed callback UPnPDeviceFactory x = new UPnPDeviceFactory(DescLocation, MaxSeconds, new UPnPDeviceFactory.UPnPDeviceHandler(HandleFactory), new UPnPDeviceFactory.UPnPDeviceFailedHandler(FactoryFailedSink), localaddr, usn); CreateTable[x] = x; } }
private void FactoryFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { lock (CreateTable) { CreateTable.Remove(sender); sender.Shutdown(); } if (OnFailed != null) { OnFailed(this, URL, e, urn); } }
/// <summary> /// Triggered when a new UPnP device is created. /// </summary> private void DeviceFactoryCreationSink(UPnPDeviceFactory sender, UPnPDevice device, Uri locationURL) { // Hardening if (deviceTable.Contains(device.UniqueDeviceName) == false && deviceTable.Contains("FORCEDDEVICE") == false) { OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "UPnPDevice[" + device.FriendlyName + "]@" + device.LocationURL + " advertised UDN[" + device.UniqueDeviceName + "] in xml but not in SSDP"); return; } lock (deviceTableLock) { DeviceInfo deviceInfo; if (deviceTable.Contains(device.UniqueDeviceName) == false) { // This must be the forced device deviceInfo = (DeviceInfo)deviceTable["FORCEDDEVICE"]; deviceTable.Remove("FORCEDDEVICE"); deviceTable[device.UniqueDeviceName] = deviceInfo; } // Hardening - Creating a device we have should never happen. if (((DeviceInfo)deviceTable[device.UniqueDeviceName]).Device != null) { OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Error, "Unexpected UPnP Device Creation: " + device.FriendlyName + "@" + device.LocationURL); return; } // Lets update out state and notify the user. deviceInfo = (DeviceInfo)deviceTable[device.UniqueDeviceName]; deviceInfo.Device = device; deviceTable[device.UniqueDeviceName] = deviceInfo; deviceLifeTimeClock.Add(device.UniqueDeviceName, device.ExpirationTimeout); activeDeviceList.Add(device); } OnAddedDeviceEvent.Fire(this, device); }
private void ProxySink(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri) { FactoryTable.Remove(sender); sender.Shutdown(); CpGateKeeper CP = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]); string useThisIP = d.InterfaceToHost.ToString(); if(this.PublicIP!="") {useThisIP = PublicIP;} lock(RegisteredTable) { RegisteredTable[CP.GetUPnPService().ParentDevice.UniqueDeviceName] = CP; object[] PL = (object[])ProcessLaterList.ToArray(typeof(object)); foreach(object PL2 in PL) { object[] PL3 = (object[])PL2; string SenderUDN = (string)PL3[0]; string DeviceUDN = (string)PL3[1]; if(RegisteredTable.ContainsKey(SenderUDN)) { CpGateKeeper HOME = (CpGateKeeper)RegisteredTable[SenderUDN]; HOME.GetDocument(DeviceUDN,"",null,new CpGateKeeper.Delegate_OnResult_GetDocument(CPGetDocumentSink)); ProcessLaterList.Remove(PL2); } } } foreach(UPnPDevice t in ShareList) { CP.AddDevice(Root.UniqueDeviceName,t.UniqueDeviceName); } CP.Register(new Uri("http://" + useThisIP + ":" + Port.ToString()),false); }
private void manuallyAddDeviceMenuItem_Click(object sender, System.EventArgs e) { ForceLoad fl = new ForceLoad(); if (fl.ShowDialog() == DialogResult.OK) { UPnPDeviceFactory df = new UPnPDeviceFactory(fl.NetworkUri, 1800, new UPnPDeviceFactory.UPnPDeviceHandler(ForceDeviceOKSink), new UPnPDeviceFactory.UPnPDeviceFailedHandler(ForceDeviceFailSink), null, null); ForceDeviceList[df] = df; } fl.Dispose(); }
private void ForceDeviceFailSink(UPnPDeviceFactory sender, Uri LocationUri, Exception e, string urn) { ForceDeviceList.Remove(sender); MessageBox.Show("Could not load device!"); }
public void ShutDown() { this.deviceFactory.OnDevice -= this.DeviceFactoryCreationSink; this.deviceLifeTimeClock.OnExpired -= this.DeviceLifeTimeClockSink; this.deviceUpdateClock.OnExpired -= this.DeviceUpdateClockSink; this.hostNetworkInfo.OnInterfaceDisabled -= this.NetworkInfoOldInterfaceSink; this.genericControlPoint.OnSearch -= this.UPnPControlPointSearchSink; this.genericControlPoint.OnNotify -= this.SSDPNotifySink; this.deviceFactory.Shutdown(); this.deviceFactory = null; this.hostNetworkInfo = null; this.genericControlPoint = null; }
private void FactoryFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { lock (CreateTable) { CreateTable.Remove(sender); sender.Shutdown(); } if (OnFailed != null) OnFailed(this, URL, e, urn); }
private void UpdateDeviceSink(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri) { lock (UpdateTable) { UpdateTable.Remove(sender); } this.BaseURL = d.BaseURL; this.InterfaceToHost = d.InterfaceToHost; foreach (UPnPDevice ed in this.EmbeddedDevices) { SetInterfaceToHost(ed); } UpdateDeviceSink2(d); }
public void UpdateDevice(Uri LocationUri, IPAddress HostInterface) { lock (UpdateTable) { UPnPDeviceFactory df = new UPnPDeviceFactory(LocationUri, 250, new UPnPDeviceFactory.UPnPDeviceHandler(UpdateDeviceSink), null, null, null); UpdateTable[df] = df; } }
private void DeviceFactoryFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { lock (deviceTableLock) { if (deviceTable.ContainsKey(urn)) deviceTable.Remove(urn); } }
private void ForceDeviceOKSink(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri) { ForceDeviceList.Remove(sender); this.HandleCreate(d, LocationUri); }
private void ProxySink_NoReverse(UPnPDeviceFactory sender, UPnPDevice d, Uri LocationUri) { FactoryTable.Remove(sender); sender.Shutdown(); CpGateKeeper CP = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]); lock(RegisteredTable) { RegisteredTable[CP.GetUPnPService().ParentDevice.UniqueDeviceName] = CP; object[] PL = (object[])ProcessLaterList.ToArray(typeof(object)); foreach(object PL2 in PL) { object[] PL3 = (object[])PL2; string SenderUDN = (string)PL3[0]; string DeviceUDN = (string)PL3[1]; if(RegisteredTable.ContainsKey(SenderUDN)) { CpGateKeeper HOME = (CpGateKeeper)RegisteredTable[SenderUDN]; HOME.GetDocument(DeviceUDN,"",null,new CpGateKeeper.Delegate_OnResult_GetDocument(CPGetDocumentSink)); ProcessLaterList.Remove(PL2); } } } foreach(UPnPDevice t in ShareList) { CP.AddDevice(Root.UniqueDeviceName,t.UniqueDeviceName); } }
/// <summary> /// Create a UPnPDevice from a Uri /// </summary> /// <param name="DescLocation">XML Description Uri</param> /// <param name="MaxSeconds">Device refresh Cycle</param> public void CreateDevice(Uri DescLocation, int MaxSeconds, IPAddress localaddr, string usn) { OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Information, "Creating Device: " + usn); lock (CreateTable) { // TODO: Fix the failed callback UPnPDeviceFactory x = new UPnPDeviceFactory(DescLocation, MaxSeconds, new UPnPDeviceFactory.UPnPDeviceHandler(HandleFactory), new UPnPDeviceFactory.UPnPDeviceFailedHandler(FactoryFailedSink), localaddr, usn); CreateTable[x] = x; } }
private void RegisterSink(System.Uri Proxy, bool Reverse) { UPnPDeviceFactory df; if(Reverse) { df = new UPnPDeviceFactory(Proxy,1000,new UPnPDeviceFactory.UPnPDeviceHandler(ProxySink), null, null, null); } else { df = new UPnPDeviceFactory(Proxy, 1000, new UPnPDeviceFactory.UPnPDeviceHandler(ProxySink_NoReverse), null, null, null); } FactoryTable[df] = df; }
private void HandleFactory(UPnPDeviceFactory Factory, UPnPDevice device, Uri URL) { lock (CreateTable) { CreateTable.Remove(Factory); } Factory.Shutdown(); if (OnDevice != null) OnDevice(this, device, URL); }
private void ConnectFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { devicefactory = null; statusBar.Text = "Connection Failed"; }
private void connectMenuItem_Click(object sender, System.EventArgs e) { ConnectionForm connectionform = new ConnectionForm(); connectionform.AddressText = ""; if (connectionform.ShowDialog() == DialogResult.OK) { // TODO Uri ConnectUri = new Uri("http://" + connectionform.AddressText); shareuri = ConnectUri.ToString(); devicefactory = new UPnPDeviceFactory(ConnectUri, 1000, new UPnPDeviceFactory.UPnPDeviceHandler(ConnectSink), new UPnPDeviceFactory.UPnPDeviceFailedHandler(ConnectFailedSink), null, null); statusBar.Text = string.Format("Attempting Connection to {0}.", connectionform.AddressText); } connectionform.Dispose(); }
private void ConnectSink(UPnPDeviceFactory sender, UPnPDevice d, Uri ConnectUri) { string useIP = d.InterfaceToHost.ToString(); disconnectMenuItem.Enabled = false; CheckIconState(); if(this.overrideIP!="") {useIP = this.overrideIP;} statusBar.Text = "Connected to Peer Relay"; devicefactory = null; home = new CpGateKeeper(d.GetServices(CpGateKeeper.SERVICE_NAME)[0]); home.Register(new Uri("http://" + useIP + ":" + this.PortNumber.ToString()),true); }
private void DeviceFactoryCreationSink(UPnPDeviceFactory sender, UPnPDevice device, Uri locationURL) { //Console.WriteLine("UPnPDevice[" + device.FriendlyName + "]@" + device.LocationURL + " advertised UDN[" + device.UniqueDeviceName + "]"); if (!this.deviceTable.Contains(device.UniqueDeviceName)) { EventLogger.Log( this, EventLogEntryType.Error, "UPnPDevice[" + device.FriendlyName + "]@" + device.LocationURL + " advertised UDN[" + device.UniqueDeviceName + "] in xml but not in SSDP" ); } else { lock (this.deviceTableLock) { DeviceInfo info2 = (DeviceInfo)this.deviceTable[device.UniqueDeviceName]; if (info2.Device != null) { EventLogger.Log( this, EventLogEntryType.Information, "Unexpected UPnP Device Creation: " + device.FriendlyName + "@" + device.LocationURL ); return; } DeviceInfo info = (DeviceInfo)this.deviceTable[device.UniqueDeviceName]; info.Device = device; this.deviceTable[device.UniqueDeviceName] = info; this.deviceLifeTimeClock.Add(device.UniqueDeviceName, device.ExpirationTimeout); this.activeDeviceList.Add(device); } this.OnAddedDeviceEvent.Fire(this, device); } }
private void FactoryFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn) { OpenSource.Utilities.EventLogger.Log(this, System.Diagnostics.EventLogEntryType.Warning, "Factory Failed Sync!!"); lock (CreateTable) { CreateTable.Remove(sender); sender.Shutdown(); } if (OnFailed != null) OnFailed (this, URL, e, urn); }