Ejemplo n.º 1
0
        public static Channel FromXmlType(ChannelBaseType oio)
        {
            if (oio != null)
            {
                Channel dbChannel = new Channel();
                dbChannel.ChannelId = Guid.NewGuid();

                if (oio is WebServiceChannelType)
                {
                    WebServiceChannelType webServiceChannel = oio as WebServiceChannelType;
                    dbChannel.ChannelTypeId = (int)ChannelType.ChannelTypes.WebService;
                    dbChannel.Url           = webServiceChannel.WebServiceUrl;
                }
                else if (oio is FileShareChannelType)
                {
                    FileShareChannelType fileShareChannel = oio as FileShareChannelType;
                    dbChannel.ChannelTypeId = (int)ChannelType.ChannelTypes.FileShare;
                    dbChannel.Url           = fileShareChannel.Path;
                }
                else
                {
                    return(null);
                }
                return(dbChannel);
            }
            return(null);
        }
Ejemplo n.º 2
0
 public SubscribeOnBirthdateFacadeMethod(ChannelBaseType notificationChannel, int?years, int priordays, Guid[] personUuids, string appToken, string userToken)
     : base(appToken, userToken)
 {
     NotificationChannel = notificationChannel;
     PersonUuids         = personUuids;
     Years     = years;
     PriorDays = priordays;
 }
Ejemplo n.º 3
0
        public static StandardReturType ValidateChannel(ChannelBaseType notificationChannel)
        {
            if (notificationChannel == null)
            {
                return(StandardReturType.NullInput("NotificationChannel"));
            }

            if (notificationChannel is WebServiceChannelType)
            {
                if (string.IsNullOrEmpty((notificationChannel as WebServiceChannelType).WebServiceUrl))
                {
                    return(StandardReturType.NullInput("WebServiceUrl"));
                }
            }
            else if (notificationChannel is FileShareChannelType)
            {
                if (string.IsNullOrEmpty((notificationChannel as FileShareChannelType).Path))
                {
                    return(StandardReturType.NullInput("Path"));
                }
            }
            else
            {
                return(StandardReturType.UnknownObject("Unknown channel type"));
            }

            var dbChannel = Data.Channel.FromXmlType(notificationChannel);

            if (dbChannel == null)
            {
                return(StandardReturType.UnknownObject("NotificationChannel"));
            }

            var channel = Notifications.Channel.Create(dbChannel);

            try
            {
                if (channel == null || !channel.IsAlive())
                {
                    // TODO: Call StandardReturType.UnreachableChannel()
                    return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, "Unreachable channel"));
                }
            }
            catch (Exception ex)
            {
                Engine.Local.Admin.LogException(ex);
                // TODO: Call StandardReturType.UnreachableChannel()
                return(StandardReturType.Create(HttpErrorCode.BAD_CLIENT_REQUEST, "Unreachable channel"));
            }
            return(StandardReturType.OK());
        }
 /// <summary>
 /// Interface implementation
 /// </summary>
 public ChangeSubscriptionType Subscribe(ChannelBaseType notificationChannel, Guid[] personUuids)
 {
     using (EventBrokerDataContext dataContext = new EventBrokerDataContext())
     {
         Data.Subscription subscription = AddSubscription(dataContext, Data.SubscriptionType.SubscriptionTypes.DataChange, CprBroker.Engine.BrokerContext.Current.ApplicationId.Value, notificationChannel, personUuids, null);
         if (subscription != null)
         {
             subscription.DataSubscription = new DataSubscription();
         }
         dataContext.SubmitChanges();
         if (subscription != null)
         {
             // Now get the subscription from the database to make sure everything is OK
             return(GetActiveSubscriptionsList(subscription.SubscriptionId).SingleOrDefault() as ChangeSubscriptionType);
         }
     }
     return(null);
 }
        /// <summary>
        /// Interface implementation
        /// </summary>
        public BirthdateSubscriptionType SubscribeOnBirthdate(ChannelBaseType notificationChannel, Nullable <int> years, int priorDays, Guid[] personUuids)
        {
            using (EventBrokerDataContext dataContext = new EventBrokerDataContext())
            {
                Data.Subscription subscription = AddSubscription(dataContext, Data.SubscriptionType.SubscriptionTypes.Birthdate, CprBroker.Engine.BrokerContext.Current.ApplicationId.Value, notificationChannel, personUuids, null);
                if (subscription != null)
                {
                    subscription.BirthdateSubscription           = new BirthdateSubscription();
                    subscription.BirthdateSubscription.AgeYears  = years;
                    subscription.BirthdateSubscription.PriorDays = priorDays;
                }

                dataContext.SubmitChanges();
                if (subscription != null)
                {
                    // Now get the subscription from the database to make sure everything is OK
                    return(GetActiveSubscriptionsList(subscription.SubscriptionId).SingleOrDefault() as BirthdateSubscriptionType);
                }
            }
            return(null);
        }
 /// <summary>
 /// Interface implementation
 /// </summary>
 public ChangeSubscriptionType SubscribeOnCriteria(ChannelBaseType notificationChannel, SoegObjektType criteria)
 {
     using (EventBrokerDataContext dataContext = new EventBrokerDataContext())
     {
         /*
          * For now we assign this data type as a data change type.
          */
         Data.Subscription subscription = AddSubscription(dataContext, Data.SubscriptionType.SubscriptionTypes.DataChange /* May be changed later */, CprBroker.Engine.BrokerContext.Current.ApplicationId.Value, notificationChannel, new Guid[0], criteria);
         if (subscription != null)
         {
             subscription.DataSubscription = new DataSubscription();
         }
         dataContext.SubmitChanges();
         if (subscription != null)
         {
             // Now get the subscription from the database to make sure everything is OK
             return(GetActiveSubscriptionsList(subscription.SubscriptionId).SingleOrDefault() as ChangeSubscriptionType);
         }
     }
     return(null);
 }
