Esempio n. 1
0
        public ArrayList GetMessage(string hach, int maxId)
        {
            int       id   = swh.GetIdUserByHach(hach);
            ArrayList list = new ArrayList();

            using (UserContext db1 = new UserContext())
            {
                foreach (var m in db1.Messages)
                {
                    if (m.idUserMessage == id && m.id > maxId)
                    {
                        MessageC message = new MessageC
                        {
                            id            = m.id,
                            idReseiver    = m.idReseiver,
                            idSender      = m.idSender,
                            idUserMessage = m.idUserMessage,
                            message       = m.message,
                            status        = m.status,
                            time          = m.time
                        };
                        list.Add(message);
                    }
                }
            }
            return(list);
        }
Esempio n. 2
0
        public int GetLastIdMessage(string hach, int idUs)
        {
            List <MessageC> list = new List <MessageC>();
            int             id   = swh.GetIdUserByHach(hach);

            using (UserContext db1 = new UserContext())
            {
                foreach (var m in db1.Messages)
                {
                    if ((m.idUserMessage == id && m.idReseiver == idUs) || (m.idUserMessage == id && m.idSender == idUs))
                    {
                        MessageC message = new MessageC
                        {
                            message       = m.message,
                            id            = m.id,
                            idReseiver    = m.idReseiver,
                            idSender      = m.idSender,
                            idUserMessage = m.idUserMessage,
                            status        = m.status,
                            time          = m.time
                        };
                        list.Add(message);
                    }
                }
            }
            return(ServerWorksHelper.GetMessageLastId(list));
        }
Esempio n. 3
0
        public List <ArrayList> GetAllUserMessage(string hach, int idUs)
        {
            List <ArrayList> list = new List <ArrayList>();
            int id = swh.GetIdUserByHach(hach);

            using (UserContext db1 = new UserContext())
            {
                foreach (var m in db1.Messages)
                {
                    if ((m.idUserMessage == id && m.idReseiver == idUs) || (m.idUserMessage == id && m.idSender == idUs))
                    {
                        MessageC message = new MessageC
                        {
                            message       = m.message,
                            id            = m.id,
                            idReseiver    = m.idReseiver,
                            idSender      = m.idSender,
                            idUserMessage = m.idUserMessage,
                            status        = m.status,
                            time          = m.time
                        };
                        list.Add(Package.PackageClass(message));
                    }
                }
            }
            return(list);
        }
Esempio n. 4
0
        /// <summary>
        /// Does STUN transaction. Returns transaction response or null if transaction failed.
        /// </summary>
        /// <param name="request">STUN message.</param>
        /// <param name="socket">Socket to use for send/receive.</param>
        /// <param name="remoteEndPoint">Remote end point.</param>
        /// <returns>Returns transaction response or null if transaction failed.</returns>
        private static MessageC DoTransaction(MessageC request, Socket socket, IPEndPoint remoteEndPoint)
        {
            byte[]   requestBytes = request.ToByteData();
            DateTime startTime    = DateTime.Now;

            // We do it only 2 sec and retransmit with 100 ms.
            while (startTime.AddSeconds(2) > DateTime.Now)
            {
                try{
                    socket.SendTo(requestBytes, remoteEndPoint);

                    // We got response.
                    if (socket.Poll(100, SelectMode.SelectRead))
                    {
                        byte[] receiveBuffer = new byte[512];
                        socket.Receive(receiveBuffer);

                        // Parse message
                        MessageC response = new MessageC();
                        response.Parse(receiveBuffer);

                        // Check that transaction ID matches or not response what we want.
                        if (request.TransactionID.Equals(response.TransactionID))
                        {
                            return(response);
                        }
                    }
                }
                catch {
                }
            }

            return(null);
        }
Esempio n. 5
0
        public void return_type_of_a_subscription_is_treated_as_message()
        {
            MessageC msgC = null;

            _bus.Subscribe((MessageC msg) => msgC = msg);
            _bus.Publish(new MessageB());

            msgC.ShouldNotBeNull();
            msgC.ShouldBeEqualTo(_handler.MsgC);
        }
