コード例 #1
0
 public void DataFactory_DoesNotThrow_Save()
 {
     Assert.DoesNotThrow(delegate
     {
         var request = NPIRequest.Create(new ZipcodeMetadata());
         DataFactory.SaveProvider(NpiResponse.Create(request, ""));
     });
 }
コード例 #2
0
        private void ZipCodeComplete(NpiResponse response)
        {
            var filter = Builders <ZipcodeMetadata> .Filter.Eq(x => x._id, response.Request.Address._id);

            var update = Builders <ZipcodeMetadata> .Update
                         .Set(x => x.BatchCount, response.Request.Skip + 1)
                         .Set(x => x.Processed, TRUE);

            var document = zipEntries.FindOneAndUpdate(filter, update);
        }
コード例 #3
0
 bool IData.SaveProvider(NpiResponse response)
 {
     try
     {
         AddDocuments(response);
         return(true);
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Failed to save provider data");
         return(false);
     }
 }
コード例 #4
0
        private void ScheduleNext(NpiResponse response)
        {
            var add    = response.Request.Address;
            var filter = Builders <ZipcodeMetadata> .Filter.Eq(x => x._id, add._id);

            var update = Builders <ZipcodeMetadata> .Update
                         .Set(x => x.BatchCount, add.BatchCount + 1)
                         .Set(x => x.Processed, FALSE);

            zipEntries.UpdateOne(filter, update);

            var request = NPIRequest.Next(response.Request);

            WebRequestScheduler.Instance.Submit(request);
        }
コード例 #5
0
        private void AddDocuments(NpiResponse response)
        {
            var obj = BsonDocument.Parse(response.Contents);

            if (obj == null)
            {
                return;
            }
            var documents = GetDocuments(obj);

            if (!documents.Any())
            {
                Log.Information($"No documents found for {response.ToString()}");
                ZipCodeComplete(response);
                return;
            }

            List <BsonDocument> uniqueDocs = new List <BsonDocument>();
            StringBuilder       builder    = new StringBuilder();
            int duplicate = 0;

            foreach (var doc in documents)
            {
                var npi = doc["number"].ToInt32();
                lock (_cache_lock)
                {
                    if (!cache.Contains(npi))
                    {
                        doc["_id"] = npi;
                        uniqueDocs.Add(doc);
                        cache.Add(npi);
                    }
                    else
                    {
                        ++duplicate;
                        builder.Append($",{npi}");
                    }
                }
            }
            Log.Warning($"{duplicate} of {documents.Count()} documents duplicate. Discarding them. Duplicated NPI's are [{builder.ToString().Substring(0,100 > builder.Length ? builder.Length : 100)} ... and more]");

            if (uniqueDocs.Any())
            {
                nppes.InsertMany(uniqueDocs);
            }

            var count = obj["result_count"].AsInt32;

            if (count < NPIRequest.MAX_RESULTS)
            {
                //If we have less than MAX_RESULTS then it means that we have
                //processed all zip codes. So we can set the "processed" flag
                //to true
                ZipCodeComplete(response);
                Log.Verbose($"{response.Request.Address} is comlete");
            }
            else
            {
                Log.Verbose($"{response.Request.Address} is scheduled for next iteration");
                ScheduleNext(response);
            }
        }
コード例 #6
0
 public static void SaveProvider(NpiResponse response) => data.SaveProvider(response);
コード例 #7
0
 public void Setup()
 {
     DataFactory.Initialize(new TestDataProvider
                                (NpiResponse.Create(NPIRequest.Create(new ZipcodeMetadata()), "")));
 }
コード例 #8
0
 public TestDataProvider(NpiResponse response)
 {
     mock.Setup(x => x.SaveProvider(response)).Returns(true);
     mock.Setup(x => x.Processed(response.Request.Address)).Returns(0);
     mock.Setup(x => x.ZipCodes()).Returns(Enumerable.Empty <ZipcodeMetadata>().ToList());
 }