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; }
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 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); }
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)); } } } }
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 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); }
protected override void Clear() { base.Clear(); mDaysBetweenPublicationAndEffective = new FrequencyCounter(); mDaysBetweenSignAndPublication = new FrequencyCounter(); StrangeAnnouncements = new RoyalGazetteList(); }
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); }
private void SetData(RoyalGazetteList value) { if (value != null) { mData = value; FillDataTable(mData); grid.Columns[mTable.Columns.Count - 1].Visible = false; } }
private void btnCheck_Click(object sender, EventArgs e) { RoyalGazetteList lList = mData.FindDuplicates(); if (lList.Count > 0) { ShowGazetteDialog(lList, false, "Duplicate entries"); } }
internal static void ShowGazetteNewsDialog(RoyalGazetteList iList) { var lNewGazetteEntries = iList.FilteredList(TambonHelper.GlobalGazetteList); if (lNewGazetteEntries.Count != 0) { ShowGazetteDialog(iList, true); } }
private void BackgroundWorker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e) { RoyalGazetteList list = e.Result as RoyalGazetteList; if (list != null) { SearchFinished(this, new RoyalGazetteEventArgs(list)); } }
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)); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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(); } }
public RoyalGazetteEventArgs(RoyalGazetteList data) : base() { Data = data; }
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); }