Esempio n. 1
0
        /// <summary>
        /// Restituisce una copia di questo oggetto.
        /// </summary>
        /// <returns>una copia di questo oggetto</returns>
        public static TaskMetadata Copy(TaskMetadata tm)
        {
            TaskMetadata copy = new TaskMetadata(null, null, null, null)
            {
                TaskPerformerClassName    = string.Copy(tm.TaskPerformerClassName),
                TaskPerformerClassVersion = string.Copy(tm.TaskPerformerClassVersion),
                PathToSourceFile          = string.Copy(tm.PathToSourceFile),
                PathToTargetFile          = string.Copy(tm.PathToTargetFile),

                State = tm.State,

                ReadyTime      = tm.ReadyTime,
                StartingTime   = tm.StartingTime,
                CompletionTime = tm.CompletionTime,

                Errors = new List <TaskErrorInfo>(tm.Errors.Count)
            };

            foreach (TaskErrorInfo error in tm.Errors)
            {
                copy.Errors.Add(TaskErrorInfo.Copy(error));
            }

            return(copy);
        }
Esempio n. 2
0
        public bool WriteError(TaskErrorInfo input, out TaskErrorInfo output)
        {
            output = input;
            TaskErrorInfo taskErrorInfo = new TaskErrorInfo();

            taskErrorInfo.SetErrorInfo(input.Exception, input.ExchangeErrorCategory.Value, input.Target, input.HelpUrl, input.TerminatePipeline, input.IsKnownError);
            this.Errors.Add(taskErrorInfo);
            return(false);
        }
        /// <summary>
        /// Gestisce l'errore dovuto al componente non trovato per l'elaborazione del task.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="className">nome completo della classe mancante</param>
        /// <param name="classVersion">versione della classe mancante</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleTaskPerformerClassError(string taskProcId, string className, string classVersion, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = string.Format("Component Not Available: class = {0}, version = {1}", className, classVersion);

            HandleError(taskProcId, errorDetails, out errorId);

            // Errore da restituire all'utente.
            error = new TaskErrorInfo()
            {
                Id = errorId, Details = errorDetails, Code = TaskErrorCode.ComponentNotFound
            };
        }
        /// <summary>
        /// Gestisce gli errori che si possono verificare durante l'apertura del file di origine contenente
        /// i dati associati al task oppure durante la creazione del file di destinazione per i risultati.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="exception">l'eccezione contenente gli eventuali dettagli dell'errore</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleInternalError(string taskProcId, Exception exception, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = exception.ToString();

            HandleError(taskProcId, errorDetails, out errorId);

            // Errore da restituire all'utente.
            error = new TaskErrorInfo()
            {
                Id      = errorId,
                Details = string.Empty,   // exception shielding
                Code    = TaskErrorCode.InternalError
            };
        }
        /// <summary>
        /// Gestisce gli errori che si possono verificare durante l'elaborazione del task.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="exception">l'eccezione contenente gli eventuali dettagli dell'errore</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleTaskPerformerError(string taskProcId, TaskPerformerException exception, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = exception.ToString();

            HandleError(taskProcId, errorDetails, out errorId);

            var inner = exception.InnerException;

            TaskErrorCode code;
            string        details;

            if (inner is TaskDataReadException)
            {
                code    = TaskErrorCode.ComponentReadDataFailed;
                details = errorDetails;
            }
            else if (inner is TaskProcessingException)
            {
                code    = TaskErrorCode.ComponentProcessingFailed;
                details = errorDetails;
            }
            else if (inner is TaskResultWriteException)
            {
                code    = TaskErrorCode.ComponentWriteResultFailed;
                details = errorDetails;
            }
            else
            {
                code    = TaskErrorCode.ComponentUnknownError;
                details = string.Empty;   // exception shielding
            }

            // Errore da restituire all'utente.
            error = new TaskErrorInfo()
            {
                Id = errorId, Details = details, Code = code
            };
        }
        /// <summary>
        /// Esegue il task identificato dai dati specificati se esso è ancora presente in elenco.
        /// </summary>
        /// <param name="id">l'identificativo di elaborazione del task da eseguire</param>
        private void ExecuteTask(object id)
        {
            string taskProcId = id as string;

            TaskMetadata tm;

            lock (m_PendingTasksLocker)
            {
                if (!m_PendingTasks.TryGetTask(taskProcId, out tm))
                {
                    return;   // task non trovato
                }

                tm.UpdateOnStarting(DateTime.Now);

                if (!m_PendingTasks.UpdateTask(taskProcId, tm))
                {
                    return;   // task non trovato
                }
            }

            WriteToLog("Starting Task (processing id = {0})...\n{1}", taskProcId, BuildTaskDescriptionString(tm));

            TaskErrorInfo error = null;

            try
            {
                TaskPerformerContext currentTaskProcessingContext;
                bool found;

                lock (m_ContextProviderLocker)
                {
                    found = m_ContextProvider.TryGetContext(tm.TaskPerformerClassName,
                                                            tm.TaskPerformerClassVersion, out currentTaskProcessingContext);
                }

                if (found)
                {
                    currentTaskProcessingContext.Execute(
                        tm.PathToSourceFile, tm.PathToTargetFile);
                }
                else
                {
                    HandleTaskPerformerClassError(taskProcId, tm.TaskPerformerClassName,
                                                  tm.TaskPerformerClassVersion, out error);
                }
            }
            catch (TaskPerformerException e)
            {
                HandleTaskPerformerError(taskProcId, e, out error);
            }
            catch (Exception e)
            {
                HandleInternalError(taskProcId, e, out error);
            }
            finally
            {
                tm.UpdateOnCompletion(DateTime.Now);
                if (error != null)
                {
                    tm.Errors.Add(error);
                }
            }

            WriteToLog("Completing Task (processing id = {0})...\n{1}", taskProcId, BuildTaskDescriptionString(tm));

            if (tm != null)
            {
                lock (m_PendingTasksLocker)
                {
                    if (!m_PendingTasks.UpdateTask(taskProcId, tm))
                    {
                        ;   // task non trovato
                    }
                }
            }
        }
        /// <summary>
        /// Gestisce gli errori che si possono verificare durante l'elaborazione del task.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="exception">l'eccezione contenente gli eventuali dettagli dell'errore</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleTaskPerformerError(string taskProcId, TaskPerformerException exception, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = exception.ToString();
            HandleError(taskProcId, errorDetails, out errorId);

            var inner = exception.InnerException;

            TaskErrorCode code;
            string details;

            if (inner is TaskDataReadException)
            {
                code = TaskErrorCode.ComponentReadDataFailed;
                details = errorDetails;
            }
            else if (inner is TaskProcessingException)
            {
                code = TaskErrorCode.ComponentProcessingFailed;
                details = errorDetails;
            }
            else if (inner is TaskResultWriteException)
            {
                code = TaskErrorCode.ComponentWriteResultFailed;
                details = errorDetails;
            }
            else
            {
                code = TaskErrorCode.ComponentUnknownError;
                details = string.Empty;   // exception shielding
            }

            // Errore da restituire all'utente.
            error = new TaskErrorInfo() { Id = errorId, Details = details, Code = code };
        }
        /// <summary>
        /// Gestisce l'errore dovuto al componente non trovato per l'elaborazione del task.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="className">nome completo della classe mancante</param>
        /// <param name="classVersion">versione della classe mancante</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleTaskPerformerClassError(string taskProcId, string className, string classVersion, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = string.Format("Component Not Available: class = {0}, version = {1}", className, classVersion);
            HandleError(taskProcId, errorDetails, out errorId);

            // Errore da restituire all'utente.
            error = new TaskErrorInfo() { Id = errorId, Details = errorDetails, Code = TaskErrorCode.ComponentNotFound };
        }
        /// <summary>
        /// Gestisce gli errori che si possono verificare durante l'apertura del file di origine contenente
        /// i dati associati al task oppure durante la creazione del file di destinazione per i risultati.
        /// </summary>
        /// <param name="taskProcId">identificativo di elaborazione del task che ha provocato l'errore</param>
        /// <param name="exception">l'eccezione contenente gli eventuali dettagli dell'errore</param>
        /// <param name="error">l'errore da restituire all'utente</param>
        private void HandleInternalError(string taskProcId, Exception exception, out TaskErrorInfo error)
        {
            string errorId;
            string errorDetails = exception.ToString();
            HandleError(taskProcId, errorDetails, out errorId);

            // Errore da restituire all'utente.
            error = new TaskErrorInfo()
            {
                Id = errorId,
                Details = string.Empty,   // exception shielding
                Code = TaskErrorCode.InternalError
            };
        }