Exemplo n.º 1
0
        public CprBroker.Schemas.Part.SubscriptionType ToOioSubscription(string appToken)
        {
            CprBroker.Schemas.Part.SubscriptionType ret = null;
            if (this.DataSubscription != null)
            {
                ChangeSubscriptionType dataSubscription = new ChangeSubscriptionType();
                ret = dataSubscription;
            }
            else // birthdate subscription
            {
                BirthdateSubscriptionType birthdateSubscription = new BirthdateSubscriptionType();
                birthdateSubscription.AgeYears  = this.BirthdateSubscription.AgeYears;
                birthdateSubscription.PriorDays = this.BirthdateSubscription.PriorDays;
                ret = birthdateSubscription;
            }
            ret.SubscriptionId   = this.SubscriptionId.ToString();
            ret.ApplicationToken = appToken;
            ret.Persons          = new SubscriptionPersonsType();
            if (this.IsForAllPersons)
            {
                ret.Persons.Item = true;
            }
            else if (this.Criteria == null)
            {
                ret.Persons.Item = new PersonUuidsType()
                {
                    UUID = this.SubscriptionPersons
                           .Select(sp => sp.PersonUuid.Value.ToString())
                           .ToArray()
                };
            }
            else
            {
                ret.Persons.Item = Utilities.Strings.Deserialize <SoegObjektType>(this.Criteria.ToString());
            }

            Channel channel = this.Channels.Single();

            switch ((ChannelType.ChannelTypes)channel.ChannelTypeId)
            {
            case ChannelType.ChannelTypes.WebService:
                CprBroker.Schemas.Part.WebServiceChannelType webServiceChannel = new WebServiceChannelType();
                webServiceChannel.WebServiceUrl = channel.Url;
                ret.NotificationChannel         = webServiceChannel;
                break;

            case ChannelType.ChannelTypes.FileShare:
                CprBroker.Schemas.Part.FileShareChannelType fileShareChannel = new FileShareChannelType();
                fileShareChannel.Path   = channel.Url;
                ret.NotificationChannel = fileShareChannel;
                break;
            }
            return(ret);
        }
        /// <summary>
        /// Retrieves the subscriptions that match the supplied criteria
        /// </summary>
        /// <param name="subscriptionId"></param>
        /// <returns></returns>
        private CprBroker.Schemas.Part.SubscriptionType[] GetActiveSubscriptionsList(Nullable <Guid> subscriptionId)
        {
            List <CprBroker.Schemas.Part.SubscriptionType> listType = new List <CprBroker.Schemas.Part.SubscriptionType>();

            using (EventBrokerDataContext context = new EventBrokerDataContext())
            {
                System.Data.Linq.DataLoadOptions loadOptions = new System.Data.Linq.DataLoadOptions();
                Subscription.SetLoadOptionsForChildren(loadOptions);
                context.LoadOptions = loadOptions;

                // Create basic LINQ expression
                System.Linq.Expressions.Expression <Func <IQueryable <Subscription> > > exp =
                    () =>
                    from sub in context.Subscriptions
                    where sub.ApplicationId == CprBroker.Engine.BrokerContext.Current.ApplicationId
                    select sub;

                // Add filter for subscription id (if required)
                IQueryable <Subscription> subscriptions;
                if (subscriptionId.HasValue)
                {
                    subscriptions = exp.Compile()().Where((Subscription sub) => sub.SubscriptionId == subscriptionId);
                }
                else
                {
                    subscriptions = exp.Compile()();
                }

                // Now create list of OIO subscriptions
                foreach (var sub in subscriptions)
                {
                    CprBroker.Schemas.Part.SubscriptionType subscriptionType = sub.ToOioSubscription(CprBroker.Engine.BrokerContext.Current.ApplicationToken);
                    listType.Add(subscriptionType);
                }
                return(listType.ToArray());
            }
        }