Ejemplo n.º 1
0
        public static void Logout(ApiConfiguration configuration, HttpClient httpClient)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/logout");
            var response   = httpClient.GetAsync(requestUri).Result;

            httpClient.DefaultRequestHeaders.Authorization = null;
            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 2
0
        public static void ChangePassword(ApiConfiguration configuration, HttpClient httpClient, string username, string password)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/changepassword");
            var body       = PostBodyBuilder.ConstructBody(new ChangePasswordBody(username, password));
            var response   = httpClient.PostAsync(requestUri, body).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 3
0
        public static void Register(ApiConfiguration configuration, HttpClient httpClient, string username, string firstName, string lastName, string password, string email)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/register");
            var body       = PostBodyBuilder.ConstructBody(new RegistrationInformation(username, firstName, lastName, password, email));
            var response   = httpClient.PostAsync(requestUri, body).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 4
0
        public static async Task DeleteViewAsync(ApiConfiguration configuration, HttpClient httpClient, string viewId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/view/delete");

            requestUri += $"?viewId={Uri.EscapeDataString(viewId)}";
            var response = await httpClient.DeleteAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 5
0
        public static void DeleteUser(ApiConfiguration configuration, HttpClient httpClient, string username)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/deleteuser");

            requestUri += $"?username={Uri.EscapeDataString(username)}";
            var response = httpClient.DeleteAsync(requestUri).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
        public static async Task UnsubscribeAllAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/subscription/unsubscribeall");

            requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 7
0
        public static async Task <string> ReplaceAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType, string json, string existingId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/dataio/submit");
            var body       = ConstructSubmitBodyFromJson(dataType, json, true, existingId);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);

            return(await response.Content.ReadAsStringAsync());
        }
Ejemplo n.º 8
0
        public static async Task <string> InsertAsync(ApiConfiguration configuration, HttpClient httpClient, object obj, string id = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/dataio/submit");
            var body       = ConstructSubmitBodyFromObject(obj, false, id);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);

            return(await response.Content.ReadAsStringAsync());
        }
Ejemplo n.º 9
0
        public static void RemoveGlobalRoleFromUser(ApiConfiguration configuration, HttpClient httpClient, string username, Role role)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/removerole");

            requestUri += $"?username={Uri.EscapeDataString(username)}";
            requestUri += $"&role={Uri.EscapeDataString(role.ToString())}";
            var response = httpClient.GetAsync(requestUri).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 10
0
        public static async Task ReserveIdAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType, string id)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/id/reserve");

            requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            requestUri += $"&id={Uri.EscapeDataString(id)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 11
0
        public static void AddCollectionRoleToUser(ApiConfiguration configuration, HttpClient httpClient, string username, Role role, string dataType)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/addrole");

            requestUri += $"?username={Uri.EscapeDataString(username)}";
            requestUri += $"&role={Uri.EscapeDataString(role.ToString())}";
            requestUri += $"&dataType={Uri.EscapeDataString(dataType)}";
            var response = httpClient.GetAsync(requestUri).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 12
0
        public static async Task <List <UserProfile> > GetAllUserProfiles(ApiConfiguration configuration, HttpClient httpClient)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/getuserprofiles");
            var response   = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var stream = await response.Content.ReadAsStreamAsync();

            return(await stream.ReadAllSearchResultsAsync <UserProfile>());
        }
Ejemplo n.º 13
0
        public static async Task DeleteNotificationAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string notificationId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/subscription/deletenotification");

            requestUri += $"?notificationId={Uri.EscapeDataString(notificationId)}";
            var response = await httpClient.DeleteAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 14
0
        public static async Task SubmitValidatorAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            ValidatorDefinition validatorDefinition,
            bool suppressAutoApprove)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/validator/submit");
            var body       = ConstructSubmitValidatorBody(validatorDefinition, suppressAutoApprove);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 15
0
        public static async Task ApproveValidatorAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string validatorId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/validator/approve");

            requestUri += $"?validatorId={Uri.EscapeDataString(validatorId)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 16
0
        public static void SetGlobalRolesForUser(ApiConfiguration configuration, HttpClient httpClient, string username, IList <Role> roles)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/setroles");

            requestUri += $"?username={Uri.EscapeDataString(username)}";
            var aggregatedRoles = roles.Select(role => role.ToString()).Aggregate((a, b) => a + "|" + b);

            requestUri += $"&roles={Uri.EscapeDataString(aggregatedRoles)}";
            var response = httpClient.GetAsync(requestUri).Result;

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 17
0
        public static async Task ApplyValidatorAsync <T>(
            ApiConfiguration configuration,
            HttpClient httpClient,
            T obj,
            string validatorId = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/validator/apply");
            var body       = ConstructApplyValidatorBodyFromObject(obj, validatorId);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 18
0
        public static async Task <List <string> > GetIdsAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType, uint count)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/id/getnew");

            requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            requestUri += $"&count={count}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var content = await response.Content.ReadAsStringAsync();

            return(content.Split('\n').Select(x => x.Trim()).ToList());
        }
