Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Updating to latest libraries and some refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonHaley committed Jan 29, 2017
1 parent a723e6e commit 770c288
Show file tree
Hide file tree
Showing 33 changed files with 363 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ private static IArgumentBinding<RedisEntity> CreateBinding(Type itemType)

private class RedisArgumentBinding<TInput> : IArgumentBinding<RedisEntity>
{
public Type ValueType
{
get { return typeof (TInput); }
}
public Type ValueType => typeof (TInput);

public Task<IValueProvider> BindAsync(RedisEntity value, ValueBindingContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));
}

IValueProvider provider = new RedisValueBinder<TInput>(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host;
Expand All @@ -17,23 +16,15 @@ public class RedisAttributeBindingProvider : IBindingProvider

public RedisAttributeBindingProvider(RedisConfiguration config, TraceWriter trace)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
if (trace == null)
{
throw new ArgumentNullException("trace");
}
_config = config;
_trace = trace;
_config = config ?? throw new ArgumentNullException(nameof(config));
_trace = trace ?? throw new ArgumentNullException(nameof(trace));
}

public Task<IBinding> TryCreateAsync(BindingProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));
}

ParameterInfo parameter = context.Parameter;
Expand All @@ -48,8 +39,7 @@ public Task<IBinding> TryCreateAsync(BindingProviderContext context)

if (argumentBinding == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"Can't bind to type '{0}'.", parameter.ParameterType));
throw new InvalidOperationException($"Can't bind to type '{parameter.ParameterType}'.");
}

var account = RedisAccount.CreateDbFromConnectionString(_config.ConnectionString);
Expand Down
22 changes: 9 additions & 13 deletions source/Redis.WebJobs.Extensions/Core/Bindings/RedisBinding.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Bindings;
using Microsoft.Azure.WebJobs.Host.Protocols;
Expand All @@ -25,20 +24,17 @@ public RedisBinding(string parameterName, IArgumentBinding<RedisEntity> argument
_account = account;
_attribute = attribute;
_mode = attribute.Mode;

_channelOrKeyPath = BindingTemplate.FromString(attribute.ChannelOrKey);
_trace = trace;
}

public bool FromAttribute
{
get { return true; }
}
public bool FromAttribute => true;

