public void CanWeSubscribe()
        {
            Account acc = zth.MakeTestAccount();
            Contact con = zth.MakeTestContact();
            PaymentMethod pay = zth.MakeTestPaymentMethod();

            String productRatePlanId = zth.CreateRatePlanToSubscribe();
            PreviewOptions po = new PreviewOptions();
            SubscribeOptions so = new SubscribeOptions();
            ProductRatePlanHolder prph = new ProductRatePlanHolder();

            ProductRatePlan prp = new ProductRatePlan();
            prp.Id = productRatePlanId;

            prph.ProductRatePlan = prp;

            ResponseHolder queryRes = zs.Query("SELECT id, ChargeModel FROM ProductRatePlanCharge WHERE productrateplanid = '" + productRatePlanId + "'");
            ProductRatePlanCharge prpc = (ProductRatePlanCharge)queryRes.Objects[0];
            prpc.DefaultQuantity = 11;

            ProductRatePlanChargeHolder prpch = new ProductRatePlanChargeHolder();
            prpch.ProductRatePlanCharge = prpc;

            prph.ProductRatePlanCharges = new List<ProductRatePlanChargeHolder> { prpch };

            SubscribeResponseHolder subResp = sm.Subscribe(acc, con, pay, new List<ProductRatePlanHolder> { prph }, zth.MakeTestSubscription(), po, so);
            Assert.True(subResp.Success);
        }
        /// <summary>
        /// 初始化消息监听器
        /// </summary>
        /// <param name="endPoint"></param>
        /// <param name="innerListener"></param>
        /// <param name="options"></param>
        public MessageListener(EndPoint endPoint, IStatusListener innerListener, SubscribeOptions options, string[] subscribeTypes)
            : this(endPoint, innerListener)
        {
            _options = options;

            if (subscribeTypes == null)
                _subscribeTypes = new List<string>();
            else
                _subscribeTypes = new List<string>(subscribeTypes);
        }
        public void Subscribe_ShouldTrackSubscriptions()
        {
            var session = new TestableMessageSession();
            var options = new SubscribeOptions();

            session.Subscribe(typeof(MyEvent), options);

            Assert.AreEqual(1, session.Subscriptions.Length);
            Assert.AreSame(options, session.Subscriptions[0].Options);
            Assert.AreEqual(typeof(MyEvent), session.Subscriptions[0].Message);
        }
Exemplo n.º 4
0
        public SubscribeContext(IBehaviorContext parentContext, Type eventType, SubscribeOptions options)
            : base(parentContext)
        {
            Guard.AgainstNull(nameof(parentContext), parentContext);
            Guard.AgainstNull(nameof(eventType), eventType);
            Guard.AgainstNull(nameof(options), options);

            parentContext.Extensions.Merge(options.Context);

            EventType = eventType;
        }
Exemplo n.º 5
0
        public void Subscribe(ISubscribeRequest <TMessage> request, SubscribeOptions options)
        {
            RemoteWampTopicSubscriber remoteSubscriber =
                new RemoteWampTopicSubscriber(this.SubscriptionId,
                                              request.Client as IWampSubscriber);

            IWampClientProxy <TMessage> client = request.Client;

            RemoteObserver observer = mSubscriberBook.Subscribe(client);

            if (!observer.IsOpen)
            {
                this.RaiseSubscriptionAdding(remoteSubscriber, options);
            }

            request.Subscribed(this.SubscriptionId);

            if (!observer.IsOpen)
            {
                this.RaiseSubscriptionAdded(remoteSubscriber, options);

                observer.Open();
            }
        }
Exemplo n.º 6
0
 public Subscription(long subscriptionId, IWampRawTopicClientSubscriber subscriber, SubscribeOptions options, string topicUri) :
     base(subscriber, options, topicUri)
 {
     SubscriptionId = subscriptionId;
 }
 public Task Subscribe(Type eventType, SubscribeOptions options)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 public BaseSubscription(IWampRawTopicClientSubscriber subscriber, SubscribeOptions options, string topicUri)
 {
     Subscriber = subscriber;
     Options    = options;
     mTopicUri  = topicUri;
 }
 public Task <long?> LookupSubscriptionIdAsync(string topicUri, SubscribeOptions options)
 {
     return(mSubscriptionDescriptor.LookupSubscriptionIdAsync(topicUri, options));
 }
 /// <summary>
 /// Maps an endpoint that will respond to requests to <c>/dapr/subscribe</c> from the
 /// Dapr runtime.
 /// </summary>
 /// <param name="endpoints">The <see cref="IEndpointRouteBuilder" />.</param>
 /// <param name="options">Configuration options</param>
 /// <returns>The <see cref="IEndpointConventionBuilder" />.</returns>
 /// <seealso cref="MapSubscribeHandler(IEndpointRouteBuilder)"/>
 public static IEndpointConventionBuilder MapSubscribeHandler(this IEndpointRouteBuilder endpoints, SubscribeOptions options)
 {
     return(CreateSubscribeEndPoint(endpoints, options));
 }
Exemplo n.º 11
0
 public void Subscribe(IWampSubscriber subscriber, long requestId, SubscribeOptions options, string topicUri)
 {
     throw new System.NotImplementedException();
 }
        public void CanWeSubscribeWithoutChargeInfo()
        {
            Account acc = zth.MakeTestAccount();
            Contact con = zth.MakeTestContact();
            PaymentMethod pay = zth.MakeTestPaymentMethod();

            String productRatePlanId = zth.CreateRatePlanToSubscribe();
            PreviewOptions po = new PreviewOptions();
            SubscribeOptions so = new SubscribeOptions();
            ProductRatePlanHolder prph = new ProductRatePlanHolder();

            ProductRatePlan prp = new ProductRatePlan();
            prp.Id = productRatePlanId;

            prph.ProductRatePlan = prp;

            SubscribeResponseHolder subResp = sm.Subscribe(acc, con, pay, new List<ProductRatePlanHolder> { prph }, zth.MakeTestSubscription(), po, so);
            Assert.True(subResp.Success);
        }
Exemplo n.º 13
0
 public override bool Handles(SubscribeOptions options)
 {
     return(options.Match == WampMatchPattern.Wildcard);
 }
