Ejemplo n.º 1
0
        public static Subscription ToSubscription(this BsonDocument doc)
        {
            if (doc == null) return null;

            var subscription = new Subscription { Id = doc[MongoDbSubscriptionRepository.FieldNames.Id].ToString() };

            if (doc.Contains(MongoDbSubscriptionRepository.FieldNames.Callback))
            {
                var callback = doc[MongoDbSubscriptionRepository.FieldNames.Callback].AsBsonDocument;
                subscription.Callback = new Callback
                                            {
                                                Kind = (CallbackKind)Enum.Parse(typeof (CallbackKind), callback[MongoDbSubscriptionRepository.FieldNames.CallbackKind].AsString),
                                                Url = new Uri(callback[MongoDbSubscriptionRepository.FieldNames.CallbackUrl].AsString)
                                            };
            }

            var targetRef = doc[MongoDbSubscriptionRepository.FieldNames.TargetRef].AsBsonDocument;
            subscription.TargetId = targetRef["$id"].ToString();
            switch(targetRef["$ref"].AsString)
            {
                case Constants.Relationships.Topic:
                    subscription.TargetKind = TargetKind.Topic;
                    break;
                case Constants.Relationships.Group:
                    subscription.TargetKind = TargetKind.Group;
                    break;
                default:
                    throw new InvalidCastException(string.Format(Messages.InvalidTargetKind, targetRef["$ref"]));
            }

            if (doc.Contains(MongoDbSubscriptionRepository.FieldNames.Filter))
            {
                subscription.Filter = doc[MongoDbSubscriptionRepository.FieldNames.Filter].AsBsonDocument.ToJson();
            }
            return subscription;
        }
Ejemplo n.º 2
0
 public Retry(Message message, Subscription subscription)
 {
     Message = message;
     Subscription = subscription;
 }