示例#1
0
        public IEnumerable <T> GenerateDiffBatchExtracts <T>(int page, int batchSize, string docket, string extract)
            where T : ClientExtract
        {
            var changes      = new List <T>();
            var finalChanges = new List <T>();

            var allDifflogs = _diffLogReader.ReadAll().ToList();

            var diffLog = allDifflogs.FirstOrDefault(x =>
                                                     x.Docket.ToLower() == docket.ToLower() && x.Extract.ToLower() == extract.ToLower());

            if (null == diffLog)
            {
                return(GenerateBatchExtracts <T, Guid>(page, batchSize));
            }

            if (diffLog.LastModified.IsNullOrEmpty() && diffLog.LastCreated.IsNullOrEmpty())
            {
                return(GenerateBatchExtracts <T, Guid>(page, batchSize));
            }

            if (diffLog.LastModified.IsNullOrEmpty() && !diffLog.LastCreated.IsNullOrEmpty())
            {
                changes = _reader.Read <T, Guid>(page, batchSize, x => x.Date_Created > diffLog.LastCreated).ToList();
            }

            if (!diffLog.LastModified.IsNullOrEmpty() && diffLog.LastCreated.IsNullOrEmpty())
            {
                changes = _reader.Read <T, Guid>(page, batchSize, x => x.Date_Created > diffLog.LastModified).ToList();
            }

            if (!diffLog.LastModified.IsNullOrEmpty() && !diffLog.LastCreated.IsNullOrEmpty())
            {
                changes = _reader.Read <T, Guid>(page, batchSize,
                                                 x => x.Date_Created > diffLog.LastCreated || x.Date_Last_Modified > diffLog.LastModified).ToList();
            }

            if (changes.Any())
            {
                var ids = changes.Select(x => new { x.PatientPK, x.SiteCode }).Distinct().ToList();
                foreach (var id in ids)
                {
                    var changedRecords = _reader.Read <T, Guid>(page, batchSize, x => x.PatientPK == id.PatientPK && x.SiteCode == id.SiteCode).ToList();
                    finalChanges.AddRange(changedRecords);
                }
                //return  _reader.Read<T, Guid>(page, batchSize, x =>  > diffLog.LastCreated).ToList();
            }
            return(finalChanges);
        }
        public void should_Read_All()
        {
            var profiles = _reader.ReadAll().ToList();

            Assert.True(profiles.Any());
        }