コード例 #1
0
ファイル: Role.cs プロジェクト: vieapps/Services.Portals
        internal static async Task <JObject> SyncRoleAsync(this RequestInfo requestInfo, CancellationToken cancellationToken = default)
        {
            var data = requestInfo.GetBodyExpando();
            var role = await data.Get <string>("ID").GetRoleByIDAsync(cancellationToken).ConfigureAwait(false);

            if (role == null)
            {
                role = Role.CreateInstance(data);
                await Role.CreateAsync(role, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                role.Fill(data);
                await Role.UpdateAsync(role, true, cancellationToken).ConfigureAwait(false);
            }

            // clear related cache
            if (requestInfo.GetHeaderParameter("x-converter") != null)
            {
                role.ClearRelatedCacheAsync(null, ServiceBase.ServiceComponent.CancellationToken, requestInfo.CorrelationID).Run();
            }
            else
            {
                await role.ClearCacheAsync(cancellationToken, requestInfo.CorrelationID).ConfigureAwait(false);
            }

            // send update messages
            var json       = role.Set().ToJson();
            var objectName = role.GetTypeName(true);
            await Task.WhenAll(
                Utility.RTUService.SendUpdateMessageAsync(new UpdateMessage
            {
                Type     = $"{requestInfo.ServiceName}#{objectName}#Update",
                Data     = json,
                DeviceID = "*"
            }, cancellationToken),
                Utility.RTUService.SendInterCommunicateMessageAsync(new CommunicateMessage(requestInfo.ServiceName)
            {
                Type           = $"{objectName}#Update",
                Data           = json,
                ExcludedNodeID = Utility.NodeID
            }, cancellationToken)
                ).ConfigureAwait(false);

            // return the response
            return(new JObject
            {
                { "Sync", "Success" },
                { "ID", role.ID },
                { "Type", objectName }
            });
        }
コード例 #2
0
ファイル: Role.cs プロジェクト: vieapps/Services.Portals
 public static Role CreateRoleInstance(this ExpandoObject data, string excluded = null, Action <Role> onCompleted = null)
 => Role.CreateInstance(data, excluded?.ToHashSet(), onCompleted);