Example #1
0
        public static async Task SearchByKeywordMfrRequestAsync(ApplicationContext context, Proxy proxy, ApiRegInfo apiRegInfo, string keyword, Manufacturer manufacturer, int records, int startingRecord)
        {
            using (var searchAPI = new SearchAPI())
            {
                var header = new MouserHeader();
                header.AccountInfo           = new AccountInfo();
                header.AccountInfo.PartnerID = apiRegInfo.PartnerId;
                searchAPI.MouserHeaderValue  = header;

                WebProxy wp = new WebProxy(proxy.IPAddress, true);
                if (proxy.UserName != "")
                {
                    ICredentials credentials = new NetworkCredential(proxy.UserName, proxy.Password);
                    wp.Credentials = credentials;
                }
                searchAPI.Proxy = wp;

                ResultParts resultParts = searchAPI.SearchByKeywordAndManufacturer(keyword, manufacturer.MouserID, records, startingRecord, String.Empty, String.Empty);

                EFManufacturer eFManufacturer = new EFManufacturer(context);
                manufacturer.StartingRecord = startingRecord;
                manufacturer.NumberOfResult = resultParts.NumberOfResult;
                await eFManufacturer.AddOrUpdateAsync(manufacturer, manufacturer.Id);

                foreach (var resultPart in resultParts.Parts.ToList())
                {
                    await SaveGoodAsync(context, resultPart, manufacturer);
                }
            }
        }