Exemple #1
0
        // Constructor

        #region ApiClient()
        public ApiClient(IApiClientSettings settings = null)
        {
            // Settings

            settings = settings ?? ApiClientSettings.Default;

            // Mapping

            MappingInstaller.Register();

//#if DEBUG
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
//#endif
            //Cache = cache;
            //Context = context;

            Accounts      = new AccountsClient(settings);
            Activations   = new ActivationsClient(Mapper.Engine, settings);
            Activities    = new ActivitiesClient(Mapper.Engine, settings);
            CalendarItems = new CalendarItemsClient(Mapper.Engine, settings);
            Devices       = new DevicesClient(Mapper.Engine, settings);
            People        = new PeopleClient(Mapper.Engine, settings);

            //People = new CachingPeopleService(Context);
        }
Exemple #2
0
        public MastodonClient(Credential credential, HttpClientHandler innerHandler = null) : base(credential, new OAuth2HttpClientHandler(innerHandler), RequestMode.FormUrlEncoded)
        {
            BinaryParameters = new List <string> {
                "avatar", "header", "file"
            };

            Account           = new AccountsClient(this);
            Apps              = new AppsClient(this);
            Auth              = new AuthClient(this);
            Blocks            = new BlocksClient(this);
            Conversations     = new ConversationsClient(this);
            CustomEmojis      = new CustomEmojisClient(this);
            DomainBlocks      = new DomainBlocksClient(this);
            Endorsements      = new EndorsementsClient(this);
            Favorites         = new FavoritesClient(this);
            Filters           = new FiltersClient(this);
            FollowRequests    = new FollowRequestsClient(this);
            Follows           = new FollowsClient(this);
            Instance          = new InstanceClient(this);
            Lists             = new ListsClient(this);
            Media             = new MediaClient(this);
            Notifications     = new NotificationsClient(this);
            Push              = new PushClient(this);
            Reports           = new ReportsClient(this);
            ScheduledStatuses = new ScheduledStatusesClient(this);
            SearchV1          = new SearchV1Client(this);
            SearchV2          = new SearchV2Client(this);
            Statuses          = new StatusesClient(this);
            Streaming         = new StreamingClient(this);
            Suggestions       = new SuggestionsClient(this);
            Timelines         = new TimelinesClient(this);
        }
    public async Task CantRegisterUserWithInvalidAccountDetails()
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        // Act
        RegisterUserResponse response = await client.RegisterAsync(new RegisterUserRequest()
        {
            FirstName = "John",
            LastName  = "Doe",
            Email     = string.Empty,
            UserName  = string.Empty,
            Password  = "******"
        });//.ResponseAsync.DefaultTimeout();

        // Assert
        //Assert.AreEqual(deadline, options.Deadline);
        //Assert.AreEqual(cancellationToken, options.CancellationToken);
        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.False(response.Response.Success);
        Assert.Single(response.Response.Errors);
        Assert.True(string.IsNullOrEmpty(response.Id));
        Assert.Equal("InvalidUserName", response.Response.Errors.First().Code);
        //Assert.Equal("'Email' is not a valid email address.", response.Response.Errors.First().Description);
    }
        private async Task <bool> Authorized(string accountId)
        {
            List <RoleNames> authorizedRoles = new List <RoleNames>()
            {
                RoleNames.AccountAdmin
            };

            var authenticateResult = await HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");

            if (authenticateResult != null)
            {
                ViewBag.authenticated = true;
                AccountsClient client = new AccountsClient();
                var            userId = authenticateResult.Identity.Claims.Where(cl => cl.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value;

                var roles = (await client.GetAccountRolesForUserAsync(accountId, userId)).Where(x => x.WorkflowState == WorkflowState.Active);

                if (roles.Select(x => x.Name).Intersect(authorizedRoles).Any())
                {
                    return(true);
                }
                else
                {
                    var account = await client.Get <Account>(accountId);

                    ViewBag.error = $"You do not have the proper roles assigned to access information for {account.Name}";
                }
            }

            return(false);
        }
Exemple #5
0
        public MastodonClient(string domain) : base($"https://{domain}", AuthMode.OAuth2, RequestMode.FormUrlEncoded)
        {
            Domain           = domain;
            BinaryParameters = new List <string> {
                "avatar", "header", "file"
            };

            Account        = new AccountsClient(this);
            Apps           = new AppsClient(this);
            Auth           = new AuthClient(this);
            Blocks         = new BlocksClient(this);
            CustomEmojis   = new CustomEmojisClient(this);
            DomainBlocks   = new DomainBlocksClient(this);
            Endorsements   = new EndorsementsClient(this);
            Favorites      = new FavoritesClient(this);
            Filters        = new FiltersClient(this);
            FollowRequests = new FollowRequestsClient(this);
            Follows        = new FollowsClient(this);
            Instance       = new InstanceClient(this);
            Lists          = new ListsClient(this);
            Media          = new MediaClient(this);
            Notifications  = new NotificationsClient(this);
            Push           = new PushClient(this);
            Reports        = new ReportsClient(this);
            SearchV1       = new SearchV1Client(this);
            SearchV2       = new SearchV2Client(this);
            Statuses       = new StatusesClient(this);
            Streaming      = new StreamingClient(this);
            Suggestions    = new SuggestionsClient(this);
            Timelines      = new TimelinesClient(this);
        }
Exemple #6
0
        private void RunSearch(int searchId, string startTermId, string endTermId)
        {
            var accountId       = ConfigurationManager.AppSettings["CanvasAccountId"];
            var accountsClient  = new AccountsClient();
            var enrollmentTerms = accountsClient.GetEnrollmentTerms(accountId).Result;

            // Start by getting all enrollment terms between range
            var subTerms = enrollmentTerms.SkipWhile(x => x.Id != startTermId.ToString()).TakeWhile(x => x.Id != endTermId.ToString()).ToList();

            subTerms.Add(enrollmentTerms.First(x => x.Id == endTermId.ToString()));

            foreach (var term in subTerms)
            {
                var courses = accountsClient.GetUnpublishedCoursesForTerm(accountId, term.Id).Result;

                foreach (var course in courses)
                {
                    if (IsUnusedCourse(course))
                    {
                        unusedCourseBll.Add(new UnusedCourse
                        {
                            CourseId            = course.Id,
                            CourseCode          = course.CourseCode,
                            CourseSISID         = course.SisCourseId,
                            CourseName          = course.Name,
                            Status              = CourseStatus.Active,
                            TermId              = term.Id,
                            Term                = term.Name,
                            CourseSearchQueueId = searchId
                        });
                    }
                }
            }
        }
        public async Task <ActionResult> Index(HomeViewModel viewModel)
        {
            courseSearchQueueBll.Add(new CourseSearchQueue()
            {
                StartTermId      = viewModel.StartTerm,
                EndTermId        = viewModel.EndTerm,
                Status           = SearchStatus.New,
                SubmittedByEmail = viewModel.UserEmail
            });

            var accountId = ConfigurationManager.AppSettings["CanvasAccountId"];
            var client    = new AccountsClient();

            var enrollmentTerms = await client.GetEnrollmentTerms(accountId);

            viewModel.Terms = enrollmentTerms.Select(x => new SelectListItem()
            {
                Text  = x.Name,
                Value = x.Id.ToString()
            }).ToList();

            viewModel.CourseSearchQueues = (await courseSearchQueueBll.GetAllAsync()).OrderBy(x => x.DateCreated);

            return(View(viewModel));
        }
        public async Task <IActionResult> OnPostDelete(string id)
        {
            try
            {
                var client  = new AccountsClient(baseUrl);
                var results = await client.DeleteAsync(id);

                if (results.IsSuccess.Value == true)
                {
                    Message = "Account closed";
                    return(Page());
                    //return RedirectToPage("Index");
                }
                else
                {
                    Error = results.Message;
                    return(Page());
                }
            }
            catch (Exception ex)
            {
                Error = $"An error occured: { ex.Message }";
                return(Page());
            }
        }
        public SignInPanelViewModel(IContainerExtension container) : base(container)
        {
            channel        = GrpcChannel.ForAddress("https://localhost:5001");
            accountsClient = new AccountsClient(channel);

            EventAggregator.GetEvent <SignUpSuccessEvent>().Subscribe(signUpArgs =>
                                                                      this.signUpArgs = signUpArgs);
        }
Exemple #10
0
 public CardsService(CardsRepository cardsRepository, ILogger<CardsService> logger, Mapper mapper, AccountsClient accountsClient, TransactionsClient transactionsClient)
 {
     this.cardsRepository = cardsRepository;
     this.logger = logger;
     this.mapper = mapper;
     this.accountsClient = accountsClient;
     this.transactionsClient = transactionsClient;
 }
        internal static bool ValidateIfNumberExists(string phoneNumber)
        {
            AccountsClient client = new AccountsClient();

            Customer customer = client.GetCustomerByPhone(int.Parse(phoneNumber));

            return customer != null;
        }
 private void SetClients(string groupName)
 {
     accounts       = new AccountsClient(client);
     groups         = new GroupsClient(client);
     rules          = new RulesClient(client);
     parameters     = new ParametersClient(client);
     rBObjects      = new RBObjectsClient(client);
     this.groupName = groupName;
 }
        private async Task <StorageAccount> CreateStorageAccountAsync(string resourceGroupName, string accountName, StorageAccountCreateParameters parameters = null)
        {
            StorageAccountCreateParameters saParameters     = parameters ?? GetDefaultStorageAccountParameters();
            Operation <StorageAccount>     accountsResponse = await AccountsClient.StartCreateAsync(resourceGroupName, accountName, saParameters);

            StorageAccount account = (await WaitForCompletionAsync(accountsResponse)).Value;

            return(account);
        }
        public async Task <IActionResult> OnGet(string nameKey)
        {
            NameKey = nameKey;

            var client = new AccountsClient(baseUrl);

            AccountDetails = await client.DetailsAsync(NameKey);

            return(Page());
        }
        public async Task <IActionResult> OnGetNext()
        {
            var client   = new AccountsClient(baseUrl);
            var response = await client.ListAsync(10, OrderBy.CreatedDate, OrderDirection.DESC, AccountListView.ContinuationToken);


            AccountListView = response;

            return(Page());
        }
 public DataFetcher(TransactionsClient transactionsClient,
                    AccountsClient accountsClient,
                    PaymentsClient paymentsClient,
                    CardsClient cardsClient,
                    LoansClient loansClient)
 {
     this.transactionsClient = transactionsClient;
     this.accountsClient     = accountsClient;
     this.paymentsClient     = paymentsClient;
     this.cardsClient        = cardsClient;
     this.loansClient        = loansClient;
 }
 public BatchesBranchService(ILogger <BatchesBranchService> logger,
                             AccountsClient accountsClient,
                             LoansClient loansClient,
                             PaymentsClient paymentsClient,
                             UsersClient usersClient)
 {
     this.logger         = logger;
     this.accountsClient = accountsClient;
     this.loansClient    = loansClient;
     this.paymentsClient = paymentsClient;
     this.usersClient    = usersClient;
 }
        /// <summary>
        ///     Creates a new instance of GeniusClient
        /// </summary>
        /// <param name="accessToken">Access Token to make authorized requests.</param>
        public GeniusClient(string accessToken)
        {
            IApiConnection apiConnection = new ApiConnection(accessToken);

            AccountsClient    = new AccountsClient(apiConnection);
            AnnotationsClient = new AnnotationsClient(apiConnection);
            ArtistsClient     = new ArtistsClient(apiConnection);
            VoteClient        = new VoteClient(apiConnection);
            ReferentsClient   = new ReferentsClient(apiConnection);
            SongsClient       = new SongsClient(apiConnection);
            SearchClient      = new SearchClient(apiConnection);
            WebPagesClient    = new WebPagesClient(apiConnection);
            LyricsClient      = new LyricsClient(apiConnection);
        }
Exemple #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Mootit.Pizzeria.Service.Store.StoreClient client = new Service.Store.StoreClient();

                client.Sync();

                Customer customer = new AccountsClient().GetCustomerByPhone(Convert.ToInt32(Session[Login.SESSION_KEY_PHONE]));

                GridView_Orders.DataSource = client.ListCustomerOrders(customer.User.Id);
                GridView_Orders.DataBind();
            }
        }
 public PanelsBranchService(ILogger <PanelsBranchService> logger,
                            TransactionsClient transactionsClient,
                            PaymentsClient paymentsClient,
                            LoansClient loansClient,
                            AccountsClient accountsClient,
                            CardsClient cardsClient
                            )
 {
     this.logger             = logger;
     this.transactionsClient = transactionsClient;
     this.paymentsClient     = paymentsClient;
     this.loansClient        = loansClient;
     this.accountsClient     = accountsClient;
     this.cardsClient        = cardsClient;
 }
        public async Task <ActionResult> Index(HomeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var courseIds = new List <string>();
                using (var reader = new StreamReader(Request.Files["CoursesDataFile"].InputStream))
                {
                    while (!reader.EndOfStream)
                    {
                        var line = await reader.ReadLineAsync();

                        Regex validator = new Regex(@"^[0-9]+$");

                        var id = line.Split(',')[0];

                        if (!validator.IsMatch(id))
                        {
                            ModelState.AddModelError(nameof(HomeViewModel.CoursesDataFile), "There was a problem while reading the input file.  Please make sure that the file chosen contains a comma delimited list and has an extension of csv.");
                            return(View(viewModel));
                        }

                        courseIds.Add(id);
                    }
                }

                var client        = new CoursesClient();
                var accountClient = new AccountsClient();

                try
                {
                    var account = accountClient.Get <Account>(viewModel.CanvasAccountId);

                    foreach (var id in courseIds)
                    {
                        await client.MoveCourse(id, viewModel.CanvasAccountId);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError(nameof(viewModel.CanvasAccountId), ex);
                    return(View(viewModel));
                }

                viewModel.Notify = true;
            }

            return(View(viewModel));
        }
