コード例 #1
0
        public bool QueryCategory(string uid, String apikey = OCTOPART_API_KEY)
        {
            if (String.IsNullOrWhiteSpace(uid))
            {
                return(false);
            }

            var    querier         = new OctoPart.Querier(apikey);
            String octopart_result = null;
            Random rnd             = new Random();

            var retries = 5;

            while (octopart_result == null)
            {
                try
                {
                    octopart_result = querier.QueryCategory(uid);
                }
                catch (OctoPart.OctopartQueryRateException ex)
                {
                    if (retries-- > 0)
                    {
                        System.Threading.Thread.Sleep(rnd.Next(5000, 10000));
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }

            if (octopart_result == null)
            {
                return(false);
            }
            else
            {
                this.Classification = GetClassification(octopart_result);
            }

            return(true);
        }
コード例 #2
0
        public bool QueryOctopartData(String apikey = "22becbab")
        {
            if (String.IsNullOrWhiteSpace(octopart_mpn))
            {
                return false;
            }

            var querier = new OctoPart.Querier(apikey);
            String octopart_result = null;
            Random rnd = new Random();

            var retries = 5;
            while (octopart_result == null)
            {
                try
                {
                    octopart_result = querier.QueryMpn(octopart_mpn);
                }
                catch (OctoPart.OctopartQueryRateException ex)
                {
                    if (retries-- > 0)
                    {
                        System.Threading.Thread.Sleep(rnd.Next(5000, 10000));
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            
            this.manufacturer = GetManufacturer(octopart_result);
            this.manufacturerPartNumber = GetManufacturerPartNumber(octopart_result);
            this.description = GetDescription(octopart_result);
            this.package = GetPackage(octopart_result);
            this.notes = GetNotes(octopart_result);
            this.SellerMapStructure = GetSellerMapStructure(octopart_result);

            return true;
        }
コード例 #3
0
        public bool QueryOctopartData(String apikey          = OCTOPART_API_KEY,
                                      bool exact_only        = false,
                                      List <string> includes = null,
                                      bool grab_first        = true)
        {
            if (String.IsNullOrWhiteSpace(octopart_mpn))
            {
                return(false);
            }

            includes = includes ?? new List <string>()
            {
                "specs", "descriptions"
            };

            var    querier         = new OctoPart.Querier(apikey);
            String octopart_result = null;
            Random rnd             = new Random();

            var retries = 5;

            while (octopart_result == null)
            {
                try
                {
                    octopart_result = querier.QueryMpn(octopart_mpn, exact_only, includes, grab_first);
                }
                catch (OctoPart.OctopartQueryRateException ex)
                {
                    if (retries-- > 0)
                    {
                        System.Threading.Thread.Sleep(rnd.Next(5000, 10000));
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }

            if (string.Compare(octopart_result, "toomany") != 0 &&
                string.Compare(octopart_result, "none") != 0)
            {
                // Default properties returned by OctoPart query
                this.valid_mpn              = true;
                this.too_broad_mpn          = false;
                this.manufacturer           = GetManufacturer(octopart_result);
                this.manufacturerPartNumber = GetManufacturerPartNumber(octopart_result);
                this.description            = GetDescription(octopart_result);
                this.package                 = GetPackage(octopart_result);
                this.notes                   = GetNotes(octopart_result);
                this.SellerMapStructure      = GetSellerMapStructure(octopart_result);
                this.TechnicalSpecifications = GetTechnicalSpecifications(octopart_result);

                // Non-default returned properties (for custom "includes" passed to Query function
                if (includes.Contains("category_uids"))
                {
                    this.categoryuid = GetCategoryUID(octopart_result);
                }
                if (includes.Contains("imagesets"))
                {
                    this.icon = GetIcon(octopart_result);
                }
                if (includes.Contains("datasheets"))
                {
                    this.datasheet = GetDatasheet(octopart_result);
                }
            }
            else
            {
                if (string.Compare(octopart_result, "toomany") == 0)
                {
                    this.valid_mpn     = true;
                    this.too_broad_mpn = true;
                }
                else if (string.Compare(octopart_result, "none") == 0)
                {
                    this.valid_mpn     = false;
                    this.too_broad_mpn = false;
                }

                return(false);
            }

            return(true);
        }