Skip to content

Commit 93b4408

Browse files
committed
Merge remote-tracking branch 'origin/dotnet'
Conflicts: .gitignore
2 parents d785564 + 4f36024 commit 93b4408

27 files changed

+2475
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ gmon.out
8888
# VSCode
8989
/.vscode/
9090

91+
.vs/
9192

9293
## Go .gitignore
9394

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
3+
namespace Imageflow
4+
{
5+
/// <summary>
6+
/// The exception that is thrown when a native buffer is too large to be marshaled into a managed byte array.
7+
/// </summary>
8+
/// <seealso cref="Exception" />
9+
public class BufferOverflowException : Exception
10+
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="BufferOverflowException"/> class.
13+
/// </summary>
14+
/// <param name="bufferSize">Size of the buffer.</param>
15+
public BufferOverflowException(long bufferSize)
16+
{
17+
BufferSize = bufferSize;
18+
}
19+
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="BufferOverflowException"/> class.
22+
/// </summary>
23+
/// <param name="message">The message.</param>
24+
/// <param name="bufferSize">Size of the buffer.</param>
25+
public BufferOverflowException(string message, long bufferSize) : base(message)
26+
{
27+
BufferSize = bufferSize;
28+
}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="BufferOverflowException"/> class.
32+
/// </summary>
33+
/// <param name="message">The message.</param>
34+
/// <param name="bufferSize">Size of the buffer.</param>
35+
/// <param name="innerException">The inner exception.</param>
36+
public BufferOverflowException(string message, long bufferSize, Exception innerException) : base(message, innerException)
37+
{
38+
BufferSize = bufferSize;
39+
}
40+
41+
/// <summary>
42+
/// Gets the size of the buffer.
43+
/// </summary>
44+
/// <value>
45+
/// The size of the buffer.
46+
/// </value>
47+
public long BufferSize
48+
{
49+
get;
50+
}
51+
52+
/// <summary>
53+
/// Gets a message that describes the current exception.
54+
/// </summary>
55+
public override string Message => $"The native buffer was too large to be marshaled into a managed byte array. Native Buffer Size: {BufferSize}.";
56+
}
57+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma warning disable HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
2+
using System;
3+
4+
namespace Imageflow
5+
{
6+
/// <summary>
7+
/// Common Exceptions
8+
/// </summary>
9+
internal static class Exceptions
10+
{
11+
/// <summary>
12+
/// Parameter is not the correct.
13+
/// </summary>
14+
/// <typeparam name="TWantedType">The type of the wanted type.</typeparam>
15+
/// <param name="nameOfParameter">The name of parameter.</param>
16+
/// <returns>An <see cref="ArgumentException"/> with filled in message and parameter.</returns>
17+
public static ArgumentException ParameterIsNotTheCorrectType<TWantedType>(string nameOfParameter) => new ArgumentException($"{nameOfParameter} is not an {typeof(TWantedType).Name}.");
18+
}
19+
}
20+
#pragma warning restore HeapAnalyzerExplicitNewObjectRule // Explicit new reference type allocation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+

