Example #1
0
        public static Facade.Subscription ToFacade(this Subscription from)
        {
            if (from == null) return null;

            Guard.Instance
                .ArgumentNotNull(() => from.Id, from.Id)
                .ArgumentNotNull(() => from.TargetId, from.TargetId);

            var subscription  = new Facade.Subscription
            {
                Callback = from.Callback.ToFacade(),
            // ReSharper disable PossibleInvalidOperationException
                Id = from.Id.Value.ToFacade(),
            // ReSharper restore PossibleInvalidOperationException
            };

            switch(from.TargetKind)
            {
                case TargetKind.Topic:
                    subscription.Target = new Facade.Link(ResourceLocation.OfTopic(from.TargetId.Value),
                                                          Constants.Relationships.Topic);
                    break;
                case TargetKind.Group:
                    subscription.Target = new Facade.Link(ResourceLocation.OfGroup(from.TargetId.Value),Constants.Relationships.Group);
                    break;
                default:
                    throw new InvalidOperationException(string.Format(Messages.TargetKindUnknown, from.TargetKind));
            }

            return subscription;
        }
Example #2
0
        static public Facade.Subscription ToFacade(this Subscription from)
        {
            if (from == null)
            {
                return(null);
            }

            Guard.Instance
            .ArgumentNotNull(() => from.Id, from.Id)
            .ArgumentNotNull(() => from.TargetId, from.TargetId);

            var subscription = new Facade.Subscription
            {
                Callback = from.Callback.ToFacade(),
// ReSharper disable PossibleInvalidOperationException
                Id = from.Id.Value.ToFacade(),
// ReSharper restore PossibleInvalidOperationException
            };

            switch (from.TargetKind)
            {
            case TargetKind.Topic:
                subscription.Target = new Facade.Link(ResourceLocation.OfTopic(from.TargetId.Value),
                                                      Constants.Relationships.Topic);
                break;

            case TargetKind.Group:
                subscription.Target = new Facade.Link(ResourceLocation.OfGroup(from.TargetId.Value), Constants.Relationships.Group);
                break;

            default:
                throw new InvalidOperationException(string.Format(Messages.TargetKindUnknown, from.TargetKind));
            }

            return(subscription);
        }