Example #1
0
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RoyalGazetteList list = new RoyalGazetteList();
            SearchData       data = e.Argument as SearchData;

            if (data != null)
            {
                var      searcher = new RoyalGazetteOnlineSearch();
                DateTime dateStart;
                DateTime dateEnd;
                dateStart = new DateTime(Math.Max(1800, data.StartYear), 1, 1);
                dateEnd   = new DateTime(Math.Max(1800, data.EndYear), 1, 1);

                if (!String.IsNullOrEmpty(data.SearchString))
                {
                    list.AddRange(searcher.SearchString(dateStart, dateEnd, data.SearchString));
                    // Thread.Sleep(1000);  // seems the Gazette website blocks when to many requests are received
                }

                if (data.EntityTypes.Any() && data.EntityModifications.Any())
                {
                    list.AddRange(searcher.SearchNewsRangeAdministrative(dateStart, dateEnd, data.EntityTypes, data.EntityModifications));
                    // Thread.Sleep(1000);  // seems the Gazette website blocks when to many requests are received
                }
            }
            e.Result = list;
        }
        public RoyalGazetteList SearchNewsRange(DateTime beginDate, DateTime endDate)
        {
            RoyalGazetteList result = new RoyalGazetteList();
            var protecteAreaTypes   = new List <ProtectedAreaTypes>();

            foreach (ProtectedAreaTypes protectedArea in Enum.GetValues(typeof(ProtectedAreaTypes)))
            {
                protecteAreaTypes.Add(protectedArea);
            }
            var protectedAreasList = SearchNewsProtectedAreas(beginDate, endDate, protecteAreaTypes);

            result.AddRange(protectedAreasList);

            var entityTypes = new List <EntityType>();

            foreach (EntityType entityType in Enum.GetValues(typeof(EntityType)))
            {
                if (entityType != EntityType.Sukhaphiban)
                {
                    entityTypes.Add(entityType);
                }
            }
            var entityModifications = new List <EntityModification>();

            foreach (EntityModification entityModification in Enum.GetValues(typeof(EntityModification)))
            {
                entityModifications.Add(entityModification);
            }
            var administrativeEntitiesList = SearchNewsRangeAdministrative(beginDate, endDate, entityTypes, entityModifications);

            result.AddRange(administrativeEntitiesList);
            result.SortByPublicationDate();
            return(result);
        }
        public RoyalGazetteList SearchNewsRangeAdministrative(DateTime beginDate, DateTime endDate, IEnumerable <EntityType> types, IEnumerable <EntityModification> modifications)
        {
            RoyalGazetteList result      = new RoyalGazetteList();
            Int32            volumeBegin = beginDate.Year - 2007 + 124;
            Int32            volumeEnd   = endDate.Year - 2007 + 124;

            for (Int32 volume = volumeBegin; volume <= volumeEnd; volume++)
            {
                foreach (KeyValuePair <EntityModification, Dictionary <EntityType, String> > outerKeyValuePair in SearchKeys)
                {
                    if (modifications.Contains(outerKeyValuePair.Key))
                    {
                        foreach (KeyValuePair <EntityType, String> keyValuePair in outerKeyValuePair.Value)
                        {
                            if (types.Contains(keyValuePair.Key))
                            {
                                var list = GetListDescription(keyValuePair.Value, volume, ModificationText(outerKeyValuePair.Key, keyValuePair.Key));
                                if (list != null)
                                {
                                    result.AddRange(list);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
        public RoyalGazetteList SearchNewsProtectedAreas(DateTime beginDate, DateTime endDate, IEnumerable <ProtectedAreaTypes> values)
        {
            RoyalGazetteList result      = new RoyalGazetteList();
            Int32            volumeBegin = beginDate.Year - 2007 + 124;
            Int32            volumeEnd   = endDate.Year - 2007 + 124;

            for (Int32 volume = volumeBegin; volume <= volumeEnd; volume++)
            {
                foreach (KeyValuePair <EntityModification, Dictionary <ProtectedAreaTypes, String> > outerKeyValuePair in SearchKeysProtectedAreas)
                {
                    foreach (KeyValuePair <ProtectedAreaTypes, String> keyValuePair in outerKeyValuePair.Value)
                    {
                        if (values.Contains(keyValuePair.Key))
                        {
                            var list = GetListDescription(keyValuePair.Value, volume, ModificationText(outerKeyValuePair.Key, keyValuePair.Key));
                            if (list != null)
                            {
                                result.AddRange(list);
                            }
                        }
                    }
                }
            }
            result.SortByPublicationDate();
            return(result);
        }
        public RoyalGazetteList DoGetList(String searchKey, Int32 volume)
        {
            _searchKey = searchKey;
            _volume    = Math.Max(0, volume);
            // _cookie = String.Empty;
            _cookie        = _defaultCookie;
            _dataUrl       = String.Empty;
            _numberOfPages = 0;

            RoyalGazetteList result = null;

            try
            {
                PerformRequest();
                result = new RoyalGazetteList();
                if (_dataUrl != String.Empty)
                {
                    Stream receivedData = DoDataDownload(0);
                    result = DoParseStream(receivedData);
                    for (Int32 page = 2; page <= _numberOfPages; page++)
                    {
                        PerformRequestPage(page);
                        Stream receivedDataPage = DoDataDownload(page);
                        result.AddRange(DoParseStream(receivedDataPage));
                    }
                }
            }
            catch (WebException)
            {
                // result = null;
                // TODO
            }
            return(result);
        }
        public RoyalGazetteList SearchNews(DateTime date)
        {
            RoyalGazetteList result = new RoyalGazetteList();

            result.AddRange(SearchNewsRange(date, date));
            result.SortByPublicationDate();
            return(result);
        }
        private RoyalGazetteList DoParseStream(Stream data)
        {
            var reader = new System.IO.StreamReader(data, TambonHelper.ThaiEncoding);
            RoyalGazetteList result = new RoyalGazetteList();

            result.AddRange(DoParse(reader));
            return(result);
        }
        public void SearchNewsNow()
        {
            RoyalGazetteList gazetteList = SearchNews(DateTime.Now);

            if (DateTime.Now.Month == 1)
            {
                // Check news from last year as well, in case something was added late
                gazetteList.AddRange(SearchNews(DateTime.Now.AddYears(-1)));
            }
            gazetteList.SortByPublicationDate();
            OnProcessingFinished(new RoyalGazetteEventArgs(gazetteList));
        }
        private RoyalGazetteList DoParseStream(Stream data)
        {
            var reader = new System.IO.StreamReader(data, TambonHelper.ThaiEncoding);

            //var fileStream = new FileStream("c:\\temp\\out.htm", FileMode.OpenOrCreate);
            //TambonHelper.StreamCopy(data, fileStream);
            //fileStream.Close();

            RoyalGazetteList result = new RoyalGazetteList();

            result.AddRange(DoParse(reader));
            return(result);
        }
Example #10
0
        private void openFileDialogXML_FileOk(Object sender, CancelEventArgs e)
        {
            this.Activate();
            String[]         files = openFileDialogXML.FileNames;
            RoyalGazetteList currentGazetteList = new RoyalGazetteList();

            foreach (String fileName in files)
            {
                RoyalGazetteList loadedGazetteList = RoyalGazetteList.Load(fileName);
                currentGazetteList.AddRange(loadedGazetteList);
            }
            ShowGazetteDialog(currentGazetteList);
        }
        public RoyalGazetteList SearchString(DateTime beginDate, DateTime endDate, String searchKey)
        {
            RoyalGazetteList result      = new RoyalGazetteList();
            Int32            volumeBegin = beginDate.Year - 2007 + 124;
            Int32            volumeEnd   = endDate.Year - 2007 + 124;

            for (Int32 volume = volumeBegin; volume <= volumeEnd; volume++)
            {
                var list = GetListDescription(searchKey, volume, "");
                if (list != null)
                {
                    result.AddRange(list);
                }
            }
            result.SortByPublicationDate();
            return(result);
        }
Example #12
0
        public RoyalGazetteList FindDuplicates()
        {
            RoyalGazetteList lResult = new RoyalGazetteList();
            RoyalGazetteList lTemp   = new RoyalGazetteList();

            lTemp.AddRange(this);
            URIComparer lComparer = new URIComparer();

            lTemp.Sort(lComparer.Compare);
            int lIndex = 0;

            while (lIndex < lTemp.Count)
            {
                RoyalGazette lEntry = lTemp[lIndex];
                lTemp.RemoveAt(lIndex);
                int lFound = lTemp.BinarySearch(lEntry, lComparer);
                if (lFound >= 0)
                {
                    lResult.Add(lEntry);
                }
            }
            return(lResult);
        }