Exemple #1
0
        public async Task <PartialViewResult> ListSubscriptionsAsync(string customerId)
        {
            IAggregatePartner operations;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            try
            {
                operations = await new SdkContext().GetOperationsAsync();

                SubscriptionsModel subscriptionsModel = new SubscriptionsModel()
                {
                    CustomerId    = customerId,
                    Subscriptions = await GetSubscriptionsAsync(customerId)
                };

                return(PartialView("ListSubscriptions", subscriptionsModel));
            }
            finally
            {
                operations = null;
            }
        }
Exemple #2
0
 public void Update(SubscriptionsModel subscription)
 {
     SubscriptionId       = subscription.SubscriptionId;
     StartDate            = subscription.StartDate;
     PawzeUserId          = subscription.PawzeUserId;
     StripeSubscriptionId = subscription.StripeSubscriptionId;
 }
        public ActionResult AddOrDeleteSubscriptions(int feedId, bool add)
        {
            try
            {
                var user = BS.UtilitiesBusiness.GetSession();
                if (add)
                {
                    BS.FeedBusiness.AddSubscription(new Subscription {
                        UserId = user.Id, FeedId = feedId
                    });
                }
                else
                {
                    BS.FeedBusiness.RemoveSubscription(new Subscription {
                        UserId = user.Id, FeedId = feedId
                    });
                }

                var res = new SubscriptionsModel
                {
                    FeedList      = BS.FeedBusiness.RetrieveFeedByUser(user.Id),
                    Subscriptions = BS.FeedBusiness.RetrieveFeedSubscriptions(user.Id)
                };

                ViewBag.Create = false;
                return(RedirectToAction("Subscriptions", res));
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
        public async Task <PartialViewResult> ListSubscriptions(string customerId)
        {
            IAggregatePartner operations;
            ResourceCollection <Subscription> subscriptions;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            try
            {
                operations    = await new SdkContext().GetOperationsAsync();
                subscriptions = await operations.Customers.ById(customerId).Subscriptions.GetAsync();

                SubscriptionsModel subscriptionsModel = new SubscriptionsModel()
                {
                    CustomerId    = customerId,
                    Subscriptions = subscriptions.Items.ToList()
                };

                return(PartialView(subscriptionsModel));
            }
            finally
            {
                operations = null;
            }
        }
        public ViewResult Subscriptions(string customerId)
        {
            SubscriptionsModel subscriptionsModel = new SubscriptionsModel()
            {
                CustomerId = customerId
            };

            return(View(subscriptionsModel));
        }
        public void SubscriptionsJsonShouldHaveValidPaths()
        {
            SubscriptionsModel subscriptionsModel = InitializeSubscriptionsModel();

            foreach (string path in subscriptionsModel.Subscriptions.SelectMany(s => s.TriggerPaths))
            {
                Assert.True(Uri.IsWellFormedUriString(path, UriKind.Absolute), $"The path '{path}' is not valid.");
            }
        }
        public void SubscriptionsJsonShouldHaveValidHandlers()
        {
            SubscriptionsModel subscriptionsModel = InitializeSubscriptionsModel();
            HandlerResolver    resolver           = new HandlerResolver(subscriptionsModel);

            foreach (Subscription subscription in subscriptionsModel.Subscriptions)
            {
                resolver.Resolve(subscription);
            }
        }
Exemple #8
0
        public void Model_Subbscription_Valid_ExpectTypeRquiredErrors()
        {
            var model = new SubscriptionsModel
            {
                Name = "Temp"
            };

            var results = TestModelHelper.Validate(model);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("The Type field is required.", results[0].ErrorMessage);
        }
        private async Task <SubscriptionsModel> GetSubscriptionsAsync(string customerId)
        {
            IAggregatePartner operations;
            ResourceCollection <Subscription> subscriptions;
            SubscriptionsModel subscriptionsModel;

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(nameof(customerId));
            }

            try
            {
                operations    = await new SdkContext().GetPartnerOperationsAysnc();
                subscriptions = await operations.Customers.ById(customerId).Subscriptions.GetAsync();

                subscriptionsModel = new SubscriptionsModel()
                {
                    Subscriptions = new List <SubscriptionModel>()
                };

                foreach (Subscription s in subscriptions.Items)
                {
                    subscriptionsModel.Subscriptions.Add(new SubscriptionModel()
                    {
                        AutoRenewEnabled   = s.AutoRenewEnabled,
                        BillingType        = s.BillingType,
                        CommitmentEndDate  = s.CommitmentEndDate,
                        CreationDate       = s.CreationDate,
                        CustomerId         = customerId,
                        EffectiveStartDate = s.EffectiveStartDate,
                        FriendlyName       = s.FriendlyName,
                        Id                   = s.Id,
                        OfferId              = s.OfferId,
                        OfferName            = s.OfferName,
                        ParentSubscriptionId = s.ParentSubscriptionId,
                        PartnerId            = s.PartnerId,
                        Quantity             = s.Quantity,
                        Status               = s.Status,
                        SuspensionReasons    = s.SuspensionReasons,
                        UnitType             = s.UnitType
                    });
                }

                return(subscriptionsModel);
            }
            finally
            {
                subscriptions = null;
            }
        }
Exemple #10
0
        public ViewResult Subscriptions(string customerId)
        {
            if (string.IsNullOrEmpty(customerId))
            {
                throw new ArgumentNullException(customerId);
            }

            SubscriptionsModel subscriptionsModel = new SubscriptionsModel()
            {
                CustomerId = customerId
            };

            return(View(subscriptionsModel));
        }
        /// <summary>
        /// Gets the subscriptions for the specified customer.
        /// </summary>
        /// <param name="customerId">Identifier of the customer.</param>
        /// <returns>An instance of <see cref="SubscriptionsModel"/> that contains the subscriptions for the customer.</returns>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="customerId"/> is empty or null.
        /// </exception>
        private async Task <SubscriptionsModel> GetSubscriptionsAsync(string customerId)
        {
            List <Subscription> subscriptions;
            SubscriptionsModel  subscriptionsModel;

            customerId.AssertNotEmpty(nameof(customerId));

            try
            {
                subscriptions = await this.Service.PartnerOperations.GetSubscriptionsAsync(customerId);

                subscriptionsModel = new SubscriptionsModel()
                {
                    Subscriptions = new List <SubscriptionModel>()
                };

                foreach (Subscription s in subscriptions.Where(x => x.Status != SubscriptionStatus.Deleted))
                {
                    subscriptionsModel.Subscriptions.Add(new SubscriptionModel()
                    {
                        AutoRenewEnabled   = s.AutoRenewEnabled,
                        BillingType        = s.BillingType,
                        CommitmentEndDate  = s.CommitmentEndDate,
                        CreationDate       = s.CreationDate,
                        CustomerId         = customerId,
                        EffectiveStartDate = s.EffectiveStartDate,
                        FriendlyName       = s.FriendlyName,
                        Id                   = s.Id,
                        OfferId              = s.OfferId,
                        OfferName            = s.OfferName,
                        ParentSubscriptionId = s.ParentSubscriptionId,
                        PartnerId            = s.PartnerId,
                        Quantity             = s.Quantity,
                        Status               = s.Status,
                        SuspensionReasons    = s.SuspensionReasons,
                        UnitType             = s.UnitType
                    });
                }

                return(subscriptionsModel);
            }
            finally
            {
                subscriptions = null;
            }
        }
        public ActionResult Subscriptions()
        {
            //Validates user session
            var user = BS.UtilitiesBusiness.GetSession();

            if (user == null)
            {
                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var model = new SubscriptionsModel
            {
                FeedList      = BS.FeedBusiness.RetrieveFeedByUser(user.Id),
                Subscriptions = BS.FeedBusiness.RetrieveFeedSubscriptions(user.Id)
            };

            return(View(model));
        }
Exemple #13
0
        public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "users/{userId}/subscriptions")]
            HttpRequestMessage req,
            string userId,
            [Table(TableNames.GroupEventSubscription, "{userId}", Connection = "AzureWebJobsStorage")]
            IQueryable <GroupEventSubscriptionEntity> inTable,
            TraceWriter log)
        {
            var model = new SubscriptionsModel
            {
                Subscriptions = inTable.Where(x => x.PartitionKey == userId).AsEnumerable().Select(CreateGroupEventModel).ToArray()
            };

            var json = JsonConvert.SerializeObject(model);

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(json, Encoding.UTF8, "application/json")
            });
        }
