repo creation with initial code after cloning public repo
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Class BaseExtensions.
|
||||
/// </summary>
|
||||
public static partial class BaseExtensions
|
||||
{
|
||||
// http://stackoverflow.com/questions/1349023/how-can-i-strip-html-from-text-in-net
|
||||
[GeneratedRegex(@"<(.|\n)*?>")]
|
||||
private static partial Regex StripHtmlRegex();
|
||||
|
||||
/// <summary>
|
||||
/// Strips the HTML.
|
||||
/// </summary>
|
||||
/// <param name="htmlString">The HTML string.</param>
|
||||
/// <returns><see cref="string" />.</returns>
|
||||
public static string StripHtml(this string htmlString)
|
||||
=> StripHtmlRegex().Replace(htmlString, string.Empty).Trim();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Md5.
|
||||
/// </summary>
|
||||
/// <param name="str">The string.</param>
|
||||
/// <returns><see cref="Guid" />.</returns>
|
||||
public static Guid GetMD5(this string str)
|
||||
{
|
||||
#pragma warning disable CA5351
|
||||
return new Guid(MD5.HashData(Encoding.Unicode.GetBytes(str)));
|
||||
#pragma warning restore CA5351
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Static class containing extension methods for <see cref="HttpContext"/>.
|
||||
/// </summary>
|
||||
public static class HttpContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks the origin of the HTTP context.
|
||||
/// </summary>
|
||||
/// <param name="context">The incoming HTTP context.</param>
|
||||
/// <returns><c>true</c> if the request is coming from the same machine as is running the server, <c>false</c> otherwise.</returns>
|
||||
public static bool IsLocal(this HttpContext context)
|
||||
{
|
||||
return (context.Connection.LocalIpAddress is null
|
||||
&& context.Connection.RemoteIpAddress is null)
|
||||
|| Equals(context.Connection.LocalIpAddress, context.Connection.RemoteIpAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the remote IP address of the caller of the HTTP context.
|
||||
/// </summary>
|
||||
/// <param name="context">The HTTP context.</param>
|
||||
/// <returns>The remote caller IP address.</returns>
|
||||
public static IPAddress GetNormalizedRemoteIP(this HttpContext context)
|
||||
{
|
||||
// Default to the loopback address if no RemoteIpAddress is specified (i.e. during integration tests)
|
||||
var ip = context.Connection.RemoteIpAddress ?? IPAddress.Loopback;
|
||||
|
||||
if (ip.IsIPv4MappedToIPv6)
|
||||
{
|
||||
ip = ip.MapToIPv4();
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Class MethodNotAllowedException.
|
||||
/// </summary>
|
||||
public class MethodNotAllowedException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MethodNotAllowedException" /> class.
|
||||
/// </summary>
|
||||
public MethodNotAllowedException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MethodNotAllowedException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
public MethodNotAllowedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="Process"/>.
|
||||
/// </summary>
|
||||
public static class ProcessExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Asynchronously wait for the process to exit.
|
||||
/// </summary>
|
||||
/// <param name="process">The process to wait for.</param>
|
||||
/// <param name="timeout">The duration to wait before cancelling waiting for the task.</param>
|
||||
/// <returns>A task that will complete when the process has exited, cancellation has been requested, or an error occurs.</returns>
|
||||
/// <exception cref="OperationCanceledException">The timeout ended.</exception>
|
||||
public static async Task WaitForExitAsync(this Process process, TimeSpan timeout)
|
||||
{
|
||||
using (var cancelTokenSource = new CancellationTokenSource(timeout))
|
||||
{
|
||||
await process.WaitForExitAsync(cancelTokenSource.Token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
public class RateLimitExceededException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RateLimitExceededException" /> class.
|
||||
/// </summary>
|
||||
public RateLimitExceededException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RateLimitExceededException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
public RateLimitExceededException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Common.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ResourceNotFoundException.
|
||||
/// </summary>
|
||||
public class ResourceNotFoundException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ResourceNotFoundException" /> class.
|
||||
/// </summary>
|
||||
public ResourceNotFoundException()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ResourceNotFoundException" /> class.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
public ResourceNotFoundException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user