Esempio n. 6
0
 public void Reset()
 {
     _c.Dispose();
     MessageA.Reset();
     MessageB.Reset();
     MessageC.Reset();
     _aCount = 0;
     _bCount = 0;
     _cCount = 0;
 }
Esempio n. 7
0
        public static object Upackage(ArrayList list)
        {
            if (list != null)
            {
                switch ((string)list[0])
                {
                case "UserC":
                {
                    UserC user = new UserC
                    {
                        email    = (string)list[1],
                        name     = (string)list[2],
                        phone    = (string)list[3],
                        surname  = (string)list[4],
                        userName = (string)list[5]
                    };
                    return(user);
                }

                case "MessageC":
                {
                    MessageC message = new MessageC
                    {
                        message       = (string)list[1],
                        id            = (int)list[2],
                        idReseiver    = (int)list[3],
                        idSender      = (int)list[4],
                        idUserMessage = (int)list[5],
                        status        = (int)list[6],
                        time          = (string)list[7]
                    };
                    return(message);
                }

                case "LastMessageC":
                {
                    LastMessageC message = new LastMessageC
                    {
                        message         = (string)list[1],
                        id              = (int)list[2],
                        idReseiver      = (int)list[3],
                        idSender        = (int)list[4],
                        idUserMessage   = (int)list[5],
                        status          = (int)list[6],
                        time            = (string)list[7],
                        CountNewMessage = (int)list[8]
                    };
                    return(message);
                }

                default: return(null);
                }
            }
            return(null);
        }
Esempio n. 8
0
 static void Main(string[] args)
 {
     MessageA messageA = new MessageA() { Element = "A" };
     messageA.MyMethod();
     MessageB messageB = new MessageB() { Element = "B" };
     messageB.MyMethod();
     messageB.MySpecificMethod();
     MessageC message = new MessageC() { Element = "C" };
     message.MyMethod();
     Console.ReadLine();
     
 }
    public void Go()
    {
        var a = new MessageA();
        var b = new MessageB();
        var c = new MessageC();

        var router = new MessageRouter();

        router.RegisterHandler(new HandlerA());
        router.RegisterHandler(new HandlerB());

        router.Route(a);
        router.Route(b);
        router.Route(c);
    }
Esempio n. 10
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Start !!");

            AMessage messageA    = new MessageA();
            AMessage messageB    = new MessageB();
            AMessage messageC    = new MessageC();
            MessageB messageBBis = null;

            ExecutMessageMethod(messageA);
            ExecutMessageMethod(messageB);
            ExecutMessageMethod(messageC);
            ExecutMessageMethod(messageBBis);

            Console.ReadLine();
        }
Esempio n. 11
0
        internal static IEnumerable <MessageC> GetMessages(MessageC msg)
        {
            List <MessageC> MessageList = new List <MessageC>();
            string          connString  = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                string statement = "SELECT * FROM `messages` WHERE (idS = @u1 and idR = @u2) or(idS = @u2 and idR = @u1)";

                MySqlCommand cmd = new MySqlCommand(statement, conn);

                cmd.Parameters.AddWithValue("@u1", msg.IdR);
                cmd.Parameters.AddWithValue("@u2", msg.IdS);

                MySqlDataReader reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        MessageC m = new MessageC();
                        m.Id       = reader.GetInt32("Id");
                        m.IdR      = reader.GetInt32("IdR");
                        m.IdS      = reader.GetInt32("IdS");
                        m.MessageS = reader.GetString("message");
                        m.Seen     = reader.GetBoolean("seen");

                        MessageList.Add(m);
                    }
                }
            }

            connString = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.Connection  = conn;
                cmd.CommandText = "UPDATE `Messages` SET `seen` = 1 WHERE idR =" + msg.IdS + ";";
                cmd.Prepare();

                cmd.ExecuteNonQuery();
            }
            return(MessageList);
        }
