Commit 02be8041 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

working on save/delete of spectrum and children

parent 5eb7e1d7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
		<operation type="IsAnySpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsAnySpectrumTypeSavedOnCloud</operation>
		<operation type="IsSpectrumTypeSavedOnCloud">AppSpectraFilesActions/IsSpectrumTypeSavedOnCloud</operation>
		<operation type="GetSampleDataValues">AppSpectraFilesActions/GetSampleDataValues</operation>
		<operation type="GetChildrenSpectraTypes">AppSpectraFilesActions/GetChildrenSpectraTypes</operation>
		<!-- USERS -->
		<operation type="GetUserPermissions">Users/GetUserPermissions</operation>
	</operationUrls>
+27 −0
Original line number Diff line number Diff line
@@ -232,6 +232,33 @@ namespace INAF.Apps.Uwp.SLabDataManager.Converters
        }
    }

    public sealed class SmoothedSpectrumCreatedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            try
            {
                bool isEnableButtonRequested = System.Convert.ToBoolean(value);

                SpectrumType destSpectrumType = ((string)parameter).ToSpectrumType();

                SpectraContainer spectraContainer = Ioc.Default.GetService<SpectraContainer>();

                return isEnableButtonRequested && spectraContainer.isAnySpectrumOfType(destSpectrumType);
            }
            catch (Exception)
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }


    public sealed class SmoothingButtonVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
+32 −0
Original line number Diff line number Diff line
@@ -113,6 +113,38 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
            return result;
        }

        private async Task<T> getAsync<T>(RemoteOperationType remoteOperationType, string args)
        {
            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 url = remoteOperationsRepository.getUrl(remoteOperationType, args);
                    using (var response = await httpClient.GetAsync(new Uri(url)))
                    {
                        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(postAsync)} - ex: {ex.Message}", Serilog.Events.LogEventLevel.Error);
            }

            return result;
        }

        private async Task<T> postAsync<T>(object model, RemoteOperationType remoteOperationType)
        {
            T result = default;
+5 −0
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
{
    public partial class RemoteOperationsManager
    {
        public async Task<int> getChildrenSpectraTypes(SpectrumType spectrumType)
        {
            return await getAsync<int>(RemoteOperationType.GetChildrenSpectraTypes, string.Join("=", string.Join(string.Empty, nameof(SpectrumType), "Id"), ((int)spectrumType).ToString()));
        }

        public async Task<GenericIdResponseModel> isAnySpectrumTypeSavedOnCloudAsync(IsAnySpectrumTypeSavedOnCloudRequestModel model)
        {
            return await postAsync<GenericIdResponseModel>(model, RemoteOperationType.IsAnySpectrumTypeSavedOnCloud);
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.RemoteOperations
            return string.Join("/", BaseUrl, RemoteOperations.FirstOrDefault(x => x.Type == type).Url);
        }

        public string getUrl(RemoteOperationType type, string args)
        {
            string baseUrl = string.Join("/", BaseUrl, RemoteOperations.FirstOrDefault(x => x.Type == type).Url);
            return string.Join("?", baseUrl, args);
        }

        public void setBaseUrl(string baseUrl)
        {
            BaseUrl = baseUrl;
Loading