97 lines
2.7 KiB
C#
97 lines
2.7 KiB
C#
|
|
using Ease.NetCore.Utility;
|
|||
|
|
using Microsoft.Reporting.NETCore;
|
|||
|
|
using System;
|
|||
|
|
using System.Security.Claims;
|
|||
|
|
|
|||
|
|
namespace OnlineSalesAutoCrop.CoreAPI
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public static class Helper
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Creates a new claim with the specified type and value.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="type">The type of the claim, such as a role or permission identifier. Cannot be null or empty.</param>
|
|||
|
|
/// <param name="value">The value of the claim, representing the associated data for the specified type. Cannot be null or empty.</param>
|
|||
|
|
/// <returns>A <see cref="Claim"/> object initialized with the specified type and value.</returns>
|
|||
|
|
public static Claim CreateClaim(string type, string value)
|
|||
|
|
{
|
|||
|
|
return new Claim(type: type, value: value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="expirationInMinutes"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static DateTimeOffset CreateEaseCacheOptions(double expirationInMinutes = 1440)
|
|||
|
|
{
|
|||
|
|
return DateTime.Now.AddMinutes(expirationInMinutes);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Decrypt data by 128 bit AES encryption algorithm
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="secret">Used to decrypt data</param>
|
|||
|
|
/// <param name="data">Value to decrypt and value must be Base64String</param>
|
|||
|
|
/// <returns>Return plain text data if successful otherwise throw error</returns>
|
|||
|
|
public static string DecryptData(string secret, string data)
|
|||
|
|
{
|
|||
|
|
if (data == null || data.Length <= 0)
|
|||
|
|
throw new ArgumentNullException(nameof(data));
|
|||
|
|
|
|||
|
|
if (secret == null || secret.Length <= 0)
|
|||
|
|
throw new ArgumentNullException(nameof(secret));
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
data = Global.CipherFunctions.DecryptByAES(privateKey: secret, publicKey: secret, data: data, input: 2, output: 3);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
data = "*Key/Data Error*";
|
|||
|
|
}
|
|||
|
|
return data;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="report"></param>
|
|||
|
|
/// <param name="format"></param>
|
|||
|
|
/// <param name="contentType"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// <exception cref="Exception"></exception>
|
|||
|
|
public static byte[] GenerateRdlcOutputFile(LocalReport report, string format, out string contentType)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
byte[] bytes = report.Render(format: format, deviceInfo: null, mimeType: out contentType, encoding: out string _, fileNameExtension: out string _, streams: out string[] _, warnings: out Warning[] _);
|
|||
|
|
return bytes;
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
throw new InvalidOperationException(e.Message, e);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public static partial class StatusCodesExt
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public const int PasswordChanged = 898;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public const int StatusSessionExpired = 899;
|
|||
|
|
}
|
|||
|
|
}
|