Skip to content

Commit

Permalink
Merge pull request #12 from lillo42/fixes-error-to-integrate-with-gat…
Browse files Browse the repository at this point in the history
…eway

Fixes error to integrate with gateway
  • Loading branch information
lillo42 authored Feb 12, 2020
2 parents bf7dc38 + e2b35a9 commit e58a57a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion sample/Multi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseRouting();

Expand Down
2 changes: 1 addition & 1 deletion sample/Multi/Things/ExampleDimmableLight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class FadeAction : Action

protected override async ValueTask ExecuteAsync(CancellationToken cancellation)
{
int value = Input["input"] as int? ?? 0;
int value = Input?["input"] as int? ?? 0;
await Task.Delay(value, cancellation);

var property = Thing.Properties.FirstOrDefault(x => x.Name == "brightness");
Expand Down
2 changes: 1 addition & 1 deletion sample/Multi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Debug"
}
},
"AllowedHosts": "*"
Expand Down
2 changes: 1 addition & 1 deletion sample/Single/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseHttpsRedirection();
//app.UseHttpsRedirection();

app.UseRouting();

Expand Down
2 changes: 1 addition & 1 deletion sample/Single/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Debug"
}
},
"AllowedHosts": "*"
Expand Down
10 changes: 9 additions & 1 deletion src/Mozilla.IoT.WebThing/Activator/ThingActivator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -38,6 +38,13 @@ public void Register<T>(IServiceProvider service) where T : Thing
{
string name = typeof(T).Name;
Register<T>(service, name.Replace("Thing", ""));

var thing = CreateInstance(service, name.Replace("Thing", ""));

if (thing.Name != null)
{
_thingType.TryAdd(thing.Name, typeof(T));
}
}

public void Register<T>(IServiceProvider service, string thing)
Expand All @@ -53,6 +60,7 @@ public void Register<T>(IServiceProvider service, T thing)
{
_thingType.TryAdd(thing.Name, typeof(T));
_typeActivatorCache.TryAdd(typeof(T), thing);

BindingThingNotify(thing, service, thing.Name);
}

Expand Down
16 changes: 7 additions & 9 deletions src/Mozilla.IoT.WebThing/Property.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;

Expand All @@ -20,18 +20,16 @@ public Property(string name, object value, IDictionary<string, object> metadata)
{
}

private T _value;

public new virtual T Value
{
get
get => _value;
set
{
if (base.Value == null)
{
return default;
}

return (T)base.Value;
_value = value;
OnValueChanged();
}
set => base.Value = value;
}

internal override Type Type => typeof(T);
Expand Down
2 changes: 1 addition & 1 deletion src/Mozilla.IoT.WebThing/ServiceRouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal IEnumerable<IEndpointConventionBuilder> Build(IEndpointRouteBuilder end

if (!_option.IsSingleThing)
{
prefix = "/{{thing}}";
prefix = "/things/{thing}";
result.AddLast(endpointRouteBuilder.MapGet("/", GetThings.Invoke));
result.AddLast(endpointRouteBuilder.MapGet(prefix, GetThing.Invoke));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public static ThingEndpointConventionBuilder MapThing<T>(this IEndpointRouteBuil

var activator = builder.ServiceProvider.GetService<IThingActivator>();
activator.Register<T>(builder.ServiceProvider, thing);




var serviceRouteBuilder = builder.ServiceProvider.GetRequiredService<ServiceRouteBuilder>();
var endpointConventionBuilders = serviceRouteBuilder.Build(builder);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Mozilla.IoT.WebThing.Activator;
using Mozilla.IoT.WebThing.Activator;
#if DEBUG
using System.Linq;
using System;
Expand Down Expand Up @@ -295,7 +295,6 @@ public void GetEnumerator_Should_ReturnAllInstance()

private class SampleThing : Thing
{

}
}
}
Expand Down

0 comments on commit e58a57a

Please sign in to comment.