-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding isolated worker model trigger binding
- Loading branch information
Showing
11 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
demos/Demo.Azure.Functions.Worker.RethinkDb/local.settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", | ||
"RethinkDbHostname": "[Enter RethinkDB hostname here]", | ||
"RethinkDbUser": "[Enter RethinkDB user name here]", | ||
"RethinkDbPassword": "[Enter RethinkDB user password here]" | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/RethinkDb.Azure.Functions.Worker.Extensions/Model/DocumentChange.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Collections.Generic; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RethinkDb.Azure.Functions.Worker.Extensions.Model | ||
{ | ||
/// <summary> | ||
/// Represents a document change in RethinkDB table. | ||
/// </summary> | ||
public class DocumentChange | ||
{ | ||
#region Properties | ||
/// <summary> | ||
/// Gets or sets the old value. When a document is inserted, old value will be null. | ||
/// </summary> | ||
[JsonPropertyName("old_val")] | ||
public dynamic OldValue { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the new value. When a document is deleted, new value will be null. | ||
/// </summary> | ||
[JsonPropertyName("new_val")] | ||
public dynamic NewValue { get; set; } | ||
|
||
/// <summary> | ||
/// If <see cref="RethinkDbTriggerAttribute.IncludeTypes"/> is set to true, this property will indicate the type of change. | ||
/// </summary> | ||
[JsonPropertyName("type")] | ||
public DocumentChangeType? Type { get; set; } | ||
#endregion | ||
} | ||
|
||
/// <summary> | ||
/// Represents a document change in RethinkDB table. | ||
/// </summary> | ||
public class DocumentChange<T> | ||
{ | ||
#region Properties | ||
/// <summary> | ||
/// Gets or sets the old value. When a document is inserted, old value will be null. | ||
/// </summary> | ||
[JsonPropertyName("old_val")] | ||
public T OldValue { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the new value. When a document is deleted, new value will be null. | ||
/// </summary> | ||
[JsonPropertyName("new_val")] | ||
public T NewValue { get; set; } | ||
|
||
/// <summary> | ||
/// If <see cref="RethinkDbTriggerAttribute.IncludeTypes"/> is set to true, this property will indicate the type of change. | ||
/// </summary> | ||
[JsonPropertyName("type")] | ||
public DocumentChangeType? Type { get; set; } | ||
#endregion | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/RethinkDb.Azure.Functions.Worker.Extensions/Model/DocumentChangeType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RethinkDb.Azure.Functions.Worker.Extensions.Model | ||
{ | ||
/// <summary> | ||
/// The type of <see cref="DocumentChange"/>. | ||
/// </summary> | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public enum DocumentChangeType | ||
{ | ||
/// <summary> | ||
/// Document was added. | ||
/// </summary> | ||
Add, | ||
/// <summary> | ||
/// Document was removed. | ||
/// </summary> | ||
Remove, | ||
/// <summary> | ||
/// Document was changed. | ||
/// </summary> | ||
Change, | ||
/// <summary> | ||
/// Initial document. | ||
/// </summary> | ||
Initial, | ||
/// <summary> | ||
/// If an initial result for a document has been sent and a change is made to that document that would move it to the unsent part of the result set | ||
/// (e.g., a changefeed monitors the top 100 posters, the first 50 have been sent, and poster 48 has become poster 52), | ||
/// an 'uninitial' notification will be sent, with an old_val field but no new_val field. | ||
/// </summary> | ||
Uninitial, | ||
/// <summary> | ||
/// A state document. | ||
/// </summary> | ||
State | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/RethinkDb.Azure.Functions.Worker.Extensions/RethinkDbTriggerAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions; | ||
|
||
namespace RethinkDb.Azure.Functions.Worker.Extensions | ||
{ | ||
/// <summary> | ||
/// Attribute used to define a trigger that binds to a RethinkDB table. | ||
/// </summary> | ||
public sealed class RethinkDbTriggerAttribute : TriggerBindingAttribute | ||
{ | ||
/// <summary> | ||
/// The name of the database containing the table to which the parameter applies (may include binding parameters). | ||
/// </summary> | ||
public string DatabaseName { get; private set; } | ||
|
||
/// <summary> | ||
/// The name of the table to which the parameter applies (may include binding parameters). | ||
/// </summary> | ||
public string TableName { get; private set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the hostname or IP address of the server to which the parameter applies. | ||
/// </summary> | ||
public string HostnameSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the TCP port of the server to which the parameter applies. | ||
/// </summary> | ||
public string PortSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the authorization key to the server to which the parameter applies. | ||
/// </summary> | ||
public string AuthorizationKeySetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the user account to connect as to the server to which the parameter applies. | ||
/// </summary> | ||
public string UserSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the user account password to connect as to the server to which the parameter applies. | ||
/// </summary> | ||
public string PasswordSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the value indicating if SSL/TLS encryption should be enabled for connection to the server. | ||
/// </summary> | ||
/// <remarks>The underlying driver (RethinkDb.Driver) requires a commercial license for SSL/TLS encryption.</remarks> | ||
public string EnableSslSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the "license to" of underlying driver (RethinkDb.Driver) commercial license. | ||
/// </summary> | ||
public string LicenseToSetting { get; set; } | ||
|
||
/// <summary> | ||
/// The name of the app setting containing the "license key" of underlying driver (RethinkDb.Driver) commercial license. | ||
/// </summary> | ||
public string LicenseKeySetting { get; set; } | ||
|
||
/// <summary> | ||
/// The value indicating if <see cref="DocumentChange.Type"/> field should be included for <see cref="DocumentChange"/>. | ||
/// </summary> | ||
public bool IncludeTypes { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Defines a trigger that binds to a RethinkDB table. | ||
/// </summary> | ||
/// <param name="databaseName">Name of the database of the table to which the parameter applies (may include binding parameters).</param> | ||
/// <param name="tableName">Name of the table to which the parameter applies (may include binding parameters).</param> | ||
public RethinkDbTriggerAttribute(string databaseName, string tableName) | ||
{ | ||
if (String.IsNullOrWhiteSpace(databaseName)) | ||
{ | ||
throw new ArgumentNullException(nameof(databaseName)); | ||
} | ||
|
||
if (String.IsNullOrWhiteSpace(tableName)) | ||
{ | ||
throw new ArgumentNullException(nameof(tableName)); | ||
} | ||
|
||
DatabaseName = databaseName; | ||
TableName = tableName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/RethinkDb.Azure.WebJobs.Extensions/Trigger/RethinkDbTriggerValueBinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.WebJobs.Host.Bindings; | ||
using Newtonsoft.Json; | ||
|
||
namespace RethinkDb.Azure.WebJobs.Extensions.Trigger | ||
{ | ||
internal class RethinkDbTriggerValueBinder : IValueProvider | ||
{ | ||
#region Fields | ||
private static readonly Type STRING_TYPE = typeof(string); | ||
|
||
private readonly ParameterInfo _parameter; | ||
private readonly object _value; | ||
private readonly bool _parameterTypeIsString; | ||
#endregion | ||
|
||
#region Properties | ||
public Type Type => _parameter.ParameterType; | ||
#endregion | ||
|
||
#region Constructor | ||
public RethinkDbTriggerValueBinder(ParameterInfo parameter, object value) | ||
{ | ||
_parameter = parameter; | ||
_value = value; | ||
_parameterTypeIsString = parameter.ParameterType == STRING_TYPE; | ||
} | ||
#endregion | ||
|
||
#region Methods | ||
public Task<object> GetValueAsync() | ||
{ | ||
if (_parameterTypeIsString) | ||
{ | ||
return Task.FromResult((object)JsonConvert.SerializeObject(_value)); | ||
} | ||
|
||
return Task.FromResult(_value); | ||
} | ||
|
||
public string ToInvokeString() => String.Empty; | ||
#endregion | ||
} | ||
} |