Skip to content

Commit

Permalink
WIP5
Browse files Browse the repository at this point in the history
  • Loading branch information
meebey committed Nov 21, 2013
1 parent 6413cf2 commit eb64cb2
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 6 deletions.
15 changes: 14 additions & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ TWITTERIZER_ASSEMBLY_TARGET = $(OUTPUT_DIR)/$(TWITTERIZER_ASSEMBLY_NAME)
TWITTERIZER_BUILD_FILE = $(TWITTERIZER_SRCDIR)/Twitterizer2.csproj
TWITTERIZER_XBUILD_FLAGS = $(XBUILD_FLAGS) /p:PostBuildEvent=

TWITTERIZER_STREAMING_SRCDIR = $(srcdir)/$(TWITTERIZER_SUBDIR)/Twitterizer2.Streaming
TWITTERIZER_STREAMING_SOURCE_FILES = $(foreach pattern, ../*.cs $(SOURCE_PATTERNS), $(wildcard $(TWITTERIZER_STREAMING_SRCDIR)/$(pattern)))
TWITTERIZER_STREAMING_EXTRA_FILES = $(TWITTERIZER_STREAMING_BUILD_FILE)
TWITTERIZER_STREAMING_ASSEMBLY_NAME = Twitterizer2.Streaming.dll
TWITTERIZER_STREAMING_ASSEMBLY_TARGET = $(OUTPUT_DIR)/$(TWITTERIZER_STREAMING_ASSEMBLY_NAME)
TWITTERIZER_STREAMING_BUILD_FILE = $(TWITTERIZER_STREAMING_SRCDIR)/Twitterizer2.Streaming.csproj
TWITTERIZER_STREAMING_XBUILD_FLAGS = $(XBUILD_FLAGS)

JABBER_NET_SUBDIR = agsxmpp/agsxmpp
JABBER_NET_SRCDIR = $(srcdir)/$(JABBER_NET_SUBDIR)
JABBER_NET_SOURCE_FILES = $(foreach pattern, $(SOURCE_PATTERNS), $(wildcard $(JABBER_NET_SRCDIR)/$(pattern)))
Expand Down Expand Up @@ -161,7 +169,8 @@ if ENABLE_ENGINE_TWITTER
EXTRA_JSON_LIBS = \
$(JSON_ASSEMBLY_TARGET) $(JSON_ASSEMBLY_TARGET).mdb
EXTRA_TWITTER_LIBS = \
$(TWITTERIZER_ASSEMBLY_TARGET) $(TWITTERIZER_ASSEMBLY_TARGET).mdb
$(TWITTERIZER_ASSEMBLY_TARGET) $(TWITTERIZER_ASSEMBLY_TARGET).mdb \
$(TWITTERIZER_STREAMING_ASSEMBLY_TARGET) $(TWITTERIZER_STREAMING_ASSEMBLY_TARGET).mdb
endif
if ENABLE_ENGINE_XMPP
EXTRA_XMPP_LIBS = \
Expand Down Expand Up @@ -206,6 +215,7 @@ EXTRA_DIST = \
$(SERVICESTACK_COMMON_SRCDIR) $(SERVICESTACK_COMMON_EXTRA_FILES) \
$(JSON_SRCDIR) $(JSON_EXTRA_FILES) \
$(TWITTERIZER_SRCDIR) $(TWITTERIZER_EXTRA_FILES) \
$(TWITTERIZER_STREAMING_SRCDIR) $(TWITTERIZER_STREAMING_EXTRA_FILES) \
$(JABBER_NET_SRCDIR) $(JABBER_NET_EXTRA_FILES) \
$(DB4O_SRCDIR) $(DB4O_EXTRA_FILES) \
$(STARKSOFTPROXY_SRCDIR) $(STARKSOFTPROXY_EXTRA_FILES) \
Expand Down Expand Up @@ -248,6 +258,9 @@ $(JSON_ASSEMBLY_TARGET) $(JSON_ASSEMBLY_TARGET).mdb: $(JSON_BUILD_FILE) $(JSON_S
$(TWITTERIZER_ASSEMBLY_TARGET) $(TWITTERIZER_ASSEMBLY_TARGET).mdb: $(TWITTERIZER_BUILD_FILE) $(TWITTERIZER_SOURCE_FILES)
$(XBUILD) $(TWITTERIZER_XBUILD_FLAGS) $(TWITTERIZER_BUILD_FILE)

$(TWITTERIZER_STREAMING_ASSEMBLY_TARGET) $(TWITTERIZER_STREAMING_ASSEMBLY_TARGET).mdb: $(TWITTERIZER_STREAMING_BUILD_FILE) $(TWITTERIZER_STREAMING_SOURCE_FILES)
$(XBUILD) $(TWITTERIZER_STREAMING_XBUILD_FLAGS) $(TWITTERIZER_STREAMING_BUILD_FILE)

$(JABBER_NET_ASSEMBLY_TARGET) $(JABBER_NET_ASSEMBLY_TARGET).mdb: $(JABBER_NET_BUILD_FILE) $(JABBER_NET_SOURCE_FILES)
$(XBUILD) $(JABBER_NET_XBUILD_FLAGS) $(JABBER_NET_BUILD_FILE)

Expand Down
5 changes: 5 additions & 0 deletions src/Engine-Twitter/Engine-Twitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Protocols\Twitter\TwitterProtocolManager.cs" />
<Compile Include="Protocols\Twitter\TwitterMessageBuilder.cs" />
<Compile Include="Protocols\Twitter\TwitterSearchStream.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Protocols\" />
Expand All @@ -61,6 +62,10 @@
<Project>{2FDC3492-6B9E-4771-9755-7892C9CB1E96}</Project>
<Name>Twitterizer2</Name>
</ProjectReference>
<ProjectReference Include="..\..\lib\Twitterizer\Twitterizer2.Streaming\Twitterizer2.Streaming.csproj">
<Project>{AFDC57ED-C013-4581-9D06-54D8A42D696D}</Project>
<Name>Twitterizer2.Streaming</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
11 changes: 7 additions & 4 deletions src/Engine-Twitter/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ ASSEMBLY_TARGET = $(TARGET_DIR)/$(ASSEMBLY_FILENAME)
SOURCES = $(top_srcdir)/src/AssemblyVersion.cs \
AssemblyInfo.cs \
Protocols/Twitter/TwitterProtocolManager.cs \
Protocols/Twitter/TwitterMessageBuilder.cs
Protocols/Twitter/TwitterMessageBuilder.cs \
Protocols/Twitter/TwitterSearchStream.cs

REFERENCES = $(LOG4NET_LIBS) \
$(SMARTIRC4NET_LIBS) \
System.Web \
System.Core

DLL_REFERENCES = $(TARGET_DIR)/Twitterizer2.dll \
$(TARGET_DIR)/smuxi-common.dll \
$(TARGET_DIR)/smuxi-engine.dll
DLL_REFERENCES = \
$(TARGET_DIR)/Twitterizer2.dll \
$(TARGET_DIR)/Twitterizer2.Streaming.dll \
$(TARGET_DIR)/smuxi-common.dll \
$(TARGET_DIR)/smuxi-engine.dll

SOURCES_BUILD = $(addprefix $(srcdir)/, $(SOURCES))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public override void Connect(FrontendManager fm, ServerModel server)
if (!whitelist.Contains("api.twitter.com")) {
whitelist.Add("api.twitter.com");
}
if (!whitelist.Contains("stream.twitter.com")) {
whitelist.Add("stream.twitter.com");
}
}
}

Expand Down Expand Up @@ -1069,6 +1072,9 @@ public void CommandSearch(CommandModel cmd)
}
}
Session.SyncChat(chat);

var stream = new TwitterSearchStream(this, chat, keyword,
f_OAuthTokens, f_WebProxy);
}

private List<TwitterDirectMessage> SortTimeline(TwitterDirectMessageCollection timeline)
Expand Down Expand Up @@ -1744,7 +1750,7 @@ private bool IsTemporilyErrorResponse<T>(TwitterResponse<T> response)
return false;
}

private PersonModel GetPerson(TwitterUser user)
internal PersonModel GetPerson(TwitterUser user)
{
if (user == null) {
throw new ArgumentNullException("user");
Expand Down
132 changes: 132 additions & 0 deletions src/Engine-Twitter/Protocols/Twitter/TwitterSearchStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Smuxi - Smart MUltipleXed Irc
//
// Copyright (c) 2013 Mirco Bauer <meebey@meebey.net>
//
// Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Net;
using Twitterizer;
using Twitterizer.Streaming;
using Smuxi.Common;

namespace Smuxi.Engine
{
public class TwitterSearchStream
{
#if LOG4NET
static readonly log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endif
TwitterProtocolManager ProtocolManager { get; set; }
Session Session { get; set; }
TwitterStream Stream { get; set; }
GroupChatModel Chat { get; set; }

public TwitterSearchStream(TwitterProtocolManager protocolManager,
GroupChatModel chat, string keyword,
OAuthTokens tokens, WebProxy proxy)
{
if (protocolManager == null) {
throw new ArgumentNullException("protocolManager");
}
if (chat == null) {
throw new ArgumentNullException("chat");
}
if (keyword == null) {
throw new ArgumentNullException("keyword");
}
if (tokens == null) {
throw new ArgumentNullException("tokens");
}

ProtocolManager = protocolManager;
Session = protocolManager.Session;
Chat = chat;

var options = new StreamOptions();
options.Track.Add(keyword);

Stream = new TwitterStream(tokens, null, options);
Stream.Proxy = proxy;
Stream.StartPublicStream(OnStreamStopped, OnStatusCreated, OnStatusDeleted, OnEvent);
}

protected TwitterMessageBuilder CreateMessageBuilder()
{
var builder = new TwitterMessageBuilder();
builder.ApplyConfig(Session.UserConfig);
return builder;
}

void OnStreamStopped(StopReasons reason)
{
Trace.Call(reason);

try {
Session.DisableChat(Chat);
} catch (Exception ex) {
#if LOG4NET
Logger.Error("OnStreamStopped()", ex);
#endif
}
}

void OnStatusCreated(TwitterStatus status)
{
Trace.Call(status);

try {
var sender = ProtocolManager.GetPerson(status.User);
var userId = status.User.Id.ToString();
if (!Chat.UnsafePersons.ContainsKey(userId)) {
Session.AddPersonToGroupChat(Chat, sender);
}
var msg = CreateMessageBuilder().
Append(status, sender).
ToMessage();
Session.AddMessageToChat(Chat, msg);
} catch (Exception ex) {
#if LOG4NET
Logger.Error("OnStatusCreated()", ex);
#endif
}
}

void OnStatusDeleted(TwitterStreamDeletedEvent status)
{
Trace.Call(status);

try {
} catch (Exception ex) {
#if LOG4NET
Logger.Error("OnStatusDeleted()", ex);
#endif
}
}

void OnEvent(TwitterStreamEvent @event)
{
Trace.Call(@event);

try {
} catch (Exception ex) {
#if LOG4NET
Logger.Error("OnEvent()", ex);
#endif
}
}
}
}
14 changes: 14 additions & 0 deletions src/smuxi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarkSoftProxy", "..\lib\St
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend-GNOME-Twitter", "Frontend-GNOME-Twitter\Frontend-GNOME-Twitter.csproj", "{298A5895-D8C8-45EB-AC57-1B6AAD05D6AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Twitterizer2.Streaming", "..\lib\Twitterizer\Twitterizer2.Streaming\Twitterizer2.Streaming.csproj", "{AFDC57ED-C013-4581-9D06-54D8A42D696D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Expand Down Expand Up @@ -152,6 +154,8 @@ Global
{3F8CF2C1-EA37-444F-8693-A3A00B1131D2}.Release-Win32|x86.Build.0 = Release|Any CPU
{405874F0-A58A-4E79-8766-2150D069F691}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{405874F0-A58A-4E79-8766-2150D069F691}.Debug|Any CPU.Build.0 = Debug|Any CPU
{405874F0-A58A-4E79-8766-2150D069F691}.Debug-Win32|Any CPU.ActiveCfg = Release|Any CPU
{405874F0-A58A-4E79-8766-2150D069F691}.Debug-Win32|Any CPU.Build.0 = Release|Any CPU
{405874F0-A58A-4E79-8766-2150D069F691}.Debug-Win32|x86.ActiveCfg = Debug-Win32|x86
{405874F0-A58A-4E79-8766-2150D069F691}.Debug-Win32|x86.Build.0 = Debug-Win32|x86
{405874F0-A58A-4E79-8766-2150D069F691}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -278,6 +282,16 @@ Global
{AB347741-B8CC-4B6B-BD39-826C77BE0694}.Debug-Win32|Any CPU.Build.0 = Debug|Any CPU
{AB347741-B8CC-4B6B-BD39-826C77BE0694}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB347741-B8CC-4B6B-BD39-826C77BE0694}.Release|Any CPU.Build.0 = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug-Win32|Any CPU.ActiveCfg = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug-Win32|Any CPU.Build.0 = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug-Win32|x86.ActiveCfg = Debug|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Debug-Win32|x86.Build.0 = Debug|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Release|Any CPU.Build.0 = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Release-Win32|x86.ActiveCfg = Release|Any CPU
{AFDC57ED-C013-4581-9D06-54D8A42D696D}.Release-Win32|x86.Build.0 = Release|Any CPU
{B68687B3-E45A-410E-BAE6-A7B2590E17B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B68687B3-E45A-410E-BAE6-A7B2590E17B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B68687B3-E45A-410E-BAE6-A7B2590E17B1}.Debug-Win32|x86.ActiveCfg = Debug-Win32|x86
Expand Down

0 comments on commit eb64cb2

Please sign in to comment.