Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jirenius committed Aug 15, 2019
2 parents c7dd3bb + ca4d447 commit 01c7ded
Show file tree
Hide file tree
Showing 61 changed files with 2,921 additions and 695 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ bld/
[Oo]bj/
[Ll]og/

# NuGet package files
*.nupkg
*.snupkg

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
1 change: 0 additions & 1 deletion ResgateIO.Service.UnitTests/CreateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Xunit;
using NATS.Client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="NATS.Client" Version="0.8.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="NATS.Client" Version="0.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion ResgateIO.Service.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResgateIO.Service.UnitTests
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWorld", "examples\HelloWorld\HelloWorld.csproj", "{B0C17113-0EF1-431C-AC38-495E6FEA9DE5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookCollection", "examples\BookCollection\BookCollection.csproj", "{CEEE43F2-361C-4D1A-911F-57C56B09FF60}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BookCollection", "examples\BookCollection\BookCollection.csproj", "{CEEE43F2-361C-4D1A-911F-57C56B09FF60}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
19 changes: 0 additions & 19 deletions ResgateIO.Service/BaseModelHandler.cs

This file was deleted.

7 changes: 0 additions & 7 deletions ResgateIO.Service/IAccessHandler.cs

This file was deleted.

7 changes: 0 additions & 7 deletions ResgateIO.Service/IAuthHandler.cs

This file was deleted.

7 changes: 0 additions & 7 deletions ResgateIO.Service/ICallHandler.cs

This file was deleted.

11 changes: 0 additions & 11 deletions ResgateIO.Service/ICollectionHandler.cs

This file was deleted.

11 changes: 0 additions & 11 deletions ResgateIO.Service/IModelHandler.cs

This file was deleted.

156 changes: 156 additions & 0 deletions ResgateIO.Service/IResourceContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
using System.Collections;
using System.Collections.Generic;

namespace ResgateIO.Service
{
public delegate void QueryCallBack(IQueryRequest request);

/// <summary>
/// Provides context information and methods for emitting events for a resource.
/// </summary>
public interface IResourceContext
{
/// <summary>
/// Service instance.
/// </summary>
ResService Service { get; }

/// <summary>
/// Resource name.
/// </summary>
string ResourceName { get; }

/// <summary>
/// Parameters that are derived from the resource name.
/// </summary>
IDictionary<string, string> PathParams { get; }

/// <summary>
/// Returns the parameter derived from the resource name for the key placeholder.
/// </summary>
/// <param name="key">Name of the placeholder key.</param>
/// <returns>Path parameter value.</returns>
string PathParam(string key);

/// <summary>
/// Query part of the resource ID without the question mark separator.
/// </summary>
string Query { get; }

/// <summary>
/// Context scoped key/value collection used to store and share data between handlers.
/// </summary>
IDictionary Items { get; }

/// <summary>
/// Resource handler.
/// </summary>
IResourceHandler Handler { get; }

/// <summary>
/// Gets the resource data object as provided from the Get resource handler.
/// If the get handler fails, or no get handler is defined, it return with null.
/// If the get handler responds with a different type than T, it throws an exception.
/// </summary>
/// <typeparam name="T">Type of resource data object.</typeparam>
/// <returns>Resource data object.</returns>
T Value<T>() where T : class;

/// <summary>
/// Gets the resource data object as provided from the Get resource handler.
/// If the get handler fails, or no get handler is defined, or the get handler responds
/// with a different type than T, it throws an exception.
/// </summary>
/// <typeparam name="T">Type of resource data object.</typeparam>
/// <returns>Resource data object.</returns>
T RequireValue<T>() where T : class;

/// <summary>
/// Sends a custom event on the resource.
/// Throws an exception if the event is one of the pre-defined or reserved events,
/// "change", "delete", "add", "remove", "patch", "reaccess", "unsubscribe", or "query".
/// For pre-defined events, the matching method, ChangeEvent, AddEvent,
/// RemoveEvent, or ReaccessEvent should be used instead.
/// </summary>
/// <remarks>
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#custom-event
/// </remarks>
/// <param name="eventName">Name of the event</param>
/// <param name="payload">JSON serializable payload. May be null.</param>
void Event(string eventName, object payload);

/// <summary>
/// Sends a change event.
/// If properties is null or empty, no event is sent.
/// Throws an exception if the resource is not of ResourceType.Model.
/// </summary>
/// <remarks>
/// The values must be serializable into JSON primitives, resource references,
/// or a delete action objects.
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#model-change-event
/// </remarks>
/// <param name="properties">Properties that has been changed with their new values.</param>
void ChangeEvent(Dictionary<string, object> properties);

/// <summary>
/// Sends an add event, adding the value at index idx.
/// Throws an exception if the resource is not of ResourceType.Collection.
/// </summary>
/// <remarks>
/// The value must be serializable into a JSON primitive or resource reference.
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#collection-add-event
/// </remarks>
/// <param name="value">Value that has been added.</param>
/// <param name="idx">Index position where the value has been added.</param>
void AddEvent(object value, int idx);

/// <summary>
/// Sends a remove event, removing the value at index idx.
/// Throws an exception if the resource is not of ResourceType.Collection.
/// </summary>
/// <remarks>
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#collection-remove-event
/// </remarks>
/// <param name="idx">Index position where the value has been added.</param>
void RemoveEvent(int idx);

/// <summary>
/// Sends a reaccess event to signal that the resource's access permissions has changed.
/// It will invalidate any previous access response sent for the resource.
/// </summary>
/// <remarks>
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#reaccess-event
/// </remarks>
void ReaccessEvent();

// QueryEvent sends a query event to signal that the query resource's underlying data has been modified.
// See the protocol specification for more information:
// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#query-event

/// <summary>
/// Sends a query event to signal that the query resource's underlying data has been modified.
/// </summary>
/// <remarks>
/// See the protocol specification for more information:
/// https://github.com/resgateio/resgate/blob/master/docs/res-service-protocol.md#query-event
/// </remarks>
/// <param name="callback">Query request callback delegate.</param>
void QueryEvent(QueryCallBack callback);

/// <summary>
/// Sends a create event to signal the resource has been created.
/// </summary>
/// <param name="data">Resource data object.</param>
void CreateEvent(object data);

/// <summary>
/// Sends a delete event to signal the resource has been deleted.
/// </summary>
void DeleteEvent();
}
}
11 changes: 0 additions & 11 deletions ResgateIO.Service/IResourceHandler.cs

This file was deleted.

75 changes: 0 additions & 75 deletions ResgateIO.Service/IResourceRequest.cs

This file was deleted.

21 changes: 21 additions & 0 deletions ResgateIO.Service/JsonUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Newtonsoft.Json;
using System.IO;
using System.Text;

namespace ResgateIO.Service
{
internal static class JsonUtils
{
public static T Deserialize<T>(byte[] data) where T : class
{
using (var stream = new MemoryStream(data))
using (var reader = new StreamReader(stream, Encoding.UTF8))
return JsonSerializer.Create().Deserialize(reader, typeof(T)) as T;
}

public static byte[] Serialize(object item)
{
return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(item));
}
}
}
Loading

0 comments on commit 01c7ded

Please sign in to comment.