예제 #1
0
        /// <summary>
        /// Initializes the device. This method builds the colletion of internal device services, sets
        /// the devices transport address and adds DPWS required namespaces to the devices namespace collection.
        /// </summary>
        public static void Initialize(Binding binding, ProtocolVersion v)
        {
            m_binding = binding;

            string addr  = binding.Transport.EndpointAddress.AbsoluteUri;
            int    index = addr.LastIndexOf('/');

            m_address = "urn:uuid:" + addr.Substring(index + 1);

            SubscriptionManager = new DpwsWseSubscriptionMgr(binding, v);

            if (v != null)
            {
                // Add disco services to udp service endpoints collection
                m_discoveryService = new DpwsDeviceDiscoService(v);
                m_discoGreeting    = new DpwsDiscoGreeting(v);
                // Create a new udp service host and add the discovery endpoints
                WsUdpServiceHost.Instance.AddServiceEndpoint(m_discoveryService);
            }

            // Add metadata get service endpoint
            m_discoMexService = new DpwsDeviceMexService(v);
            m_hostedServices.DiscoMexService = m_discoMexService;

            // Add direct probe service endpoint
            if (m_discoveryService != null)
            {
                m_hostedServices.Add(m_discoveryService);
            }

            // Create a new http service host and add hosted services endpoints
            m_httpServiceHost = new WsHttpServiceHost(m_binding, m_hostedServices);

            System.Ext.Console.Write("IP Address: " + WsNetworkServices.GetLocalIPV4Address());
        }
예제 #2
0
        public MFTestResults DeviceTest_ThisDevice()
        {
            /// <summary>
            /// 1. Verifies that each of the properties of the Device.ThisModel object is the correct type
            /// 2. Sets settable properties
            /// 3. Verifies their type again, and their data for non-nullable properties
            /// </summary>
            ///

            Device.Initialize(new WS2007HttpBinding(new HttpTransportBindingConfig("urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51", 8084)), new ProtocolVersion10());

            // Set device information
            //Device.EndpointAddress = "urn:uuid:3cb0d1ba-cc3a-46ce-b416-212ac2419b51";
            Device.ThisModel.Manufacturer    = "Microsoft Corporation";
            Device.ThisModel.ManufacturerUrl = "http://www.microsoft.com/";
            Device.ThisModel.ModelName       = "SimpleService Test Device";
            Device.ThisModel.ModelNumber     = "1.0";
            Device.ThisModel.ModelUrl        = "http://www.microsoft.com/";
            Device.ThisModel.PresentationUrl = "http://www.microsoft.com/";

            Device.ThisDevice.FriendlyName    = "SimpleService";
            Device.ThisDevice.FirmwareVersion = "alpha";
            Device.ThisDevice.SerialNumber    = "12345678";


            bool testResult = true;

            try
            {
                WsServiceEndpoints testWSEs = Device.HostedServices;
                if (testWSEs.GetType() != Type.GetType("Ws.Services.WsServiceEndpoints"))
                {
                    throw new Exception("HostedServices bad type");
                }

                string testString = Device.IPV4Address;
                if (testString.GetType() != Type.GetType("System.String"))
                {
                    throw new Exception("IPV4Address bad type");
                }

                int testInt = Device.MetadataVersion;
                if (testInt.GetType() != Type.GetType("System.Int32"))
                {
                    throw new Exception("MetadataVersion bad type");
                }

                Device.MetadataVersion = -12;
                if (Device.MetadataVersion != -12)
                {
                    throw new Exception("MetadataVersion did not set to invalid int value");
                }

                Device.MetadataVersion = 2;
                if (Device.MetadataVersion != 2)
                {
                    throw new Exception("MetadataVersion did not set to valid value");
                }

                testInt = Device.ProbeMatchDelay;
                if (testInt.GetType() != Type.GetType("System.Int32"))
                {
                    throw new Exception("ProbeMatchDelay bad type");
                }

                Device.ProbeMatchDelay = 2;
                if (Device.ProbeMatchDelay != 2)
                {
                    throw new Exception("ProbeMatchDelay did not set to valid value");
                }

                DpwsHostedService testDHS = Device.Host;
                if (testDHS != null)
                {
                    if (testDHS.GetType() !=
                        Type.GetType("Dpws.Device.Services.DpwsHostedService"))
                    {
                        throw new Exception("DpwsHostedService bad type");
                    }
                }

                Device.Host = new DpwsHostedService(new ProtocolVersion10());
                testDHS     = Device.Host;
                if (testDHS != null)
                {
                    if (testDHS.GetType() !=
                        Type.GetType("Dpws.Device.Services.DpwsHostedService"))
                    {
                        throw new Exception("DpwsHostedService bad type after set to new");
                    }
                }

                DpwsWseSubscriptionMgr testDWSM = Device.SubscriptionManager;
                if (testDWSM != null)
                {
                    if (testDWSM.GetType() !=
                        Type.GetType("Dpws.Device.Services.DpwsWseSubscriptionMgr"))
                    {
                        throw new Exception("DpwsWseSubscriptionMgr bad type");
                    }
                }

                // EndpointAddress will be defined by each event sink
                Device.SubscriptionManager = new DpwsWseSubscriptionMgr(new WS2007HttpBinding(), new ProtocolVersion10());
                testDWSM = Device.SubscriptionManager;
                if (testDWSM != null)
                {
                    if (testDWSM.GetType() !=
                        Type.GetType("Dpws.Device.Services.DpwsWseSubscriptionMgr"))
                    {
                        throw new Exception("DpwsWseSubscriptionMgr bad type after set to new");
                    }
                }
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Comment("Incorrect exception caught: " + e.Message);
            }
            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }