[IoTConnectivity] Added Base implementation
[platform/core/csapi/iotcon.git] / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / IoTConnectivityClientManager.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9 using System;
10 using System.Collections.Generic;
11
12 namespace Tizen.Network.IoTConnectivity
13 {
14     public static class IoTConnectivityClientManager
15     {
16         public const string MulticastAddress = null;
17
18         private static int s_presenceListenerId = 1;
19         private static Dictionary<IntPtr, Interop.IoTConnectivity.Client.Presence.PresenceCallback> s_presenceCallbacksMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Client.Presence.PresenceCallback>();
20         private static Dictionary<IntPtr, IntPtr> s_presenceHandlesMap = new Dictionary<IntPtr, IntPtr>();
21
22         private static int s_requestId = 1;
23         private static Dictionary<IntPtr, Interop.IoTConnectivity.Client.ResourceFinder.FoundResourceCallback> s_resourceFoundCallbacksMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Client.ResourceFinder.FoundResourceCallback>();
24         private static Dictionary<IntPtr, Interop.IoTConnectivity.Client.DeviceInformation.DeviceInformationCallback> s_deviceInformationCallbacksMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Client.DeviceInformation.DeviceInformationCallback>();
25         private static Dictionary<IntPtr, Interop.IoTConnectivity.Client.PlatformInformation.PlatformInformationCallback> s_platformInformationCallbacksMap = new Dictionary<IntPtr, Interop.IoTConnectivity.Client.PlatformInformation.PlatformInformationCallback>();
26
27         /// <summary>
28         /// presence event on the resource
29         /// </summary>
30         public static event EventHandler<PresenceReceivedEventArgs> PresenceReceived;
31
32         /// <summary>
33         /// Resource found event handler
34         /// </summary>
35         public static event EventHandler<ResourceFoundEventArgs> ResourceFound;
36
37         /// <summary>
38         /// PlatformInformationFound event handler
39         /// </summary>
40         public static event EventHandler<PlatformInformationFoundEventArgs> PlatformInformationFound;
41
42         /// <summary>
43         /// DeviceInformationFound event handler
44         /// </summary>
45         public static event EventHandler<DeviceInformationFoundEventArgs> DeviceInformationFound;
46
47         /// <summary>
48         /// FoundError event handler
49         /// </summary>
50         public static event EventHandler<FindingErrorOccurredEventArgs> FindingErrorOccurred;
51
52         /// <summary>
53         /// Timeout property
54         /// </summary>
55         public static int TimeOut
56         {
57             get
58             {
59                 int timeout;
60                 int ret = Interop.IoTConnectivity.Client.IoTCon.GetTimeout(out timeout);
61                 if (ret != (int)IoTConnectivityError.None)
62                 {
63                     Log.Warn(IoTConnectivityErrorFactory.LogTag, "Failed to get timeout");
64                     return 0;
65                 }
66                 return timeout;
67             }
68             set
69             {
70                 int ret = Interop.IoTConnectivity.Client.IoTCon.SetTimeout(value);
71                 if (ret != (int)IoTConnectivityError.None)
72                 {
73                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to set timeout");
74                     throw IoTConnectivityErrorFactory.GetException(ret);
75                 }
76             }
77         }
78
79         /// <summary>
80         /// Connects to the iotcon service
81         /// </summary>
82         public static void Initialize()
83         {
84             int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize();
85             if (ret != (int)IoTConnectivityError.None)
86             {
87                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
88                 throw IoTConnectivityErrorFactory.GetException(ret);
89             }
90         }
91
92         /// <summary>
93         /// Disconnects from the iotcon service
94         /// </summary>
95         public static void Deinitialize()
96         {
97             Interop.IoTConnectivity.Client.IoTCon.Deinitialize();
98         }
99
100         /// <summary>
101         /// Starts receiving presence events
102         /// </summary>
103         /// <returns>
104         /// PresenceId
105         /// </returns>
106         public static int StartReceivingPresence(string hostAddress, string resourceType)
107         {
108             Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
109             if (connectivityType == Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None)
110             {
111                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Unable to parse host address");
112                 throw new ArgumentException("Unable to parse host address");
113             }
114
115             if (resourceType != null && !ResourceTypes.IsValid(resourceType))
116             {
117                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Invalid type");
118                 throw new ArgumentException("Invalid type");
119             }
120
121             IntPtr id = IntPtr.Zero;
122             lock (s_presenceCallbacksMap)
123             {
124                 id = (IntPtr)s_presenceListenerId++;
125             }
126             s_presenceCallbacksMap[id] = (IntPtr presence, int result, IntPtr presenceResponseHandle, IntPtr userData) =>
127             {
128                 if (presenceResponseHandle != IntPtr.Zero)
129                 {
130                     int presenceId = (int)userData;
131                     if (result == 0)
132                     {
133                         PresenceReceivedEventArgs e = GetPresenceReceivedEventArgs(presenceId, presenceResponseHandle);
134                         if (e == null)
135                         {
136                             Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't get PresenceReceivedEventArgs");
137                             return;
138                         }
139                         PresenceReceived?.Invoke(null, e);
140                     }
141                     else
142                     {
143                         FindingErrorOccurredEventArgs e = GetFindingErrorOccurredEventArgs(presenceId, result);
144                         FindingErrorOccurred?.Invoke(null, e);
145                     }
146                 }
147             };
148
149             IntPtr presenceHandle;
150             int errorCode = Interop.IoTConnectivity.Client.Presence.AddPresenceCb(hostAddress, (int)connectivityType, resourceType, s_presenceCallbacksMap[id], id, out presenceHandle);
151             if (errorCode != (int)IoTConnectivityError.None)
152             {
153                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to register presence event handler");
154                 lock (s_presenceCallbacksMap)
155                 {
156                     s_presenceCallbacksMap.Remove(id);
157                 }
158                 throw IoTConnectivityErrorFactory.GetException(errorCode);
159             }
160
161             lock (s_presenceHandlesMap)
162             {
163                 s_presenceHandlesMap[id] = presenceHandle;
164             }
165             return (int)id;
166         }
167
168         /// <summary>
169         /// Stops receiving presence events
170         /// </summary>
171         public static void StopReceivingPresence(int presenceId)
172         {
173             if (s_presenceHandlesMap.ContainsKey((IntPtr)presenceId))
174             {
175                 IntPtr presenceHandle = s_presenceHandlesMap[(IntPtr)presenceId];
176                 int ret = Interop.IoTConnectivity.Client.Presence.RemovePresenceCb(presenceHandle);
177                 if (ret != (int)IoTConnectivityError.None)
178                 {
179                     Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to deregister presence event handler");
180                     throw IoTConnectivityErrorFactory.GetException(ret);
181                 }
182
183                 lock (s_presenceHandlesMap)
184                 {
185                     s_presenceHandlesMap.Remove((IntPtr)presenceId);
186                 }
187             }
188
189             if (s_presenceCallbacksMap.ContainsKey((IntPtr)presenceId))
190             {
191                 lock (s_presenceCallbacksMap)
192                 {
193                     s_presenceCallbacksMap.Remove((IntPtr)presenceId);
194                 }
195             }
196         }
197
198         /// <summary>
199         /// Starts finding resource events
200         /// </summary>
201         /// <returns>
202         /// RequestId
203         /// </returns>
204         public static int StartFindingResource(string hostAddress, string resourceType, bool isSecure = false)
205         {
206             Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
207             if (connectivityType == Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None)
208             {
209                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Unable to parse host address");
210                 throw new ArgumentException("Unable to parse host address");
211             }
212
213             if (resourceType != null && !ResourceTypes.IsValid(resourceType))
214             {
215                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Invalid type");
216                 throw new ArgumentException("Invalid type");
217             }
218
219             IntPtr id = IntPtr.Zero;
220             lock (s_resourceFoundCallbacksMap)
221             {
222                 id = (IntPtr)s_requestId++;
223             }
224             s_resourceFoundCallbacksMap[id] = (IntPtr remoteResourceHandle, int result, IntPtr userData) =>
225             {
226                 if (remoteResourceHandle != IntPtr.Zero)
227                 {
228                     int requestId = (int)userData;
229                     if (result == (int)IoTConnectivityError.None)
230                     {
231                         RemoteResource resource = null;
232                         try
233                         {
234                             resource = new RemoteResource(remoteResourceHandle);
235                         }
236                         catch (Exception exp)
237                         {
238                             Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't clone RemoteResource's handle: " + exp.Message);
239                             return;
240                         }
241                         ResourceFoundEventArgs e = new ResourceFoundEventArgs()
242                         {
243                             RequestId = requestId,
244                             Resource = resource
245                         };
246                         ResourceFound?.Invoke(null, e);
247                     }
248                     else
249                     {
250                         FindingErrorOccurredEventArgs e = GetFindingErrorOccurredEventArgs(requestId, result);
251                         FindingErrorOccurred?.Invoke(null, e);
252
253                         lock (s_resourceFoundCallbacksMap)
254                         {
255                             s_resourceFoundCallbacksMap.Remove(id);
256                         }
257                     }
258                 }
259             };
260
261             int errorCode = Interop.IoTConnectivity.Client.ResourceFinder.AddResourceFoundCb(hostAddress, (int)connectivityType, resourceType, isSecure, s_resourceFoundCallbacksMap[id], id);
262             if (errorCode != (int)IoTConnectivityError.None)
263             {
264                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to register resource found event handler");
265                 lock (s_resourceFoundCallbacksMap)
266                 {
267                     s_resourceFoundCallbacksMap.Remove(id);
268                 }
269                 throw IoTConnectivityErrorFactory.GetException(errorCode);
270             }
271             return (int)id;
272         }
273
274         /// <summary>
275         /// Starts finding device information events
276         /// </summary>
277         /// <returns>
278         /// RequestId
279         /// </returns>
280         public static int StartFindingDeviceInformation(string hostAddress)
281         {
282             Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
283             if (connectivityType == Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None)
284             {
285                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Unable to parse host address");
286                 throw new ArgumentException("Unable to parse host address");
287             }
288
289             IntPtr id = IntPtr.Zero;
290             lock (s_deviceInformationCallbacksMap)
291             {
292                 id = (IntPtr)s_requestId++;
293             }
294             s_deviceInformationCallbacksMap[id] = (IntPtr deviceInfoHandle, int result, IntPtr userData) =>
295             {
296                 if (deviceInfoHandle != IntPtr.Zero)
297                 {
298                     int requestId = (int)userData;
299                     if (result == 0)
300                     {
301                         DeviceInformationFoundEventArgs e = GetDeviceInformationFoundEventArgs(requestId, deviceInfoHandle);
302                         if (e == null)
303                         {
304                             Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't get DeviceInformationFoundEventArgs");
305                             return;
306                         }
307                         DeviceInformationFound?.Invoke(null, e);
308                     }
309                     else
310                     {
311                         FindingErrorOccurredEventArgs e = GetFindingErrorOccurredEventArgs(requestId, result);
312                         FindingErrorOccurred?.Invoke(null, e);
313
314                         lock (s_deviceInformationCallbacksMap)
315                         {
316                             s_deviceInformationCallbacksMap.Remove(id);
317                         }
318                     }
319                 }
320             };
321
322             int errorCode = Interop.IoTConnectivity.Client.DeviceInformation.Get(hostAddress, (int)connectivityType, s_deviceInformationCallbacksMap[id], id);
323             if (errorCode != (int)IoTConnectivityError.None)
324             {
325                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device information");
326                 lock (s_deviceInformationCallbacksMap)
327                 {
328                     s_deviceInformationCallbacksMap.Remove(id);
329                 }
330                 throw IoTConnectivityErrorFactory.GetException(errorCode);
331             }
332
333             return (int)id;
334         }
335
336         /// <summary>
337         /// Starts finding platform information events
338         /// </summary>
339         /// <returns>
340         /// RequestId
341         /// </returns>
342         public static int StartFindingPlatformInformation(string hostAddress)
343         {
344             Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = RemoteResource.GetConnectivityType(hostAddress);
345             if (connectivityType == Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None)
346             {
347                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Unable to parse host address");
348                 throw new ArgumentException("Unable to parse host address");
349             }
350
351             IntPtr id = IntPtr.Zero;
352             lock (s_platformInformationCallbacksMap)
353             {
354                 id = (IntPtr)s_requestId++;
355             }
356             s_platformInformationCallbacksMap[id] = (IntPtr platformInfoHandle, int result, IntPtr userData) =>
357             {
358                 if (platformInfoHandle != IntPtr.Zero)
359                 {
360                     int requestId = (int)userData;
361                     if (result == 0)
362                     {
363                         PlatformInformationFoundEventArgs e = GetPlatformInformationFoundEventArgs(requestId, platformInfoHandle);
364                         if (e == null)
365                         {
366                             Log.Error(IoTConnectivityErrorFactory.LogTag, "Can't get PlatformInformationFoundEventArgs");
367                             return;
368                         }
369                         PlatformInformationFound?.Invoke(null, e);
370                     }
371                     else
372                     {
373                         FindingErrorOccurredEventArgs e = GetFindingErrorOccurredEventArgs(requestId, result);
374                         FindingErrorOccurred?.Invoke(null, e);
375
376                         lock (s_platformInformationCallbacksMap)
377                         {
378                             s_platformInformationCallbacksMap.Remove(id);
379                         }
380                     }
381                 }
382             };
383
384             int errorCode = Interop.IoTConnectivity.Client.PlatformInformation.Get(hostAddress, (int)connectivityType, s_platformInformationCallbacksMap[id], id);
385             if (errorCode != (int)IoTConnectivityError.None)
386             {
387                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get platform information");
388                 lock (s_platformInformationCallbacksMap)
389                 {
390                     s_platformInformationCallbacksMap.Remove(id);
391                 }
392                 throw IoTConnectivityErrorFactory.GetException(errorCode);
393             }
394
395             return (int)id;
396         }
397
398         private static PresenceReceivedEventArgs GetPresenceReceivedEventArgs(int presenceId, IntPtr presenceResponseHandle)
399         {
400             int trigger;
401             string host, type;
402
403             int ret = Interop.IoTConnectivity.Client.PresenceResponse.GetHostAddress(presenceResponseHandle, out host);
404             if (ret != (int)IoTConnectivityError.None)
405             {
406                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get host address");
407                 return null;
408             }
409
410             ret = Interop.IoTConnectivity.Client.PresenceResponse.GetResourceType(presenceResponseHandle, out type);
411             if (ret != (int)IoTConnectivityError.None)
412             {
413                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get resource type");
414                 return null;
415             }
416
417             ret = Interop.IoTConnectivity.Client.PresenceResponse.GetTrigger(presenceResponseHandle, out trigger);
418             if (ret != (int)IoTConnectivityError.None)
419             {
420                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get event type");
421                 return null;
422             }
423
424             PresenceReceivedEventArgs e = new PresenceReceivedEventArgs()
425             {
426                 PresenceId = presenceId,
427                 HostAddress = host,
428                 Type = type,
429                 EventType = (PresenceEventType)trigger
430             };
431
432             return e;
433         }
434
435         private static DeviceInformationFoundEventArgs GetDeviceInformationFoundEventArgs(int requestId, IntPtr deviceInfoHandle)
436         {
437             string name, specVersion, deviceId, dataModelVersion;
438
439             int ret = Interop.IoTConnectivity.Client.DeviceInformation.GetProperty(deviceInfoHandle, (int)Interop.IoTConnectivity.Client.DeviceInformation.Property.Name, out name);
440             if (ret != (int)IoTConnectivityError.None)
441             {
442                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get name");
443                 return null;
444             }
445
446             ret = Interop.IoTConnectivity.Client.DeviceInformation.GetProperty(deviceInfoHandle, (int)Interop.IoTConnectivity.Client.DeviceInformation.Property.SpecVersion, out specVersion);
447             if (ret != (int)IoTConnectivityError.None)
448             {
449                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get spec version");
450                 return null;
451             }
452
453             ret = Interop.IoTConnectivity.Client.DeviceInformation.GetProperty(deviceInfoHandle, (int)Interop.IoTConnectivity.Client.DeviceInformation.Property.Id, out deviceId);
454             if (ret != (int)IoTConnectivityError.None)
455             {
456                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device id");
457                 return null;
458             }
459
460             ret = Interop.IoTConnectivity.Client.DeviceInformation.GetProperty(deviceInfoHandle, (int)Interop.IoTConnectivity.Client.DeviceInformation.Property.DataModelVersion, out dataModelVersion);
461             if (ret != (int)IoTConnectivityError.None)
462             {
463                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get data model version");
464                 return null;
465             }
466
467             DeviceInformationFoundEventArgs e = new DeviceInformationFoundEventArgs()
468             {
469                 RequestId = requestId,
470                 Name = name,
471                 SpecVersion = specVersion,
472                 DeviceId = deviceId,
473                 DataModelVersion = dataModelVersion
474             };
475
476             return e;
477         }
478
479         private static PlatformInformationFoundEventArgs GetPlatformInformationFoundEventArgs(int requestId, IntPtr platformInfoHandle)
480         {
481             string platformId, manufacturerName, manufacturerUrl, modelNumber, dateOfManufacture, platformVersion, osVersion, hardwareVersion, firmwareVersion, supportUrl, systemTime;
482
483             int ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.Id, out platformId);
484             if (ret != (int)IoTConnectivityError.None)
485             {
486                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get platform id");
487                 return null;
488             }
489
490             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.MfgName, out manufacturerName);
491             if (ret != (int)IoTConnectivityError.None)
492             {
493                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get manufacturer name");
494                 return null;
495             }
496
497             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.MfgUrl, out manufacturerUrl);
498             if (ret != (int)IoTConnectivityError.None)
499             {
500                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get manufacturer url");
501                 return null;
502             }
503
504             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.ModelNumber, out modelNumber);
505             if (ret != (int)IoTConnectivityError.None)
506             {
507                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get model number");
508                 return null;
509             }
510
511             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.DateOfMfg, out dateOfManufacture);
512             if (ret != (int)IoTConnectivityError.None)
513             {
514                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get date of manufacture");
515                 return null;
516             }
517
518             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.PlatformVer, out platformVersion);
519             if (ret != (int)IoTConnectivityError.None)
520             {
521                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get platform version");
522                 return null;
523             }
524
525             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.OsVer, out osVersion);
526             if (ret != (int)IoTConnectivityError.None)
527             {
528                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to os version");
529                 return null;
530             }
531
532             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.HardwareVer, out hardwareVersion);
533             if (ret != (int)IoTConnectivityError.None)
534             {
535                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to hardware version");
536                 return null;
537             }
538
539             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.FirmwareVer, out firmwareVersion);
540             if (ret != (int)IoTConnectivityError.None)
541             {
542                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get firmware version");
543                 return null;
544             }
545
546             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.SupportUrl, out supportUrl);
547             if (ret != (int)IoTConnectivityError.None)
548             {
549                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get support url");
550                 return null;
551             }
552
553             ret = Interop.IoTConnectivity.Client.PlatformInformation.GetProperty(platformInfoHandle, (int)Interop.IoTConnectivity.Client.PlatformInformation.Propery.SystemTime, out systemTime);
554             if (ret != (int)IoTConnectivityError.None)
555             {
556                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get system time");
557                 return null;
558             }
559
560             PlatformInformationFoundEventArgs e = new PlatformInformationFoundEventArgs()
561             {
562                 RequestId = requestId,
563                 PlatformId = platformId,
564                 ManufacturerName = manufacturerName,
565                 ManufacturerURL = manufacturerUrl,
566                 DateOfManufacture = dateOfManufacture,
567                 ModelNumber = modelNumber,
568                 PlatformVersion = platformVersion,
569                 OsVersion = osVersion,
570                 HardwareVersion = hardwareVersion,
571                 FirmwareVersion = firmwareVersion,
572                 SupportUrl = supportUrl,
573                 SystemTime = systemTime
574             };
575
576             return e;
577         }
578
579         private static FindingErrorOccurredEventArgs GetFindingErrorOccurredEventArgs(int requestId, int err)
580         {
581             FindingErrorOccurredEventArgs e = new FindingErrorOccurredEventArgs()
582             {
583                 RequestId = requestId,
584                 Error = IoTConnectivityErrorFactory.GetException(err)
585             };
586             return e;
587         }
588     }
589 }