Beispiel #1
0
 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 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);
            }
        }
        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;
        }
Beispiel #4
0
        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();
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public void ShutDown()
 {
     deviceFactory.OnDevice              -= DeviceFactoryCreationSink;
     deviceLifeTimeClock.OnExpired       -= DeviceLifeTimeClockSink;
     deviceUpdateClock.OnExpired         -= DeviceUpdateClockSink;
     hostNetworkInfo.OnInterfaceDisabled -= NetworkInfoOldInterfaceSink;
     genericControlPoint.OnSearch        -= UPnPControlPointSearchSink;
     genericControlPoint.OnNotify        -= SSDPNotifySink;
     deviceFactory.Shutdown();
     deviceFactory = null;
     foreach (UPnPDevice dev in activeDeviceList)
     {
         dev.Removed();
     }
     hostNetworkInfo = null;
     genericControlPoint.Dispose();
     genericControlPoint = null;
 }
        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);
        }
Beispiel #8
0
 void factory_OnDevice(UPnPDeviceFactory sender, UPnPDevice device, Uri URL)
 {
     device.Advertise();
 }
Beispiel #9
0
 private void ConnectFailedSink(UPnPDeviceFactory sender, Uri URL, Exception e, string urn)
 {
     devicefactory  = null;
     statusBar.Text = "Connection Failed";
 }