private async void Search(object param)
        {
            m_searchResults.Clear();
            m_searchContext  = null;
            IsFavouritesMode = false;
            Searching        = true;
            m_filteredResults.SortDescriptions.Clear();
            m_filteredResults.Refresh();

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchField);

                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
示例#2
0
        public static PartViewModel FromAllDataSheetPart(AllDataSheetPart part)
        {
            PartViewModel result = new PartViewModel();

            result.Name                  = part.Name;
            result.Description           = part.Description;
            result.Manufacturer          = part.Manufacturer;
            result.ManufacturerImageLink = part.ManufacturerImageLink;
            result.DatasheetSiteLink     = part.DatasheetSiteLink;
            result.RebuildTags();
            result.Context       = part;
            result.MoreInfoState = PartMoreInfoState.NotAvailable;
            result.CheckState();
            return(result);
        }
示例#3
0
        public PartViewModel(Part model, bool modelValid = true)
            : base(model)
        {
            m_tags = new SynchronizedPerItemObservableCollection <ValueViewModel <string>, string>(model.Tags, x => new ValueViewModel <string>(x));
            m_tags.CollectionChanged += (s, e) => RaisePropertyChanged(nameof(MoreInfoDisplay));
            m_tags.ItemPropertyInCollectionChanged += (s, e) => RaisePropertyChanged(nameof(MoreInfoDisplay));

            m_moreInfoState = PartMoreInfoState.Available;
            if (modelValid)
            {
                if (!model.Custom)
                {
                    m_context = new AllDataSheetPart(DatasheetSiteLink);
                }

                // can't call CheckState because it will result in a call to virtual method (RaisePropertyChanged) by setting State
                // set m_state insead of State in constructor
                if (model.Custom)
                {
                    m_state = PartDatasheetState.Saved;
                }
                else
                {
                    string code = Code;

                    string pdfPath = Global.BuildSavedDatasheetPath(code);
                    if (File.Exists(pdfPath))
                    {
                        m_state = PartDatasheetState.Saved;
                    }
                    else
                    {
                        pdfPath = Global.BuildCachedDatasheetPath(code);
                        if (File.Exists(pdfPath))
                        {
                            m_state = PartDatasheetState.Cached;
                        }
                        else
                        {
                            m_state = PartDatasheetState.NotDownloaded;
                        }
                    }
                }
            }
        }
        private async void LoadMoreResults(object param)
        {
            Searching = true;

            try
            {
                ActionsCount++;
                AllDataSheetSearchResult result = await AllDataSheetPart.SearchAsync(m_searchContext);

                m_searchContext = result.SearchContext;
                AddResults(result.Parts);
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringSearchError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }

            Searching = false;
        }