Exemple #22
0
        public void Create()
        {
            // Arrange

            var account = new AccountsClient();

            // Act

            //var result = account.Create(CreateEmail(), null, "test");
            var result = account.Create("*****@*****.**", null, "test");

            // Assert

            Assert.IsNotNull(result);
            Assert.IsNotNullOrEmpty(result.ActivationCode);
        }
        public async Task <IActionResult> OnGet()
        {
            var client   = new AccountsClient(baseUrl);
            var response = await client.ListAsync(10, OrderBy.CreatedDate, OrderDirection.DESC, "");

            if (response != null)
            {
                AccountListView = response;
            }
            else
            {
                AccountListView.Count = 0;
            }

            return(Page());
        }
    public async Task CanDeleteUserWithValidAccountDetails()
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        DeleteUserResponse response = await client.DeleteAsync(new StringInputParameter()
        {
            Value = "deleteme"
        });

        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.True(response.Response.Success);
        Assert.Empty(response.Response.Errors);
        Assert.False(string.IsNullOrEmpty(response.Id));
    }
Exemple #25
0
 public SetupController(AccountsClient accountsClient,
                        CardsClient cardsClient,
                        LoansClient loansClient,
                        PaymentsClient paymentsClient,
                        TransactionsClient transactionsClient,
                        UsersClient usersClient,
                        Mapper mapper)
 {
     this.accountsClient     = accountsClient;
     this.cardsClient        = cardsClient;
     this.loansClient        = loansClient;
     this.paymentsClient     = paymentsClient;
     this.transactionsClient = transactionsClient;
     this.usersClient        = usersClient;
     this.mapper             = mapper;
 }
    public async Task CanFindByEmail()
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        FindUserResponse response = await client.FindByEmailAsync(new StringInputParameter()
        {
            Value = "*****@*****.**"
        });                                                                                                                  // UserManager is NOT case sensitive!

        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.True(response.Response.Success);
        Assert.Empty(response.Response.Errors);
        Assert.False(string.IsNullOrEmpty(response.Id));
        Assert.Equal("41532945-599e-4910-9599-0e7402017fbe", response.Id);
    }
    public async Task CanFindById(string id)
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        FindUserResponse response = await client.FindByIdAsync(new StringInputParameter()
        {
            Value = id
        });

        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.True(response.Response.Success);
        Assert.Empty(response.Response.Errors);
        Assert.False(string.IsNullOrEmpty(response.Id));
        Assert.Equal(id, response.Id);
    }
        protected void Register_Customer()
        {
            Customer customer = null;

            try
            {
                this.Label_Response.Text = String.Empty;

                if (ValidateIfValidNumber(this.TextBox_Phone.Text))
                    if (!ValidateIfNumberExists(this.TextBox_Phone.Text))
                    {
                        AccountsClient client = new AccountsClient();
                        customer = client.InsertCustomer(new Customer()
                        {
                            Address = this.TextBox_Address.Text,
                            Fullname = this.TextBox_FullName.Text,
                            PhoneNumer = int.Parse(this.TextBox_Phone.Text),
                            User = new User()
                            {
                                Username = this.TextBox_UserName.Text
                            }
                        });

                        if (customer != null)
                        {
                            Session[Login.SESSION_KEY_PHONE] = customer.PhoneNumer.ToString();
                            Response.Redirect("~/Main.aspx", true);
                        }
                        else
                            throw new Exception(USER_RESPONSES_ERROR_REGISTER);
                    }
                    else
                        throw new Exception(USER_RESPONSES_PHONE_EXISTS);
                else
                    throw new Exception(USER_RESPONSES_INVALID_NUMBER);
            }
            catch (Exception ex)
            {
                this.Label_Response.Text = ex.Message;
            }
            finally
            {
                customer = null;
            }
        }
    public async Task CantDeleteUserWithInvalidAccountDetails()
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        DeleteUserResponse response = await client.DeleteAsync(new StringInputParameter()
        {
            Value = "DeleteMeNot"
        });

        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.False(response.Response.Success);
        Assert.Single(response.Response.Errors);
        Assert.True(string.IsNullOrEmpty(response.Id));
        Assert.Equal(HttpStatusCode.BadRequest.ToString(), response.Response.Errors.First().Code);
        Assert.Equal("Invalid user!", response.Response.Errors.First().Description);
    }
        public async Task <ActionResult> Index()
        {
            var authenticateResult = await HttpContext.GetOwinContext().Authentication.AuthenticateAsync("ExternalCookie");

            if (authenticateResult == null)
            {
                return(RedirectToAction("ExternalLogin"));
            }

            if (!(await Authorized(ConfigurationManager.AppSettings["CanvasAccountId"])))
            {
                // return unauthorized view
                var model = new HomeViewModel()
                {
                    Authorized = false,
                    Terms      = new List <SelectListItem>()
                };
                return(View(model));
            }
            else
            {
                var accountId = ConfigurationManager.AppSettings["CanvasAccountId"];
                var client    = new AccountsClient();

                var enrollmentTerms = await client.GetEnrollmentTerms(accountId);

                var model = new HomeViewModel()
                {
                    Authorized = true,
                    Terms      = enrollmentTerms.Select(x => new SelectListItem()
                    {
                        Text  = x.Name,
                        Value = x.Id.ToString()
                    }).ToList(),
                    CourseSearchQueues = await courseSearchQueueBll.GetAllAsync(),
                    UserEmail          = await GetCurrentUserEmail()
                };

                //model.Terms.Insert(0, new SelectListItem() { Text = "Select Term", Value = null });

                return(View(model));
            }
        }
