public List <E> Update(List <E> data) { Contract.Requires(sink != null); Contract.Requires(!ReflectionUtils.IsNull(data)); ProcessResponse <List <E> > response = Execute(data, context, null); Conditions.NotNull(response); if (!ReflectionUtils.IsNull(response.Data)) { if (response.State == EProcessResponse.OK || response.State == EProcessResponse.StopWithOk) { return(sink.Update(response.Data)); } else { if (response.State == EProcessResponse.FatalError) { string mesg = String.Format("Error fetching entity : [type={0}]", typeof(E).FullName); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } else if (response.State == EProcessResponse.ContinueWithError || response.State == EProcessResponse.StopWithError) { Exception ex = response.GetError(); if (ex != null) { LogUtils.Error(ex); } return(sink.Update(response.Data)); } else { string mesg = String.Format("Unhandled State : [type={0}]", typeof(E).FullName); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } } } return(null); }
public List <E> Fetch(string condition) { Contract.Requires(source != null); List <E> data = source.Search(condition); if (data != null && data.Count > 0) { ProcessResponse <List <E> > response = Execute(data, context, null); Conditions.NotNull(response); if (response.State == EProcessResponse.OK || response.State == EProcessResponse.StopWithOk) { return(response.Data); } else { if (response.State == EProcessResponse.FatalError) { string mesg = String.Format("Error fetching entity : [type={0}][key={1}]", typeof(E).FullName, condition); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } else if (response.State == EProcessResponse.ContinueWithError || response.State == EProcessResponse.StopWithError) { Exception ex = response.GetError(); if (ex != null) { LogUtils.Error(ex); } return(response.Data); } else { string mesg = String.Format("Unhandled State : [type={0}][key={1}]", typeof(E).FullName, condition); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } } } return(null); }
private E ProcessData(E data) { if (data != null) { ProcessResponse <E> response = Execute(data, context, null); Conditions.NotNull(response); if (response.State == EProcessResponse.OK || response.State == EProcessResponse.StopWithOk) { return(response.Data); } else { if (response.State == EProcessResponse.FatalError) { string mesg = String.Format("Error fetching entity : [type={0}]", typeof(E).FullName); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } else if (response.State == EProcessResponse.ContinueWithError || response.State == EProcessResponse.StopWithError) { Exception ex = response.GetError(); if (ex != null) { LogUtils.Error(ex); } return(response.Data); } else { string mesg = String.Format("Unhandled State : [type={0}]", typeof(E).FullName); Exception ex = response.GetError(); if (ex != null) { throw new DataException(mesg, ex); } else { throw new DataException(mesg); } } } } return(null); }
/// <summary> /// Process method implemented to call the processors defined for this pipeline. /// </summary> /// <param name="data">Entity data input</param> /// <param name="context">Execution context</param> /// <param name="response">Reponse handle</param> /// <returns>Response</returns> protected override ProcessResponse <List <T> > ExecuteProcess(List <T> data, Context context, ProcessResponse <List <T> > response) { LogUtils.Debug("Running Process Pipeline:", data); if (processors.Count > 0) { try { foreach (Processor <List <T> > processor in processors) { Func <T, bool> func = null; if (conditions.ContainsKey(processor.Name)) { func = conditions[processor.Name]; } response = processor.Execute(response.Data, context, func); Conditions.NotNull(response); if (response.Data == null || response.Data.Count <= 0) { response.State = EProcessResponse.NullData; break; } if (response.State == EProcessResponse.FatalError) { Exception ex = response.GetError(); if (ex == null) { ex = new ProcessException("Processor raised error."); } throw new ProcessException(ex); } else if (response.State == EProcessResponse.ContinueWithError) { Exception ex = response.GetError(); if (ex != null) { LogUtils.Error(String.Format("Continuing with error: [type={0}]", processor.GetType().FullName)); LogUtils.Error(ex); } else { LogUtils.Error(String.Format("Continuing with error: [type={0}]", processor.GetType().FullName)); } } else if (response.State == EProcessResponse.StopWithOk) { LogUtils.Warn(String.Format("Terminating further processing: [type={0}][reponse={1}]", processor.GetType().FullName, response.State.ToString())); break; } else if (response.State == EProcessResponse.StopWithError) { Exception ex = response.GetError(); if (ex != null) { LogUtils.Error(String.Format("Stopping with error: [type={0}]", processor.GetType().FullName)); LogUtils.Error(ex); } else { LogUtils.Error(String.Format("Stopping with error: [type={0}]", processor.GetType().FullName)); } break; } } } catch (Exception e) { LogUtils.Error(e); response.SetError(EProcessResponse.FatalError, e); if (e.GetType() == typeof(ProcessUnhandledException)) { response.State = EProcessResponse.UnhandledError; } } } if (ReflectionUtils.IsNull(data)) { if (response.State != EProcessResponse.FatalError) { response.State = EProcessResponse.NullData; } } else { if (response.State != EProcessResponse.FatalError) { response.State = EProcessResponse.OK; } } return(response); }