Ejemplo n.º 1
0
        private void FillDataTable(RoyalGazetteList iData)
        {
            RoyalGazetteList lData = iData;

            if (filterToolStripMenuItem.Checked)
            {
                lData = lData.FilteredList(TambonHelper.GlobalGazetteList);
            }

            mTable.Rows.Clear();
            foreach (RoyalGazette lEntry in lData)
            {
                DataRow lRow = mTable.NewRow();
                lRow["Description"] = lEntry.Description;
                lRow["Title"]       = lEntry;
                lRow["Volume"]      = lEntry.Volume;
                lRow["Issue"]       = lEntry.Issue;
                lRow["Page"]        = lEntry.PageInfo;
                lRow["Publication"] = lEntry.Publication;
                lRow["Signed"]      = lEntry.Sign;
                lRow["Effective"]   = lEntry.Effective;
                lRow["SignedBy"]    = lEntry.SignedBy;
                lRow["SignedByAs"]  = lEntry.SignedByPosition;
                lRow["Gazette"]     = lEntry;
                mTable.Rows.Add(lRow);
            }
            grid.DataSource = mTable;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public static RoyalGazetteList Load(String iFromFile)
        {
            StreamReader     lReader = null;
            XmlDocument      lXmlDoc = null;
            RoyalGazetteList RetVal  = null;

            try
            {
                if (!String.IsNullOrEmpty(iFromFile) && File.Exists(iFromFile))
                {
                    lReader = new StreamReader(iFromFile);
                    lXmlDoc = new XmlDocument();
                    lXmlDoc.LoadXml(lReader.ReadToEnd());
                    RetVal = RoyalGazetteList.Load(lXmlDoc);
                }
            }
            finally
            {
                if (lReader != null)
                {
                    lReader.Close();
                }
            }
            return(RetVal);
        }
Ejemplo n.º 6
0
 internal static void ParseNode(XmlNode iNode, RoyalGazetteList ioList)
 {
     if (iNode.HasChildNodes)
     {
         foreach (XmlNode lChildNode in iNode.ChildNodes)
         {
             if (lChildNode.Name == "year")
             {
                 ParseNode(lChildNode, ioList);
             }
             else if (lChildNode.Name == "decade")
             {
                 ParseNode(lChildNode, ioList);
             }
             else if (lChildNode.Name == "month")
             {
                 ParseNode(lChildNode, ioList);
             }
             else if (lChildNode.Name == "entry")
             {
                 ioList.Add(RoyalGazette.Load(lChildNode));
             }
         }
     }
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
 protected override void Clear()
 {
     base.Clear();
     mDaysBetweenPublicationAndEffective = new FrequencyCounter();
     mDaysBetweenSignAndPublication      = new FrequencyCounter();
     StrangeAnnouncements = new RoyalGazetteList();
 }
Ejemplo n.º 10
0
        public RoyalGazetteList SearchNews(DateTime date)
        {
            RoyalGazetteList result = new RoyalGazetteList();

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

            result.AddRange(DoParse(reader));
            return(result);
        }
Ejemplo n.º 12
0
 private void SetData(RoyalGazetteList value)
 {
     if (value != null)
     {
         mData = value;
         FillDataTable(mData);
         grid.Columns[mTable.Columns.Count - 1].Visible = false;
     }
 }
Ejemplo n.º 13
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            RoyalGazetteList lList = mData.FindDuplicates();

            if (lList.Count > 0)
            {
                ShowGazetteDialog(lList, false, "Duplicate entries");
            }
        }
Ejemplo n.º 14
0
        internal static void ShowGazetteNewsDialog(RoyalGazetteList iList)
        {
            var lNewGazetteEntries = iList.FilteredList(TambonHelper.GlobalGazetteList);

            if (lNewGazetteEntries.Count != 0)
            {
                ShowGazetteDialog(iList, true);
            }
        }
Ejemplo n.º 15
0
        private void BackgroundWorker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
        {
            RoyalGazetteList list = e.Result as RoyalGazetteList;

            if (list != null)
            {
                SearchFinished(this, new RoyalGazetteEventArgs(list));
            }
        }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
        internal static void ShowGazetteDialog(RoyalGazetteList iList, Boolean iFiltered, String iTitle)
        {
            var lDataForm = new RoyalGazetteViewer();

            lDataForm.Filtered = iFiltered;
            lDataForm.Data     = iList;
            if (!String.IsNullOrEmpty(iTitle))
            {
                lDataForm.Text = iTitle;
            }
            lDataForm.Show();
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
        public RoyalGazetteList AllAboutEntity(Int32 iGeocode, Boolean iIncludeSubEntities)
        {
            var retval = new RoyalGazetteList();

            foreach (RoyalGazette lEntry in this)
            {
                if (lEntry.IsAboutGeocode(iGeocode, iIncludeSubEntities))
                {
                    retval.Add(lEntry);
                }
            }
            return(retval);
        }
Ejemplo n.º 21
0
        protected RoyalGazetteList GetListDescription(String searchKey, Int32 volume, String description)
        {
            RoyalGazetteList result = DoGetList(searchKey, volume);

            if (result != null)
            {
                foreach (RoyalGazette entry in result)
                {
                    entry.Description = description;
                }
            }
            return(result);
        }
Ejemplo n.º 22
0
        private RoyalGazetteList DoParse(TextReader reader)
        {
            RoyalGazetteList result      = new RoyalGazetteList();
            String           currentLine = String.Empty;
            int           dataState      = -1;
            StringBuilder entryData      = new StringBuilder();

            try
            {
                while ((currentLine = reader.ReadLine()) != null)
                {
                    if (currentLine.Contains(PageStart))
                    {
                        String temp = currentLine.Substring(currentLine.LastIndexOf(PageStart) + PageStart.Length, 3).Trim();
                        _numberOfPages = Convert.ToInt32(temp);
                    }
                    else if (currentLine.StartsWith(EntryStart))
                    {
                        if (entryData.Length > 0)
                        {
                            var current = ParseSingeItem(entryData.ToString());
                            if (current != null)
                            {
                                result.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.Add(current);
                    }
                }
            }
            catch (IOException)
            {
            }

            return(result);
        }
Ejemplo n.º 23
0
        public RoyalGazetteList FilteredList(RoyalGazetteList iFilter)
        {
            var lResult = new RoyalGazetteList();

            foreach (RoyalGazette lEntry in this)
            {
                if (iFilter == null)
                {
                    lResult.Add(lEntry);
                }
                else if (!iFilter.Contains(lEntry))
                {
                    lResult.Add(lEntry);
                }
            }
            return(lResult);
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
        internal static RoyalGazetteList Load(XmlNode iNode)
        {
            RoyalGazetteList RetVal = null;

            if (iNode != null)
            {
                foreach (XmlNode lNode in iNode.ChildNodes)
                {
                    if (lNode != null && lNode.Name.Equals("gazette"))
                    {
                        RetVal = new RoyalGazetteList();
                        ParseNode(lNode, RetVal);
                    }
                }
            }

            return(RetVal);
        }
Ejemplo n.º 26
0
        private RoyalGazetteList CurrentSelection()
        {
            RoyalGazetteList retval = new RoyalGazetteList();

            foreach (DataGridViewRow lRow in grid.SelectedRows)
            {
                DataRowView lRowView = lRow.DataBoundItem as DataRowView;
                // Debug.Assert(lRowView != null);

                DataRow lDataRow = lRowView.Row;
                // Debug.Assert(lDataRow != null);

                RoyalGazette lGazette = lDataRow["Title"] as RoyalGazette;
                if (lGazette != null)
                {
                    retval.Add(lGazette);
                }
            }
            return(retval);
        }
Ejemplo n.º 27
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);
        }
Ejemplo n.º 28
0
        private void btn_GazetteLoad_Click(object sender, EventArgs e)
        {
            // DirectoryInfo lDirInfo = new DirectoryInfo("e:\\thailand\\dopa\\tambon\\gazette\\");

            string lDir = Path.Combine(Application.StartupPath, "gazette");

            if (Directory.Exists(lDir))
            {
                foreach (string lFilename in Directory.GetFiles(lDir, "Gazette*.XML"))
                {
                    RoyalGazetteList lCurrentGazetteList = RoyalGazetteList.Load(lFilename);
                    TambonHelper.GlobalGazetteList.AddRange(lCurrentGazetteList);
                }
                Boolean lHasEntries = (TambonHelper.GlobalGazetteList.Count > 0);
                btn_GazetteShow.Enabled    = lHasEntries;
                btn_GazetteShowAll.Enabled = lHasEntries;
            }
            else
            {
                MessageBox.Show(this, "Fatal error: Directory " + lDir + " is not existing." + Environment.NewLine + "Application will be terminated.", "Directory error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
        }
Ejemplo n.º 29
0
 public RoyalGazetteEventArgs(RoyalGazetteList data) : base()
 {
     Data = data;
 }
Ejemplo n.º 30
0
        private RoyalGazetteList DoParse(TextReader reader)
        {
            RoyalGazetteList result           = new RoyalGazetteList();
            String           currentLine      = String.Empty;
            Int32            dataState        = -1;
            Int32            currentLineIndex = 0;
            StringBuilder    entryData        = new StringBuilder();

            try
            {
                while ((currentLine = reader.ReadLine()) != null)
                {
                    currentLineIndex++;
                    currentLine = currentLine.Trim();
                    if (!String.IsNullOrWhiteSpace(currentLine))
                    {
                        if (currentLine.Contains(PageStart))
                        {
                            String temp = currentLine.Substring(currentLine.LastIndexOf(PageStart) + PageStart.Length + 1, 6);
                            temp           = temp.Substring(0, temp.IndexOf(' ')).Trim();
                            _numberOfPages = Convert.ToInt32(temp);
                            if (_numberOfPages > 100)
                            {
                                _numberOfPages = 1;  // something terrible went wrong with the search
                            }
                        }
                        else if (currentLine.StartsWith(EntryStart))
                        {
                            if (entryData.Length > 0)
                            {
                                var current = ParseSingeItem(entryData.ToString());
                                if (current != null)
                                {
                                    result.Add(current);
                                }
                                else
                                {
                                    dataState++;
                                    // failed to parse!
                                }
                                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.Add(current);
                    }
                }
            }
            catch (IOException)
            {
            }

            return(result);
        }