public Obj.PreservationTask GetPreservationTask(Guid idTask, bool fillRelations = true)
        {
            Obj.PreservationTask retval = null;

            try
            {
                System.Data.Objects.ObjectQuery <Model.PreservationTask> query = db.PreservationTask;
                if (fillRelations)
                {
                    query = query.Include(x => x.Archive)
                            .Include(x => x.PreservationTaskType)
                            .Include(x => x.PreservationTask1)
                            .Include(x => x.PreservationTask1.First().Archive)
                            .Include(x => x.PreservationTask1.First().PreservationTaskType);
                }
                Model.PreservationTask preservationTask = query.Where(x => x.IdPreservationTask == idTask).SingleOrDefault();

                if (preservationTask != null)
                {
                    retval = preservationTask.Convert(DEFAULT_LEVEL, DEFAULT_DEEP_LEVEL);
                }
            }
            finally
            {
                Dispose();
            }

            return(retval);
        }
        private static Model.PreservationTask CreateModelFromObj(Obj.PreservationTask obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var ret = new Model.PreservationTask
            {
                IdPreservationTask     = obj.IdPreservationTask,
                IdArchive              = (obj.Archive != null) ? obj.Archive.IdArchive : Guid.Empty,
                IdPreservationTaskType = (obj.TaskType != null) ? obj.TaskType.IdPreservationTaskType : Guid.Empty,
                EstimatedDate          = obj.EstimatedDate,
                ExecutedDate           = obj.ExecutedDate,
                StartDocumentDate      = obj.StartDocumentDate,
                EndDocumentDate        = obj.EndDocumentDate.Value.ToLocalTime().Date.AddDays(1).AddMilliseconds(-3),
                Enabled = obj.Enabled,
            };

            if (obj.CorrelatedTasks != null)
            {
                foreach (var corr in obj.CorrelatedTasks)
                {
                    ret.PreservationTask1.Add(CreateModelFromObj(corr));
                }
            }

            return(ret);
        }
Ejemplo n.º 3
0
        internal static PreservationTask Convert(this BibDSModel.PreservationTask tsk, int level = 0, int deeplevel = 5)
        {
            if (tsk == null || level > deeplevel)
            {
                return(null);
            }

            var retval = new PreservationTask
            {
                Archive            = tsk.Archive.Convert(level + 1, deeplevel),
                EndDocumentDate    = tsk.EndDocumentDate,
                EstimatedDate      = tsk.EstimatedDate,
                ExecutedDate       = tsk.ExecutedDate,
                IdPreservationTask = tsk.IdPreservationTask,
                StartDocumentDate  = tsk.StartDocumentDate,
                TaskType           = tsk.PreservationTaskType.Convert(level + 1, deeplevel),
                User            = tsk.PreservationUser.Convert(level + 1, deeplevel),
                TaskGroup       = tsk.PreservationTaskGroup.Convert(level + 1, deeplevel),
                Alerts          = tsk.PreservationAlert.Convert(level, deeplevel),
                CorrelatedTasks = new BindingList <PreservationTask>(),
                HasError        = tsk.HasError,
                ErrorMessages   = tsk.ErrorMessages,
                Executed        = tsk.Executed,
                Enabled         = tsk.Enabled,
                ActivationPin   = tsk.ActivationPin,
                IdPreservation  = tsk.IdPreservation,
                IdCorrelatedPreservationTask = tsk.IdCorrelatedPreservationTask,
                LockDate = tsk.LockDate
            };

            if (tsk.PreservationTask1 != null && tsk.PreservationTask1.Any())
            {
                retval.CorrelatedTasks = tsk.PreservationTask1.Convert(level, deeplevel);
            }

            if (tsk.PreservationTaskStatus != null)
            {
                retval.TaskStatus = (PreservationTaskStatus)Enum.Parse(typeof(PreservationTaskStatus), tsk.PreservationTaskStatus.Status);
            }

            return(retval);
        }