Exemplo n.º 14
0
        protected override async Task SubscribeAsyncImpl(Type messageType, Func <object, CancellationToken, Task> handler, SubscribeOptions subscribeOptions, CancellationToken cancellationToken)
        {
            await EnsureConnectionAndPublishChannelCreated().ConfigureAwait(false);

            var exchangeName = GetExchangeName(subscribeOptions.Scope, messageType);
            var queueName    = GetQueueName(subscribeOptions, messageType);

            var channel = _connection.CreateModel();

            channel.BasicQos(0, 25, true);
            channel.ExchangeDeclare(exchangeName, ExchangeType.Fanout, durable: true, autoDelete: true);
            channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: !subscribeOptions.IsExclusive);
            channel.QueueBind(queueName, exchangeName, string.Empty);

            var singleAckPerChannel = new AsyncLock();

            var consumer = new AsyncEventingBasicConsumer(channel);

            consumer.Received += async(model, ea) =>
            {
                bool TryEnqueue() => _taskQueue.Enqueue(async() =>
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        var bodyString = Encoding.UTF8.GetString(ea.Body);

                        try
                        {
                            var envelope = JsonConvert.DeserializeObject <MessageEnvelope>(bodyString, _jsonSerializerSettings);
                            var message  = JsonConvert.DeserializeObject(envelope.Data, envelope.Type, _jsonSerializerSettings);

                            await handler(message, cancellationToken).ConfigureAwait(false);
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e, $"Error while handling message: {bodyString}");
                        }

                        using (await singleAckPerChannel.LockAsync().ConfigureAwait(false))
                        {
                            try
                            {
                                channel.BasicAck(ea.DeliveryTag, false);
                            }
                            catch (Exception e)
                            {
                                _logger.LogError(e, "Error while sending Ack");
                            }
                        }
                    }
                });

                while (!cancellationToken.IsCancellationRequested && !TryEnqueue())
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(150), cancellationToken).ConfigureAwait(false);
                }
            };

            channel.BasicConsume(queueName, false, consumer);

            _subscribeChannels.Add(channel);
        }
Exemplo n.º 15
0
        internal SubscribeResult subscribe(
            String SubscriptionName,
            ProductRatePlanCharge[] charges,
            string Name, 
            string FirstName, 
            string LastName, 
            string WorkEmail, 
            string WorkPhone, 
            string Address1, 
            string Address2, 
            string City, 
            string State, 
            string Country, 
            string PostalCode, 
            string CreditCardType, 
            string CreditCardNumber, 
            string CreditCardHolderName, 
            int CreditCardExpirationMonth,
            int CreditCardExpirationYear)
        {
            Account acc = makeAccount(Name, "USD");
            Contact con = makeContact(FirstName, LastName, WorkEmail, WorkPhone, Address1, Address2, City, State, Country, PostalCode);

            PaymentMethod pm = makePaymentMethod(CreditCardHolderName, Address1, City, State, Country, PostalCode, CreditCardType, CreditCardNumber, CreditCardExpirationMonth, CreditCardExpirationYear);
            Subscription subscription = makeSubscription(SubscriptionName, null);

            SubscriptionData sd = new SubscriptionData();
            sd.Subscription = subscription;

            RatePlanData[] subscriptionRatePlanDataArray = makeRatePlanData(charges);
            sd.RatePlanData = subscriptionRatePlanDataArray;

            SubscribeOptions options = new SubscribeOptions();
            options.GenerateInvoice = GENERATE_INVOICE;
            options.ProcessPayments = PROCESS_PAYMENTS;

            SubscribeRequest sub = new SubscribeRequest();
            sub.Account = acc;
            sub.BillToContact = con;
            sub.PaymentMethod = pm;
            sub.SubscriptionData = sd;
            sub.SubscribeOptions = options;

            SubscribeRequest[] subscribes = new SubscribeRequest[1];
            subscribes[0] = sub;

            SubscribeResult[] result = binding.subscribe(subscribes);

            return result[0];
        }
Exemplo n.º 16
0
 public override IWampCustomizedSubscriptionId GetSubscriptionId(string topicUri, SubscribeOptions options)
 {
     return(new WildCardSubscriptionId(topicUri));
 }
Exemplo n.º 17
0
        /// <inheritdoc />
        public async Task Subscribe(Type eventType, SubscribeOptions options, ExecutionContext executionContext, ILogger functionsLogger = null)
        {
            await InitializeEndpointUsedOutsideHandlerIfNecessary(executionContext, functionsLogger).ConfigureAwait(false);

            await endpoint.Subscribe(eventType, options).ConfigureAwait(false);
        }
 /// <summary>
 /// Subscribes to receive published messages of the specified type.
 /// This method is only necessary if you turned off auto-subscribe.
 /// </summary>
 /// <param name="eventType">The type of event to subscribe to.</param>
 /// <param name="options">Options for the subscribe.</param>
 public virtual Task Subscribe(Type eventType, SubscribeOptions options)
 {
     subscriptions.Enqueue(new Subscription(eventType, options));
     return Task.FromResult(0);
 }
Exemplo n.º 19
0
 public SubscribeResult Subscribe(string members, SubscribeOptions options = SubscribeOptions.None)
 {
     return SubscribeOrInvite(members, SubscribeAction.Subscribe, options);
 }
Exemplo n.º 20
0
 public Task Subscribe(Type eventType, SubscribeOptions options) => Task.CompletedTask;
Exemplo n.º 21
0
 /// <summary>
 /// Subscribes to receive published messages of the specified type.
 /// This method is only necessary if you turned off auto-subscribe.
 /// </summary>
 /// <param name="eventType">The type of event to subscribe to.</param>
 /// <param name="options">Options for the subscribe.</param>
 public Task Subscribe(Type eventType, SubscribeOptions options)
 {
     return(BusOperations.Subscribe(this, eventType, options));
 }
