1: using System;
2: using System.Collections.Generic;
3: using System.Runtime.Serialization;
4: using System.Threading.Tasks;
5:
6: namespace Ia.Cl.Model
7: {
8: ////////////////////////////////////////////////////////////////////////////
9:
10: /// <summary publish="true">
11: /// Packet model
12: /// </summary>
13: ///
14: /// <remarks>
15: /// Copyright © 2006-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
16: ///
17: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
18: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
19: ///
20: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22: ///
23: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
24: ///
25: /// Copyright notice: This notice may not be removed or altered from any source distribution.
26: /// </remarks>
27: [DataContract(IsReference = true, Namespace = "kw.com.ia.api.packet", Name = "packet")]
28: public class Packet
29: {
30: /// <summary/>
31: public Packet() { }
32:
33: /// <summary/>
34: [DataMember(Name = "id")]
35: public System.Guid Id { get; set; }
36:
37: /// <summary/>
38: [DataMember(Name = "parentId")]
39: public System.Guid ParentId { get; set; }
40:
41: /// <summary/>
42: [DataMember(Name = "recipientAssemblyGuid")]
43: public System.Guid RecipientAssemblyGuid { get; set; }
44:
45: /// <summary/>
46: [DataMember(Name = "recipientAssemblyProduct")]
47: public string RecipientAssemblyProduct { get; set; }
48:
49: /// <summary/>
50: [DataMember(Name = "senderAssemblyGuid")]
51: public System.Guid SenderAssemblyGuid { get; set; }
52:
53: /// <summary/>
54: [DataMember(Name = "senderAssemblyProduct")]
55: public string SenderAssemblyProduct { get; set; }
56:
57: /// <summary/>
58: [DataMember(Name = "name")]
59: public string Name { get; set; }
60:
61: /// <summary/>
62: [DataMember(Name = "payload")]
63: public string Payload { get; set; }
64:
65: /// <summary/>
66: [DataMember(Name = "hash")]
67: public string Hash { get; set; }
68:
69: /// <summary/>
70: [DataMember(Name = "created")]
71: public DateTime Created { get; set; }
72:
73: ////////////////////////////////////////////////////////////////////////////
74:
75: /// <summary>
76: ///
77: /// </summary>
78: public static async Task PostPacketAsync(Guid recipientAssemblyGuid, Guid senderAssemblyGuid, Guid parentId, string name, string payload)
79: {
80: string hash;
81:
82: hash = Ia.Cl.Model.Cryptography.Md5.Hash(name);
83:
84: var packet = new Ia.Cl.Model.Packet()
85: {
86: Id = Guid.NewGuid(),
87: ParentId = parentId,
88: RecipientAssemblyGuid = recipientAssemblyGuid,
89: SenderAssemblyGuid = senderAssemblyGuid,
90: Name = name,
91: Payload = payload,
92: Hash = hash,
93: Created = DateTime.UtcNow.AddHours(3),
94: };
95:
96: await Ia.Cl.Model.Http.PostAsync("https://api.ia.com.kw", "api/packets", packet);
97: }
98:
99: ////////////////////////////////////////////////////////////////////////////
100:
101: /// <summary>
102: ///
103: /// </summary>
104: public static async Task PostPacketAsync(string recipientAssemblyProduct, string senderAssemblyProduct, Guid parentId, string name, string payload)
105: {
106: string hash;
107:
108: hash = Ia.Cl.Model.Cryptography.Md5.Hash(name);
109:
110: var packet = new Ia.Cl.Model.Packet()
111: {
112: Id = Guid.NewGuid(),
113: ParentId = parentId,
114: RecipientAssemblyProduct = recipientAssemblyProduct,
115: SenderAssemblyProduct = senderAssemblyProduct,
116: Name = name,
117: Payload = payload,
118: Hash = hash,
119: Created = DateTime.UtcNow.AddHours(3),
120: };
121:
122: await Ia.Cl.Model.Http.PostAsync("https://api.ia.com.kw", "api/packets", packet);
123: }
124:
125: /*
126: ////////////////////////////////////////////////////////////////////////////
127:
128: /// <summary>
129: ///
130: /// </summary>
131: public static List<Ia.Cl.Model.Packet> PacketList()
132: {
133: var list = Ia.Cl.Model.Http.GetAsync<List<Ia.Cl.Model.Packet>>("https://api.ia.com.kw", "api/packets");
134:
135: return list.Result;
136: }
137: */
138:
139: /*
140: ////////////////////////////////////////////////////////////////////////////
141:
142: /// <summary>
143: ///
144: /// </summary>
145: public static async Task<List<Ia.Cl.Model.Packet>> RecipientPacketListAsync(string recipientAssemblyProduct)
146: {
147: var list = await Ia.Cl.Model.Http.GetAsync<List<Ia.Cl.Model.Packet>>("https://api.ia.com.kw", "api/packets/recipientAssemblyProduct/" + recipientAssemblyProduct);
148:
149: return list;
150: }
151: */
152:
153: /*
154: ////////////////////////////////////////////////////////////////////////////
155:
156: /// <summary>
157: ///
158: /// </summary>
159: public static async Task<List<Ia.Cl.Model.Packet>> SenderPacketListAsync(string senderAssemblyProduct)
160: {
161: var list = await Ia.Cl.Model.Http.GetAsync<List<Ia.Cl.Model.Packet>>("https://api.ia.com.kw", "api/packets/senderAssemblyProduct/" + senderAssemblyProduct);
162:
163: return list;
164: }
165: */
166:
167: ////////////////////////////////////////////////////////////////////////////
168: ////////////////////////////////////////////////////////////////////////////
169: }
170:
171: ////////////////////////////////////////////////////////////////////////////
172: ////////////////////////////////////////////////////////////////////////////
173: }