ArchiveSettingServerFunctions.cs
2.66 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Container.ArchiveSetting;
using Newtonsoft.Json.Linq;
using Sungero.Domain.SessionExtensions;
using Sungero.Domain.Shared;
using Sungero.Metadata;
namespace DirRX.Container.Server
{
partial class ArchiveSettingFunctions
{
/// <summary>
/// Получить настройки долговременного архива.
/// </summary>
/// <returns>Настройки.</returns>
[Public]
public static IArchiveSetting GetSettings()
{
return ArchiveSettings.GetAllCached().SingleOrDefault();
}
/// <summary>
/// Получить данные записи справочника для синхронизации в ДА.
/// </summary>
/// <param name="entity">Запись синхронизируемого справочника.</param>
/// <returns>Данные для синхронизации, строка в формате json.</returns>
[Public]
public virtual string GetSyncData(Sungero.Domain.Shared.IEntity entity)
{
var syncEntity = _obj.SyncEntities.Where(x => x.Type.ToLower() == entity.Info.Name.ToLower()).FirstOrDefault();
if (syncEntity != null)
{
var json = new JObject();
if (!string.IsNullOrWhiteSpace(_obj.Name))
json.Add("SystemName", _obj.Name);
json.Add("SystemUid", _obj.SourceUid);
json.Add("SourceName", syncEntity.Name);
json.Add("SourceType", syncEntity.Type);
json.Add("ArchiveName", syncEntity.LTAName);
json.Add("ArchiveType", syncEntity.LTAType);
if (!string.IsNullOrEmpty(syncEntity.LTAProperties))
{
var jsonProperties = new JArray();
foreach (var propertyName in syncEntity.LTAProperties.Split(','))
{
var property = entity.GetType().GetProperties().Where(p => p.Name == (propertyName == "_sourceId" ? "Id" : propertyName)).LastOrDefault();
if (property != null)
{
object propertyValue = property.GetValue(entity);
var propertyStringValue = Sungero.Commons.PublicFunctions.Module.GetValueAsString(propertyValue);
{
var jsonProp = new JObject();
jsonProp.Add("Name", propertyName);
jsonProp.Add("Value", propertyStringValue);
jsonProperties.Add(jsonProp);
}
}
}
json.Add("Properties", jsonProperties);
}
return json.ToString();
}
return string.Empty;
}
}
}