Пример #1
0
        public bool SendMesssage(ClientIndetity indetity, string message)
        {
            try
            {
                if (message.Contains(indetity.PublisherId.ToString()))
                {
                    return(true);
                }

                IClientChannel clentChannel = new SockectClientChannel(Server, indetity.SessionId, Logger);
                if (clentChannel.SendMessage(message))
                {
                    return(true);
                }
                if (indetity.IsWebSite && !string.IsNullOrEmpty(indetity.WebSiteHost))
                {
                    clentChannel = new HttpClientChannel(indetity.WebSiteHost, Logger);
                    if (clentChannel.SendMessage(message))
                    {
                        return(true);
                    }
                }
            }
            catch { }
            return(false);
        }
Пример #2
0
        /// <summary>
        /// 重试远程订阅失败回调
        /// </summary>
        /// <param name="subscriber">订阅客户端凭证</param>

        public void RetryRemoteSubscriptionCallbackFailure(ClientIndetity subscriber)
        {
            try
            {
                var channel = new SendToClientChannel(Server, Logger);
                var records = Storage.FindRemoteSubscriptionCallbackFailureRecord(subscriber.PublisherId);
                foreach (var item in records)
                {
                    if (channel.SendMesssage(subscriber, item.Content))
                    {
                        Storage.RemoveRemoteSubscriptionCallbackFailureRecord(item._id);
                    }
                }
            }
            catch (Exception ex)
            {
                Task.Factory.StartNew((e) =>
                {
                    var exception = e as Exception;
                    if (exception != null && Logger != null)
                    {
                        Logger.Error("失败消息重试推送时失败!", exception);
                    }
                }, ex);
            }
        }
 /// <summary>
 /// 新增客户端凭证
 /// </summary>
 /// <param name="subscriber">客户端凭证</param>
 /// <returns>是否保存成功</returns>
 public bool AddClientIndetity(ClientIndetity subscriber)
 {
     try
     {
         GetEntities <ClientIndetity>().InsertOne(subscriber);
         return(true);
     }
     catch { }
     return(false);
 }
 /// <summary>
 /// 尝试获取客户端凭证
 /// </summary>
 /// <param name="publisherId">事件发布器Id</param>
 /// <param name="subscriber">客户端凭证</param>
 /// <returns>是否存在</returns>
 public bool TryGetClientIndetity(Guid publisherId, out ClientIndetity subscriber)
 {
     subscriber = null;
     try
     {
         subscriber = GetEntities <ClientIndetity>().Find(o => o.PublisherId == publisherId).FirstOrDefault();
         return(subscriber != null);
     }
     catch { }
     return(false);
 }
 /// <summary>
 /// 保存已更新的客户端凭证
 /// </summary>
 /// <param name="subscriber">客户端凭证</param>
 /// <returns>保存是否成功</returns>
 public bool SaveUpdateClientIndetity(ClientIndetity subscriber)
 {
     try
     {
         GetEntities <ClientIndetity>().ReplaceOne(o => o.PublisherId == subscriber.PublisherId, subscriber, new UpdateOptions {
             IsUpsert = true
         });
         return(true);
     }
     catch { }
     return(false);
 }
Пример #6
0
        /// <summary>
        /// 身份验证
        /// </summary>
        /// <param name="subscriber">订阅对象信息</param>
        /// <param name="key">密钥</param>
        /// <returns>是否成功</returns>
        public bool Authentication(ClientIndetity subscriber, string key)
        {
            if (key.Trim() != MQMConfigurationSection.GetConfig().Password.Trim())
            {
                throw new NotAuthenticationException("授权验证失败,请提供正确的授权码!");
            }
            ClientIndetity old;

            if (Storage.TryGetClientIndetity(subscriber.PublisherId, out old))
            {
                old.SessionId   = subscriber.SessionId;
                old.IsWebSite   = subscriber.IsWebSite;
                old.WebSiteHost = subscriber.WebSiteHost;
                old.AgentId     = AgentId;
                Storage.SaveUpdateClientIndetity(old);
            }
            else
            {
                subscriber.AgentId = AgentId;
                Storage.AddClientIndetity(subscriber);
            }
            return(true);
        }