示例#1
0
        public void Lookup()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_Url.Replace("ssdp", "environment"));
                request.Accept = "application/json";

                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    var serializer = new JsonSerializer();
                    using (var sr = new StreamReader(response.GetResponseStream()))
                        using (var jsonTextReader = new JsonTextReader(sr))
                        {
                            EnvironmentModel Model = (EnvironmentModel)serializer.Deserialize(jsonTextReader, typeof(EnvironmentModel));

                            string IPWithPort = m_IpAddress.Address + ((m_IpAddress.Port != 80) ? ":" + m_IpAddress.Port : "");

                            Resolved?.Invoke(this, new DataGridRow()
                            {
                                Name = Model.machineName, Url = "http://" + IPWithPort + "/", IpAddress = IPWithPort, Location = Model.location
                            });
                        }
                }
            }
            catch (WebException)
            {
                LookupLegacy();
            }
            catch (Exception)
            {
                Errored?.Invoke(this, m_Url);
            }
        }
示例#2
0
        private object InternalResolve(IInjectContext injectContext)
        {
            object instance;

            BoundObjects = BoundObjects ?? new List <object>();

            switch (BindingType)
            {
            case BindingType.Singleton:
                if (BoundObjects.Count == 0)
                {
                    instance = ResolveNew(injectContext);
                    BoundObjects.Add(instance);

                    Container.Injector.Inject(instance, injectContext);

                    Resolved?.Invoke(true, this, null);
                }
                else
                {
                    instance = BoundObjects.FirstOrDefault();

                    Resolved?.Invoke(false, this, null);
                }
                break;

            case BindingType.Transient:
                instance = ResolveNew(injectContext);
                Container.Injector.Inject(instance, injectContext);

                Resolved?.Invoke(true, this, null);
                break;

            default:
                throw new InvalidOperationException();
            }

            return(instance);
        }
示例#3
0
        public void LookupLegacy()
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_Url);
                request.Accept = "application/xml";

                using (WebResponse response = request.GetResponse())
                {
                    Stream       dataStream = response.GetResponseStream();
                    StreamReader reader     = new StreamReader(dataStream);

                    XmlSerializer serializer = new XmlSerializer(typeof(DiscoveryDeviceDescriptionModel));

                    DiscoveryDeviceDescriptionModel deserialized = null;
                    try
                    {
                        deserialized = (DiscoveryDeviceDescriptionModel)serializer.Deserialize(reader);
                    }
                    catch (InvalidOperationException)
                    {
                    }

                    if (deserialized == null)
                    {
                        return;
                    }

                    Resolved?.Invoke(this, new DataGridRow()
                    {
                        Name = deserialized.Device.FriendlyName, Url = deserialized.Device.PresentationURL, IpAddress = m_IpAddress.Address.ToString(), Location = "Unknown"
                    });
                }
            }
            catch (Exception)
            {
                Errored?.Invoke(this, m_Url);
            }
        }
 /// <summary>
 /// Occurs On <see cref="Resolved"/> event.
 /// </summary>
 /// <param name="e"></param>
 /// <see cref="IProblemSolver.Resolved"/>
 protected virtual void OnResolved(EventArgs e)
 {
     Resolved?.Invoke(this, e);
 }
示例#5
0
 public void NotifyResolved(bool success, object value)
 {
     Resolved?.Invoke(success, this, value);
 }
示例#6
0
 private void Lookup_Resolved(object sender, DataGridRow theNewDeviceRow)
 {
     Resolved?.Invoke(this, theNewDeviceRow);
 }