/// <summary> /// The function which execute an action or a reaction register. /// </summary> /// <param name="obj">The parameters of the action / reaction register.</param> /// <returns></returns> public static int Callback(Packet obj) { Network.Client.Instance.SendDataToServer(new Network.NetTools.Packet { Name = obj.Name, Key = obj.Key, Data = new KeyValuePair <Network.NetTools.PacketCommand, object>(Network.NetTools.PacketCommand.C_UNLOCK, null) }); Console.WriteLine("Hello from " + _name); Console.WriteLine("--> " + obj.Data.Key); switch (obj.Data.Key) { case PacketCommand.S_DISCONNECT: Console.Error.WriteLine("Disconnect by the server"); Environment.Exit(84); break; case PacketCommand.ERROR: Environment.Exit(84); break; case PacketCommand.ACTION: { ServiceActionContent data = JsonConvert.DeserializeObject <ServiceActionContent>(obj.Data.Value.ToString()); _controller.Action(data); break; } case PacketCommand.REACTION_REGISTER: { Console.WriteLine("Lol"); ReactionRegisterContent data = JsonConvert.DeserializeObject <ReactionRegisterContent>(obj.Data.Value.ToString()); User user = data.Owner; Console.WriteLine("-------------->" + data.Owner.Email + " - " + data.ReactionName); foreach (var it in _tasks) { if (it.Key.Email == user.Email) { _tasks[it.Key].Add(data, _controller.Reaction(data)); return(0); } } _tasks.Add(user, new ThreadPool()); _tasks[user].Add(data, _controller.Reaction(data)); break; } default: break; } return(0); }
/// <summary> /// Register a reaction for the user /// </summary> /// <param name="user">An <see cref="User"/></param> /// <param name="serviceName">The <see cref="Service"/>'s name</param> /// <param name="reactionName">The reaction name</param> public static void RegisterReactionForUser(User user, string serviceName, string reactionName) { ReactionRegisterContent rrc = new ReactionRegisterContent { Owner = user, ReactionName = reactionName, ServiceName = serviceName }; Packet p = new Packet { Name = "Server", Key = 0, Data = new KeyValuePair <PacketCommand, object>(PacketCommand.REACTION_REGISTER, rrc) }; Network.Server.Instance.SendMessageBusEventToService(p, serviceName); }
public void ListenTweetFromAnyoneButMe(ReactionRegisterContent obj) { var user = obj.Owner; Authentification(obj); var stream = Stream.CreateUserStream(); stream.TweetCreatedByAnyoneButMe += (sender, args) => { SendData(obj, args.Tweet.CreatedBy.ScreenName + " tweet on your page : " + args.Tweet.FullText); }; stream.StartStream(); }
public void Authentification(ReactionRegisterContent obj) { if (obj.Owner.AccessToken.Count <= 0 || obj.Owner.AccessTokenSecret.Count <= 0) { return; } var user = obj.Owner; string accessTokenSecret = user.AccessTokenSecret[_name]; string accessToken = user.AccessToken[_name]; Auth.SetUserCredentials(_consumerKey, _consumerKeySecret, accessToken, accessTokenSecret); }
/// <summary> /// Create a new thread and add it into the thread pool. /// </summary> /// <param name="obj">The parameters of the function to launch.</param> /// <param name="func">The function to launch into the new thread.</param> public void Add(ReactionRegisterContent obj, ReactionDelegate func) { foreach (var it in _threads) { if (it.Key == obj.ReactionName) { return; } } var newThread = new Thread(() => func(obj));; newThread.Start(); _threads.Add(obj.ReactionName, newThread); }
public void ListenTweetWithKeyWord(ReactionRegisterContent obj) { string regex = ""; Authentification(obj); var stream = Stream.CreateFilteredStream(); stream.AddTrack(regex); stream.MatchingTweetReceived += (sender, args) => { var txt = "A tweet containing '" + regex + "' has been found : " + args.Tweet.FullText; SendData(obj, txt); }; }
/// <summary> /// Stop a thread. /// </summary> /// <param name="reaction">The name of the thread to stop.</param> public void Remove(ReactionRegisterContent obj) { _threads[obj.ReactionName].Abort(); _threads.Remove(obj.ReactionName); }
public ReactionDelegate Reaction(ReactionRegisterContent obj) { return(_reactions[obj.ReactionName]); }