예제 #1
0
        private List <SdnEntry> compareLists(SdnList listToDate, SdnList KnownList)
        {
            List <SdnEntry> changes = new List <SdnEntry>();

            listToDate.sdnEntries.ForEach(e => {
                // if it doesn't exist in our old list then it's been added //
                var existing = KnownList.sdnEntries.FirstOrDefault(x => x.uid == e.uid);
                if (existing == null)
                {
                    // which means it's a changes //
                    e.changeType = "New Entry";
                    e.changetime = DateTime.Now;
                    changes.Add(e);
                }
                // if it does exist then lets compare it with it's cougnterpart to see if they changed naything within //
                else if (EntriesAreDifferent(existing, e))
                {
                    e.changeType = "Ammendment";
                    e.changetime = DateTime.Now;
                    changes.Add(e);
                }
            });

            // lets look for any that existed in our original but no longer do //
            var removals = KnownList.sdnEntries.Where(k => !listToDate.sdnEntries.Any(y => y.uid == k.uid));

            foreach (var del in removals)
            {
                del.changeType = "Entry Deleted";
                del.changetime = DateTime.Now;
                changes.Add(del);
            }
            return(changes);
        }
예제 #2
0
        private SdnList CreateModel(string xml)
        {
            SdnList sdn = new SdnList();

            // convert our xml string to xml //
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            /**
             * loop through the nodes
             * Again here i probably would have prefered to use recursion.
             */
            var nodes = xmlDoc.GetElementsByTagName("sdnEntry");

            foreach (XmlNode node in nodes)
            {
                SdnEntry entry = new SdnEntry();

                foreach (XmlNode child in node.ChildNodes)
                {
                    // find out what node type it is and handle //
                    switch (child.Name)
                    {
                    case "uid":
                        entry.uid = Convert.ToInt32(child.InnerText);
                        break;

                    case "lastName":
                        entry.lastName = child.InnerText;
                        break;

                    case "sdnType":
                        entry.sdnType = child.InnerText;
                        break;

                    case "addressList":
                        entry.addressList = CreateAddressList(child.ChildNodes);
                        break;

                    case "programList":
                        entry.programList = CreateProgramList(child.ChildNodes);
                        break;

                    case "akaList":
                        entry.akaList = CreateAkaList(child.ChildNodes);
                        break;

                    default:
                        break;
                    }
                }
                SdnEntry t = entry;
                sdn.sdnEntries.Add(entry);
            }

            return(sdn);
        }
예제 #3
0
        public void DownloadAndStoreNewSdn_WhenDownloadSucceeds_ShouldParseTryParseXml()
        {
            SdnList result = null;
            var     xml    = "aka xml";

            _contentDownloader.Setup(x => x.DownloadUpdatedSdns()).Returns(xml);

            Sut.DownloadAndStoreNewSdn();

            _xmlParser.Verify(x => x.TryDeserializeObject <SdnList>(out result, xml));
        }
예제 #4
0
        public void DownloadAndStoreNewSdn_WhenParsingSucceeds_ShouldCallRepository()
        {
            var xml    = "aka xml";
            var result = new SdnList();

            _contentDownloader.Setup(x => x.DownloadUpdatedSdns()).Returns(xml);
            _xmlParser.Setup(x => x.TryDeserializeObject <SdnList>(out result, xml)).Returns(() => true);

            Sut.DownloadAndStoreNewSdn();

            _sdnRepository.Verify(x => x.AddMany(It.IsAny <SdnList>()));
        }
예제 #5
0
        public async Task <List <SdnEntry> > getChanges(SdnList knownList)
        {
            // lets get a more updated version of the list //
            SdnList listToDate = await getSDNList();

            // compare the two and extract any changes //
            var changes = compareLists(listToDate, knownList);

            // lets set the more recent list as our seesion variable //
            Session["sdnList"] = listToDate;

            return(changes);
        }
예제 #6
0
 public void AddMany(SdnList items) => _sdnStorage.StoreSdn(items);