/// <summary> /// Create a Subscription that will be associated to the Consumer. /// </summary> /// <param name="subscription">Subscription to create.</param> /// <returns>Instance of the created Subscription.</returns> private subscriptionType CreateSubscription(subscriptionType subscription) { string url = $"{EnvironmentUtils.ParseServiceUrl(Environment, ServiceType.UTILITY, InfrastructureServiceNames.subscriptions)}"; string body = SerialiseSubscription(subscription); string xml = HttpUtils.PostRequest(url, RegistrationService.AuthorisationToken, body); if (log.IsDebugEnabled) log.Debug($"Response from POST {url} request ..."); if (log.IsDebugEnabled) log.Debug(xml); return DeserialiseSubscription(xml); }
public JsonResult addsubscriptionType(subscriptionType model) { Ctx.subscriptionTypes.Add(new subscriptionType { subscription_name = model.subscription_name, Price = model.Price, Days = model.Days }); Ctx.SaveChanges(); return(Json("تم اضافة نوع الاشتراك بنجاح", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Create a Subscription that will be associated to the Consumer. /// </summary> /// <param name="subscription">Subscription to create.</param> /// <returns>Instance of the created Subscription.</returns> private subscriptionType CreateSubscription(subscriptionType subscription) { string url = $"{EnvironmentUtils.ParseServiceUrl(Environment, ServiceType.UTILITY, InfrastructureServiceNames.subscriptions)}"; string requestBody = SerialiseSubscription(subscription); string responseBody = HttpUtils.PostRequest( url, RegistrationService.AuthorisationToken, requestBody, contentTypeOverride: ContentType.ToDescription(), acceptOverride: Accept.ToDescription()); if (log.IsDebugEnabled) { log.Debug($"Response from POST {url} request ..."); } if (log.IsDebugEnabled) { log.Debug(responseBody); } return(DeserialiseSubscription(responseBody)); }
/// <summary> /// <see cref="IEventConsumer.Start(string, string)">Start</see> /// </summary> public void Start(string zoneId = null, string contextId = null) { if (log.IsDebugEnabled) log.Debug($"Started Consumer to wait for SIF Events of type {TypeName}."); try { // Register the Event Consumer with the SIF Broker. RegistrationService.Register(ref environment); // Retrieve the Subscription identifier (if exist). string subscriptionId = SessionsManager.ConsumerSessionService.RetrieveSubscriptionId( Environment.ApplicationInfo.ApplicationKey, Environment.SolutionId, Environment.UserToken, Environment.InstanceId); // If the Subscription identifier does NOT exist, create a Subscription and associated Queue. if (string.IsNullOrWhiteSpace(subscriptionId)) { // For the SIF Broker, the name property is a mandatory. queueType queue = new queueType { name = $"{TypeName}-event-consumer" }; Queue = CreateQueue(queue); subscriptionType subscription = new subscriptionType() { contextId = contextId, queueId = Queue.id, serviceName = $"{TypeName}s", serviceType = ServiceType.OBJECT.ToDescription(), zoneId = zoneId }; Subscription = CreateSubscription(subscription); // Store Queue and Subscription identifiers. SessionsManager.ConsumerSessionService.UpdateQueueId( Queue.id, Environment.ApplicationInfo.ApplicationKey, Environment.SolutionId, Environment.UserToken, Environment.InstanceId); SessionsManager.ConsumerSessionService.UpdateSubscriptionId( Subscription.id, Environment.ApplicationInfo.ApplicationKey, Environment.SolutionId, Environment.UserToken, Environment.InstanceId); } // If the Subscription identifier does exist, retrieve the Queue. else { try { string queueId = SessionsManager.ConsumerSessionService.RetrieveQueueId( Environment.ApplicationInfo.ApplicationKey, Environment.SolutionId, Environment.UserToken, Environment.InstanceId); Queue = RetrieveQueue(queueId); } catch (Exception e) { string errorMessage = $"Could not retrieve Queue details due to the following error:\n{e.GetBaseException().Message}."; if (log.IsErrorEnabled) log.Error($"{errorMessage}\n{e.StackTrace}"); throw e; } } // Manage SIF Events using background tasks. cancellationTokenSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationTokenSource.Token; task = Task.Factory.StartNew( () => ProcessEvents(cancellationToken), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); } catch (RegistrationException e) { string errorMessage = $"Error registering the Event Consumer:\n{e.GetBaseException().Message}.\n{e.StackTrace}"; if (log.IsErrorEnabled) log.Error(e, errorMessage); throw e; } catch (Exception e) { string errorMessage = $"Error starting the Event Consumer:\n{e.GetBaseException().Message}.\n{e.StackTrace}"; if (log.IsErrorEnabled) log.Error(e, errorMessage); throw e; } }
/// <summary> /// Serialise a subscriptionType object. /// </summary> /// <param name="subscription">subscriptionType object.</param> /// <returns>XML string representation of the subscriptionType object.</returns> private string SerialiseSubscription(subscriptionType subscription) { return SerialiserFactory.GetXmlSerialiser<subscriptionType>().Serialise(subscription); }
/// <summary> /// Serialise a subscriptionType object. /// </summary> /// <param name="subscription">subscriptionType object.</param> /// <returns>String representation of the subscriptionType object.</returns> private string SerialiseSubscription(subscriptionType subscription) { return(SerialiserFactory.GetSerialiser <subscriptionType>(ContentType).Serialise(subscription)); }