예제 #1
0
파일: TaskHelper.cs 프로젝트: lpyqyc/swm
        public async Task <ArchivedTransportTask> ArchiveAsync(TransportTask transTask, bool cancelled, Location actualEnd)
        {
            _logger.Information("正在归档任务 {taskCode}", transTask.TaskCode);
            ArchivedTransportTask archived = new ArchivedTransportTask();

            archived.Unitload = _unitloadSnapshopHelper.GetSnapshot(transTask.Unitload);
            await _session.SaveAsync(archived.Unitload).ConfigureAwait(false);

            await _session.FlushAsync().ConfigureAwait(false);

            CopyUtil.CopyProperties(transTask, archived, new[]
            {
                nameof(ArchivedTransportTask.ArchivedAt),
                nameof(ArchivedTransportTask.Cancelled),
                nameof(ArchivedTransportTask.ActualEnd),
            });
            archived.ArchivedAt = DateTime.Now;
            archived.Cancelled  = cancelled;
            archived.ActualEnd  = actualEnd;

            await _session.DeleteAsync(transTask).ConfigureAwait(false);

            await _session.SaveAsync(archived).ConfigureAwait(false);

            _logger.Information("已归档任务 {taskCode}", transTask.TaskCode);
            return(archived);
        }
예제 #2
0
        public UnitloadSnapshot GetSnapshot(Unitload unitload)
        {
            UnitloadSnapshot snapshot = _unitloadSnapshotFactory.CreateUnitloadSnapshot();

            CopyUtil.CopyProperties(unitload, snapshot, new[]
            {
                nameof(UnitloadSnapshot.UnitloadSnapshotId),
                nameof(UnitloadSnapshot.SnapshotTime),
                nameof(UnitloadSnapshot.Items)
            });
            snapshot.SnapshotTime = DateTime.Now;

            foreach (var item in unitload.Items)
            {
                UnitloadItemSnapshot itemSnapshot = _unitloadSnapshotFactory.CreateUnitloadItemSnapshot();
                CopyUtil.CopyProperties(item, itemSnapshot, new[]
                {
                    nameof(UnitloadItemSnapshot.UnitloadItemSnapshotId),
                    nameof(UnitloadItemSnapshot.Unitload),
                });
                snapshot.AddItem(itemSnapshot);
            }
            _logger.Information("已获取 {unitload} 的快照", unitload);

            return(snapshot);
        }