コード例 #1
0
        /// <summary>
        /// Method to execute the processor on the data element.
        /// </summary>
        /// <param name="data">Data element</param>
        /// <param name="context">Execution context</param>
        /// <param name="condition">Condition clause to check prior to processing</param>
        /// <returns>Process response</returns>
        public override ProcessResponse <T> Execute(T data, Context context, object condition)
        {
            ProcessResponse <T> response = new ProcessResponse <T>();

            response.Data  = data;
            response.State = EProcessResponse.None;
            if (!ReflectionUtils.IsNull(data))
            {
                if (!MatchCondition(data, condition))
                {
                    response.State = EProcessResponse.NotExecuted;
                    response.Data  = data;
                    return(response);
                }
                else
                {
                    return(ExecuteProcess(data, context, response));
                }
            }
            else
            {
                response.Data  = default(T);
                response.State = EProcessResponse.NullData;
            }
            return(response);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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);
 }
コード例 #5
0
 /// <summary>
 /// Execute the processor on the specified entity data.
 /// </summary>
 /// <param name="data">Entity data input</param>
 /// <param name="context">Execution context</param>
 /// <param name="response">Reponse handle</param>
 /// <returns>Response</returns>
 protected abstract ProcessResponse <List <T> > ExecuteProcess(List <T> data, Context context, ProcessResponse <List <T> > response);
コード例 #6
0
        /// <summary>
        /// Method to execute the processor on the data element.
        /// </summary>
        /// <param name="data">Data element</param>
        /// <param name="context">Execution context</param>
        /// <param name="condition">Condition clause to check prior to processing</param>
        /// <returns>Process response</returns>
        public override ProcessResponse <List <T> > Execute(List <T> data, Context context, object condition)
        {
            ProcessResponse <List <T> > response = new ProcessResponse <List <T> >();

            response.Data  = data;
            response.State = EProcessResponse.None;
            if (data != null && data.Count > 0)
            {
                List <T> included = new List <T>();
                List <T> excluded = new List <T>();
                foreach (T value in data)
                {
                    if (MatchCondition(value, condition))
                    {
                        included.Add(value);
                    }
                    else
                    {
                        excluded.Add(value);
                    }
                }
                if (included.Count > 0)
                {
                    response = ExecuteProcess(data, context, response);
                    Conditions.NotNull(response);
                    if (response.Data == null || response.Data.Count <= 0)
                    {
                        if (FilterResults)
                        {
                            response.Data  = null;
                            response.State = EProcessResponse.NullData;
                            return(response);
                        }
                        else
                        {
                            response.Data  = excluded;
                            response.State = EProcessResponse.OK;
                            return(response);
                        }
                    }
                    else
                    {
                        if (FilterResults)
                        {
                            return(response);
                        }
                        else
                        {
                            if (excluded.Count > 0)
                            {
                                foreach (T value in excluded)
                                {
                                    response.Data.Add(value);
                                }
                            }
                            return(response);
                        }
                    }
                }
                else
                {
                    response = new ProcessResponse <List <T> >();
                    if (FilterResults)
                    {
                        response.Data  = null;
                        response.State = EProcessResponse.NullData;
                        return(response);
                    }
                    else
                    {
                        response.Data  = excluded;
                        response.State = EProcessResponse.OK;
                        return(response);
                    }
                }
            }
            else
            {
                response.Data  = null;
                response.State = EProcessResponse.NullData;
            }
            return(response);
        }
コード例 #7
0
 /// <summary>
 /// Execute the processor on the specified entity data.
 /// </summary>
 /// <param name="data">Entity data input</param>
 /// <param name="context">Execution context</param>
 /// <param name="response">Reponse handle</param>
 /// <returns>Response</returns>
 protected abstract ProcessResponse <T> ExecuteProcess(T data, Context context, ProcessResponse <T> response);
コード例 #8
0
 /// <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);
 }