示例#5
0
        private static List <AllDataSheetPart> FilterResults(HtmlDocument document)
        {
            HtmlNode rootNode = document.DocumentNode;
            HtmlNode htmlNode = rootNode.Element("html");
            HtmlNode bodyNode = htmlNode.Element("body");

            IEnumerable <HtmlNode> tableWithElementsNodes = from node in bodyNode.Descendants("table")
                                                            where IsAttributeValueLike(node, "width", "100%") && IsAttributeValueLike(node, "height", "100%") &&
                                                            IsAttributeValueLike(node, "border", "0") && IsAttributeValueLike(node, "bgcolor", "#cccccc") &&
                                                            IsAttributeValueLike(node, "cellpadding", "1") && IsAttributeValueLike(node, "cellspacing", "1") &&
                                                            IsAttributeValueLike(node, "class", "main") && IsAttributeValueLike(node, "align", "center")
                                                            select node;

            HtmlNode tableNode = tableWithElementsNodes.ElementAt(0);

            IEnumerable <HtmlNode> tableRows = from node in tableNode.Elements("tr") where IsAttributeValueLike(node, "class", "nv_td") select node;

            List <AllDataSheetPart> parts = new List <AllDataSheetPart>();

            AllDataSheetPart previous = new AllDataSheetPart();

            foreach (HtmlNode row in tableRows)
            {
                AllDataSheetPart part = new AllDataSheetPart();

                IEnumerable <HtmlNode> columns = row.Elements("td");
                int columnsCount = columns.Count();
                if (columnsCount < 3)
                {
                    continue;
                }
                int offset = 0;

                if (columnsCount == 3)
                {
                    offset = -1;
                    part.m_manufacturer          = previous.m_manufacturer;
                    part.m_manufacturerImageLink = previous.m_manufacturerImageLink;
                }
                else
                {
                    HtmlNode imgNode = columns.ElementAt(0).Element("img");
                    if (imgNode != null)
                    {
                        part.m_manufacturer          = GetAttributeValueOrEmpty(imgNode, "alt");
                        part.m_manufacturerImageLink = GetAttributeValueOrEmpty(imgNode, "src");
                    }
                }

                HtmlNode secondColumn = columns.ElementAt(1 + offset);
                HtmlNode aNode        = secondColumn.Element("a");
                if (aNode != null)
                {
                    part.m_datasheetSiteLink = GetAttributeValueOrEmpty(aNode, "href");
                    part.m_name = aNode.InnerText.Replace("\n", "");
                }

                HtmlNode descriptionNode = columns.ElementAt(3 + offset);
                if (descriptionNode != null)
                {
                    part.m_description = descriptionNode.InnerText;
                }

                previous = part;
                parts.Add(part);
            }
            return(parts);
        }
        private static List<AllDataSheetPart> FilterResults(HtmlDocument document)
        {
            HtmlNode rootNode = document.DocumentNode;
            HtmlNode htmlNode = rootNode.Element("html");
            HtmlNode bodyNode = htmlNode.Element("body");

            IEnumerable<HtmlNode> tableWithElementsNodes = from node in bodyNode.Descendants("table")
                                                           where IsAttributeValueLike(node, "width", "100%") && IsAttributeValueLike(node, "height", "100%") &&
                                                                 IsAttributeValueLike(node, "border", "0") && IsAttributeValueLike(node, "bgcolor", "#cccccc") &&
                                                                 IsAttributeValueLike(node, "cellpadding", "1") && IsAttributeValueLike(node, "cellspacing", "1") &&
                                                                 IsAttributeValueLike(node, "class", "main") && IsAttributeValueLike(node, "align", "center")
                                                           select node;

            HtmlNode tableNode = tableWithElementsNodes.ElementAt(0);

            IEnumerable<HtmlNode> tableRows = from node in tableNode.Elements("tr") where IsAttributeValueLike(node, "class", "nv_td") select node;

            List<AllDataSheetPart> parts = new List<AllDataSheetPart>();

            AllDataSheetPart previous = new AllDataSheetPart();

            foreach (HtmlNode row in tableRows)
            {
                AllDataSheetPart part = new AllDataSheetPart();

                IEnumerable<HtmlNode> columns = row.Elements("td");
                int columnsCount = columns.Count();
                if (columnsCount < 3) continue;
                int offset = 0;

                if (columnsCount == 3)
                {
                    offset = -1;
                    part.m_manufacturer = previous.m_manufacturer;
                    part.m_manufacturerImageLink = previous.m_manufacturerImageLink;
                }
                else
                {
                    HtmlNode imgNode = columns.ElementAt(0).Element("img");
                    if (imgNode != null)
                    {
                        part.m_manufacturer = GetAttributeValueOrEmpty(imgNode, "alt");
                        part.m_manufacturerImageLink = GetAttributeValueOrEmpty(imgNode, "src");
                    }
                }

                HtmlNode secondColumn = columns.ElementAt(1 + offset);
                HtmlNode aNode = secondColumn.Element("a");
                if (aNode != null)
                {
                    part.m_datasheetSiteLink = GetAttributeValueOrEmpty(aNode, "href");
                    part.m_name = aNode.InnerText.Replace("\n", "");
                }

                HtmlNode descriptionNode = columns.ElementAt(3 + offset);
                if (descriptionNode != null)
                {
                    part.m_description = descriptionNode.InnerText;
                }

                previous = part;
                parts.Add(part);
            }
            return parts;
        }