Exemple #1
0
        public static bool IsSubscribed(this ISubscriptionProvider provider, INotifyAction action, IRecipient recipient, string objectID)
        {
            var result = false;

            try
            {
                var subscriptionRecord = provider.GetSubscriptionRecord(action, recipient, objectID);
                if (subscriptionRecord != null)
                {
                    var properties = subscriptionRecord.GetType().GetProperties();
                    if (properties.Any())
                    {
                        var property = properties.Single(p => p.Name == "Subscribed");
                        if (property != null)
                        {
                            result = (bool)property.GetValue(subscriptionRecord, null);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                LogManager.GetLogger("ASC").Error(exception);
            }

            return(result);
        }
        public IDictionary <string, T> HashGetAll <T>(string key)
        {
            var dic = _redis.Database.HashGetAll(key);

            return(dic
                   .Select(e =>
            {
                var val = default(T);
                try
                {
                    val = (string)e.Value != null ? JsonConvert.DeserializeObject <T>(e.Value) : default(T);
                }
                catch (Exception ex)
                {
                    if (!e.Value.IsNullOrEmpty)
                    {
                        LogManager.GetLogger("ASC").ErrorFormat("RedisCache HashGetAll value: {0}", e.Value);
                    }

                    LogManager.GetLogger("ASC").Error(string.Format("RedisCache HashGetAll key: {0}", key), ex);
                }

                return new { Key = (string)e.Name, Value = val };
            })
                   .Where(e => e.Value != null && !e.Value.Equals(default(T)))
                   .ToDictionary(e => e.Key, e => e.Value));
        }
Exemple #3
0
 private void ValidateNotifySource(INotifySource source)
 {
     foreach (var a in source.GetActionProvider().GetActions())
     {
         IEnumerable <string> senderNames;
         lock (channels)
         {
             senderNames = channels.Values.Select(s => s.SenderName);
         }
         foreach (var s in senderNames)
         {
             try
             {
                 var pattern = source.GetPatternProvider().GetPattern(a, s);
                 if (pattern == null)
                 {
                     throw new NotifyException(string.Format("In notify source {0} pattern not found for action {1} and sender {2}", source.ID, a.ID, s));
                 }
             }
             catch (Exception error)
             {
                 LogManager.GetLogger("ASC.Notify").ErrorFormat("Source: {0}, action: {1}, sender: {2}, error: {3}", source.ID, a.ID, s, error);
             }
         }
     }
 }
        public T HashGet <T>(string key, string field)
        {
            var value = (string)(_redis.Database.HashGet(key, field));

            try
            {
                return(value != null?JsonConvert.DeserializeObject <T>(value) : default(T));
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ASC").Error(string.Format("RedisCache HashGet key: {0}, field: {1}", key, field), ex);

                return(default(T));
            }
        }
Exemple #5
0
        internal bool Intercept(InterceptorPlace place)
        {
            var result = false;

            foreach (var interceptor in Interceptors)
            {
                if ((interceptor.PreventPlace & place) == place)
                {
                    try
                    {
                        if (interceptor.PreventSend(this, place))
                        {
                            result = true;
                        }
                    }
                    catch (Exception err)
                    {
                        LogManager.GetLogger("ASC.Notify").ErrorFormat("{0} {1} {2}: {3}", interceptor.Name, NotifyAction, Recipient, err);
                    }
                }
            }
            return(result);
        }