Exemplo n.º 1
0
        public static O ExecuteService <S, O>(ConfiguracionSistemaURLsEnumDestino destino, Func <S, O> methodName)
        {
            ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino);

            client.Open();
            S service = client.CreateChannel();

            using (new OperationContextScope((IContextChannel)service))
            {
                try
                {
                    return(methodName(service));
                }
                catch (CommunicationException ce)
                {
                    throw new M4TraderApplicationException("Error de comunicación", ce);
                }
                finally
                {
                    try
                    {
                        ((IClientChannel)service).Close();
                    }
                    catch (CommunicationException)
                    {
                        // Ignore various exceptions regarding the Channel's current state
                    }
                    catch (TimeoutException)
                    {
                        // Ignore Timeouts
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void ExecuteService <S>(ConfiguracionSistemaURLsEnumDestino destino, Action <S> methodName)
        {
            ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino);

            client.Open();
            S service = client.CreateChannel();

            using (OperationContextScope ocs = new OperationContextScope((IContextChannel)service))
            {
                try
                {
                    methodName(service);
                }

                finally
                {
                    try
                    {
                        ((IClientChannel)service).Close();
                    }
                    catch (CommunicationException ce)
                    {
                        throw new MAECommunicationException("Error de comunicación", ce);
                    }
                    catch (TimeoutException)
                    {
                        // Ignore Timeouts
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void InformarNuevoGrupo(ChatEntity chat, string usuarios, int idOwner)
        {
            //agrego el owner a participantes
            usuarios += "," + idOwner.ToString();
            DTONuevoChat nuevoChat = new DTONuevoChat()
            {
                IdChat        = chat.IdChat,
                Nombre        = chat.Nombre,
                Participantes = usuarios.Split(',').Select(x => new DTOUsuario()
                {
                    IdUsuario = int.Parse(x)
                }).ToList(),
                IdOwner = idOwner,
                Fecha   = chat.Fecha
            };

            WCFHelper.ExecuteService <IChatService>(ConfiguracionSistemaURLsEnumDestino.ChatService, i => i.InformarNuevoGrupo(nuevoChat));
        }
Exemplo n.º 4
0
        public static void InformarNuevoMensaje(int idChat, string mensaje, int idUsuarioOrigen, int idChatMensaje)
        {
            List <DTOUsuario> participantes;
            ChatEntity        chat;
            string            nombreChat;

            using (OrdenesContext mc = new OrdenesContext())
            {
                participantes = (from p in mc.ChatUsuarios where p.IdChat == idChat select new DTOUsuario()
                {
                    IdUsuario = p.IdUsuario
                }).ToList();
                chat          = (from c in mc.Chats where c.IdChat == idChat select c).FirstOrDefault();
                if (chat.EsGrupo)
                {
                    nombreChat = chat.Nombre;
                }
                else
                {
                    //Si no es grupo, en participantes solo hay 2 usuarios, porque es chat individual. Como busco la contraparte, pongo que sea distinto a idUsuarioOrigen
                    int idContraparte = participantes.Find(x => x.IdUsuario != idUsuarioOrigen).IdUsuario;
                    nombreChat = (from u in mc.Usuario where u.IdUsuario == idContraparte select u).FirstOrDefault().Username;
                }
            }
            DTONuevoMensajeChat nuevoMensajeChat = new DTONuevoMensajeChat()
            {
                IdChat          = idChat,
                Mensaje         = mensaje,
                Target          = nombreChat,
                Participantes   = participantes,
                Fecha           = DateTime.Now,
                EsGrupo         = chat.EsGrupo,
                IdUsuarioOrigen = idUsuarioOrigen,
                UsernameOrigen  = MAEUserSession.Instancia.UserName,
                IdChatMensaje   = idChatMensaje
            };

            WCFHelper.ExecuteService <IChatService>(ConfiguracionSistemaURLsEnumDestino.ChatService, i => i.InformarNuevoMensaje(nuevoMensajeChat));
        }
Exemplo n.º 5
0
        private static ChannelFactory <T> CreateChannelFactory <T>(ConfiguracionSistemaURLsEnumDestino destino)
        {
            string             uri             = WCFHelper.GetServiceUrl(destino);
            EndpointAddress    endpointAddress = new EndpointAddress(uri);
            ChannelFactory <T> channelFactory;

            if (uri.StartsWith("net.pipe", StringComparison.OrdinalIgnoreCase))
            {
                NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
                channelFactory = new ChannelFactory <T>();
                channelFactory.Endpoint.Binding = binding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            else if (uri.StartsWith("net.tcp", StringComparison.OrdinalIgnoreCase))
            {
                NetTcpBinding binding = new NetTcpBinding
                {
                    MaxReceivedMessageSize = TwoGigaBytes,
                    MaxBufferPoolSize      = TwoGigaBytes,
                    MaxBufferSize          = TwoGigaBytes,
                };
                binding.Security.Mode           = SecurityMode.None;
                channelFactory                  = new ChannelFactory <T>();
                channelFactory.Endpoint.Binding = binding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            else
            {
                WebHttpBinding webHttpBinding = WCFHelper.CreateWebHttpBinding(uri);
                channelFactory = new ChannelFactory <T>();
                channelFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());
                channelFactory.Endpoint.Binding = webHttpBinding;
                channelFactory.Endpoint.Address = endpointAddress;
            }
            return(channelFactory);
        }
Exemplo n.º 6
0
 public static void PublicarMensajes(DTOChat chat)
 {
     WCFHelper.ExecuteService <IChatService>(ConfiguracionSistemaURLsEnumDestino.ChatService, i => i.EnviarMensaje(chat));
 }