Ejemplo n.º 19
0
        public static async Task <List <Role> > GetGlobalRolesForUserAsync(ApiConfiguration configuration, HttpClient httpClient, string username)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/getglobalroles");

            requestUri += $"?username={Uri.EscapeDataString(username)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var json = await response.Content.ReadAsStringAsync();

            var roles = ConfiguredJsonSerializer.Deserialize <List <Role> >(json);

            return(roles);
        }
Ejemplo n.º 20
0
        public static async Task <List <SubscriptionInfo> > GetSubscriptionsAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/subscription/getsubscriptions");

            if (!string.IsNullOrEmpty(dataType))
            {
                requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            }
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var stream = await response.Content.ReadAsStreamAsync();

            return(await stream.ReadAllSearchResultsAsync <SubscriptionInfo>());
        }
Ejemplo n.º 21
0
        public static async Task <List <CollectionUserPermissions> > GetCollectionPermissions(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string dataType)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/account/getcollectionpermissions");

            requestUri += $"?collectionName={Uri.EscapeDataString(dataType)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var json = await response.Content.ReadAsStringAsync();

            return(ConfiguredJsonSerializer.Deserialize <List <CollectionUserPermissions> >(json));
        }
        public static bool IsAvailable(ApiConfiguration configuration, HttpClient httpClient)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/servicestatus/ping");

            try
            {
                var response = httpClient.GetAsync(requestUri).Result;
                ErrorReporter.EnsureSuccesStatusCode(response);
                var content = response.Content.ReadAsStringAsync().Result;
                return(content.ToLowerInvariant() == "pong");
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        public static async Task <Stream> GetViewAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string viewId,
            ResultFormat resultFormat,
            Dictionary <string, string> parameters = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/view/get");

            requestUri += BuildGetQuery(viewId, parameters, resultFormat);
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            return(await response.Content.ReadAsStreamAsync());
        }
Ejemplo n.º 24
0
        public static async Task <ValidatorDefinition> GetValidatorDefinitionAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string validatorId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/validator/get");

            requestUri += $"?validatorId={Uri.EscapeDataString(validatorId)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var json = await response.Content.ReadAsStringAsync();

            return(ConfiguredJsonSerializer.Deserialize <ValidatorDefinition>(json));
        }
Ejemplo n.º 25
0
        public static async Task ReportTo(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string recipient,
            string dataType,
            string dataObjectId)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/subscription/reportto");

            requestUri += $"?recipient={Uri.EscapeDataString(recipient)}";
            requestUri += $"&dataType={Uri.EscapeDataString(dataType)}";
            requestUri += $"&id={Uri.EscapeDataString(dataObjectId)}";
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);
        }
Ejemplo n.º 26
0
        public static async Task <string> SubscribeAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string dataType,
            IList <DataModificationType> modificationTypes,
            string filter = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/subscription/subscribe");
            var body       = ConstructSubscriptionBody(dataType, modificationTypes, filter);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var subscriptionId = await response.Content.ReadAsStringAsync();

            return(subscriptionId);
        }
Ejemplo n.º 27
0
        public static async Task <ViewInformation> CreateViewAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string query,
            DateTime expires,
            string viewId = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/view/create");
            var body       = ConstructCreateViewBody(query, expires, viewId);
            var response   = await httpClient.PostAsync(requestUri, body);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var json = await response.Content.ReadAsStringAsync();

            return(ConfiguredJsonSerializer.Deserialize <ViewInformation>(json));
        }
Ejemplo n.º 28
0
        public static async Task <bool> ExistsAsync(ApiConfiguration configuration, HttpClient httpClient, string dataType, string id)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/dataio/exists");

            requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            requestUri += $"&id={Uri.EscapeDataString(id)}";
            var response = await httpClient.GetAsync(requestUri);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                return(true);
            }
            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(false);
            }
            ErrorReporter.EnsureSuccesStatusCode(response);
            throw new Exception("Didn't expect to get to this line of code");
        }
Ejemplo n.º 29
0
        public static async Task <List <ValidatorDefinition> > GetAllValidatorDefinitionsAsync(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string dataType = null)
        {
            var requestUri = RequestUriBuilder.Build(configuration, "api/validator/getall");

            if (!string.IsNullOrEmpty(dataType))
            {
                requestUri += $"?dataType={Uri.EscapeDataString(dataType)}";
            }
            var response = await httpClient.GetAsync(requestUri);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var json = await response.Content.ReadAsStringAsync();

            return(ConfiguredJsonSerializer.Deserialize <List <ValidatorDefinition> >(json));
        }
Ejemplo n.º 30
0
        public static async Task <DownloadStream> GetFile(
            ApiConfiguration configuration,
            HttpClient httpClient,
            string dataType,
            string id)
        {
            var url = RequestUriBuilder.Build(configuration, "/Download/GetFile");

            url += $"?dataType={Uri.EscapeDataString(dataType)}";
            url += $"&id={Uri.EscapeDataString(id)}";
            var response = await httpClient.GetAsync(url);

            ErrorReporter.EnsureSuccesStatusCode(response);

            var contentDispositionHeader = response.Content.Headers.ContentDisposition;
            var filename = StripQuotes(contentDispositionHeader?.FileName);

            return(new DownloadStream(
                       await response.Content.ReadAsStreamAsync(),
                       filename));
        }