Esempio n. 1
0
        public GazetteList SearchNewsRangeAdministrative(DateTime beginDate, DateTime endDate, IEnumerable <EntityType> types, IEnumerable <EntityModification> modifications)
        {
            GazetteList result      = new GazetteList();
            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.entry.AddRange(list.entry);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 2
0
        public GazetteList SearchNewsRange(DateTime beginDate, DateTime endDate)
        {
            GazetteList result            = new GazetteList();
            var         protecteAreaTypes = new List <ParkType>();

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

            result.entry.AddRange(protectedAreasList.entry);

            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.entry.AddRange(administrativeEntitiesList.entry);
            result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            return(result);
        }
Esempio n. 3
0
        public GazetteList DoGetList(String searchKey, Int32 volume)
        {
            _searchKey = searchKey;
            _volume    = volume;
            _cookie    = String.Empty;
            GazetteList result = null;

            try
            {
                PerformRequest();
                result = new GazetteList();
                if (_dataUrl != String.Empty)
                {
                    Stream lData = DoDataDownload(0);
                    result = DoParseStream(lData);
                    for (Int32 page = 2; page <= _numberOfPages; page++)
                    {
                        PerformRequestPage(page);
                        Stream lDataPage = DoDataDownload(page);
                        result.entry.AddRange(DoParseStream(lDataPage).entry);
                    }
                }
            }
            catch (WebException)
            {
                result = null;
                // TODO
            }
            return(result);
        }
Esempio n. 4
0
        public GazetteList SearchNewsProtectedAreas(DateTime beginDate, DateTime endDate, IEnumerable <ParkType> values)
        {
            GazetteList result      = new GazetteList();
            Int32       volumeBegin = beginDate.Year - 2007 + 124;
            Int32       volumeEnd   = endDate.Year - 2007 + 124;

            for (Int32 volume = volumeBegin; volume <= volumeEnd; volume++)
            {
                foreach (KeyValuePair <EntityModification, Dictionary <ParkType, String> > outerKeyValuePair in SearchKeysProtectedAreas)
                {
                    foreach (KeyValuePair <ParkType, 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.entry.AddRange(list.entry);
                            }
                        }
                    }
                }
            }
            result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            return(result);
        }
Esempio n. 5
0
        public GazetteList SearchNews(DateTime date)
        {
            GazetteList result = new GazetteList();

            result.entry.AddRange(SearchNewsRange(date, date).entry);
            result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            return(result);
        }
Esempio n. 6
0
        private GazetteList DoParseStream(Stream data)
        {
            var         reader = new System.IO.StreamReader(data, ThaiEncoding);
            GazetteList result = new GazetteList();

            result.entry.AddRange(DoParse(reader).entry);
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// Calculates the statistics for all the given announcements.
        /// </summary>
        /// <param name="gazetteList">List of announcements.</param>
        /// <exception cref="ArgumentNullException"><paramref name="gazetteList"/> is <c>null</c>.</exception>
        public void Calculate(GazetteList gazetteList)
        {
            if (gazetteList == null)
            {
                throw new ArgumentNullException("gazetteList");
            }

            Calculate(gazetteList.AllGazetteEntries);
        }
Esempio n. 8
0
        public void SearchNewsNow()
        {
            GazetteList gazetteList = SearchNews(DateTime.Now);

            if (DateTime.Now.Month == 1)
            {
                // Check news from last year as well, in case something was added late
                gazetteList.entry.AddRange(SearchNews(DateTime.Now.AddYears(-1)).entry);
            }
            gazetteList.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            OnProcessingFinished(new RoyalGazetteEventArgs(gazetteList));
        }
Esempio n. 9
0
        protected GazetteList GetListDescription(String searchKey, Int32 volume, String description)
        {
            GazetteList result = DoGetList(searchKey, volume);

            if (result != null)
            {
                foreach (var entry in result.entry)
                {
                    entry.description = description;
                }
            }
            return(result);
        }
Esempio n. 10
0
        public GazetteList SearchString(DateTime beginDate, DateTime endDate, String searchKey)
        {
            GazetteList result      = new GazetteList();
            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.entry.AddRange(list.entry);
                }
            }
            return(result);
        }
Esempio n. 11
0
        private GazetteList DoParse(TextReader reader)
        {
            GazetteList   result      = new GazetteList();
            String        currentLine = String.Empty;
            int           dataState   = -1;
            StringBuilder entryData   = new StringBuilder();

            while ((currentLine = reader.ReadLine()) != null)
            {
                if (currentLine.Contains(PageStart))
                {
                    String lTemp = currentLine.Substring(currentLine.LastIndexOf(PageStart) + PageStart.Length, 3).Trim();
                    _numberOfPages = Convert.ToInt32(lTemp);
                }
                else if (currentLine.StartsWith(EntryStart))
                {
                    if (entryData.Length > 0)
                    {
                        var current = ParseSingeItem(entryData.ToString());
                        if (current != null)
                        {
                            result.entry.Add(current);
                        }
                        entryData.Remove(0, entryData.Length);
                    }
                    dataState++;
                }
                else if (dataState >= 0)
                {
                    entryData.Append(currentLine.Trim() + " ");
                }
            }
            if (entryData.Length > 0)
            {
                var current = ParseSingeItem(entryData.ToString());
                if (current != null)
                {
                    result.entry.Add(current);
                }
            }
            return(result);
        }
