Beispiel #1
0
        public void ImportTest()
        {
            XModelInventoryImporter inventoryImporter = new XModelInventoryImporter();
            var ds     = new DownloadService();
            var xml    = ds.GetFileAsStringAsync(new Uri("http://hohenseefamily.com/xlights/boscoyo.xml"));
            var result = inventoryImporter.Import(xml.Result);

            result.Wait();
            Assert.IsNotNull(result.Result.Vendor);
            Assert.IsNotNull(result.Result.Vendor.Name);
            Assert.IsNotNull(result.Result.Vendor.Contact);
            Assert.IsNotNull(result.Result.Vendor.Email);
        }
Beispiel #2
0
        /// <summary>
        /// Method to invoke when the OpenVendorBrowserCommand command is executed.
        /// </summary>
        private async Task OpenVendorBrowserAsync()
        {
            XModelInventoryImporter mi = new XModelInventoryImporter();

            List <ModelInventory> vendorInventories = new List <ModelInventory>();

            var vendorLinks = await GetVendorUrls();

            if (!vendorLinks.Any())
            {
                return;
            }


            var dependencyResolver = this.GetDependencyResolver();
            var ds = dependencyResolver.Resolve <IDownloadService>();

            foreach (var vendorLink in vendorLinks)
            {
                try
                {
                    var xml = await ds.GetFileAsStringAsync(new Uri(vendorLink.Url));

                    vendorInventories.Add(await mi.Import(xml));
                }
                catch (Exception e)
                {
                    Logging.Error(e, $"An error occurred retrieveing the inventory from: {vendorLink}");
                    var mbs = dependencyResolver.Resolve <IMessageBoxService>();
                    mbs.ShowError($"Unable to retrieve inventory from {vendorLink.Name}\nEnsure you have an active internet connection.", "Error Retrieving Inventory");
                }
            }

            if (!vendorInventories.Any())
            {
                return;
            }
            var  uiVisualizerService = dependencyResolver.Resolve <IUIVisualizerService>();
            var  vm     = new VendorInventoryWindowViewModel(vendorInventories, dependencyResolver.Resolve <IProcessService>());
            bool?result = await uiVisualizerService.ShowDialogAsync(vm);

            if (result.HasValue && result.Value)
            {
                var status = await LoadVendorModel(vm.SelectedModelLink);

                if (status.Item1)
                {
                    if (status.Item2 == ModelType.XModel)
                    {
                        Prop.PhysicalMetadata.Width     = vm.SelectedProduct.Width;
                        Prop.PhysicalMetadata.Height    = vm.SelectedProduct.Height;
                        Prop.PhysicalMetadata.Depth     = vm.SelectedProduct.Thickness;
                        Prop.PhysicalMetadata.Material  = vm.SelectedProduct.Material;
                        Prop.PhysicalMetadata.BulbType  = vm.SelectedProduct.PixelDescription;
                        Prop.PhysicalMetadata.NodeCount = vm.SelectedProduct.PixelCount.ToString();
                        Prop.InformationMetadata.Notes  = vm.SelectedProduct.Notes;
                        Prop.Type = vm.SelectedProduct.ProductType;
                    }

                    //Ensure the Vendor info is populated
                    if (string.IsNullOrEmpty(Prop.VendorMetadata.Name))
                    {
                        Prop.VendorMetadata.Name = vm.SelectedInventory.Vendor.Name;
                    }

                    if (string.IsNullOrEmpty(Prop.VendorMetadata.Contact))
                    {
                        Prop.VendorMetadata.Contact = vm.SelectedInventory.Vendor.Contact;
                    }

                    if (string.IsNullOrEmpty(Prop.VendorMetadata.Email))
                    {
                        Prop.VendorMetadata.Email = vm.SelectedInventory.Vendor.Email;
                    }

                    if (string.IsNullOrEmpty(Prop.VendorMetadata.Phone))
                    {
                        Prop.VendorMetadata.Phone = vm.SelectedInventory.Vendor.Phone;
                    }

                    if (string.IsNullOrEmpty(Prop.VendorMetadata.Website))
                    {
                        var website = vm.SelectedInventory.Vendor.WebLinks.Where(x => x.Name.Equals("Website"));
                        if (website.Any())
                        {
                            Prop.VendorMetadata.Website = website.First().Link.AbsoluteUri;
                        }
                    }
                }
            }
        }