Exemplo n.º 22
0
        protected void DoAction(object sender, EventArgs e)
        {
            zs = (ZuoraService)Session["zs"];
            AccountManager am = new AccountManager(zs);
            PaymentManager pm = new PaymentManager(zs);
            ProductCatalogManager pcm = new ProductCatalogManager(zs,   "C:\\localCache.txt");
            SubscriptionManager sm = new SubscriptionManager(zs);

            if (zs != null)
            {
                var operation = ddl1.SelectedValue;

                if (operation == "Create Account")
                {
                    result.Text += "<br/>";
                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    var res = am.CreateAccount(acc, con);
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Create Child Account And Increase Credit Balance")
                {
                    result.Text += "<br/>";

                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    var res = am.CreateChildAccountAndIncreaseCreditBalance(acc, ParentAccountId.Text, con, Convert.ToDecimal(AmountBox.Text));
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Cancel Credit Balance Adjustment On Invoice")
                {
                    result.Text += "<br/>";
                    var res = pm.CancelCreditBalanceAdjustmentOnInvoice(InvoiceId.Text);
                    result.Text += res.Success ? res.Id : res.Message;
                }
                else if (operation == "Get Invoices For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetInvoicesForAccount(AccountId.Text);
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    //var res = zs.Query("");
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                Invoice inv = (Invoice)zo;
                                result.Text += "Invoice Number: " + inv.InvoiceNumber + " Invoice Amount: " + inv.Amount + " Status: " + inv.Status + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Refunds For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetRefundsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                Refund refund = (Refund)zo;
                                result.Text += "Refund Id: " + refund.Id + " Refund Amount: " + refund.Amount + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Credit Balance Adjustments For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetCreditBalanceAdjustmentsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                CreditBalanceAdjustment cba = (CreditBalanceAdjustment)zo;
                                result.Text += "CBA Id: " + cba.Id + " CBA Amount: " + cba.Amount + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Credit Cards For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetCreditCardsForAccount(AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            foreach (zObject zo in res.Objects)
                            {
                                PaymentMethod payMethod = (PaymentMethod)zo;
                                result.Text += "PM Id: " + payMethod.Id + " PM Type: " + payMethod.Type + "<br/>";
                            }
                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get PO For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetPOForAccount(AccountId.Text);
                    result.Text += "PO: " + res;
                }
                else if (operation == "Get Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetAccount(AccountId.Text);
                    if (res.Success && res.Objects != null)
                    {
                        Account acc = (Account)res.Objects[0];
                        result.Text += "Account Name: " + acc.Name + "<br/>";
                        result.Text += "Account Credit Balance: " + acc.CreditBalance + "<br/>";
                    }
                    else
                    {
                        result.Text += res.Message;
                    }

                }
                else if (operation == "Get Contact")
                {
                    var res = am.GetContact(AccountId.Text);

                    if (res.Success && res.Objects != null)
                    {
                        result.Text += "<br/>";
                        foreach (zObject zo in res.Objects)
                        {
                            Contact con = (Contact)zo;
                            result.Text += "Contact First Name: " + con.FirstName + "<br/>";
                            result.Text += "Contact Last Name: " + con.LastName + "<br/>";
                            result.Text += "Contact Email: " + con.WorkEmail + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Change Invoice Template")
                {
                    result.Text += "<br/>";
                    var res = am.ChangeInvoiceTemplate(AccountId.Text, InvoiceTemplateId.Text);
                    if (res.Success)
                    {
                        result.Text += res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Does Account Name Exist In Zuora")
                {
                    result.Text += "<br/>";
                    var res = am.DoesAccountNameExistInZuora(AccountName.Text);
                    result.Text += "Account Exists? " + res;
                }
                else if (operation == "Get Child Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetChildAccount(AccountId.Text);
                    if (res.Success && res.Objects != null)
                    {
                        Account acc = (Account)res.Objects[0];
                        result.Text += "Account Name: " + acc.Name + "<br/>";
                        result.Text += "Account Credit Balance: " + acc.CreditBalance + "<br/>";
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Set Parent Account")
                {
                    result.Text += "<br/>";
                    var res = am.SetParentAccount(ParentAccountId.Text, AccountId.Text);
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Single Invoice")
                {
                    result.Text += "<br/>";
                    //var res = am.GetSingleInvoice(InvoiceId.Text);
                    //var res = zs.Query("SELECT id, status FROM Invoice WHERE Id = '" + InvoiceId.Text + "'").FirstOrDefault<Invoice>();
                    Boolean withBody = false;
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Status";
                    var query = string.Format("SELECT {0} FROM invoice WHERE Id = '{1}'", FIELDS_INVOICE, InvoiceId.Text);
                    var res = zs.Query(query);
                    if (res.Success && res.Objects != null)
                    {
                        result.Text += "Success: " + res.Id;
                        result.Text += "Invoice Amount: " + ((Invoice)res.Objects[0]).Amount;
                        result.Text += " Status: " + ((Invoice)res.Objects[0]).Status;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Increase Credit Balance")
                {
                    var res = pm.IncreaseCreditBalance(AccountId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Apply Credit Balance To Invoice")
                {
                    var res = pm.ApplyCreditBalanceToInvoice(InvoiceId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Refund Electronic Payment")
                {
                    result.Text += "<br/>";
                    var res = pm.RefundElectronicPayment(PaymentId.Text, Convert.ToDecimal(RefundAmount.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Decrease Credit Balance")
                {
                    result.Text += "<br/>";
                    var res = pm.DecreaseCreditBalance(AccountId.Text, Convert.ToDecimal(AmountBox.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Apply Payment To Invoice")
                {
                    result.Text += "<br/>";
                    var res = pm.ApplyPaymentToInvoice(AccountId.Text, InvoiceId.Text, PaymentMethodId.Text, Convert.ToDecimal(PaymentAmount.Text),PaymentMethodType.SelectedValue );
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Refund External Payment")
                {
                    result.Text += "<br/>";
                    var res = pm.RefundExternalPayment(PaymentId.Text, Convert.ToDecimal(RefundAmount.Text), PaymentMethodType.SelectedValue, Convert.ToDateTime(RefundDate.Text) );
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Product Catalog")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductCatalog();
                    if (res != null)
                    {
                        result.Text += "Success: " + "<br/>";
                        foreach (var ph in res)
                        {
                            result.Text += "<b>Product Name:</b>" + ph.Product.Name + "<br/>";
                            foreach (var prph in ph.ProductRatePlans)
                            {
                                result.Text += "<b>Product Rate Plan Name:</b>" + prph.ProductRatePlan.Name + "<br/>";
                            }
                        }
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Get Rate Plan By Name")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductRatePlanByName(Name.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.ProductRatePlan.Name;
                    }
                    else
                    {
                        result.Text += "Didn't find";
                    }
                }
                else if (operation == "Disable Rate Plan")
                {
                    result.Text += "<br/>";
                    var res = pcm.DisableRatePlan(ProductRatePlanId.Text, Convert.ToDateTime(DisableDate.Text));
                    if (res.Success)
                    {
                        result.Text += "Success: " + res.Id;
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                else if (operation == "Get Product By Name")
                {
                    result.Text += "<br/>";
                    var res = pcm.GetProductByName(Name.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.Product.Name;
                    }
                    else
                    {
                        result.Text += "Didn't Find";
                    }
                }
                else if (operation == "Create Product")
                {
                    result.Text += "<br/>";
                    Constants.ProductType pt = new Constants.ProductType();
                    if (ProductType.Text == "Application")
                    {
                        pt = Constants.ProductType.Application;
                    }
                    else if (ProductType.Text == "iCredits")
                    {
                        pt = Constants.ProductType.iCredits;
                    }
                    else if (ProductType.Text == "Storage")
                    {
                        pt = Constants.ProductType.Storage;
                    }

                    var res = pcm.CreateProduct(Name.Text, pt, SKU.Text, Description.Text);
                    if (res != null)
                    {
                        result.Text += "Success: " + res.Product.Id;
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Create Rate Plan With One Time Charge")
                {
                    Product prod = new Product();
                    prod.Id = ProductId.Text;
                    result.Text += "<br/>";
                    var res = pcm.CreateRatePlanWithOneTimeCharge(prod, Name.Text, Convert.ToDecimal(Price.Text));
                    if (res != null)
                    {
                        result.Text += "Success: " + res.ProductRatePlan.Id;
                    }
                    else
                    {
                        result.Text += "Error";
                    }
                }
                else if (operation == "Delete Rate Plan")
                {
                    pcm.DeleteRatePlan(IdToDelete.Text);
                }
                else if (operation == "Delete Product")
                {
                    pcm.DeleteProduct(IdToDelete.Text);
                }
                else if (operation == "Change Price For Product")
                {
                    List<ResponseHolder> resps = pcm.ChangePriceForProduct(ProductRatePlanChargeId.Text, new decimal[] { Convert.ToDecimal(Price.Text) }, "USD");
                    result.Text += "<br/>";
                    foreach (ResponseHolder resp in resps)
                    {
                        if (resp.Success)
                        {
                            result.Text += resp.Id;
                        }
                        else
                        {
                            result.Text += resp.Message;
                        }
                    }
                }
                else if (operation == "Subscribe")
                {
                    result.Text += "<br/>";
                    Account acc = new Account();
                    acc.Name = AccountName.Text;
                    acc.BillCycleDaySpecified = true;
                    acc.BillCycleDay = Convert.ToInt16(BillCycleDay.Text);
                    acc.Currency = Currency.Text;
                    acc.PaymentTerm = PaymentTermDropDown.SelectedValue;
                    acc.Batch = Batch.Text;

                    Contact con = new Contact();
                    con.Address1 = Address1.Text;
                    con.Address2 = Address2.Text;
                    con.City = City.Text;
                    con.State = State.Text;
                    con.LastName = LastName.Text;
                    con.FirstName = FirstName.Text;
                    con.Country = Country.Text;
                    con.PostalCode = Zip.Text;

                    DateTime date = Convert.ToDateTime(SubscriptionDate.Text);

                    Subscription sub = new Subscription();
                    sub.ContractAcceptanceDateSpecified = true;
                    sub.ContractAcceptanceDate = date;
                    sub.ServiceActivationDateSpecified = true;
                    sub.ServiceActivationDate = date;
                    sub.ContractEffectiveDateSpecified = true;
                    sub.ContractEffectiveDate = date;

                    sub.TermType = SubscriptionTermType.Text;
                    if (SubscriptionTermType.Text == "TERMED")
                    {
                        sub.InitialTermSpecified = true;
                        sub.InitialTerm = 12;
                        sub.RenewalTermSpecified = true;
                        sub.RenewalTerm = 12;
                    }

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    SubscribeOptions so = new SubscribeOptions();
                    so.GenerateInvoiceSpecified = false;
                    so.GenerateInvoice = false;
                    so.ProcessPaymentsSpecified = false;
                    so.ProcessPayments = false;

                    ProductRatePlanHolder prph = pcm.GetProductRatePlanByName(ProductRatePlanName.Text);

                    SubscribeResponseHolder resp = sm.Subscribe( acc, con, null, new List<ProductRatePlanHolder> { prph }, sub, po, so);

                    if (resp.Success)
                    {
                        result.Text += resp.SubRes.AccountId;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }

                }
                else if (operation == "Subscribe With Existing Account")
                {
                    result.Text += "<br/>";
                    DateTime date = Convert.ToDateTime(SubscriptionDate.Text);

                    Subscription sub = new Subscription();
                    sub.ContractAcceptanceDateSpecified = true;
                    sub.ContractAcceptanceDate = date;
                    sub.ServiceActivationDateSpecified = true;
                    sub.ServiceActivationDate = date;
                    sub.ContractEffectiveDateSpecified = true;
                    sub.ContractEffectiveDate = date;

                    sub.TermType = SubscriptionTermType.Text;
                    if (SubscriptionTermType.Text == "TERMED")
                    {
                        sub.InitialTermSpecified = true;
                        sub.InitialTerm = 12;
                        sub.RenewalTermSpecified = true;
                        sub.RenewalTerm = 12;
                    }

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    SubscribeOptions so = new SubscribeOptions();
                    so.GenerateInvoiceSpecified = false;
                    so.GenerateInvoice = false;
                    so.ProcessPaymentsSpecified = false;
                    so.ProcessPayments = false;

                    ProductRatePlanHolder prph = pcm.GetProductRatePlanByName(ProductRatePlanName.Text);

                    SubscribeResponseHolder resp = sm.SubscribeWithExisitingAccount(AccountId.Text, new List<ProductRatePlanHolder>{prph}, sub, po, so);
                    if (resp.Success)
                    {
                        result.Text += resp.SubRes.AccountId;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Add Product Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = false;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoAddProductAmendment(SubscriptionId.Text, Convert.ToDateTime(AmendmentStartDate.Text), ProductRatePlanId.Text, ao, po);
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Renewal Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = true;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoRenewalAmendment(SubscriptionId.Text, Convert.ToDateTime(AmendmentStartDate.Text), ao, po);
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Do Terms And Conditions Amendment")
                {
                    AmendOptions ao = new AmendOptions();
                    ao.GenerateInvoiceSpecified = true;
                    ao.GenerateInvoice = false;

                    ao.ProcessPaymentsSpecified = true;
                    ao.ProcessPayments = false;

                    PreviewOptions po = new PreviewOptions();
                    po.EnablePreviewModeSpecified = false;
                    po.EnablePreviewMode = false;

                    AmendResponseHolder resp = sm.DoTermsAndConditionsAmendment(
                                                    SubscriptionId.Text,
                                                    Convert.ToDateTime(AmendmentStartDate.Text),
                                                    SubscriptionTermType.SelectedValue,
                                                    Convert.ToInt32(InitialTerm.Text),
                                                    Convert.ToInt32(RenewalTerm.Text),
                                                    ao,
                                                    po
                                               );
                    if (resp.Success)
                    {
                        result.Text += resp.AmendRes.AmendmentIds[0];
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Get Subscription And Charge Info")
                {
                    SubscriptionInfoHolder sih = sm.GetSubscriptionAndChargeInfo(SubscriptionId.Text);
                    if (sih.Success)
                    {
                        result.Text += "<b>SubId:</b>" + sih.Subscription.Id + "<br/>";
                        foreach (RatePlan rp in sih.RatePlanList)
                        {
                            result.Text += "<b>RP Name:</b>" + rp.Name + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += sih.Message;
                    }
                }
                else if (operation == "Update Contact")
                {
                    ResponseHolder resp = am.UpdateContact(AccountId.Text, LastName.Text, FirstName.Text, Address1.Text, City.Text, State.Text, Zip.Text, Country.Text);

                    if (resp.Success)
                    {
                        result.Text += resp.Id;
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if(operation == "Get Credit Cards")
                {
                    ResponseHolder resp = am.GetCreditCardsPaymentMethods(AccountId.Text);

                    if (resp.Success)
                    {
                        foreach (zObject zo in resp.Objects)
                        {
                            PaymentMethod paymentMethod = (PaymentMethod)zo;
                            result.Text += "Payment Method: " + paymentMethod.Id + "<br/>";
                        }
                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if (operation == "Get Invoices PDF For Account")
                {
                    result.Text += "<br/>";
                    var res = am.GetInvoicesForAccount(AccountId.Text);
                    //string FIELDS_INVOICE = "Id, AccountId, AdjustmentAmount, Amount, AmountWithoutTax, Balance, Comments, CreatedDate, DueDate, IncludesOneTime, IncludesRecurring, IncludesUsage, InvoiceDate, InvoiceNumber, LastEmailSentDate, PaymentAmount, PostedDate, RefundAmount, Source, SourceId, Status, TargetDate, TaxAmount, TaxExemptAmount, TransferredToAccounting, UpdatedDate";
                    //var res = zs.Query("");
                    if (res.Success)
                    {
                        result.Text += "<br/>";
                        if (res.Objects != null)
                        {
                            Invoice invoice = (Invoice) res.Objects[0];
                            foreach (zObject zo in res.Objects)
                            {
                                Invoice inv = (Invoice)zo;
                                if (inv.CreatedDate > invoice.CreatedDate)
                                {
                                    invoice = inv;
                                }
                                result.Text += "Invoice Number: " + inv.InvoiceNumber + " Invoice Amount: " + inv.Amount + " Status: " + inv.Status + "<br/>";
                            }

                            Invoice invRes = (Invoice)am.GetInvoicePDFForAccount(invoice.Id).Objects[0];
                            var invoiceBody = invRes.Body;

                            Byte[] bytes = System.Convert.FromBase64String(invoiceBody.ToString());

                            string pathString = @"C:\Users\sxuereb\Documents\Invoices";
                            string fileName = invRes.InvoiceNumber +".pdf";
                            pathString = System.IO.Path.Combine(pathString, fileName);

                            if (!System.IO.File.Exists(pathString))
                            {
                                using (System.IO.FileStream fs = System.IO.File.Create(pathString))
                                {
                                    for (int i = 0; i < bytes.Length; i++)
                                    {
                                        fs.WriteByte(bytes[i]);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("File \"{0}\" already exists.", fileName);
                                return;
                            }

                        }
                        else
                        {
                            result.Text += res.Message;
                        }
                    }
                    else
                    {
                        result.Text += res.Message;
                    }
                }
                /*else if(operation == "Get Current Subscription")
                {
                    ResponseHolder resp = sm.GetCurrentSubscription(AccountId.Text);

                    if (resp.Success)
                    {

                    }
                    else
                    {
                        result.Text += resp.Message;
                    }
                }
                else if(operation == "New Credit Card")
                {

                }*/
                else if (operation == "Delete Payment Method")
                {
                    List<ResponseHolder> resp = am.DeletePaymentMethod(PaymentMethodId.Text);

                    if (resp[0].Success)
                    {
                        result.Text += "Successfully Deleted Payment Method.";
                    }
                    else
                    {
                        result.Text += resp[0].Message;
                    }
                }

            }
            else
            {
                result.Text += "Please Login" + "<br/>";
            }

            ddl1.SelectedIndex = 0;
        }
Exemplo n.º 23
0
 public bool CanSubscribe(SubscribeOptions options, string topicUri)
 {
     return(true);
 }
Exemplo n.º 24
0
        public Task <IAsyncDisposable> Subscribe(IWampRawTopicClientSubscriber subscriber, SubscribeOptions options)
        {
            Task <IAsyncDisposable> task =
                mSubscriber.Subscribe(subscriber, options, this.TopicUri);

            return(task);
        }
        public void CanWeSubscribeToMultipleRatePlansWithExistingAccount()
        {
            String accId = zth.MakeSubscription(true).SubRes.AccountId;
            String productRatePlanId = zth.CreateRatePlanToSubscribe();
            PreviewOptions po = new PreviewOptions();
            SubscribeOptions so = new SubscribeOptions();

            ProductRatePlanHolder prph = new ProductRatePlanHolder();

            ProductRatePlan prp = new ProductRatePlan();
            prp.Id = productRatePlanId;

            prph.ProductRatePlan = prp;

            ResponseHolder queryRes = zs.Query("SELECT id, ChargeModel FROM ProductRatePlanCharge WHERE productrateplanid = '" + productRatePlanId + "'");
            ProductRatePlanCharge prpc = (ProductRatePlanCharge)queryRes.Objects[0];
            prpc.DefaultQuantity = 11;

            ProductRatePlanChargeHolder prpch = new ProductRatePlanChargeHolder();
            prpch.ProductRatePlanCharge = prpc;

            prph.ProductRatePlanCharges = new List<ProductRatePlanChargeHolder> { prpch };

            SubscribeResponseHolder subResp = sm.SubscribeWithExisitingAccount(accId, new List<ProductRatePlanHolder> { prph, prph }, zth.MakeTestSubscription(), po, so);
            Assert.True(subResp.Success);
        }
Exemplo n.º 26
0
 public WampMessage <object> Subscribe(long requestId, SubscribeOptions options, string topicUri)
 {
     return(mSerializer.SerializeRequest(mSubscribe3, new object[] { requestId, options, topicUri }));
 }
        /// <inheritdoc />
        public async Task Subscribe(Type eventType, SubscribeOptions options, ILambdaContext lambdaContext)
        {
            await InitializeEndpointIfNecessary(lambdaContext).ConfigureAwait(false);

            await endpoint.Subscribe(eventType, options).ConfigureAwait(false);
        }
Exemplo n.º 28
0
 public long?LookupSubscriptionId(string topicUri, SubscribeOptions options)
 {
     return(mSubscriptionDescriptor.LookupSubscriptionId(topicUri, options));
 }
        /*public ResponseHolder GetCurrentSubscription(String subscriptionId)
        {
            String subscriptionQuery = "SELECT Id,Name,Status,Version,PreviousSubscriptionId,ContractEffectiveDate,TermStartDate FROM Subscription WHERE AccountId='" + subscriptionId + "' AND Status='Active'AND Status='Active'";
            Subscription activeSubscription = (Subscription)zs.Query(subscriptionQuery).Objects[0];

            String RatePlanString = "SELECT Id,Name,ProductRatePlanId FROM RatePlan WHERE SubscriptionId='" + activeSubscription.Id + "'";
            ResponseHolder ratePlans = zs.Query(RatePlanString);

            foreach (zObject ratePlan in ratePlans.Objects)
            {

            }
        }*/
        public SubscribeResponseHolder Subscribe(Account acc, Contact con, PaymentMethod pay, List<ProductRatePlanHolder> productRatePlans, Subscription sub, PreviewOptions po, SubscribeOptions so)
        {
            SubscribeRequest subscribeRequest = new SubscribeRequest();
            subscribeRequest.SubscribeOptions = so;
            subscribeRequest.PreviewOptions = po;

            subscribeRequest.Account = acc;
            subscribeRequest.BillToContact = con;
            //Payment Method isn't required to subscribe
            if (pay != null)
            {
                subscribeRequest.PaymentMethod = pay;
            }

            SubscriptionData subData = new SubscriptionData();
            sub.AccountId = acc.Id;
            subData.Subscription = sub;
            List<RatePlanData> rpdList = new List<RatePlanData>();

            foreach (ProductRatePlanHolder prph in productRatePlans)
            {

                RatePlanData ratePlanData = new RatePlanData();
                RatePlan ratePlan = new RatePlan();
                ratePlan.ProductRatePlanId = prph.ProductRatePlan.Id;
                ratePlanData.RatePlan = ratePlan;
                List<RatePlanChargeData> rpcData = new List<RatePlanChargeData>();
                if (prph.ProductRatePlanCharges != null)
                {
                    foreach (ProductRatePlanChargeHolder prpch in prph.ProductRatePlanCharges)
                    {
                        ProductRatePlanCharge prpc = prpch.ProductRatePlanCharge;
                        //set quantity and add chargeData if applicable
                        if ((prpc.ChargeModel.Equals("Per Unit Pricing") || prpc.ChargeModel.Equals("Tiered Pricing") || prpc.ChargeModel.Equals("Volume Pricing")))
                        {
                            RatePlanChargeData ratePlanChargeData = new RatePlanChargeData();
                            RatePlanCharge ratePlanCharge = new RatePlanCharge();
                            ratePlanCharge.ProductRatePlanChargeId = prpc.Id;
                            ratePlanCharge.QuantitySpecified = true;
                            ratePlanCharge.Quantity = prpc.DefaultQuantity;
                            ratePlanChargeData.RatePlanCharge = ratePlanCharge;
                            rpcData.Add(ratePlanChargeData);
                        }
                    }
                }
                if (rpcData.Count != 0)
                {
                    ratePlanData.RatePlanChargeData = rpcData.ToArray();
                }
                rpdList.Add(ratePlanData);

            }

            subData.RatePlanData = rpdList.ToArray();
            subscribeRequest.SubscriptionData = subData;
            return zs.Subscribe(new List<SubscribeRequest> { subscribeRequest })[0];
        }
Exemplo n.º 30
0
 public Task Subscribe(Type eventType, SubscribeOptions subscribeOptions)
 {
     Guard.AgainstNull(nameof(eventType), eventType);
     Guard.AgainstNull(nameof(subscribeOptions), subscribeOptions);
     return(messageOperations.Subscribe(context, eventType, subscribeOptions));
 }
        public SubscribeResponseHolder SubscribeWithExisitingAccount(String accountId, List<ProductRatePlanHolder> productRatePlans, Subscription sub, PreviewOptions po, SubscribeOptions so)
        {
            SubscribeRequest subscribeRequest = new SubscribeRequest();
            subscribeRequest.SubscribeOptions = so;
            subscribeRequest.PreviewOptions = po;

            Account acc = new Account();
            acc.Id = accountId;
            subscribeRequest.Account = acc;

            SubscriptionData subData = new SubscriptionData();
            sub.AccountId = accountId;
            subData.Subscription = sub;

            List<RatePlanData> rpdList = new List<RatePlanData>();

            foreach (ProductRatePlanHolder prph in productRatePlans)
            {

                RatePlanData ratePlanData = new RatePlanData();
                RatePlan ratePlan = new RatePlan();
                ratePlan.ProductRatePlanId = prph.ProductRatePlan.Id;
                ratePlanData.RatePlan = ratePlan;
                List<RatePlanChargeData> rpcData = new List<RatePlanChargeData>();
                foreach(ProductRatePlanChargeHolder prpch in prph.ProductRatePlanCharges)
                {
                    ProductRatePlanCharge prpc = prpch.ProductRatePlanCharge;
                    //set quantity and add chargeData if applicable
                    if ((prpc.ChargeModel.Equals("Per Unit Pricing") || prpc.ChargeModel.Equals("Tiered Pricing") || prpc.ChargeModel.Equals("Volume Pricing")))
                    {
                        RatePlanChargeData ratePlanChargeData = new RatePlanChargeData();
                        RatePlanCharge ratePlanCharge = new RatePlanCharge();
                        ratePlanCharge.ProductRatePlanChargeId = prpc.Id;
                        ratePlanCharge.QuantitySpecified = true;
                        ratePlanCharge.Quantity = prpc.DefaultQuantity;
                        ratePlanChargeData.RatePlanCharge = ratePlanCharge;
                        rpcData.Add(ratePlanChargeData);
                    }
                }
                if (rpcData.Count != 0)
                {
                    ratePlanData.RatePlanChargeData = rpcData.ToArray();
                }
                rpdList.Add(ratePlanData);

            }

            subData.RatePlanData = rpdList.ToArray();
            subscribeRequest.SubscriptionData = subData;
            return zs.Subscribe(new List<SubscribeRequest>{subscribeRequest})[0];
        }
        private static IEndpointConventionBuilder CreateSubscribeEndPoint(IEndpointRouteBuilder endpoints, SubscribeOptions options = null)
        {
            if (endpoints is null)
            {
                throw new System.ArgumentNullException(nameof(endpoints));
            }

            return(endpoints.MapGet("dapr/subscribe", async context =>
            {
                var logger = context.RequestServices.GetService <ILoggerFactory>().CreateLogger("DaprTopicSubscription");
                var dataSource = context.RequestServices.GetRequiredService <EndpointDataSource>();
                var subscriptions = dataSource.Endpoints
                                    .OfType <RouteEndpoint>()
                                    .Where(e => e.Metadata.GetOrderedMetadata <ITopicMetadata>().Any(t => t.Name != null)) // only endpoints which have TopicAttribute with not null Name.
                                    .SelectMany(e =>
                {
                    var topicMetadata = e.Metadata.GetOrderedMetadata <ITopicMetadata>();
                    var subs = new List <(string PubsubName, string Name, bool?EnableRawPayload, string Match, int Priority, RoutePattern RoutePattern)>();

                    for (int i = 0; i < topicMetadata.Count(); i++)
                    {
                        subs.Add((topicMetadata[i].PubsubName,
                                  topicMetadata[i].Name,
                                  (topicMetadata[i] as IRawTopicMetadata)?.EnableRawPayload,
                                  topicMetadata[i].Match,
                                  topicMetadata[i].Priority,
                                  e.RoutePattern));
                    }

                    return subs;
                })
                                    .Distinct()
                                    .GroupBy(e => new { e.PubsubName, e.Name })
                                    .Select(e => e.OrderBy(e => e.Priority))
                                    .Select(e =>
                {
                    var first = e.First();
                    var rawPayload = e.Any(e => e.EnableRawPayload.GetValueOrDefault());
                    var rules = e.Where(e => !string.IsNullOrEmpty(e.Match)).ToList();
                    var defaultRoutes = e.Where(e => string.IsNullOrEmpty(e.Match)).Select(e => RoutePatternToString(e.RoutePattern)).ToList();
                    var defaultRoute = defaultRoutes.FirstOrDefault();

                    if (logger != null)
                    {
                        if (defaultRoutes.Count > 1)
                        {
                            logger.LogError("A default subscription to topic {name} on pubsub {pubsub} already exists.", first.Name, first.PubsubName);
                        }

                        var duplicatePriorities = rules.GroupBy(e => e.Priority)
                                                  .Where(g => g.Count() > 1)
                                                  .ToDictionary(x => x.Key, y => y.Count());

                        foreach (var entry in duplicatePriorities)
                        {
                            logger.LogError("A subscription to topic {name} on pubsub {pubsub} has duplicate priorities for {priority}: found {count} occurrences.", first.Name, first.PubsubName, entry.Key, entry.Value);
                        }
                    }

                    var subscription = new Subscription
                    {
                        Topic = first.Name,
                        PubsubName = first.PubsubName,
                        Metadata = rawPayload ? new Metadata
                        {
                            RawPayload = "true",
                        } : null,
                    };

                    // Use the V2 routing rules structure
                    if (rules.Count > 0)
                    {
                        subscription.Routes = new Routes
                        {
                            Rules = rules.Select(e => new Rule
                            {
                                Match = e.Match,
                                Path = RoutePatternToString(e.RoutePattern),
                            }).ToList(),
                            Default = defaultRoute,
                        };
                    }
                    // Use the V1 structure for backward compatibility.
                    else
                    {
                        subscription.Route = defaultRoute;
                    }

                    return subscription;
                })
                                    .OrderBy(e => (e.PubsubName, e.Topic));

                await context.Response.WriteAsync(JsonSerializer.Serialize(subscriptions,
                                                                           new JsonSerializerOptions
                {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
                    DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
                }));
            }));
        }
 public static async Task <Statuses> SubscribeAsync(this IMessages api, GoogleApiClient client, Android.App.PendingIntent pendingIntent, SubscribeOptions options)
 {
     return((await api.Subscribe(client, pendingIntent, options)).JavaCast <Statuses> ());
 }
Exemplo n.º 34
0
 /// <summary>
 /// Subscribes to receive published messages of the specified type.
 /// This method is only necessary if you turned off auto-subscribe.
 /// </summary>
 /// <param name="eventType">The type of event to subscribe to.</param>
 /// <param name="options">Options for the subscribe.</param>
 public virtual Task Subscribe(Type eventType, SubscribeOptions options, CancellationToken cancellationToken = default)
 {
     subscriptions.Enqueue(new Subscription(eventType, options));
     return(Task.FromResult(0));
 }
 public SubscriberRegistrationInterceptor(SubscribeOptions subscriptionOptions)
 {
     mSubscriptionOptions = subscriptionOptions;
 }
Exemplo n.º 36
0
 public SubscribeRequest(IWampFormatter <TMessage> formatter, IWampRawTopicClientSubscriber subscriber, SubscribeOptions options, string topicUri) :
     base(subscriber, options, topicUri)
 {
     mPendingRequest = new WampPendingRequest <TMessage, IAsyncDisposable>(formatter);
 }
Exemplo n.º 37
0
 public Task Subscribe(Type eventType, SubscribeOptions subscribeOptions, CancellationToken cancellationToken = default)
 {
     Guard.AgainstNull(nameof(eventType), eventType);
     Guard.AgainstNull(nameof(subscribeOptions), subscribeOptions);
     return(messageOperations.Subscribe(new BehaviorContext(context, cancellationToken), eventType, subscribeOptions));
 }
Exemplo n.º 38
0
        public Task <IAsyncDisposable> Subscribe(IWampRawTopicClientSubscriber subscriber, SubscribeOptions options, string topicUri)
        {
            if (!IsConnected)
            {
                throw new WampSessionNotEstablishedException();
            }

            SubscribeRequest request   = new SubscribeRequest(Formatter, subscriber, options, topicUri);
            long             requestId = mPendingSubscriptions.Add(request);

            request.RequestId = requestId;

            mProxy.Subscribe(requestId, options, topicUri);

            return(request.Task);
        }
Exemplo n.º 39
0
 public Task SubscribeAll(Type[] eventTypes, SubscribeOptions subscribeOptions, CancellationToken cancellationToken = default)
 {
     // set a flag on the context so that subscribe implementations know which send API was used.
     subscribeOptions.Context.Set(SubscribeAllFlagKey, true);
     return(messageOperations.Subscribe(new BehaviorContext(context, cancellationToken), eventTypes, subscribeOptions));
 }
Exemplo n.º 40
0
 public SubscribeResponseHolder MakeSubscription(bool processPayment, bool generateInvoice, DateTime date)
 {
     SubscribeRequest sr = CreatSubscriptionRequest(date);
     SubscribeOptions so = new SubscribeOptions();
     so.GenerateInvoiceSpecified = true;
     so.GenerateInvoice = generateInvoice;
     so.ProcessPaymentsSpecified = true;
     so.ProcessPayments = processPayment;
     sr.SubscribeOptions = so;
     SubscribeResponseHolder sub = zs.Subscribe(new List<SubscribeRequest> { sr })[0];
     AddToCleanup(sub.SubRes.AccountId, "Account");
     return sub;
 }
Exemplo n.º 41
0
        private SubscribeResult SubscribeOrInvite(string members, SubscribeAction action, SubscribeOptions options = SubscribeOptions.None)
        {
            var result = new SubscribeResult();

            if (!String.IsNullOrWhiteSpace(members))
            {
                var req = new RestRequest();
                req.AddParameter("subscribees", members);
                req.AddParameter("subscribe_or_invite", action == SubscribeAction.Subscribe ? 0 : 1);
                req.AddParameter("send_welcome_msg_to_this_batch", options.HasFlag(SubscribeOptions.SendWelcomeMessage).ToInt());
                req.AddParameter("send_notifications_to_list_owner", options.HasFlag(SubscribeOptions.NotifyOwner).ToInt());

                var resp = this.GetClient().ExecutePostAdminRequest(_addPage, req);
                var doc = GetHtmlDocument(resp.Content);
                
                string verb = action == SubscribeAction.Invite ? "invited" : "subscribed";
                string xpath = String.Format("//h5[contains(translate(text(), 'SI', 'si'), 'successfully {0}')]/following-sibling::ul[1]/li", verb);
                foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath))
                    result.Subscribed.Add(node.InnerText.Trim());

                verb = action == SubscribeAction.Invite ? "inviting" : "subscribing";
                xpath = String.Format("//h5[contains(translate(text(), 'ESI', 'esi'),'error {0}')]/following-sibling::ul[1]/li", verb);
                foreach (var node in doc.DocumentNode.SafeSelectNodes(xpath))
                {
                    var match = Regex.Match(node.InnerText, "(.*) -- (.*)");
                    var email = match.Groups[1].Value;
                    var reason = match.Groups[2].Value;
                    if (Regex.IsMatch(reason, "Already", RegexOptions.IgnoreCase))
                        result.AlreadyMembers.Add(email);
                    else if (Regex.IsMatch(reason, "Bad/Invalid", RegexOptions.IgnoreCase))
                        result.BadEmails.Add(email);
                }

                if (action == SubscribeAction.Subscribe && _emailListPopulated)
                    PopulateEmailList();
            }

            return result;
        }
Exemplo n.º 42
0
 public Task Subscribe(Type eventType, SubscribeOptions options)
 {
     return(MessageOperations.Subscribe(context, eventType, options));
 }
Exemplo n.º 43
0
 public Task Subscribe(Type eventType, SubscribeOptions options)
 {
     return(messageSession.Subscribe(eventType, options));
 }
 public void Subscribe(long requestId, SubscribeOptions options, string topicUri)
 {
     Send(mSubscribe3, requestId, options, topicUri);
 }
Exemplo n.º 45
0
 public SubscribeResult Subscribe(IEnumerable<string> members, SubscribeOptions options = SubscribeOptions.None)
 {
     return Subscribe(members.Cat(), options);
 }