public Task<IValueProvider> BindAsync(BindingContext context)
{
context.CancellationToken.ThrowIfCancellationRequested();

var entity = CreateEntity(context.BindingData);

return BindAsync(entity, context.ValueContext);
Expand Down Expand Up @@ -82,15 +78,15 @@ internal static ParameterDisplayHints CreateParameterDisplayHints(string channel

if (mode == Mode.PubSub)
{
descriptor.Description = isInput
? string.Format(CultureInfo.CurrentCulture, "publish to channel '{0}'", channelOrKey)
: string.Format(CultureInfo.CurrentCulture, "subscribe to channel '{0}'", channelOrKey);
descriptor.Description = isInput ?
$"publish to channel '{channelOrKey}'" :
$"subscribe to channel '{channelOrKey}'";
}
else
{
descriptor.Description = isInput
? string.Format(CultureInfo.CurrentCulture, "key to get from cache '{0}'", channelOrKey)
: string.Format(CultureInfo.CurrentCulture, "key to add to cache'{0}'", channelOrKey);
descriptor.Description = isInput ?
$"key to get from cache '{channelOrKey}'" :
$"key to add to cache'{channelOrKey}'";
}
descriptor.Prompt = isInput ?
"Enter the channel name" :
Expand Down
14 changes: 5 additions & 9 deletions source/Redis.WebJobs.Extensions/Core/Bindings/RedisEntity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Bindings.Path;
using Microsoft.Azure.WebJobs.Host.Bindings;
Expand All @@ -17,17 +16,14 @@ public RedisEntity(RedisAccount account, BindingTemplate channelOrKeyPath, Mode
{
Account = account;
Mode = mode;
_channelOrKeyPath = channelOrKeyPath;
_bindingData = bindingData;
_channelOrKeyPath = channelOrKeyPath;
}

public RedisAccount Account { get; set; }
public Mode Mode { get; set; }

public string ChannelOrKey
{
get { return _channelOrKeyPath.Bind(_bindingData); }
}
public string ChannelOrKey => _channelOrKeyPath.Bind(_bindingData);

public void SetBindingData(Type contractType, object value)
{
Expand All @@ -41,19 +37,19 @@ public Task SendAsync(string message)
}
public async Task SetAsync(string value)
{
await Account.RedisDb.StringSetAsync(ChannelOrKey, value, null, When.Always, CommandFlags.None);
await Account.RedisDb.StringSetAsync(ChannelOrKey, value, null);
}

public async Task<string> GetAsync()
{
RedisValue value = await Account.RedisDb.StringGetAsync(ChannelOrKey, CommandFlags.None);
RedisValue value = await Account.RedisDb.StringGetAsync(ChannelOrKey);
if (!value.HasValue)
{
return null;
}
else
{
return (string)value;
return value;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ public RedisValueBinder(RedisEntity entity)
_entity = entity;
}

public override object GetValue()
public override Task<object> GetValueAsync()
{
string value = _entity.GetAsync().Result;

if (value == null)
{
return default(TInput);
return Task.FromResult<object>(default(TInput));
}

TInput contents;
if (TryJsonConvert(value, out contents))
{
return contents;
return Task.FromResult<object>(contents);
}
else
{
return value;
return Task.FromResult<object>(value);
}
}

public override string ToInvokeString()
{
return _entity.ChannelOrKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Host.Bindings;
using Microsoft.Azure.WebJobs.Host.Config;
using Microsoft.Azure.WebJobs.Host.Triggers;
using Redis.WebJobs.Extensions.Bindings;
using Redis.WebJobs.Extensions.Triggers;

Expand All @@ -15,22 +12,17 @@ internal class RedisExtensionConfig : IExtensionConfigProvider

public RedisExtensionConfig(RedisConfiguration redisConfig)
{
if (redisConfig == null)
{
throw new ArgumentNullException("redisConfig");
}

_redisConfig = redisConfig;
_redisConfig = redisConfig ?? throw new ArgumentNullException(nameof(redisConfig));
}

public RedisConfiguration Config { get { return _redisConfig; } }
public RedisConfiguration Config => _redisConfig;

/// <inheritdoc />
public void Initialize(ExtensionConfigContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));
}

context.Config.RegisterBindingExtensions(
Expand Down
5 changes: 2 additions & 3 deletions source/Redis.WebJobs.Extensions/Core/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Redis.WebJobs.Extensions
{
Expand All @@ -9,7 +8,7 @@ internal static class Constants
{
DateParseHandling = DateParseHandling.DateTimeOffset,
NullValueHandling = NullValueHandling.Ignore,
Formatting = Formatting.Indented
Formatting = Formatting.None
};
}
}
65 changes: 30 additions & 35 deletions source/Redis.WebJobs.Extensions/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,50 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Azure.WebJobs, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Core.1.1.2-alpha-10282\lib\net45\Microsoft.Azure.WebJobs.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.KeyVault.Core.2.0.4\lib\net45\Microsoft.Azure.KeyVault.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.WebJobs.Extensions, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Extensions.1.0.2-alpha-10258\lib\net45\Microsoft.Azure.WebJobs.Extensions.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.WebJobs, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Core.2.0.0-beta2-10504\lib\net45\Microsoft.Azure.WebJobs.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.WebJobs.Host, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.1.1.2-alpha-10282\lib\net45\Microsoft.Azure.WebJobs.Host.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.WebJobs.Extensions, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Extensions.2.0.0-beta2-10392\lib\net45\Microsoft.Azure.WebJobs.Extensions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Edm, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.7.0\lib\net40\Microsoft.Data.Edm.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.WebJobs.Host, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.2.0.0-beta2-10504\lib\net45\Microsoft.Azure.WebJobs.Host.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.OData.5.7.0\lib\net40\Microsoft.Data.OData.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Azure.WebJobs.Script.Extensibility, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.WebJobs.Script.Extensibility.1.0.0-beta2-10726\lib\net45\Microsoft.Azure.WebJobs.Script.Extensibility.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Services.Client, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Services.Client.5.7.0\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.Data.Edm, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.8.1\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.OData, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.OData.5.8.1\lib\net40\Microsoft.Data.OData.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Services.Client, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Services.Client.5.8.1\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.1\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Microsoft.WindowsAzure.ConfigurationManager.3.2.3\lib\net40\Microsoft.WindowsAzure.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
<Private>True</Private>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=8.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsAzure.Storage.8.0.1\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="NCrontab, Version=3.1.19111.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ncrontab.3.1.0\lib\net45\NCrontab.dll</HintPath>
<Private>True</Private>
<Reference Include="NCrontab, Version=3.2.20120.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ncrontab.3.3.0\lib\net35\NCrontab.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.2-beta2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="StackExchange.Redis, Version=1.0.316.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.1.0.488\lib\net45\StackExchange.Redis.dll</HintPath>
<Private>True</Private>
<Reference Include="StackExchange.Redis, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.1.2.0\lib\net45\StackExchange.Redis.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Spatial, Version=5.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.7.0\lib\net40\System.Spatial.dll</HintPath>
<Private>True</Private>
<Reference Include="System.IO.Compression" />
<Reference Include="System.Spatial, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.8.1\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Dataflow, Version=4.5.24.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Tpl.Dataflow.4.5.24\lib\portable-net45+win8+wpa81\System.Threading.Tasks.Dataflow.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Host.Config;
using Redis.WebJobs.Extensions.Config;

namespace Redis.WebJobs.Extensions
Expand All @@ -12,7 +10,7 @@ public static void UseRedis(this JobHostConfiguration config)
{
if (config == null)
{
throw new ArgumentNullException("config");
throw new ArgumentNullException(nameof(config));
}

config.UseRedis(new RedisConfiguration());
Expand All @@ -22,11 +20,10 @@ public static void UseRedis(this JobHostConfiguration config, TimeSpan checkCach
{
if (config == null)
{
throw new ArgumentNullException("config");
throw new ArgumentNullException(nameof(config));
}

var redisConfig = new RedisConfiguration();
redisConfig.CheckCacheFrequency = checkCacheFrequency;
var redisConfig = new RedisConfiguration {CheckCacheFrequency = checkCacheFrequency};

config.UseRedis(redisConfig);
}
Expand All @@ -35,12 +32,12 @@ public static void UseRedis(this JobHostConfiguration config, RedisConfiguration
{
if (config == null)
{
throw new ArgumentNullException("config");
throw new ArgumentNullException(nameof(config));
}

if (redisConfig == null)
{
throw new ArgumentNullException("redisConfig");
throw new ArgumentNullException(nameof(redisConfig));
}

config.RegisterExtensionConfigProvider(new RedisExtensionConfig(redisConfig));
Expand Down
Loading

0 comments on commit 770c288

Please sign in to comment.