示例#1
0
 private static void Publish(RapidsConnection rapidsConnection)
 {
     while (true)
     {
         System.Threading.Thread.Sleep(5000);
     }
 }
示例#2
0
 private static void UnexpectedSuccess(RapidsConnection connection, JObject jsonPacket,
                                       PacketProblems warnings)
 {
     Assert.Fail("Unexpected success parsing JSON packet. Packet is:\n"
                 + jsonPacket
                 + "\nConclusions from parsing/validation are:\n"
                 + warnings);
 }
示例#3
0
 private static void Publish(RapidsConnection rapidsConnection)
 {
     while (true)
     {
         var jsonMessage = NeedPacket();
         Console.WriteLine(" [<] {0}", jsonMessage);
         rapidsConnection.Publish(jsonMessage);
         System.Threading.Thread.Sleep(5000);
     }
 }
        public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
        {
            Console.WriteLine(" [*] {0}", warnings);

            var needId = jsonPacket["id"].ToString();

            _currentBestSolution[needId] = DetermineBestOffer(needId, jsonPacket);

            Console.WriteLine(
                $" [======] current best offer for {needId} is from {_currentBestSolution[needId]["solution"]}");
        }
示例#5
0
        public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
        {
            var need = jsonPacket.ToObject <NeedClass>();

            if (need.Forbidden == "y" && need.Membership == "P")
            {
                string newJSON = "{\"need\":\"" + need.Need + "\", \"ID\": \"" + need.ID + "\"," +
                                 " \"Forbidden\":\"" + need.Forbidden + "\", \"Value\":\"2500\", \"Probability\":\"0.0\", \"Membership\":\"P\"}";

                Console.WriteLine("Solution for Member: {0}", newJSON);
                rapidsConnection.Publish(newJSON);
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            string host = "192.168.254.120";
            string port = "5676";

            rapidsConnection = new RabbitMqRapids("monitor_in_csharp", host, port);
            var river = new River(rapidsConnection);

            // See RiverTest for various functions River supports to aid in filtering, like:
            //river.RequireValue("key", "expected_value");  // Reject packet unless key exists and has expected value
            //river.Require("key1", "key2");       // Reject packet unless it has key1 and key2
            //river.Forbid("key1", "key2");        // Reject packet if it does have key1 or key2
            river.Register(new MemberShipMonitor());         // Hook up to the river to start receiving traffic
        }
示例#7
0
        public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
        {
            Console.WriteLine(" [*] {0}", warnings);

            jsonPacket["solution"] = "solution_provider";
            if (jsonPacket["level"] != null)
            {
                jsonPacket["offer"] = DetermineDiscount(int.Parse(jsonPacket["level"].ToString()));
            }

            jsonPacket["price"]     = _randomGen.Next(1000, 5000);
            jsonPacket["frequency"] = Math.Round(_randomGen.NextDouble(), 1);

            connection.Publish(jsonPacket.ToString());
        }
示例#8
0
        public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
        {
            Console.WriteLine(" [*] {0}", warnings);

            var userId = int.Parse(jsonPacket["user_id"].ToString());

            if (!NewUsers.Contains(userId))
            {
                return;
            }

            Console.WriteLine($" [+] user with id {userId} is new user");

            jsonPacket["solution"] = "joining_offer";

            connection.Publish(jsonPacket.ToString());
        }
示例#9
0
        public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
        {
            Console.WriteLine(" [*] {0}", warnings);

            var userId = int.Parse(jsonPacket["user_id"].ToString());

            if (!_users.ContainsKey(userId))
            {
                Console.WriteLine($" [-] user with id {userId} not found");

                return;
            }

            Console.WriteLine($" [+] user with id {userId} has membership level {_users[userId]}");
            jsonPacket["level"] = _users[userId];
            connection.Publish(jsonPacket.ToString());
        }
示例#10
0
 private static void UnexpectedFailure(RapidsConnection connection, PacketProblems errors)
 {
     Assert.Fail("Unexpected JSON packet problem(s):\n" + errors);
 }
示例#11
0
 public void ProcessError(RapidsConnection connection, PacketProblems errors)
 {
     _failureDelegate(connection, errors);
 }
示例#12
0
 public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
 {
     _successDelegate(connection, jsonPacket, warnings);
 }
示例#13
0
 public void ProcessError(RapidsConnection connection, PacketProblems errors)
 {
     Console.WriteLine(" [x] {0}", errors);
 }
示例#14
0
 public void ProcessPacket(RapidsConnection connection, JObject jsonPacket, PacketProblems warnings)
 {
     Console.WriteLine(" [x] {0}", warnings);
 }
示例#15
0
 public void ProcessError(RapidsConnection connection, PacketProblems errors)
 {
     throw new NotImplementedException();
 }