Exemple #14
0
        public IHttpActionResult PostSubscription(SubscriptionsModel subscription)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbSubscription = new Subscription();

            dbSubscription.StartDate = DateTime.Now;
            dbSubscription.PawzeUser = _pawzeUserRepository.GetFirstOrDefault(u => u.UserName == User.Identity.Name);
            _subscriptionRepository.Add(dbSubscription);

            _unitOfWork.Commit();

            subscription.SubscriptionId = dbSubscription.SubscriptionId;


            return(CreatedAtRoute("DefaultApi", new { id = subscription.SubscriptionId }, subscription));
        }
        public async Task <List <SubscriptionModel> > GetSubscriptions(string access_token)
        {
            string url     = "https://management.chinacloudapi.cn/subscriptions?api-version=2018-02-01";
            var    request = new HttpRequestMessage(HttpMethod.Get, url);
            var    client  = this._clientFactory.CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);
            var response = await client.SendAsync(request);

            string data = await response.Content.ReadAsStringAsync();

            SubscriptionsModel subscriptions = new SubscriptionsModel();

            if (response.IsSuccessStatusCode)
            {
                subscriptions = JsonConvert.DeserializeObject <SubscriptionsModel>(data);
            }
            else
            {
                Console.WriteLine("Error." + response.ReasonPhrase);
            }
            return(subscriptions.value);
        }
        public ActionResult AddFeed(Feed model)
        {
            try
            {
                var user = BS.UtilitiesBusiness.GetSession();
                model.CreateDate = DateTime.Now;
                model.CreatedBy  = user.Id;
                BS.FeedBusiness.AddFeed(model);

                var res = new SubscriptionsModel
                {
                    FeedList      = BS.FeedBusiness.RetrieveFeedByUser(user.Id),
                    Subscriptions = BS.FeedBusiness.RetrieveFeedSubscriptions(user.Id)
                };

                ViewBag.Create = true;
                return(RedirectToAction("Subscriptions", res));
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }
Exemple #17
0
        public IHttpActionResult PutSubscription(int id, SubscriptionsModel subscription)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != subscription.SubscriptionId)
            {
                return(BadRequest());
            }

            Subscription dbSubscription = _subscriptionRepository.GetById(id);

            dbSubscription.Update(subscription);

            _subscriptionRepository.Update(dbSubscription);

            try
            {
                _unitOfWork.Commit();
            }
            catch (Exception)
            {
                if (!SubscriptionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private async Task InitializeSubscriptionModel()
        {
            string subscriptionsString = await s_client.GetStringAsync(Config.Instance.SubscriptionsUrl);

            SubscriptionModel = JsonConvert.DeserializeObject <SubscriptionsModel>(subscriptionsString);
        }
Exemple #19
0
        public async Task Post(PushWebHookEvent e)
        {
            Trace.TraceInformation($"CommitPushed Started: {e}");

            try
            {
                if (e.Commits != null)
                {
                    SubscriptionsModel subscriptionsModel = await SubscriptionsModel.CreateAsync();

                    // only invoke a specific handler once per a push notification
                    HashSet <ISubscriptionHandler> handlers = new HashSet <ISubscriptionHandler>();

                    foreach (Commit c in e.Commits)
                    {
                        foreach (string changedFilePath in c.GetAllChangedFiles())
                        {
                            ModifiedFileModel modifiedFile;
                            if (!ModifiedFileModel.TryParse(e.Repository.Full_Name, e.Ref, changedFilePath, c, out modifiedFile))
                            {
                                Trace.TraceWarning($"Skipping file '{changedFilePath}'");
                                continue;
                            }

                            foreach (ISubscriptionHandler handler in subscriptionsModel.GetHandlers(modifiedFile))
                            {
                                handlers.Add(handler);
                            }
                        }
                    }

                    List <Task> handlerTasks = new List <Task>();
                    foreach (ISubscriptionHandler handler in handlers)
                    {
                        if (handler.Delay.HasValue)
                        {
                            DelayedMessage message = new DelayedMessage();
                            message.HandlerType = handler.GetType().AssemblyQualifiedName;
                            message.HandlerData = JsonConvert.SerializeObject(handler);

                            handlerTasks.Add(
                                _storageService.EnqueueMessage(
                                    DelayedMessage.QueueName,
                                    JsonConvert.SerializeObject(message),
                                    handler.Delay));
                        }
                        else
                        {
                            handlerTasks.Add(handler.Execute());
                        }
                    }

                    await Task.WhenAll(handlerTasks);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError($"An unhandled exception occurred handling PushWebHookEvent {e} : Exception: {ex}");

                throw;
            }

            Trace.TraceInformation("CommitPushed Complete");
        }
Exemple #20
0
        public void Model_Subbscription_Valid_Exists()
        {
            var model = new SubscriptionsModel();

            Assert.IsNotNull(model);
        }
Exemple #21
0
 public Subscription(SubscriptionsModel subscription)
 {
     this.Update(subscription);
 }
Exemple #22
0
 public HandlerResolver(SubscriptionsModel subscriptionsModel)
 {
     _subscriptionsModel = subscriptionsModel;
 }
        private SubscriptionsModel InitializeSubscriptionsModel()
        {
            string subscriptionsJsonContent = File.ReadAllText("subscriptions.json");

            return(SubscriptionsModel.Create(subscriptionsJsonContent));
        }
Exemple #24
0
 public void Model_Subbscription_Valid_Exists()
 {
     var model = new SubscriptionsModel();
     Assert.IsNotNull(model);
 }
Exemple #25
0
        public void Model_Subbscription_Valid_ExpectTypeRquiredErrors()
        {
            var model = new SubscriptionsModel
            {
                Name = "Temp"
            };

            var results = TestModelHelper.Validate(model);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("The Type field is required.", results[0].ErrorMessage);
        }