2+
// This file is used by Code Analysis to maintain SuppressMessage
3+
// attributes that are applied to this project.
4+
// Project-level suppressions either have no target or are given
5+
// a specific target and scoped to a namespace, type, member, etc.
6+
7+
using System.Diagnostics.CodeAnalysis;
8+
9+
[assembly: SuppressMessage("Style", "CC0105:You should use 'var' whenever possible.", Justification = "var is only useful with IDEs")]
10+
[assembly: SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.", Justification = "var is only useful with IDEs")]
11+
[assembly: SuppressMessage("Language Usage Opportunities", "RECS0091:Use 'var' keyword when possible", Justification = "var is only useful with IDEs")]
12+
[assembly: SuppressMessage("Style", "RECS0129: C# modifier is redundant", Justification = "Modifiers should always be explicitly stated")]
13+
[assembly: SuppressMessage("Style", "RECS0145: C# 'private' modifier is redundant", Justification = "Modifiers should always be explicitly stated")]
14+
[assembly: SuppressMessage("Maintainability", "S1309:Track uses of in-source issue suppressions", Justification = "Redunent")]
15+
[assembly: SuppressMessage("General", "RCS1024:Format accessor list.", Justification = "LINES")]
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Imageflow", "Imageflow.xproj", "{8A354FA1-4F06-4267-99A9-57A879A94110}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{8A354FA1-4F06-4267-99A9-57A879A94110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{8A354FA1-4F06-4267-99A9-57A879A94110}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{8A354FA1-4F06-4267-99A9-57A879A94110}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{8A354FA1-4F06-4267-99A9-57A879A94110}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>8a354fa1-4f06-4267-99a9-57a879a94110</ProjectGuid>
11+
<RootNamespace>Imageflow</RootNamespace>
12+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
13+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
14+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
17+
<PropertyGroup>
18+
<SchemaVersion>2.0</SchemaVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Threading;
2+
3+
namespace Imageflow
4+
{
5+
/// <summary>
6+
/// Very simple cross-thread preventions lock.
7+
/// </summary>
8+
internal struct LightLock
9+
{
10+
/// <summary>
11+
/// The true value.
12+
/// </summary>
13+
private const int TRUE = 1;
14+
/// <summary>
15+
/// The false value.
16+
/// </summary>
17+
private const int FALSE = 0;
18+
19+
/// <summary>
20+
/// If the lock has been taken.
21+
/// </summary>
22+
private int taken;
23+
24+
/// <summary>
25+
/// Takes the lock.
26+
/// </summary>
27+
/// <returns></returns>
28+
public bool Take() => Interlocked.CompareExchange(ref taken, TRUE, FALSE) == FALSE;
29+
30+
/// <summary>
31+
/// Release the lock.
32+
/// </summary>
33+
public void Release() => Interlocked.Exchange(ref taken, FALSE);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Imageflow.Native
2+
{
3+
/// <summary>
4+
/// When a resource should be closed/freed/cleaned up
5+
/// </summary>
6+
/// <seealso href="https://s3-us-west-1.amazonaws.com/imageflow-nightlies/master/doc/imageflow/enum.CleanupWith.html"/>
7+
internal enum CleanupWith
8+
{
9+
/// <summary>
10+
/// When the context is destroyed
11+
/// </summary>
12+
Context = 0,
13+
/// <summary>
14+
/// When the first job that the item is associated with is destroyed.
15+
/// </summary>
16+
FirstJob = 1,
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Imageflow.Native
5+
{
6+
/// <summary>
7+
/// Pointer for an Imageflow Context;
8+
/// </summary>
9+
/// <seealso cref="System.IEquatable{T}" />
10+
/// <seealso href="https://s3-us-west-1.amazonaws.com/imageflow-nightlies/master/doc/imageflow/struct.Context.html"/>
11+
[StructLayout(LayoutKind.Sequential)]
12+
internal struct ContextPointer : IEquatable<ContextPointer>
13+
{
14+
/// <summary>
15+
/// The internal pointer.
16+
/// </summary>
17+
private readonly IntPtr contextPointer;
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="ContextPointer"/> struct.
21+
/// </summary>
22+
/// <param name="pointer">The pointer.</param>
23+
public ContextPointer(IntPtr pointer)
24+
{
25+
contextPointer = pointer;
26+
}
27+
28+
/// <summary>
29+
/// Indicates whether the current <see cref="ContextPointer"/> is equal to another <see cref="ContextPointer"/>.
30+
/// </summary>
31+
/// <param name="other">A <see cref="ContextPointer"/> to compare with this <see cref="ContextPointer"/>.</param>
32+
/// <returns>
33+
/// <see langword="true"/> if the current <see cref="ContextPointer"/> is equal to the <paramref name="other" /> parameter; otherwise, <see langword="false"/>.
34+
/// </returns>
35+
public bool Equals(ContextPointer other) => contextPointer == other.contextPointer;
36+
37+
/// <summary>
38+
/// Determines whether the specified <see cref="object" />, is equal to this <see cref="ContextPointer"/>.
39+
/// </summary>
40+
/// <param name="obj">The <see cref="object" /> to compare with this <see cref="ContextPointer"/>.</param>
41+
/// <returns>
42+
/// <see langword="true"/> if the specified <see cref="object" /> is equal to this <see cref="ContextPointer"/>; otherwise, <see langword="false"/>.
43+
/// </returns>
44+
public override bool Equals(object obj)
45+
{
46+
if (obj is ContextPointer)
47+
{
48+
return Equals((ContextPointer)obj);
49+
}
50+
return false;
51+
}
52+
53+
/// <summary>
54+
/// Returns a hash code for this <see cref="ContextPointer"/>.
55+
/// </summary>
56+
/// <returns>
57+
/// A hash code for this <see cref="ContextPointer"/>, suitable for use in hashing algorithms and data structures like a hash table.
58+
/// </returns>
59+
public override int GetHashCode() => contextPointer.GetHashCode();
60+
61+
/// <summary>
62+
/// Returns a <see cref="string" /> that represents this <see cref="ContextPointer"/>.
63+
/// </summary>
64+
/// <returns>
65+
/// A <see cref="string" /> that represents this <see cref="ContextPointer"/>.
66+
/// </returns>
67+
public override string ToString() => contextPointer.ToString();
68+
69+
/// <summary>
70+
/// Gets the size of this instance.
71+
/// </summary>
72+
/// <value>
73+
/// The size of this instance.
74+
/// </value>
75+
/// <seealso cref="IntPtr.Size"/>
76+
public static int Size => IntPtr.Size;
77+
78+
/// <summary>
79+
/// Gets the <see langword="null"/> value.
80+
/// </summary>
81+
/// <value>
82+
/// The <see langword="null"/> value.
83+
/// </value>
84+
public static ContextPointer Zero { get; } = new ContextPointer(IntPtr.Zero);
85+
86+
public static bool operator ==(ContextPointer left, ContextPointer right) => left.contextPointer == right.contextPointer;
87+
88+
public static bool operator !=(ContextPointer left, ContextPointer right) => left.contextPointer != right.contextPointer;
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Imageflow.Native
2+
{
3+
/// <summary>
4+
/// Input or output
5+
/// </summary>
6+
/// <seealso href="https://s3-us-west-1.amazonaws.com/imageflow-nightlies/master/doc/imageflow/enum.Direction.html"/>
7+
internal enum Direction
8+
{
9+
Out = 8,
10+
In = 4,
11+
}
12+
}

0 commit comments

Comments
 (0)