Esempio n. 12
0
        public void DeeplyNestedMessagesShouldApplyEventsProperly()
        {
            var g = new MessageG();

            g.H.Add(1);
            AssertEventsStable(g);

            var f = new MessageF();

            f.G = g;
            f.G.H.Add(2);
            AssertEventsStable(f);

            var e = new MessageE();

            e.F = f;
            e.F.G.H.Add(3);
            AssertEventsStable(e);

            var d = new MessageD();

            d.E = e;
            d.E.F.G.H.Add(4);
            AssertEventsStable(d);

            var c = new MessageC();

            c.D["foo"] = d;
            c.D["foo"].E.F.G.H.Add(5);
            AssertEventsStable(c);

            var b = new MessageB();

            b.C["bar"] = c;
            b.C["bar"].D["foo"].E.F.G.H.Add(6);
            AssertEventsStable(b);

            var a = new MessageA();

            a.B = b;
            a.B.C["bar"].D["foo"].E.F.G.H.Add(7);
            AssertEventsStable(a);
        }
Esempio n. 13
0
        internal static void InsertMessage(MessageC m)
        {
            string connString = ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString;

            using (MySqlConnection conn = new MySqlConnection(connString))
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "INSERT INTO messages(idS, idR, message) VALUES(@idS, @idR, @message)";
                cmd.Prepare();

                cmd.Parameters.AddWithValue("@idS", m.IdS);
                cmd.Parameters.AddWithValue("@idR", m.IdR);
                cmd.Parameters.AddWithValue("@message", m.MessageS);

                cmd.ExecuteNonQuery();
            }
        }
Esempio n. 14
0
                public void Handle <T>(T args)
                {
                    var msgB = args as MessageB;

                    if (msgB == null)
                    {
                        msgB = new MessageB {
                            TextB = "~B~"
                        }
                    }
                    ;

                    _builder.Append(msgB.TextB);

                    var msgC = new MessageC {
                        TextC = "~C~"
                    };

                    _innerHandler.Handle(msgC);
                }
            }
Esempio n. 15
0
 // AddConsultation
 public IEnumerable <MessageC> GetMessages([FromBody] MessageC m)
 {
     return(UserProvider.GetMessages(m));
 }
Esempio n. 16
0
 public void Consume(MessageC message)
 {
 }
 public Task Consume(MessageC message)
 {
     throw new NotImplementedException();
 }
Esempio n. 18
0
 private void OnMessageC(MessageC obj)
 {
     Interlocked.Increment(ref _cCount);
 }
Esempio n. 19
0
 public void Consume(MessageC message, CancellationToken cancellationToken)
 {
 }
Esempio n. 20
0
 public Task Consume(MessageC message)
 {
     return(CompletedTask());
 }
 void IConsume <MessageC> .Consume(MessageC message)
 {
 }
