Exemplo n.º 1
0
        public void Load(string mapJson, bool import = false, bool clearEvents = true)
        {
            lock (MapLock)
            {
                var up    = Up;
                var down  = Down;
                var left  = Left;
                var right = Right;
                base.Load(mapJson);
                if (import)
                {
                    Up    = up;
                    Down  = down;
                    Left  = left;
                    Right = right;
                }

                Autotiles = new MapAutotiles(this);

                //Initialize Local Events
                if (clearEvents)
                {
                    LocalEvents.Clear();
                    foreach (var id in EventIds)
                    {
                        var evt = EventBase.Get(id);
                        LocalEvents.Add(id, evt);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void LoadInternal(MapSaveState state, bool import = false)
 {
     LocalEvents.Clear();
     LocalEventsJson = state.EventData;
     Load(state.Metadata, import, false);
     LoadTileData(state.Tiles);
     AttributeData = state.Attributes;
 }
Exemplo n.º 3
0
    public virtual async Task CompleteAsync(CancellationToken cancellationToken = default)
    {
        // 是否已经进行了回滚操作,如果进行了回滚操作,则不提交工作单元
        if (_isRolledback)
        {
            return;
        }

        // 防止多次调用 Complete 方法,原理就是看 _isCompleting 或者 IsCompleted 是不是已经为 True 了
        PreventMultipleComplete();

        try
        {
            _isCompleting = true;
            await SaveChangesAsync(cancellationToken);

            while (LocalEvents.Any() || DistributedEvents.Any())
            {
                // 发布本地事件
                if (LocalEvents.Any())
                {
                    var localEventsToBePublished = LocalEvents.OrderBy(e => e.EventOrder).ToArray();
                    LocalEvents.Clear();
                    await UnitOfWorkEventPublisher.PublishLocalEventsAsync(localEventsToBePublished);
                }

                // 发布分布式事件
                if (DistributedEvents.Any())
                {
                    var distributedEventsToBePublished = DistributedEvents.OrderBy(e => e.EventOrder).ToArray();
                    DistributedEvents.Clear();
                    await UnitOfWorkEventPublisher.PublishDistributedEventsAsync(distributedEventsToBePublished);
                }

                await SaveChangesAsync(cancellationToken);
            }

            await CommitTransactionsAsync();

            IsCompleted = true;

            // 数据储存了,事务提交了,则说明工作单元已经完成了,遍历完成事件集合,依次调用这些方法
            await OnCompletedAsync();
        }
        catch (Exception ex)
        {
            // 一旦在持久化或者是提交事务时出现了异常,则往上层抛出
            _exception = ex;
            throw;
        }
    }
Exemplo n.º 4
0
        public virtual async Task CompleteAsync(CancellationToken cancellationToken = default)
        {
            if (_isRolledback)
            {
                return;
            }

            PreventMultipleComplete();

            try
            {
                _isCompleting = true;
                await SaveChangesAsync(cancellationToken);

                while (LocalEvents.Any() || DistributedEvents.Any())
                {
                    if (LocalEvents.Any())
                    {
                        var localEventsToBePublished = LocalEvents.OrderBy(e => e.EventOrder).ToArray();
                        LocalEvents.Clear();
                        await UnitOfWorkEventPublisher.PublishLocalEventsAsync(
                            localEventsToBePublished
                            );
                    }

                    if (DistributedEvents.Any())
                    {
                        var distributedEventsToBePublished = DistributedEvents.OrderBy(e => e.EventOrder).ToArray();
                        DistributedEvents.Clear();
                        await UnitOfWorkEventPublisher.PublishDistributedEventsAsync(
                            distributedEventsToBePublished
                            );
                    }

                    await SaveChangesAsync(cancellationToken);
                }

                await CommitTransactionsAsync();

                IsCompleted = true;
                await OnCompletedAsync();
            }
            catch (Exception ex)
            {
                _exception = ex;
                throw;
            }
        }
Exemplo n.º 5
0
 public WebShellFolderServer()
 {
     _menuIconBitmapPath = new Lazy <string>(() => GetMenuIconBitmapPath(), true);
     _serverEvents       = new ServerEvents(this);
     LocalEvents         = new LocalEvents(this);
 }