ServiceResult.cs :  » Template-Engines » netTiers » PetShop » Services » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Template Engines » netTiers 
netTiers » PetShop » Services » ServiceResult.cs

using System;
using System.ComponentModel;
using System.Collections.Generic;

using PetShop.Business;
using PetShop.Business.Validation;

namespace PetShop.Services{
  /// <summary>
  /// The class provides a notification pattern for the processor execution.
  /// </summary>
  public class ServiceResult
  {
    private Dictionary<ProcessorBase, BrokenRulesList>  processBrokenRuleLists;
        private Dictionary<ProcessorBase, Exception> exceptionList = null;
    private List<IProcessorResult> processorResultList = null;

    /// <summary>
    ///    Determines whethere the containing service, has errors.
    /// </summary>
    public virtual bool HasErrors
    {
      get
      { 
        //unhandled exception
        if (ExceptionList.Count > 0)
          return true; 
          
        //or process just failed.
        foreach (IProcessorResult processorResult in ProcessorResultList)
        {
          if (processorResult == null || !processorResult.Result)
            return true;
        }
        return false;
      }
    }
  
    /// <summary>
    ///    Provides a string of errors accumulated with a new line of delimeted errors.
    /// </summary>
    public virtual string Error
    {
      get
      {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        
        foreach (KeyValuePair<ProcessorBase, Exception> excPair in ExceptionList)
        {
          if (excPair.Value != null)
          {
            sb.Append(excPair.Value.Message.Replace("\n", ""));
            sb.Append("\n");
          }
        }
        
        for(int i = 0; i < ProcessorResultList.Count; i++)
        {
          if (processorResultList[i] == null)
            continue;
          foreach(KeyValuePair<Type, BrokenRulesList> kvp in processorResultList[i].BrokenRulesLists)
          {  
            if (kvp.Value != null && kvp.Value.Count > 0)
              sb.Append(kvp.Value.ToString());
          }
        }
        
        return sb.ToString();
      }
    }
    
    /// <summary>
    ///    Provides an aggregated group of BrokenRuleList for each of the executed processes.
    /// </summary>
    public virtual Dictionary<ProcessorBase, BrokenRulesList> ProcessBrokenRuleLists
    {
      get
      {
        if ( processBrokenRuleLists == null )
          processBrokenRuleLists = new Dictionary<ProcessorBase, BrokenRulesList>();

        return processBrokenRuleLists;
      }
    }
    
    /// <summary>
    ///    Determines whethere the containing processs results that were enlisted in the service.
    /// </summary>
    public virtual List<IProcessorResult> ProcessorResultList
    {  
      get
      {
        if (processorResultList == null)
          processorResultList = new List<IProcessorResult>();
        
        return processorResultList;
      }
    }
    
    /// <summary>
    ///  Provides the List of UnHandled Exceptions that occured during processing.
    /// </summary>
    ///<value>A list of rules that were broken in the process</value>    
    public virtual Dictionary<ProcessorBase, Exception> ExceptionList 
    {  
      get
      {
        if(exceptionList == null)
          exceptionList = new Dictionary<ProcessorBase, Exception>();
                return exceptionList;
      }
    }
  }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.