Esempio n. 22
0
 public Task ConsumeAsync(MessageC message, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
 void IConsume <MessageC> .Consume(MessageC message, CancellationToken cancellationToken)
 {
 }
Esempio n. 24
0
 public void SomeOtherMethod(MessageC msg)
 {
     MsgCCalls++;
 }
Esempio n. 25
0
        /// <summary>
        /// Gets NAT info from STUN server.
        /// </summary>
        /// <param name="host">STUN server name or IP.</param>
        /// <param name="port">STUN server port. Default port is 3478.</param>
        /// <param name="socket">UDP socket to use.</param>
        /// <returns>Returns UDP netwrok info.</returns>
        /// <exception cref="Exception">Throws exception if unexpected error happens.</exception>
        public static Result Query(string host, int port, Socket socket)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            if (port < 1)
            {
                throw new ArgumentException("Port value must be >= 1 !");
            }
            if (socket.ProtocolType != ProtocolType.Udp)
            {
                throw new ArgumentException("Socket must be UDP socket !");
            }

            // Add try/catch to if the host cannot be resolved
            IPEndPoint remoteEndPoint = null;

            try
            {
                remoteEndPoint = new IPEndPoint(Dns.GetHostAddresses(host)[0], port);
            } catch (SocketException)
            {
                return(new Result(NetType.NotAvailable, null));
            }

            socket.ReceiveTimeout = 3000;
            socket.SendTimeout    = 3000;

            /*
             *  In test I, the client sends a STUN Binding Request to a server, without any flags set in the
             *  CHANGE-REQUEST attribute, and without the RESPONSE-ADDRESS attribute. This causes the server
             *  to send the response back to the address and port that the request came from.
             *
             *  In test II, the client sends a Binding Request with both the "change IP" and "change port" flags
             *  from the CHANGE-REQUEST attribute set.
             *
             *  In test III, the client sends a Binding Request with only the "change port" flag set.
             *
             +--------+
             |  Test  |
             |   I    |
             +--------+
             |
             |
             |                           V
             |                          /\              /\
             |                       N /  \ Y          /  \ Y             +--------+
             |        UDP     <-------/Resp\--------->/ IP \------------->|  Test  |
             |        Blocked         \ ?  /          \Same/              |   II   |
             \  /            \? /               +--------+
             \/              \/                    |
             | N                  |
             |                    V
             |                                           V                    /\
             +--------+  Sym.      N /  \
             |  Test  |  UDP    <---/Resp\
             |   II   |  Firewall   \ ?  /
             +--------+              \  /
             |                    \/
             |                                           V                     |Y
             |                /\                         /\                    |
             | Symmetric  N  /  \       +--------+   N  /  \                   V
             |    NAT  <--- / IP \<-----|  Test  |<--- /Resp\               Open
             |              \Same/      |   I    |     \ ?  /               Internet
             \? /       +--------+      \  /
             \/                         \/
             |                           |Y
             |                           |
             |                           V
             |                           Full
             |                           Cone
             |                V              /\
             +--------+        /  \ Y
             |  Test  |------>/Resp\---->Restricted
             |   III  |       \ ?  /
             +--------+        \  /
             \/
             |N
             |       Port
             +------>Restricted
             |
             */

            // Test I
            MessageC test1 = new MessageC();

            test1.Type = Message.MessageType.BindingRequest;
            MessageC test1response = DoTransaction(test1, socket, remoteEndPoint);

            // UDP blocked.
            if (test1response == null)
            {
                return(new Result(NetType.UdpBlocked, null));
            }
            else
            {
                // Test II
                MessageC test2 = new MessageC();
                test2.Type          = Message.MessageType.BindingRequest;
                test2.ChangeRequest = new TChangeRequest(true, true);

                // No NAT.
                if (socket.LocalEndPoint.Equals(test1response.MappedAddress))
                {
                    MessageC test2Response = DoTransaction(test2, socket, remoteEndPoint);
                    // Open Internet.
                    if (test2Response != null)
                    {
                        return(new Result(NetType.OpenInternet, test1response.MappedAddress));
                    }
                    // Symmetric UDP firewall.
                    else
                    {
                        return(new Result(NetType.SymmetricUdpFirewall, test1response.MappedAddress));
                    }
                }
                // NAT
                else
                {
                    MessageC test2Response = DoTransaction(test2, socket, remoteEndPoint);
                    // Full cone NAT.
                    if (test2Response != null)
                    {
                        return(new Result(NetType.FullCone, test1response.MappedAddress));
                    }
                    else
                    {
                        /*
                         *  If no response is received, it performs test I again, but this time, does so to
                         *  the address and port from the CHANGED-ADDRESS attribute from the response to test I.
                         */

                        // Test I(II)
                        MessageC test12 = new MessageC();
                        test12.Type = Message.MessageType.BindingRequest;

                        MessageC test12Response = DoTransaction(test12, socket, test1response.ChangedAddress);
                        if (test12Response == null)
                        {
                            throw new Exception("STUN Test I(II) dind't get resonse !");
                        }
                        else
                        {
                            // Symmetric NAT
                            if (!test12Response.MappedAddress.Equals(test1response.MappedAddress))
                            {
                                return(new Result(NetType.Symmetric, test1response.MappedAddress));
                            }
                            else
                            {
                                // Test III
                                MessageC test3 = new MessageC();
                                test3.Type          = Message.MessageType.BindingRequest;
                                test3.ChangeRequest = new TChangeRequest(false, true);

                                MessageC test3Response = DoTransaction(test3, socket, test1response.ChangedAddress);
                                // Restricted
                                if (test3Response != null)
                                {
                                    return(new Result(NetType.RestrictedCone, test1response.MappedAddress));
                                }
                                // Port restricted
                                else
                                {
                                    return(new Result(NetType.PortRestrictedCone, test1response.MappedAddress));
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 26
0
 public void sendMessage([FromBody] MessageC m)
 {
     UserProvider.InsertMessage(m);
 }