From e2578b1e80882f9bbdd91a8f5fdf085a60f35991 Mon Sep 17 00:00:00 2001 From: Jiyun Yang Date: Wed, 31 Mar 2021 17:50:30 +0900 Subject: [PATCH] [NUI] Suppress CA1054 and CA1056 (forced to use Uri) and clean code (#2811) Signed-off-by: Jiyun Yang --- src/Tizen.NUI.Components/Controls/Slider.cs | 44 ++-- .../Tizen.NUI.Components.csproj | 2 +- src/Tizen.NUI/Tizen.NUI.csproj | 2 +- .../BaseComponents/AnimatedVectorImageView.cs | 2 - .../src/public/BaseComponents/VideoView.cs | 13 -- src/Tizen.NUI/src/public/Images/ImageLoading.cs | 260 --------------------- .../src/public/Images/NativeImageSource.cs | 4 +- src/Tizen.NUI/src/public/Images/PixelData.cs | 4 +- .../src/public/ViewProperty/ImageShadow.cs | 21 -- .../Tizen.NUI.Samples/Samples/CaptureTest.cs | 6 +- 10 files changed, 22 insertions(+), 336 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Slider.cs b/src/Tizen.NUI.Components/Controls/Slider.cs index 1b2d968..7a31df3 100755 --- a/src/Tizen.NUI.Components/Controls/Slider.cs +++ b/src/Tizen.NUI.Components/Controls/Slider.cs @@ -457,7 +457,7 @@ namespace Tizen.NUI.Components /// /// Gets or sets the resource url of the thumb image object. /// - /// Please use ThumbImageUri property. + /// Please use ThumbImageUrl property. /// /// 6 public string ThumbImageURL @@ -480,7 +480,7 @@ namespace Tizen.NUI.Components /// Gets or sets the resource url selector of the thumb image object. /// Getter returns copied selector value if exist, null otherwise. /// - /// Please use ThumbImageUri property. + /// Please use ThumbImageUrl property. /// /// Thrown when setting null value. /// 6 @@ -502,12 +502,12 @@ namespace Tizen.NUI.Components } /// - /// Gets or sets the Uri of the thumb image. + /// Gets or sets the Url of the thumb image. /// /// Thrown when setting null value. /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public Selector ThumbImageUri + public Selector ThumbImageUrl { get { @@ -517,20 +517,19 @@ namespace Tizen.NUI.Components } else { - return ((Selector)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty)).Clone(str => { return new Uri(str); }); + return (Selector)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty); } } set { if (value == null || thumbImage == null) { - throw new NullReferenceException("Slider.ThumbImageUri is null"); + throw new NullReferenceException("Slider.ThumbImageUrl is null"); } else { - Selector stringValue = value.Clone(m => m?.AbsoluteUri); - thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, stringValue); - thumbImageUrlSelector = stringValue; + thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value); + thumbImageUrlSelector = value; } } } @@ -668,43 +667,26 @@ namespace Tizen.NUI.Components } /// - /// Gets or sets the resource url of the warning thumb image object. - /// - /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API. - [EditorBrowsable(EditorBrowsableState.Never)] - public string WarningThumbImageUrl - { - get - { - return warningThumbImageUrl; - } - set - { - warningThumbImageUrl = value; - } - } - - /// - /// Gets or sets the Uri of the warning thumb image. + /// Gets or sets the Url of the warning thumb image. /// /// Thrown when setting null value. /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] - public Selector WarningThumbImageUri + public Selector WarningThumbImageUrl { get { - return warningThumbImageUrlSelector?.Clone(str => { return new Uri(str); }); + return warningThumbImageUrlSelector; } set { if (value == null || thumbImage == null) { - throw new NullReferenceException("Slider.WarningThumbImageUri is null"); + throw new NullReferenceException("Slider.WarningThumbImageUrl is null"); } else { - warningThumbImageUrlSelector = value.Clone(m => m?.AbsoluteUri); + warningThumbImageUrlSelector = value; } } } diff --git a/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj b/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj index b701655..5ddc9e6 100755 --- a/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj +++ b/src/Tizen.NUI.Components/Tizen.NUI.Components.csproj @@ -2,7 +2,7 @@ netstandard2.0 - $(NoWarn);CS0618 + $(NoWarn);CS0618;CA1054;CA1056 diff --git a/src/Tizen.NUI/Tizen.NUI.csproj b/src/Tizen.NUI/Tizen.NUI.csproj index 921b206..c7f1bf7 100644 --- a/src/Tizen.NUI/Tizen.NUI.csproj +++ b/src/Tizen.NUI/Tizen.NUI.csproj @@ -2,7 +2,7 @@ netstandard2.0 - $(NoWarn);CS0618;CS0809;CS1591 + $(NoWarn);CS0618;CS0809;CS1591;CA1054;CA1056 diff --git a/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs b/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs index 14c13aa..0abf21f 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs @@ -79,7 +79,6 @@ namespace Tizen.NUI.BaseComponents /// Set Resource URL /// // Suppress warning : This has been being used by users, so that the interface can not be changed. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Uri properties should not be strings", Justification = "")] [EditorBrowsable(EditorBrowsableState.Never)] public string ResourceURL { @@ -105,7 +104,6 @@ namespace Tizen.NUI.BaseComponents /// Set Resource URL /// // Suppress warning : This has been being used by users, so that the interface can not be changed. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1056:Uri properties should not be strings", Justification = "")] [EditorBrowsable(EditorBrowsableState.Never)] public new string ResourceUrl { diff --git a/src/Tizen.NUI/src/public/BaseComponents/VideoView.cs b/src/Tizen.NUI/src/public/BaseComponents/VideoView.cs index ca38d84..40ce8e4 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/VideoView.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/VideoView.cs @@ -154,19 +154,6 @@ namespace Tizen.NUI.BaseComponents } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Creates an initialized VideoView. - /// If the string is empty, VideoView will not display anything. - /// - /// The URI of the video resource to display. - [EditorBrowsable(EditorBrowsableState.Never)] - public VideoView(Uri uri) : this(Interop.VideoView.New((uri == null) ? String.Empty : uri.AbsoluteUri), true) - { - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - } - - /// /// Creates an initialized VideoView.
/// If the string is empty, VideoView will not display anything.
///
diff --git a/src/Tizen.NUI/src/public/Images/ImageLoading.cs b/src/Tizen.NUI/src/public/Images/ImageLoading.cs index e55243d..f1f1096 100755 --- a/src/Tizen.NUI/src/public/Images/ImageLoading.cs +++ b/src/Tizen.NUI/src/public/Images/ImageLoading.cs @@ -55,40 +55,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from local file. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// The method used to fit the shape of the image before loading to the shape defined by the size parameter. - /// The filtering method used when sampling pixels from the input image while fitting it to desired size. - /// Reorient the image to respect any orientation metadata in its header. - /// Handle to the loaded PixelBuffer object or an empty handle in case loading failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer LoadImageFromFile(Uri uri, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - PixelBuffer ret; - using (var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height)) - { - ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode, orientationCorrection), true); - } - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Load an image synchronously from local file. /// /// The URL of the image file to load. @@ -114,38 +80,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from local file. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// The method used to fit the shape of the image before loading to the shape defined by the size parameter. - /// The filtering method used when sampling pixels from the input image while fitting it to desired size. - /// Handle to the loaded PixelBuffer object or an empty handle in case loading failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer LoadImageFromFile(Uri uri, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - - uSize.Dispose(); - return ret; - } - - /// /// Load an image synchronously from local file. /// /// The URL of the image file to load. @@ -170,36 +104,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from local file. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// The method used to fit the shape of the image before loading to the shape defined by the size parameter. - /// Handle to the loaded PixelBuffer object or an empty handle in case loading failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer LoadImageFromFile(Uri uri, Size2D size, FittingModeType fittingMode) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode), true); - uSize.Dispose(); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Load an image synchronously from local file. /// /// The URL of the image file to load. @@ -223,35 +127,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from local file. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// Handle to the loaded PixelBuffer object or an empty handle in case loading failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer LoadImageFromFile(Uri uri, Size2D size) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize)), true); - uSize.Dispose(); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Load an image synchronously from local file. /// /// The URL of the image file to load. @@ -267,27 +142,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from local file. - /// - /// The URI of the image file to load. - /// Handle to the loaded PixelBuffer object or an empty handle in case loading failed. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer LoadImageFromFile(Uri uri) - { - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri), true); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Determine the size of an image that LoadImageFromFile will provide when given the same image loading parameters. /// /// The name of the image. @@ -455,39 +309,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from a remote resource. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// The method used to fit the shape of the image before loading to the shape defined by the size parameter. - /// The filtering method used when sampling pixels from the input image while fitting it to desired size. - /// Reorient the image to respect any orientation metadata in its header. - /// Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer DownloadImageSynchronously(Uri uri, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode, bool orientationCorrection) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode, orientationCorrection), true); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - - uSize.Dispose(); - return ret; - } - - /// /// Load an image synchronously from a remote resource. /// /// The URL of the image file to load. @@ -513,37 +334,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from a remote resource. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// The method used to fit the shape of the image before loading to the shape defined by the size parameter. - /// The filtering method used when sampling pixels from the input image while fitting it to desired size. - /// Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer DownloadImageSynchronously(Uri uri, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true); - uSize.Dispose(); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Load an image synchronously from a remote resource. /// /// The URL of the image file to load. @@ -621,35 +411,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from a remote resource. - /// - /// The URI of the image file to load. - /// The width and height to fit the loaded image to, 0.0 means whole image. - /// Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed. - /// Thrown when size is null. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer DownloadImageSynchronously(Uri uri, Size2D size) - { - if (null == size) - { - throw new ArgumentNullException(nameof(size)); - } - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - var uSize = new Uint16Pair((uint)size.Width, (uint)size.Height); - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize)), true); - uSize.Dispose(); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - - /// /// Load an image synchronously from a remote resource. /// /// The URL of the image file to load. @@ -664,26 +425,5 @@ namespace Tizen.NUI return ret; } - /// - /// Hidden API (Inhouse API). - /// Using Uri class to provide safe service and secure API. - /// Load an image synchronously from a remote resource. - /// - /// The URI of the image file to load. - /// Handle to the loaded PixelBuffer object or an empty handle in case downloading or decoding failed. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public static PixelBuffer DownloadImageSynchronously(Uri uri) - { - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - - PixelBuffer ret = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(uri.AbsoluteUri), true); - if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); - return ret; - } - } } diff --git a/src/Tizen.NUI/src/public/Images/NativeImageSource.cs b/src/Tizen.NUI/src/public/Images/NativeImageSource.cs index 3204293..1ec852c 100755 --- a/src/Tizen.NUI/src/public/Images/NativeImageSource.cs +++ b/src/Tizen.NUI/src/public/Images/NativeImageSource.cs @@ -41,14 +41,14 @@ namespace Tizen.NUI /// Get URI from native image source. /// [EditorBrowsable(EditorBrowsableState.Never)] - public Uri Uri + public string Url { get { string uri = ""; uri = Interop.NativeImageSource.GenerateUrl(this.SwigCPtr.Handle); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return new Uri(uri); + return uri; } } diff --git a/src/Tizen.NUI/src/public/Images/PixelData.cs b/src/Tizen.NUI/src/public/Images/PixelData.cs index 3ffd0a6..251c2c4 100755 --- a/src/Tizen.NUI/src/public/Images/PixelData.cs +++ b/src/Tizen.NUI/src/public/Images/PixelData.cs @@ -82,14 +82,14 @@ namespace Tizen.NUI /// Get URI from pixel data. /// [EditorBrowsable(EditorBrowsableState.Never)] - public Uri Uri + public string Url { get { string Uri = ""; Uri = Interop.PixelData.GenerateUrl(this.SwigCPtr.Handle); if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve()); - return new Uri(Uri); + return Uri; } } diff --git a/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs b/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs index a5d3743..6756a61 100755 --- a/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs +++ b/src/Tizen.NUI/src/public/ViewProperty/ImageShadow.cs @@ -49,27 +49,6 @@ namespace Tizen.NUI } /// - /// Hidden API (Inhouse API). - /// Constructor. - /// Using Uri class to provide safe service and secure API. - /// - /// uri. - /// border. - /// offset. - /// extents. - /// Thrown when uri is null. - [EditorBrowsable(EditorBrowsableState.Never)] - public ImageShadow(Uri uri, Rectangle border, Vector2 offset, Vector2 extents) : base(offset, extents) - { - if (uri == null) - { - throw new ArgumentNullException(nameof(uri)); - } - Url = uri.AbsoluteUri; - Border = border == null ? null : new Rectangle(border); - } - - /// /// Constructor /// /// Thrown when other is null. diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CaptureTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CaptureTest.cs index 372af2b..5ca6d03 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CaptureTest.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CaptureTest.cs @@ -58,9 +58,9 @@ namespace Tizen.NUI.Samples if (sender is Capture) { log.Debug(tag, $"sender is Capture \n"); - var uri = capture.GetNativeImageSource().Uri; - capturedImage = new ImageView(uri.AbsoluteUri); - log.Debug(tag, $"url={uri} \n"); + var url = capture.GetNativeImageSource().Url; + capturedImage = new ImageView(url); + log.Debug(tag, $"url={url} \n"); capturedImage.Size = new Size(510, 510); capturedImage.Position = new Position(10, 10); -- 2.7.4