public IMQUnsubscribeResult Unsubscribe(IMQUnsubscribeParams paramsUnsubscribe)
        {
            var result = new DbMQUnsubscribeResult();

            string        spName = "[SP_Unsubscribe_From_Channel]";
            SqlConnection conn   = OpenConnection("ConnectionString");

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = schema + "." + spName;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = conn;

            try
            {
                SqlParameter paramChannelId = new SqlParameter("@Channel_Id",
                                                               SqlDbType.BigInt, 0,
                                                               ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current,
                                                               paramsUnsubscribe.ChannelId);

                SqlParameter paramSubscriberId = new SqlParameter("@Subscriber_Id",
                                                                  SqlDbType.BigInt, 0,
                                                                  ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current,
                                                                  paramsUnsubscribe.SubscriberId);


                cmd.Parameters.Add(paramChannelId);
                cmd.Parameters.Add(paramSubscriberId);
                cmd.ExecuteNonQuery();

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Errors.Add(new Interfaces.Error()
                {
                    Message = ex.Message,
                    Code    = Interfaces.EErrorCodes.MQDbError,
                    Type    = Interfaces.EErrorType.Error
                });
            }

            conn.Close();

            return(result);
        }
Exemple #2
0
        public bool Unsubscribe(string channel = null)
        {
            ValidateInitialized();

            List <long> chnls = new List <long>();

            if (channel != null)
            {
                lock (_lockChannels)
                {
                    if (_channels.ContainsKey(channel))
                    {
                        chnls.Add(_channels[channel]);
                    }
                }
            }
            else
            {
                lock (_lockChannels)
                {
                    chnls.AddRange(_channels.Values);
                }
            }

            IMQUnsubscribeParams paramsUnsusb = _mq.CreateUnsubscribeParams();

            foreach (var c in chnls)
            {
                paramsUnsusb.ChannelId    = c;
                paramsUnsusb.SubscriberId = _subscriberId;
                var resUnsubscr = _mq.Unsubscribe(paramsUnsusb);
                if (resUnsubscr.Success)
                {
                    lock (_lockChannels)
                    {
                        _channels.Remove(_channels.FirstOrDefault(x => x.Value == c).Key);
                    }
                }
            }

            return(true);
        }