-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestChannel.cs
97 lines (86 loc) · 2.65 KB
/
TestChannel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Nuclear.Channels;
using Nuclear.Channels.Base.Enums;
using Nuclear.Channels.Decorators;
using Nuclear.Channels.Base.Decorators;
using Nuclear.Channels.Messaging;
using Nuclear.ExportLocator.Decorators;
using System;
using Nuclear.Channels.Authentication;
using Nuclear.Channels.Heuristics;
using System.Collections.Generic;
namespace ConsoleApp1
{
[Channel/*(EnableSessions = true)*/]
//[AuthorizeChannel(ChannelAuthenticationSchemes.Token, "Role", "Admin")]
public class TestChannel : ChannelBase
{
[ImportedService]
public ITestService Service { get; set; }
[ChannelMethod]
[EnableCache(20, CacheDurationUnit.Seconds)]
public string HelloWorld()
{
return Service.Write();
}
[ChannelMethod]
[EnableCache(1, CacheDurationUnit.Minutes)]
public string PostParams(string name)
{
return $"Hello {name} from ChannelMethod";
}
[ChannelMethod]
public void WriteStringWithMessageWriter(string message)
{
ChannelMessageWriter.Write(new ChannelMessage()
{
Success = true,
Output = message,
Message = message
}, Context.Response);
}
[ChannelMethod(ChannelHttpMethod.POST)]
public void CreateTestClass(string id, string name)
{
ChannelMessage msg = new ChannelMessage()
{
Message = string.Empty,
Output = new TestClass() { Id = id, Name = name },
Success = true
};
ChannelMessageWriter.Write(msg, Context.Response);
}
[ChannelMethod]
public void DictionaryTest()
{
var testDictionary = new Dictionary<string, string>();
testDictionary.Add("TestKey", "TestValue");
testDictionary.Add("TestKey1", "TestValue2");
var msg = new ChannelMessage
{
Message = string.Empty,
Output = testDictionary,
Success = true
};
ChannelMessageWriter.Write(msg, Context.Response);
}
[ChannelMethod]
public void RedirectionTest(string url)
{
RedirectToUrl(url);
}
}
public interface ITestService { string Write(); }
[Export(typeof(ITestService))]
public class TestService : ITestService
{
public string Write()
{
return "HELLO WORLD FROM CHANNEL METHOD";
}
}
public class TestClass
{
public string Id { get; set; }
public string Name { get; set; }
}
}