Пример #1
0
 private void SubscribeForEvents()
 {
     SubscriptionServiceClient lClient = new SubscriptionServiceClient();
     lClient.Subscribe("Silver", cAddress);
     lClient.Subscribe("Gold", cAddress);
     lClient.Subscribe("Platinum", cAddress);
 }
Пример #2
0
        /// <summary>Opens the connection.</summary>
        /// <returns>The result.</returns>
        private async Task <bool> OpenAsync()
        {
            try
            {
                this._client = new SubscriptionServiceClient(new InstanceContext(this));

                // state change information (non-essential)
                _client.InnerChannel.Opening += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection opening...");

                _client.InnerChannel.Opened += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection opened.");

                _client.InnerChannel.Closing += async(s, e) => await _guiCallback.ConnectionStateChangedAsync("event", "Connection closing...");

                // maintaining the connection!
                // Note: These events come for netTcpBinding, but NOT for wsDualHttpBinding!
                _client.InnerChannel.Closed  += InnerChannel_ClosedAsync;
                _client.InnerChannel.Faulted += InnerChannel_FaultedAsync;

                _client.Open(); // failure to open will also raise a faulted event!
                return(true);
            }
            catch (Exception ex)
            {
                await _guiCallback.ServiceCallExceptionAsync("Open", ex);

                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// Update subscription data
        /// </summary>
        /// <param name="id"></param>
        /// <param name="subscription"></param>
        /// <returns></returns>
        public HttpResponseMessage Put(int id, [FromBody] Models.SubscriptionSubmission subscription)
        {
            var model = new SubscriptionService.Subscription
            {
                Name = subscription.Name,
                PriceIncVatAmount = subscription.Price,
                Price             = subscription.Price,
                CallMinutes       = subscription.Callminutes
            };

            using (var client = new SubscriptionServiceClient())
            {
                var result = client.GetById(id);

                if (result == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Subscription id is not found"));
                }

                model.Identifier = result.Identifier;
                model.Id         = result.Id;
                client.Put(model);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #4
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         client?.Dispose();
         int timeout = GetPreferredTimeout();
         WriteDebug($"Cmdlet Timeout : {timeout} milliseconds.");
         client = new SubscriptionServiceClient(AuthProvider, new Oci.Common.ClientConfiguration
         {
             RetryConfiguration = retryConfig,
             TimeoutMillis      = timeout,
             ClientUserAgent    = PSUserAgent
         });
         string region = GetPreferredRegion();
         if (region != null)
         {
             WriteDebug("Choosing Region:" + region);
             client.SetRegion(region);
         }
         if (Endpoint != null)
         {
             WriteDebug("Choosing Endpoint:" + Endpoint);
             client.SetEndpoint(Endpoint);
         }
     }
     catch (Exception ex)
     {
         TerminatingErrorDuringExecution(ex);
     }
 }
Пример #5
0
 public ServiceRepository(SubscriptionServiceClient client)
 {
     if (client == null)
     {
         throw new ArgumentNullException("client");
     }
     _subClient = client;
 }
Пример #6
0
        private static void SubscribeForEvents()
        {
            SubscriptionServiceClient lClient = new SubscriptionServiceClient();

            lClient.Subscribe("TransferComplete", cAddress);
            lClient.Subscribe("TransferError", cAddress);
            lClient.Subscribe("DeliverySubmittedOutcome", cAddress);
            lClient.Subscribe("DeliveryCompletedOutcome", cAddress);
        }
        private static void SubscribeForEvents()
        {
            SubscriptionServiceClient lClient = new SubscriptionServiceClient();

            lClient.Subscribe("FundsTransferSuccessful", cAddress);
            lClient.Subscribe("FundsTransferError", cAddress);
            lClient.Subscribe("DeliverySubmitted", cAddress);
            lClient.Subscribe("DeliveryStatus", cAddress);
        }
Пример #8
0
        /// <summary>Handles the closed event.</summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private async void InnerChannel_ClosedAsync(object sender, EventArgs e)
        {
            // connection got closed and client is no longer needed...
            // this happens implicitly if the unsubscribe operation has IsTerminating=true.
            await _guiCallback.ConnectionStateChangedAsync("EVENT", "Connection closed.");

            // cleanup
            SetSubscription(false);
            _client = null;
        }
Пример #9
0
 public void Initialize()
 {
     settings = new Mock <IAppSettings>();
     settings.Setup(s => s.GetString(It.IsAny <string>()))
     .Returns("aurl");
     serviceClientFactory = new Mock <IEventServiceClientFactory>();
     client = new SubscriptionServiceClient(settings.Object)
     {
         ServiceClientFactory = serviceClientFactory.Object
     };
 }
Пример #10
0
        internal static Client <SubscriptionServiceClient> ConstructSubscriptionServiceClient(string endpointConfigName, string userName, string userPassword)
        {
            SubscriptionServiceClient client    = null;
            ChannelEndpointElement    channelEE = _configDictionary[typeof(SubscriptionService).FullName].Find(delegate(ChannelEndpointElement cee) { return(cee.Name == endpointConfigName); });

            if (null != channelEE)
            {
                client = new SubscriptionServiceClient(endpointConfigName, channelEE.Address.ToString());
                client.ClientCredentials.UserName.UserName = userName;
                client.ClientCredentials.UserName.Password = userPassword;
            }

            return(ClientFactory.CreateClient <SubscriptionServiceClient, SubscriptionService>(client));
        }
Пример #11
0
        /// <summary>
        /// Delete subscription
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public HttpResponseMessage Delete(int id)
        {
            using (var client = new SubscriptionServiceClient())
            {
                var subscription = client.GetById(id);

                if (subscription == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Subscription id is not found"));
                }

                client.Delete(id);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
Пример #12
0
        public HttpResponseMessage Get()
        {
            using (var client = new SubscriptionServiceClient())
            {
                var result = client.Get().Select(x => new Models.Subscription
                {
                    Id                = x.Identifier,
                    Name              = x.Name,
                    Price             = x.Price,
                    Priceincvatamount = x.PriceIncVatAmount,
                    Callminutes       = x.CallMinutes
                }).ToList();

                return(Request.CreateResponse(result));
            }
        }
Пример #13
0
        public HttpResponseMessage Post([FromBody] Models.SubscriptionSubmission subscription)
        {
            var model = new SubscriptionService.Subscription
            {
                Name = subscription.Name,
                PriceIncVatAmount = subscription.Price,
                Price             = subscription.Price,
                CallMinutes       = subscription.Callminutes
            };

            using (var client = new SubscriptionServiceClient())
            {
                var subscriptionId = client.Create(model);
                var response       = Request.CreateResponse(HttpStatusCode.Created);
                var uri            = Url.Link("SubscriptionApi", new { id = subscriptionId });
                response.Headers.Location = new Uri(uri);
                return(response);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #14
0
        public HttpResponseMessage Get(int id)
        {
            using (var client = new SubscriptionServiceClient())
            {
                var subscription = client.GetById(id);

                if (subscription == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Subscription id is not found"));
                }

                var result = new Models.Subscription
                {
                    Id                = subscription.Identifier,
                    Name              = subscription.Name,
                    Price             = subscription.Price,
                    Priceincvatamount = subscription.PriceIncVatAmount,
                    Callminutes       = subscription.CallMinutes
                };

                return(Request.CreateResponse(result));
            }
        }
Пример #15
0
        private static void SubscribeForEvents()
        {
            SubscriptionServiceClient lClient = new SubscriptionServiceClient();

            lClient.Subscribe("TransferRequest", cAddress);
        }
Пример #16
0
        private static void SubscribeForEvents()
        {
            SubscriptionServiceClient lClient = new SubscriptionServiceClient();

            lClient.Subscribe("SendEmail", cAddress);
        }
Пример #17
0
        private static void SubscribeForEvents()
        {
            SubscriptionServiceClient lClient = new SubscriptionServiceClient();

            lClient.Subscribe("OrderDelivery", cAddress);
        }
Пример #18
0
        private void disconnect_Click(object sender, RoutedEventArgs e)
        {
            disconnect.IsEnabled = false;
            approvalType.IsEnabled = false;
            docName.IsEnabled = false;
            document.IsEnabled = false;
            requestApproval.IsEnabled = false;

            SubscriptionServiceClient sclient = new SubscriptionServiceClient();

            sclient.Endpoint.Address = subscriptionAddr;

            statusWriter.WriteLine("Unsubcribing from service ...");
            try
            {
                sclient.Unsubscribe(user);
            }
            catch (Exception)
            {
                statusWriter.WriteLine("Unsubscribe failed ... forcing unsubcription");
            }
            subscribed = false;

            statusWriter.WriteLine("Unsubscribed");

            connect.IsEnabled = true;
            name.IsEnabled = true;
            userType.IsEnabled = true;
        }
Пример #19
0
        private void connect_Click(object sender, RoutedEventArgs e)
        {
            connect.IsEnabled = false;
            name.IsEnabled = false;
            userType.IsEnabled = false;

            SubscriptionServiceClient sclient = new SubscriptionServiceClient();
            // Set endpoint to previously discovered address
            sclient.Endpoint.Address = subscriptionAddr;

            statusWriter.WriteLine("Subscribing to " + sclient.Endpoint.Address + " as " + name.Text + " of type " + userType.Text);

            user = sclient.Subscribe(new User(name.Text, userType.Text, addrListenForApprovalRequests, addrListenForApprovalResponses));
            subscribed = true;

            disconnect.IsEnabled = true;
            approvalType.IsEnabled = true;
            docName.IsEnabled = true;
            document.IsEnabled = true;
            requestApproval.IsEnabled = true;

            statusWriter.WriteLine("Subscribed with user guid " + user.Id);
        }
Пример #20
0
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            // Let the approval manager know that this client is no longer participating
            //  in the approval system because the client app is closing
            if (subscribed)
            {
                SubscriptionServiceClient sclient = new SubscriptionServiceClient();

                sclient.Endpoint.Address = subscriptionAddr;

                statusWriter.WriteLine("Unsubcribing from service ...");
                try
                {
                    sclient.Unsubscribe(user);
                    statusWriter.WriteLine("Unsubscribed");
                }
                catch (Exception)
                {
                    statusWriter.WriteLine("Failed to unsubscribe from service ...");
                }
            }

            wsh.Close();
            sh.Close();

            base.OnClosing(e);
        }
 public MemberController()
 {
     _channelClient      = ChannelServiceClient.Create();
     _subscriptionClient = SubscriptionServiceClient.Create();
     _itemClient         = ItemServiceClient.Create();
 }