Esempio n. 12
0
 public RoyalGazetteEventArgs(GazetteList data)
     : base()
 {
     Data = data;
 }
 private GazetteList DoParseStream(Stream data)
 {
     var reader = new System.IO.StreamReader(data, ThaiEncoding);
     GazetteList result = new GazetteList();
     result.entry.AddRange(DoParse(reader).entry);
     return result;
 }
 private GazetteList DoParse(TextReader reader)
 {
     GazetteList result = new GazetteList();
     String currentLine = String.Empty;
     int dataState = -1;
     StringBuilder entryData = new StringBuilder();
     while ( (currentLine = reader.ReadLine()) != null )
     {
         if ( currentLine.Contains(PageStart) )
         {
             String lTemp = currentLine.Substring(currentLine.LastIndexOf(PageStart) + PageStart.Length, 3).Trim();
             _numberOfPages = Convert.ToInt32(lTemp);
         }
         else if ( currentLine.StartsWith(EntryStart) )
         {
             if ( entryData.Length > 0 )
             {
                 var current = ParseSingeItem(entryData.ToString());
                 if ( current != null )
                 {
                     result.entry.Add(current);
                 }
                 entryData.Remove(0, entryData.Length);
             }
             dataState++;
         }
         else if ( dataState >= 0 )
         {
             entryData.Append(currentLine.Trim() + " ");
         }
     }
     if ( entryData.Length > 0 )
     {
         var current = ParseSingeItem(entryData.ToString());
         if ( current != null )
         {
             result.entry.Add(current);
         }
     }
     return result;
 }
        public GazetteList SearchString(DateTime beginDate, DateTime endDate, String searchKey)
        {
            GazetteList result = new GazetteList();
            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.entry.AddRange(list.entry);
                }
            }
            return result;
        }
        public GazetteList SearchNewsRangeAdministrative(DateTime beginDate, DateTime endDate, IEnumerable<EntityType> types, IEnumerable<EntityModification> modifications)
        {
            GazetteList result = new GazetteList();
            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.entry.AddRange(list.entry);
                                }
                            }
                        }
                    }
                }
            }
            return result;
        }
 public RoyalGazetteEventArgs(GazetteList data)
     : base()
 {
     Data = data;
 }
        public GazetteList SearchNewsRange(DateTime beginDate, DateTime endDate)
        {
            GazetteList result = new GazetteList();
            var protecteAreaTypes = new List<ParkType>();
            foreach ( ParkType protectedArea in Enum.GetValues(typeof(ParkType)) )
            {
                protecteAreaTypes.Add(protectedArea);
            }
            var protectedAreasList = SearchNewsProtectedAreas(beginDate, endDate, protecteAreaTypes);
            result.entry.AddRange(protectedAreasList.entry);

            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.entry.AddRange(administrativeEntitiesList.entry);
            result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            return result;
        }
        public GazetteList SearchNewsProtectedAreas(DateTime beginDate, DateTime endDate, IEnumerable<ParkType> values)
        {
            GazetteList result = new GazetteList();
            Int32 volumeBegin = beginDate.Year - 2007 + 124;
            Int32 volumeEnd = endDate.Year - 2007 + 124;

            for ( Int32 volume = volumeBegin ; volume <= volumeEnd ; volume++ )
            {
                foreach ( KeyValuePair<EntityModification, Dictionary<ParkType, String>> outerKeyValuePair in SearchKeysProtectedAreas )
                {
                    foreach ( KeyValuePair<ParkType, 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.entry.AddRange(list.entry);
                            }
                        }
                    }
                }
            }
            result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
            return result;
        }
 public GazetteList SearchNews(DateTime date)
 {
     GazetteList result = new GazetteList();
     result.entry.AddRange(SearchNewsRange(date, date).entry);
     result.entry.Sort((x, y) => DateTime.Compare(x.publication, y.publication));
     return result;
 }
 public GazetteList DoGetList(String searchKey, Int32 volume)
 {
     _searchKey = searchKey;
     _volume = volume;
     _cookie = String.Empty;
     GazetteList result = null;
     try
     {
         PerformRequest();
         result = new GazetteList();
         if ( _dataUrl != String.Empty )
         {
             Stream lData = DoDataDownload(0);
             result = DoParseStream(lData);
             for ( Int32 page = 2 ; page <= _numberOfPages ; page++ )
             {
                 PerformRequestPage(page);
                 Stream lDataPage = DoDataDownload(page);
                 result.entry.AddRange(DoParseStream(lDataPage).entry);
             }
         }
     }
     catch ( WebException )
     {
         result = null;
         // TODO
     }
     return result;
 }