Ejemplo n.º 7
0
 public BasicOutputType <BirthdateSubscriptionType> SubscribeOnBirthdate(ChannelBaseType NotificationChannel, Nullable <int> Years, int PriorDays, Guid[] personUuids)
 {
     return(SubscriptionManager.SubscribeOnBirthdate(applicationHeader.UserToken, applicationHeader.ApplicationToken, NotificationChannel, Years, PriorDays, personUuids));
 }
Ejemplo n.º 8
0
 public BasicOutputType <ChangeSubscriptionType> Subscribe(ChannelBaseType NotificationChannel, Guid[] personUuids)
 {
     return(SubscriptionManager.Subscribe(applicationHeader.UserToken, applicationHeader.ApplicationToken, NotificationChannel, personUuids));
 }
Ejemplo n.º 9
0
 public BasicOutputType <ChangeSubscriptionType> SubscribeOnCriteria(ChannelBaseType NotificationChannel, SoegObjektType Criteria)
 {
     return(SubscriptionManager.SubscribeOnCriteria(applicationHeader.UserToken, applicationHeader.ApplicationToken, NotificationChannel, Criteria));
 }
Ejemplo n.º 10
0
        public static BasicOutputType <ChangeSubscriptionType> SubscribeOnCriteria(string userToken, string appToken, ChannelBaseType notificationChannel, SoegObjektType criteria)
        {
            SubscribeOnCriteriaFacadeMethod facade = new SubscribeOnCriteriaFacadeMethod(notificationChannel, criteria, appToken, userToken);

            return(GetMethodOutput <ChangeSubscriptionType>(facade));
        }
Ejemplo n.º 11
0
        public static BasicOutputType <BirthdateSubscriptionType> SubscribeOnBirthdate(string userToken, string appToken, ChannelBaseType notificationChannel, Nullable <int> years, int priorDays, Guid[] PersonCivilRegistrationIdentifiers)
        {
            SubscribeOnBirthdateFacadeMethod facade = new SubscribeOnBirthdateFacadeMethod(notificationChannel, years, priorDays, PersonCivilRegistrationIdentifiers, appToken, userToken);

            return(GetMethodOutput <BirthdateSubscriptionType>(facade));
        }
