/// <summary> /// ストリーミング接続を行います。 /// </summary> public StreamingConnection ConnectNew( CredentialProvider provider, StreamingDescription desc) { HttpWebRequest request; var streaming = provider.RequestStreamingAPI( GetStreamingUri(desc.Type), GetStreamingMethod(desc.Type), BuildArguments(desc), out request); if (streaming == null) { throw new InvalidOperationException("接続に失敗しました。"); } var con = new StreamingConnection(this, provider, request, streaming, desc.Timeout); if (con == null) { throw new InvalidOperationException("受信開始に失敗しました。"); } lock (conLock) { connections.Add(con); } return(con); }
/// <summary> /// Starting streaming and get streaming controller. /// </summary> /// <param name="provider">using credential</param> /// <param name="type">type of streaming</param> /// <param name="delimitered">delimiter length</param> /// <param name="count">backlog count</param> /// <param name="follow">following user's id</param> /// <param name="track">tracking keywords</param> /// <param name="locations">location area of tweet</param> /// <param name="repliesAll">use @replies=all option</param> public static StreamingController BeginStreaming (CredentialProvider provider, StreamingType type, int? delimitered = null, int? count = null, string follow = null, string track = null, string locations = null, bool repliesAll = false) { CredentialProvider.RequestMethod reqmethod = CredentialProvider.RequestMethod.GET; // argument check switch (type) { case StreamingType.firehose: if (!String.IsNullOrWhiteSpace(follow) || !String.IsNullOrWhiteSpace(track) || !String.IsNullOrWhiteSpace(locations)) throw new ArgumentException("Invalid argument is setted."); break; case StreamingType.gardenhose: if (count != null && !String.IsNullOrWhiteSpace(follow) || !String.IsNullOrWhiteSpace(track) || !String.IsNullOrWhiteSpace(locations)) throw new ArgumentException("Invalid argument is setted."); break; case StreamingType.sample: if (count != null && !String.IsNullOrWhiteSpace(follow) || !String.IsNullOrWhiteSpace(track) || !String.IsNullOrWhiteSpace(locations)) throw new ArgumentException("Invalid argument is setted."); break; case StreamingType.birddog: if (!String.IsNullOrWhiteSpace(track) || !String.IsNullOrWhiteSpace(locations)) throw new ArgumentException("Invalid argument is setted."); reqmethod = CredentialProvider.RequestMethod.POST; break; case StreamingType.shadow: if (!String.IsNullOrWhiteSpace(track) || !String.IsNullOrWhiteSpace(locations)) throw new ArgumentException("Invalid argument is setted."); reqmethod = CredentialProvider.RequestMethod.POST; break; case StreamingType.filter: if (String.IsNullOrWhiteSpace(track) && String.IsNullOrWhiteSpace(follow)) throw new ArgumentException("You must set follow or track argument."); reqmethod = CredentialProvider.RequestMethod.POST; break; } List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>(); if (delimitered != null) args.Add(new KeyValuePair<string, string>("delimitered", delimitered.Value.ToString())); if (count != null) args.Add(new KeyValuePair<string, string>("count", count.Value.ToString())); if (!String.IsNullOrWhiteSpace(follow)) args.Add(new KeyValuePair<string, string>("follow", Tweak.CredentialProviders.OAuth.UrlEncode(follow, Encoding.UTF8, true))); if (!String.IsNullOrWhiteSpace(track)) args.Add(new KeyValuePair<string, string>("track", Tweak.CredentialProviders.OAuth.UrlEncode(track, Encoding.UTF8, true))); if (!String.IsNullOrWhiteSpace(locations)) args.Add(new KeyValuePair<string, string>("locations", Tweak.CredentialProviders.OAuth.UrlEncode(locations, Encoding.UTF8, true))); if (repliesAll) args.Add(new KeyValuePair<string, string>("replies", "all")); var strm = provider.RequestStreamingAPI(GetStreamingUri(type), reqmethod, args); if (strm != null) return new StreamingController(strm); else return null; }