Saxonite 1.2.11.12
This commit is contained in:
@@ -79,7 +79,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <summary>Add entries from another dictionary.</summary>
|
||||
public static void AddRange<TKey, TValue>(this Dictionary<TKey, TValue> dict, Dictionary<TKey, TValue> dictToAdd)
|
||||
{
|
||||
dictToAdd.ForEach(x => dict.Add(x.Key, x.Value));
|
||||
dictToAdd.ForEach(x => dict[x.Key] = x.Value);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
@@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Processing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Sarand.Net.Standard.Base.Utils
|
||||
@@ -33,6 +34,21 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
public int Height { get; set; }
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
public static bool IsSvg(byte[] imageData)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!imageData.Contains((byte)'<')) return false;
|
||||
String imageText = Encoding.UTF8.GetString(imageData);
|
||||
if (!imageText.ContainsCI("<svg")) return false;
|
||||
if (!imageText.ContainsCI(" xmlns=\"http://www.w3.org/2000/svg\"")) return false;
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { }
|
||||
return false;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert the data stream to an image and extract width and height.
|
||||
@@ -41,7 +57,6 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <returns>Flag to indicate whether interpretation of image data succeeded.</returns>
|
||||
public static ImageConfig VerifyImageData(byte[] imageData)
|
||||
{
|
||||
String fn = className + ".VerifyImageData";
|
||||
ImageConfig imageConfig = new ImageConfig();
|
||||
imageConfig.ImageData = imageData;
|
||||
try
|
||||
@@ -60,11 +75,30 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
||||
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}");
|
||||
}
|
||||
return imageConfig;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Convert the SVG data stream to an image and extract width and height.
|
||||
/// </summary>
|
||||
/// <param name="imageData"></param>
|
||||
/// <returns>Flag to indicate whether interpretation of image data succeeded.</returns>
|
||||
public static ImageConfig VerifySvgImageData(byte[] imageData)
|
||||
{
|
||||
ImageConfig imageConfig = new ImageConfig();
|
||||
imageConfig.ImageData = imageData;
|
||||
imageConfig.ImageFormatName = "svg";
|
||||
imageConfig.DefaultMimeType = "svg";
|
||||
imageConfig.MimeType = EnumUtil.ParseEnum(imageConfig.ImageFormatName, Sacs.MimeType.Unknown);
|
||||
imageConfig.Width = 0;
|
||||
imageConfig.Height = 0;
|
||||
imageConfig.ValidImage = true;
|
||||
return imageConfig;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Load from byte array.
|
||||
/// <summary>Convert the data stream to an image.</summary>
|
||||
@@ -107,7 +141,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
/// <returns>Flag to indicate whether operation was successful.</returns>
|
||||
public static bool ConstrainImage(ImageConfig config, ushort widthMax, ushort heightMax)
|
||||
{
|
||||
String fn = className + ".ConstrainImage";
|
||||
if (config.Width == 0 || config.Height == 0) return true;
|
||||
if (widthMax < 1 || heightMax < 1) return false;
|
||||
if (config.Width <= widthMax && config.Height <= heightMax) return true;
|
||||
config.ValidImage = false;
|
||||
@@ -128,7 +162,7 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
||||
SaLogger.Warn($"{SysUtil.Fn} {ExceptionUtil.GetLogMessage(exc)}");
|
||||
}
|
||||
|
||||
return config.ValidImage;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -14,6 +15,11 @@ namespace Sarand.Net.Standard.Base.Utils
|
||||
// Extracting.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
public static String SerializeObject (Object data, JsonSerializerSettings settings = null)
|
||||
{
|
||||
return JsonConvert.SerializeObject (data, settings);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Parsing.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user