ModuleAsyncHandlers.cs
2.6 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.MobileApps.MobileDevice;
namespace Sungero.MobileApps.Server
{
public class ModuleAsyncHandlers
{
/// <summary>
/// Обновляет информацию об устройстве - ОС, приложение и название.
/// </summary>
/// <param name="args">Параметры вызова асинхронного обработчика.</param>
public virtual void UpdateMobileDeviceInfoHandler(Sungero.MobileApps.Server.AsyncHandlerInvokeArgs.UpdateMobileDeviceInfoHandlerInvokeArgs args)
{
var deviceId = args.Id;
var device = MobileDevices.GetAll().FirstOrDefault(x => x.Id == args.Id);
if (device == null)
{
Logger.DebugFormat("UpdateMobileDeviceInfoHandler: mobile device with id {0} not found.", deviceId);
return;
}
if (!Locks.TryLock(device))
{
Logger.DebugFormat("UpdateMobileDeviceInfoHandler: mobile device with id {0} is locked.", deviceId);
args.Retry = true;
return;
}
device.OsVersion = args.OsVersion;
device.AppVersion = args.AppVersion;
device.DeviceName = args.DeviceName;
device.Save();
Locks.Unlock(device);
Logger.DebugFormat("UpdateMobileDeviceInfoHandler: mobile device with id {0} changed info.", deviceId);
}
/// <summary>
/// Обновляет статус устройства.
/// </summary>
/// <param name="args">Параметры вызова асинхронного обработчика.</param>
public virtual void UpdateMobileDeviceStatusHandler(Sungero.MobileApps.Server.AsyncHandlerInvokeArgs.UpdateMobileDeviceStatusHandlerInvokeArgs args)
{
var deviceId = args.Id;
var deviceIntStatus = args.IntStatus;
var device = MobileDevices.GetAll().FirstOrDefault(x => x.Id == args.Id);
if (device == null)
{
Logger.DebugFormat("UpdateMobileDeviceStatusHandler: mobile device with id {0} not found.", deviceId);
return;
}
if (!Locks.TryLock(device))
{
Logger.DebugFormat("UpdateMobileDeviceStatusHandler: mobile device with id {0} is locked.", deviceId);
args.Retry = true;
return;
}
Functions.MobileDevice.SetStatusFromCode(device, deviceIntStatus);
device.Save();
Locks.Unlock(device);
Logger.DebugFormat("UpdateMobileDeviceStatusHandler: mobile device with id {0} changed device status to {1}.", deviceId, device.DeviceStatus.ToString());
}
}
}