Exemple #31
0
        public async Task <IActionResult> OnPost()
        {
            var client = new AccountsClient(baseUrl);

            CreateAccountResponse = await client.CreateAsync(NewAccount);


            // Using HttpClient without OpenAPI/Swagger:
            //HttpClient client = new HttpClient();
            //HttpResponseMessage response = await client.PostAsJsonAsync(
            //baseUrl + "/api/accounts", NewAccount);


            if (!CreateAccountResponse.IsSuccess.Value)
            {
                return(Page());
            }
            else
            {
                return(RedirectToPage("Index"));
            }
        }
    public async Task CanRegisterUserWithValidAccountDetails()
    {
        AccountsClient client = new AccountsClient(GrpcChannel);//_serviceProvider.GetRequiredService<AccountsClient>();

        Assert.NotNull(client);
        // Act
        RegisterUserResponse response = await client.RegisterAsync(new RegisterUserRequest()
        {
            FirstName = "John",
            LastName  = "Doe",
            Email     = "*****@*****.**",
            UserName  = "******",
            Password  = "******"
        });//.ResponseAsync.DefaultTimeout();

        // Assert
        //Assert.AreEqual(deadline, options.Deadline);
        //Assert.AreEqual(cancellationToken, options.CancellationToken);
        Assert.NotNull(response);
        Assert.NotNull(response.Response);
        Assert.True(response.Response.Success);
        Assert.Empty(response.Response.Errors);
        Assert.False(string.IsNullOrEmpty(response.Id));
    }
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="container"></param>
 public SignUpPanelViewModel(IContainerExtension container) : base(container)
 {
     channel        = GrpcChannel.ForAddress("https://localhost:5001");
     accountsClient = new AccountsClient(channel);
 }