示例#1
0
        private static void NotificarComentarioNuevo()
        {
            var repositorio = new RepositorioComentarios();
            var hubContext  = GlobalHost.ConnectionManager.GetHubContext <CommentHub>();

            hubContext.Clients.All.loadComments(repositorio.TraerTodo().Reverse());
        }
示例#2
0
        public static void RecibirMensaje()
        {
            QueueClient Client =
                QueueClient.CreateFromConnectionString(connectionString, "Comentarios");

            // Configure the callback options.
            OnMessageOptions options = new OnMessageOptions();

            options.AutoComplete     = false;
            options.AutoRenewTimeout = TimeSpan.FromMinutes(1);

            // Callback to handle received messages.
            Client.OnMessage((message) =>
            {
                try
                {
                    //// Process message from queue.
                    //Console.WriteLine("Body: " + message.GetBody<string>());
                    //Console.WriteLine("MessageID: " + message.MessageId);
                    //Console.WriteLine("Test Property: " +
                    //                  message.Properties["TestProperty"]);

                    var comment       = message.GetBody <CommentModel>();
                    comment.FechaHora = DateTime.Now.ToString("hh:mm:ss yyyyMMdd");
                    var repositorio   = new RepositorioComentarios();
                    repositorio.Agregar(comment);

                    // Remove message from queue.
                    message.Complete();

                    NotificarComentarioNuevo(comment);
                }
                catch (Exception)
                {
                    // Indicates a problem, unlock message in queue.
                    message.Abandon();
                }
            }, options);
        }