Ejemplo n.º 12
0
        public static BasicOutputType <ChangeSubscriptionType> Subscribe(string userToken, string appToken, ChannelBaseType notificationChannel, Guid[] personUuids)
        {
            SubscribeFacadeMethod facade = new SubscribeFacadeMethod(notificationChannel, personUuids, appToken, userToken);

            return(GetMethodOutput <ChangeSubscriptionType>(facade));
        }
Ejemplo n.º 13
0
 public SubscribeFacadeMethod(ChannelBaseType notificationChannel, Guid[] personUuids, string appToken, string userToken)
     : base(appToken, userToken)
 {
     NotificationChannel = notificationChannel;
     PersonUuids         = personUuids;
 }
 public SubscribeOnCriteriaFacadeMethod(ChannelBaseType notificationChannel, SoegObjektType criterion, string appToken, string userToken)
     : base(appToken, userToken)
 {
     NotificationChannel = notificationChannel;
     Criterion           = criterion;
 }
Ejemplo n.º 15
0
 public BasicOutputTypeOfBirthdateSubscriptionType SubscribeOnBirthdate(ApplicationHeader applicationHeader, ChannelBaseType notificationChannel,
                                                                        int?age, int priorDays,
                                                                        string[] personCivilRegistrationIdentifiers)
 {
     return(subscriptionsHandler.SubscribeOnBirthdate(applicationHeader, notificationChannel, age, priorDays, GetUuids(applicationHeader, personCivilRegistrationIdentifiers)));
 }
Ejemplo n.º 16
0
 public BasicOutputTypeOfChangeSubscriptionType Subscribe(ApplicationHeader applicationHeader, ChannelBaseType notificationChannel, string[] personCivilRegistrationIdentifiers)
 {
     return(subscriptionsHandler.Subscribe(applicationHeader, notificationChannel, GetUuids(applicationHeader, personCivilRegistrationIdentifiers)));
 }
        /// <summary>
        /// Adds a new Subscription object to the <paramref name="dataContext"/>
        /// This method inserts rows in Subscription, Channel (and children) and  SubscriptionPerson
        /// A later call to SubmitChanges() is required to save to the database
        /// </summary>
        /// <param name="dataContext"></param>
        /// <param name="subscriptionType"></param>
        /// <param name="applicationId"></param>
        /// <param name="PersonCivilRegistrationIdentifiers"></param>
        /// <param name="notificationChannel"></param>
        /// <returns></returns>
        private Subscription AddSubscription(EventBrokerDataContext dataContext, CprBroker.EventBroker.Data.SubscriptionType.SubscriptionTypes subscriptionType, Guid applicationId, ChannelBaseType notificationChannel, Guid[] personUuids, SoegObjektType soegObject)
        {
            List <Guid> listOfPersonsIDs = new List <Guid>();

            Subscription subscription = new Subscription();

            subscription.SubscriptionId     = Guid.NewGuid();
            subscription.SubscriptionTypeId = (int)subscriptionType;
            subscription.ApplicationId      = applicationId;
            subscription.Created            = DateTime.Now;
            if (soegObject != null)
            {
                var xml = Strings.SerializeObject(soegObject);
                subscription.Criteria        = System.Xml.Linq.XElement.Load(new StringReader(xml));
                subscription.LastCheckedUUID = Guid.Empty;
            }


            #region Set IsForAllPersons
            if (personUuids != null && personUuids.Length > 0)
            {
                subscription.IsForAllPersons = false;
            }
            else
            {
                subscription.IsForAllPersons = true;
            }
            #endregion

            #region Set the channel
            var dbChannel = Channel.FromXmlType(notificationChannel);
            subscription.Channels.Add(dbChannel);
            #endregion

            // Mark the new objects to be inserted later
            dataContext.Subscriptions.InsertOnSubmit(subscription);

            if (!subscription.IsForAllPersons && personUuids != null)
            {
                dataContext.SubscriptionPersons.InsertAllOnSubmit(
                    from PersonUuid in personUuids
                    select new SubscriptionPerson()
                {
                    SubscriptionPersonId = Guid.NewGuid(), SubscriptionId = subscription.SubscriptionId, PersonUuid = PersonUuid, Created = subscription.Created
                }
                    );
            }
            dataContext.Channels.InsertOnSubmit(dbChannel);

            return(subscription);
        }