forked from tjanczuk/edge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
96 lines (89 loc) · 3.2 KB
/
Startup.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ServiceStack.Text;
namespace Echo
{
public class Startup
{
public async Task<object> Invoke(object input)
{
Console.WriteLine("input: " + (input ?? "null").GetType().Name);
var objArr = input as object[];
if (objArr != null)
{
Console.WriteLine("type: object[], element {0}", objArr.Length > 0 ? objArr[0] : "null");
if (objArr.Length > 0)
{
var obj = objArr[0] as Dictionary<string, object>;
if (obj != null)
{
Console.WriteLine("element: Dictionary<string,object>, Keys: " + string.Join(", ", obj.Keys.ToArray()));
}
}
}
return input;
}
public async Task<object> DeserializeJson(object input)
{
var json = (string)input;
var to = json.FromJson<List<Customer>>();
return to.Count;
}
public async Task<object> DeserializeObject(object input)
{
var objArray = (object[])input;
var to = (from Dictionary<string, object> map in objArray
select new Customer
{
Id = (string)map["Id"],
CompanyName = (string)map["CompanyName"],
ContactName = (string)map["ContactName"],
ContactTitle = (string)map["ContactTitle"],
Address = (string)map["Address"],
City = (string)map["City"],
Region = (string)map["Region"],
PostalCode = (string)map["PostalCode"],
Country = (string)map["Country"],
Phone = (string)map["Phone"],
Fax = (string)map["Fax"],
Email = (string)map["Email"],
}).ToList();
return to.Count;
}
}
public class Customer
{
public string Id { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
public string ContactTitle { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public string Email { get; set; }
public Customer Copy()
{
return new Customer
{
Id = Id,
CompanyName = CompanyName,
ContactName = ContactName,
ContactTitle = ContactTitle,
Address = Address,
City = City,
Region = Region,
PostalCode = PostalCode,
Country = Country,
Phone = Phone,
Fax = Fax,
Email = Email,
};
}
}
}