Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1st query added to find all tweets with links in. UI to show results.

  • Loading branch information...
commit 9cf6957f0d4f4e391deae07b126babbd7413ccf5 1 parent fc19b52
@AdaTheDev authored
View
19 ElasticTweets.Library/ElasticSearcher.cs
@@ -24,15 +24,15 @@ public ElasticSearcher(IClientProvider clientProvider, IElasticConnectionSetting
_client = _clientProvider.GetClient(_elasticConnectionSettings);
}
- public IEnumerable<Tweet> SearchRaw(IElasticQuery query)
+ public IEnumerable<Tweet> SearchRaw(IElasticQuery query, int maxDocuments)
{
- var response = ExecuteRaw(query.RawQueryText);
+ var response = ExecuteRaw(query.RawQueryText, maxDocuments);
return Results(response);
}
- public IEnumerable<Tweet> SearchClientApi(IElasticQuery query)
+ public IEnumerable<Tweet> Search(IElasticQuery query, int maxDocuments)
{
- var response = ExecuteClient(query.Builder);
+ var response = ExecuteDsl(query.Query, maxDocuments);
return Results(response);
}
@@ -40,14 +40,17 @@ private IEnumerable<Tweet> Results(IQueryResponse<Tweet> response)
{
return response.Documents;
}
- private IQueryResponse<Tweet> ExecuteRaw(string query)
+
+ private IQueryResponse<Tweet> ExecuteRaw(string query, int maxDocuments)
{
- return _client.SearchRaw<Tweet>(query);
+ var searchBuilder = new SearchBuilder();
+ searchBuilder.Query(query).Size(maxDocuments);
+ return _client.Search<Tweet>(searchBuilder);
}
- private IQueryResponse<Tweet> ExecuteClient(SearchBuilder searchBuilder)
+ private IQueryResponse<Tweet> ExecuteDsl(QueryDescriptor<Tweet> query, int maxDocuments)
{
- return _client.Search<Tweet>(searchBuilder);
+ return _client.Search<Tweet>(s => s.Query(query).Size(maxDocuments));
}
}
}
View
1  ElasticTweets.Library/ElasticTweets.Library.csproj
@@ -76,6 +76,7 @@
<Compile Include="Providers\ClientProvider.cs" />
<Compile Include="Providers\IClientProvider.cs" />
<Compile Include="Queries\IElasticQuery.cs" />
+ <Compile Include="Queries\QueryDiscoverer.cs" />
<Compile Include="Queries\TweetsContainingLinksQuery.cs" />
</ItemGroup>
<ItemGroup>
View
5 ElasticTweets.Library/Queries/IElasticQuery.cs
@@ -1,4 +1,5 @@
-using Nest.FactoryDsl;
+using ElasticTweets.Library.Data;
+using Nest;
namespace ElasticTweets.Library.Queries
{
@@ -6,6 +7,6 @@ public interface IElasticQuery
{
string Description { get; }
string RawQueryText { get; }
- SearchBuilder Builder { get; }
+ QueryDescriptor<Tweet> Query { get; }
}
}
View
19 ElasticTweets.Library/Queries/QueryDiscoverer.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Linq;
+using System.Reflection;
+
+namespace ElasticTweets.Library.Queries
+{
+ public class QueryDiscoverer
+ {
+ public IElasticQuery[] FindAll()
+ {
+ return
+ Assembly
+ .GetExecutingAssembly()
+ .GetTypes()
+ .Where(t => typeof(IElasticQuery).IsAssignableFrom(t) && t.IsClass)
+ .Select(query => (IElasticQuery) Activator.CreateInstance(query)).ToArray();
+ }
+ }
+}
View
20 ElasticTweets.Library/Queries/TweetsContainingLinksQuery.cs
@@ -1,6 +1,6 @@
-using Nest.FactoryDsl;
-using Nest.FactoryDsl.Filter;
-using Nest.FactoryDsl.Query;
+using System.Linq;
+using ElasticTweets.Library.Data;
+using Nest;
namespace ElasticTweets.Library.Queries
{
@@ -11,30 +11,30 @@ public class TweetsContainingLinksQuery : IElasticQuery
* "query" : {
* "constant_score" : {
* "filter" : {
- * "exists" : { "field" : "url"}
+ * "exists" : { "field" : "entities.urls.url"}
* }
* }
* }
* }
*/
private const string RawQuery =
- "{ \"query\" : {\"constant_score\" : {\"filter\" : {\"exists\" : { \"field\" : \"url\"}}}}}";
+ "{ \"query\" : {\"constant_score\" : {\"filter\" : {\"exists\" : { \"field\" : \"entities.urls.url\"}}}}}";
public string Description
{
- get { return "Finds tweets that contain links"; }
+ get { return "Tweets that contain links"; }
}
public string RawQueryText { get { return RawQuery; } }
- public SearchBuilder Builder
+ public QueryDescriptor<Tweet> Query
{
get
{
- var searchBuilder = new SearchBuilder();
- searchBuilder.Query(new ConstantScoreQueryBuilder(new ExistsFilterBuilder("url")));
- return searchBuilder;
+ var query = new QueryDescriptor<Tweet>();
+ query.ConstantScore(cs => cs.Filter(fd => fd.Exists(t =>t.entities.urls.First().url)));
+ return query;
}
}
}
View
5 ElasticTweets.sln
@@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticTweets.Library", "El
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElasticTweets.Library.UnitTests", "ElasticTweets.Library.UnitTests\ElasticTweets.Library.UnitTests.csproj", "{5300D2DF-1462-4C4D-B3AF-D7BEE82846F6}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9ED9F41C-4F7C-4761-BDCB-964CE29AEDC6}"
+ ProjectSection(SolutionItems) = preProject
+ readme.txt = readme.txt
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
View
187 ElasticTweets/Form1.Designer.cs
@@ -31,20 +31,21 @@ private void InitializeComponent()
this.folderDialog = new System.Windows.Forms.FolderBrowserDialog();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
- this.lblElasticSearch = new System.Windows.Forms.Label();
this.btnChangeDirectory = new System.Windows.Forms.Button();
this.btnImport = new System.Windows.Forms.Button();
+ this.txtSourceDirectory = new System.Windows.Forms.TextBox();
+ this.lblSourceDirectory = new System.Windows.Forms.Label();
+ this.tabPage2 = new System.Windows.Forms.TabPage();
+ this.cboQueries = new System.Windows.Forms.ComboBox();
+ this.grdSearchResults = new System.Windows.Forms.DataGridView();
+ this.btnSearch = new System.Windows.Forms.Button();
+ this.lblElasticSearch = new System.Windows.Forms.Label();
this.txtIndexName = new System.Windows.Forms.TextBox();
this.lblIndexName = new System.Windows.Forms.Label();
this.txtPort = new System.Windows.Forms.TextBox();
this.lblPort = new System.Windows.Forms.Label();
this.txtHost = new System.Windows.Forms.TextBox();
this.lblElasticHost = new System.Windows.Forms.Label();
- this.txtSourceDirectory = new System.Windows.Forms.TextBox();
- this.lblSourceDirectory = new System.Windows.Forms.Label();
- this.tabPage2 = new System.Windows.Forms.TabPage();
- this.grdSearchResults = new System.Windows.Forms.DataGridView();
- this.btnSearch = new System.Windows.Forms.Button();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
@@ -59,43 +60,26 @@ private void InitializeComponent()
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
- this.tabControl1.Location = new System.Drawing.Point(8, 12);
+ this.tabControl1.Location = new System.Drawing.Point(8, 49);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
- this.tabControl1.Size = new System.Drawing.Size(578, 378);
+ this.tabControl1.Size = new System.Drawing.Size(970, 341);
this.tabControl1.TabIndex = 11;
//
// tabPage1
//
- this.tabPage1.Controls.Add(this.lblElasticSearch);
this.tabPage1.Controls.Add(this.btnChangeDirectory);
this.tabPage1.Controls.Add(this.btnImport);
- this.tabPage1.Controls.Add(this.txtIndexName);
- this.tabPage1.Controls.Add(this.lblIndexName);
- this.tabPage1.Controls.Add(this.txtPort);
- this.tabPage1.Controls.Add(this.lblPort);
- this.tabPage1.Controls.Add(this.txtHost);
- this.tabPage1.Controls.Add(this.lblElasticHost);
this.tabPage1.Controls.Add(this.txtSourceDirectory);
this.tabPage1.Controls.Add(this.lblSourceDirectory);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
- this.tabPage1.Size = new System.Drawing.Size(570, 352);
+ this.tabPage1.Size = new System.Drawing.Size(866, 315);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Import";
this.tabPage1.UseVisualStyleBackColor = true;
//
- // lblElasticSearch
- //
- this.lblElasticSearch.AutoSize = true;
- this.lblElasticSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.lblElasticSearch.Location = new System.Drawing.Point(20, 51);
- this.lblElasticSearch.Name = "lblElasticSearch";
- this.lblElasticSearch.Size = new System.Drawing.Size(203, 13);
- this.lblElasticSearch.TabIndex = 21;
- this.lblElasticSearch.Text = "ElasticSearch Connection Settings";
- //
// btnChangeDirectory
//
this.btnChangeDirectory.Location = new System.Drawing.Point(487, 18);
@@ -108,7 +92,7 @@ private void InitializeComponent()
//
// btnImport
//
- this.btnImport.Location = new System.Drawing.Point(23, 157);
+ this.btnImport.Location = new System.Drawing.Point(23, 54);
this.btnImport.Name = "btnImport";
this.btnImport.Size = new System.Drawing.Size(72, 26);
this.btnImport.TabIndex = 19;
@@ -116,57 +100,6 @@ private void InitializeComponent()
this.btnImport.UseVisualStyleBackColor = true;
this.btnImport.Click += new System.EventHandler(this.btnImport_Click);
//
- // txtIndexName
- //
- this.txtIndexName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtIndexName.Location = new System.Drawing.Point(91, 111);
- this.txtIndexName.Name = "txtIndexName";
- this.txtIndexName.Size = new System.Drawing.Size(132, 20);
- this.txtIndexName.TabIndex = 18;
- //
- // lblIndexName
- //
- this.lblIndexName.AutoSize = true;
- this.lblIndexName.Location = new System.Drawing.Point(21, 116);
- this.lblIndexName.Name = "lblIndexName";
- this.lblIndexName.Size = new System.Drawing.Size(64, 13);
- this.lblIndexName.TabIndex = 17;
- this.lblIndexName.Text = "Index Name";
- //
- // txtPort
- //
- this.txtPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtPort.Location = new System.Drawing.Point(91, 88);
- this.txtPort.Name = "txtPort";
- this.txtPort.Size = new System.Drawing.Size(40, 20);
- this.txtPort.TabIndex = 16;
- //
- // lblPort
- //
- this.lblPort.AutoSize = true;
- this.lblPort.Location = new System.Drawing.Point(20, 93);
- this.lblPort.Name = "lblPort";
- this.lblPort.Size = new System.Drawing.Size(26, 13);
- this.lblPort.TabIndex = 15;
- this.lblPort.Text = "Port";
- //
- // txtHost
- //
- this.txtHost.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- this.txtHost.Location = new System.Drawing.Point(91, 65);
- this.txtHost.Name = "txtHost";
- this.txtHost.Size = new System.Drawing.Size(132, 20);
- this.txtHost.TabIndex = 14;
- //
- // lblElasticHost
- //
- this.lblElasticHost.AutoSize = true;
- this.lblElasticHost.Location = new System.Drawing.Point(20, 69);
- this.lblElasticHost.Name = "lblElasticHost";
- this.lblElasticHost.Size = new System.Drawing.Size(29, 13);
- this.lblElasticHost.TabIndex = 13;
- this.lblElasticHost.Text = "Host";
- //
// txtSourceDirectory
//
this.txtSourceDirectory.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
@@ -186,16 +119,25 @@ private void InitializeComponent()
//
// tabPage2
//
+ this.tabPage2.Controls.Add(this.cboQueries);
this.tabPage2.Controls.Add(this.grdSearchResults);
this.tabPage2.Controls.Add(this.btnSearch);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
- this.tabPage2.Size = new System.Drawing.Size(570, 352);
+ this.tabPage2.Size = new System.Drawing.Size(962, 315);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Query";
this.tabPage2.UseVisualStyleBackColor = true;
//
+ // cboQueries
+ //
+ this.cboQueries.FormattingEnabled = true;
+ this.cboQueries.Location = new System.Drawing.Point(6, 6);
+ this.cboQueries.Name = "cboQueries";
+ this.cboQueries.Size = new System.Drawing.Size(378, 21);
+ this.cboQueries.TabIndex = 12;
+ //
// grdSearchResults
//
this.grdSearchResults.AllowUserToAddRows = false;
@@ -204,12 +146,12 @@ private void InitializeComponent()
this.grdSearchResults.Location = new System.Drawing.Point(6, 35);
this.grdSearchResults.Name = "grdSearchResults";
this.grdSearchResults.ReadOnly = true;
- this.grdSearchResults.Size = new System.Drawing.Size(558, 297);
+ this.grdSearchResults.Size = new System.Drawing.Size(950, 297);
this.grdSearchResults.TabIndex = 1;
//
// btnSearch
//
- this.btnSearch.Location = new System.Drawing.Point(6, 6);
+ this.btnSearch.Location = new System.Drawing.Point(390, 6);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(75, 23);
this.btnSearch.TabIndex = 0;
@@ -217,21 +159,91 @@ private void InitializeComponent()
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
+ // lblElasticSearch
+ //
+ this.lblElasticSearch.AutoSize = true;
+ this.lblElasticSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.lblElasticSearch.Location = new System.Drawing.Point(12, 9);
+ this.lblElasticSearch.Name = "lblElasticSearch";
+ this.lblElasticSearch.Size = new System.Drawing.Size(203, 13);
+ this.lblElasticSearch.TabIndex = 28;
+ this.lblElasticSearch.Text = "ElasticSearch Connection Settings";
+ //
+ // txtIndexName
+ //
+ this.txtIndexName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtIndexName.Location = new System.Drawing.Point(362, 23);
+ this.txtIndexName.Name = "txtIndexName";
+ this.txtIndexName.Size = new System.Drawing.Size(132, 20);
+ this.txtIndexName.TabIndex = 27;
+ //
+ // lblIndexName
+ //
+ this.lblIndexName.AutoSize = true;
+ this.lblIndexName.Location = new System.Drawing.Point(292, 25);
+ this.lblIndexName.Name = "lblIndexName";
+ this.lblIndexName.Size = new System.Drawing.Size(64, 13);
+ this.lblIndexName.TabIndex = 26;
+ this.lblIndexName.Text = "Index Name";
+ //
+ // txtPort
+ //
+ this.txtPort.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtPort.Location = new System.Drawing.Point(232, 23);
+ this.txtPort.Name = "txtPort";
+ this.txtPort.Size = new System.Drawing.Size(40, 20);
+ this.txtPort.TabIndex = 25;
+ //
+ // lblPort
+ //
+ this.lblPort.AutoSize = true;
+ this.lblPort.Location = new System.Drawing.Point(200, 25);
+ this.lblPort.Name = "lblPort";
+ this.lblPort.Size = new System.Drawing.Size(26, 13);
+ this.lblPort.TabIndex = 24;
+ this.lblPort.Text = "Port";
+ //
+ // txtHost
+ //
+ this.txtHost.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.txtHost.Location = new System.Drawing.Point(47, 23);
+ this.txtHost.Name = "txtHost";
+ this.txtHost.Size = new System.Drawing.Size(132, 20);
+ this.txtHost.TabIndex = 23;
+ //
+ // lblElasticHost
+ //
+ this.lblElasticHost.AutoSize = true;
+ this.lblElasticHost.Location = new System.Drawing.Point(12, 27);
+ this.lblElasticHost.Name = "lblElasticHost";
+ this.lblElasticHost.Size = new System.Drawing.Size(29, 13);
+ this.lblElasticHost.TabIndex = 22;
+ this.lblElasticHost.Text = "Host";
+ //
// frmImport
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Gainsboro;
- this.ClientSize = new System.Drawing.Size(598, 402);
+ this.ClientSize = new System.Drawing.Size(990, 402);
+ this.Controls.Add(this.lblElasticSearch);
+ this.Controls.Add(this.txtIndexName);
+ this.Controls.Add(this.lblIndexName);
+ this.Controls.Add(this.txtPort);
+ this.Controls.Add(this.lblPort);
+ this.Controls.Add(this.txtHost);
+ this.Controls.Add(this.lblElasticHost);
this.Controls.Add(this.tabControl1);
this.Name = "frmImport";
this.Text = "ElasticTweets - Import";
+ this.Load += new System.EventHandler(this.frmImport_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.grdSearchResults)).EndInit();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -241,19 +253,20 @@ private void InitializeComponent()
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
- private System.Windows.Forms.Label lblElasticSearch;
private System.Windows.Forms.Button btnChangeDirectory;
private System.Windows.Forms.Button btnImport;
+ private System.Windows.Forms.TextBox txtSourceDirectory;
+ private System.Windows.Forms.Label lblSourceDirectory;
+ private System.Windows.Forms.DataGridView grdSearchResults;
+ private System.Windows.Forms.Button btnSearch;
+ private System.Windows.Forms.ComboBox cboQueries;
+ private System.Windows.Forms.Label lblElasticSearch;
private System.Windows.Forms.TextBox txtIndexName;
private System.Windows.Forms.Label lblIndexName;
private System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.Label lblPort;
private System.Windows.Forms.TextBox txtHost;
private System.Windows.Forms.Label lblElasticHost;
- private System.Windows.Forms.TextBox txtSourceDirectory;
- private System.Windows.Forms.Label lblSourceDirectory;
- private System.Windows.Forms.DataGridView grdSearchResults;
- private System.Windows.Forms.Button btnSearch;
}
}
View
87 ElasticTweets/Form1.cs
@@ -7,13 +7,17 @@
using System.Threading.Tasks;
using System.Windows.Forms;
using ElasticTweets.Library;
+using ElasticTweets.Library.Data;
using ElasticTweets.Library.IO;
using ElasticTweets.Library.Providers;
+using ElasticTweets.Library.Queries;
namespace ElasticTweets
{
public partial class frmImport : Form
{
+ private IElasticQuery[] _queries;
+
public frmImport()
{
InitializeComponent();
@@ -29,7 +33,7 @@ private void DoImport()
}
var fileSystem = new FileSystem();
- var connectionSettings = new ElasticConnectionSettings(txtHost.Text, int.Parse(txtPort.Text), txtIndexName.Text);
+ var connectionSettings = GetElasticConnectionSettings();
try
{
@@ -64,6 +68,11 @@ private void DoImport()
}
}
+ private ElasticConnectionSettings GetElasticConnectionSettings()
+ {
+ return new ElasticConnectionSettings(txtHost.Text, int.Parse(txtPort.Text), txtIndexName.Text);
+ }
+
private void ToggleControls(bool enabled)
{
if (txtSourceDirectory.InvokeRequired)
@@ -88,17 +97,22 @@ private string ValidateInputs()
if (!Directory.Exists(txtSourceDirectory.Text))
return "The chosen data directory doesn't exist";
+
+ return ValidateConnectionSettings();
+ }
- if (String.IsNullOrWhiteSpace(txtHost.Text))
- return "Please specify the ElasticSearch host name";
+ private string ValidateConnectionSettings()
+ {
+ if (String.IsNullOrWhiteSpace(txtHost.Text))
+ return "Please specify the ElasticSearch host name";
int port;
- if (String.IsNullOrWhiteSpace(txtPort.Text) || !int.TryParse(txtPort.Text, out port))
- return "Please enter a valid ElasticSearch port number";
+ if (String.IsNullOrWhiteSpace(txtPort.Text) || !int.TryParse(txtPort.Text, out port))
+ return "Please enter a valid ElasticSearch port number";
- if (String.IsNullOrWhiteSpace(txtIndexName.Text))
+ if (String.IsNullOrWhiteSpace(txtIndexName.Text))
return "Please enter the name of the index to import into";
-
+
return String.Empty;
}
@@ -110,7 +124,55 @@ private void btnChangeDirectory_Click(object sender, EventArgs e)
private void btnSearch_Click(object sender, EventArgs e)
{
- MessageBox.Show("Schhhhtop...it's not ready yet!");
+ string error = ValidateConnectionSettings();
+ if (error != String.Empty)
+ MessageBox.Show(error);
+ else
+ {
+ var query = cboQueries.SelectedItem as IElasticQuery;
+ var searcher = new ElasticSearcher(new ClientProvider(), GetElasticConnectionSettings());
+ var results = searcher.Search(query, 1000).ToArray();
+ grdSearchResults.AutoGenerateColumns = false;
+ grdSearchResults.CellFormatting -= grdSearchResults_CellFormatting;
+ grdSearchResults.Columns.Clear();
+ var column = new DataGridViewColumn(new DataGridViewTextBoxCell())
+ {
+ Name="Date",
+ DataPropertyName = "created_at",
+ Width = 100
+ };
+ grdSearchResults.Columns.Add(column);
+
+ column = new DataGridViewColumn(new DataGridViewTextBoxCell())
+ {
+ Name="Tweet",
+ DataPropertyName = "text",
+ Width = 600
+ };
+ grdSearchResults.Columns.Add(column);
+
+ column = new DataGridViewColumn(new DataGridViewTextBoxCell())
+ {
+ Name = "URL",
+ Width = 600
+ };
+ grdSearchResults.Columns.Add(column);
+ grdSearchResults.CellFormatting += grdSearchResults_CellFormatting;
+ grdSearchResults.DataSource = results;
+ }
+ }
+
+ void grdSearchResults_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
+ {
+ if (e.ColumnIndex == 0)
+ {
+ e.Value = DateTime.ParseExact(e.Value as string, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.CurrentUICulture, DateTimeStyles.None).ToString("dd MMM yyyy HH:mm");
+ }
+ else if (e.ColumnIndex == 2)
+ {
+ var row = grdSearchResults.Rows[e.RowIndex];
+ row.Cells[e.ColumnIndex].Value = ((Tweet) row.DataBoundItem).entities.urls.First().expanded_url;
+ }
}
private void btnImport_Click(object sender, EventArgs e)
@@ -119,5 +181,14 @@ private void btnImport_Click(object sender, EventArgs e)
Task.Factory.StartNew(DoImport).ContinueWith(_ => ToggleControls(true));
}
+
+ private void frmImport_Load(object sender, EventArgs e)
+ {
+ var queryDiscoverer = new QueryDiscoverer();
+
+ cboQueries.DataSource = queryDiscoverer.FindAll();
+ cboQueries.DisplayMember = "Description";
+ cboQueries.ValueMember = "Description";
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.