Commit 59a498f0 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

added set/get spectra colors from cloud

parent b0dd2305
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@
		<operation type="GetSampleDataValues">Materials/GetSampleDataValues</operation>
		<!-- USER SETTINGS -->
		<operation type="GetFitFunctions">UserSettings/GetFitFunctions</operation>
		<operation type="GetUserSetting">UserSettings/GetUserSetting</operation>
		<operation type="GetUserSettings">UserSettings/GetUserSetting</operation>
		<operation type="GetUserSettingsByWildcard">UserSettings/GetUserSettingsByWildcard</operation>
		<operation type="SetUserSetting">UserSettings/SetUserSetting</operation>
		<!-- EXTSERVICES -->
		<operation type="GetMeteorClasses">ExtServices/GetMeteorClasses</operation>
	</operationUrls>
+0 −2
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@
        public static readonly string CURRENT_PAGE = "currentpage";
        public static readonly string LAST_PAGE = "lastpage";

        public static readonly string NUM_OF_POINTS_FOR_MISSING_POINTS = "NumOfPointsForMissingPoints";

        public static readonly string XML_ALIGNMENT_SETTINGS = "AlignmentSettings";
        public static readonly string XML_ALIGNMENT_SETTINGS_SEGMENT_BOUNDARIES = "SegmentBoundaries";
        public static readonly string XML_CONTINUUM_REMOVAL_SETTINGS = "ContinuumRemovalSettings";
+5 −0
Original line number Diff line number Diff line
@@ -112,6 +112,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Extensions
            return string.Join(string.Empty, "color", type.ToString().ToLowerInvariant());
        }

        public static string ToColorKeyForCloud(this SpectrumType type)
        {
            return string.Join(string.Empty, INAF.Libraries.NetStandard.SLabCommonModels.Values.Constants.COLOR_WILDCARD, type.ToString().ToUpperInvariant());
        }

        public static string ToFileExt(this StorageItemType fileExt)
        {
            return string.Join(string.Empty, ".", fileExt.GetDescription());
+35 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ using INAF.Libraries.Uwp.Settings;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
using System.Web;
using Windows.Web.Http;
using Windows.Web.Http.Headers;
using static INAF.Libraries.NetStandard.SLabCommonModels.Values.Enums;
@@ -145,6 +146,40 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
            return result;
        }

        private async Task<T> getAsync<T>(RemoteOperationType remoteOperationType, object model)
        {
            T result = default;

            try
            {
                using (var httpClient = new HttpClient())
                {
                    JwtTokenModel tokenModel = settingsHelper.get<JwtTokenModel>(Constants.Constants.AUTHENTICATION_TOKEN);
                    httpClient.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", tokenModel.Token);

                    var queryString = HttpUtility.ParseQueryString(string.Empty);
                    queryString["model"] = JsonConvert.SerializeObject(model);
                    var url = remoteOperationsRepository.getUrl(remoteOperationType);
                    using (var response = await httpClient.GetAsync(new Uri($"{url}?{queryString}")))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            var responseContent = await response.Content.ReadAsStringAsync();
                            //System.Diagnostics.Debug.WriteLine($"responseContent: {responseContent}");

                            result = JsonConvert.DeserializeObject<T>(responseContent);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Write<RemoteOperationsManager>($"{nameof(getAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error);
            }

            return result;
        }

        private async Task<T> postAsync<T>(object model, RemoteOperationType remoteOperationType)
        {
            T result = default;
+14 −3
Original line number Diff line number Diff line
using INAF.Libraries.NetStandard.Math.Models;
using INAF.Libraries.NetStandard.Models.UserSettings;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.SampleData;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.WebApp.Requests;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.WebApp.Responses;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -14,9 +15,19 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
            return await getAsync<List<FitMethodModel>>(RemoteOperationType.GetFitFunctions);
        }

        public async Task<GenericValueStringResponseModel> getUserSettingAsync(string key)
        public async Task<GenericValueStringResponseModel> getUserSettingAsync(string keyWildcard)
        {
            return await getAsync<GenericValueStringResponseModel>(RemoteOperationType.GetUserSetting, buildArgument(nameof(KeyValueRequestModel.Key), key));
            return await getAsync<GenericValueStringResponseModel>(RemoteOperationType.GetUserSetting, buildArgument(nameof(KeyRequestModel.Key), keyWildcard));
        }

        public async Task<KeysValuesResponseModel> getUserSettingsByWildcardAsync(string keyWildcard)
        {
            return await getAsync<KeysValuesResponseModel>(RemoteOperationType.GetUserSettingsByWildcard, buildArgument(nameof(KeyRequestModel.Key), keyWildcard));
        }

        public async Task<GenericResponseModel> setUserSettingAsync(KeyValueRequestModel keyValueRequestModel)
        {
            return await postAsync<GenericResponseModel>(keyValueRequestModel, RemoteOperationType.SetUserSetting);
        }
    }
}
Loading