Response.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » Remote » Messages » 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 » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » Remote » Messages » Response.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace ThoughtWorks.CruiseControl.Remote.Messages{
    /// <summary>
    /// The base level message for all responses.
    /// </summary>
    [XmlRoot("response")]
    [Serializable]
    public class Response
        : CommunicationsMessage
    {
        #region Private fields
        private List<ErrorMessage> errorMessages;
        private string requestIdentifier;
        private ResponseResult result = ResponseResult.Unknown;
        #endregion

        #region Constructors
        /// <summary>
        /// Initialise a new instance of <see cref="Response"/>.
        /// </summary>
        public Response()
        {
            errorMessages = new List<ErrorMessage>();
        }

        /// <summary>
        /// Initialise a new instance of <see cref="Response"/> from a request.
        /// </summary>
        /// <param name="request">The request to use.</param>
        public Response(ServerRequest request)
            : this()
        {
            requestIdentifier = request.Identifier;
        }

        /// <summary>
        /// Initialise a new instance of <see cref="Response"/> from a response.
        /// </summary>
        /// <param name="response">The response to use.</param>
        public Response(Response response)
        {
            errorMessages = response.errorMessages;
            requestIdentifier = response.requestIdentifier;
            result = response.result;
            Timestamp = response.Timestamp;
        }
        #endregion

        #region Public properties
        #region ErrorMessage
        /// <summary>
        /// Any error messages.
        /// </summary>
        [XmlElement("error")]
        public List<ErrorMessage> ErrorMessages
        {
            get { return errorMessages; }
        }
        #endregion

        #region RequestIdentifier
        /// <summary>
        /// The identifier of the request that this response is for.
        /// </summary>
        [XmlAttribute("identifier")]
        public string RequestIdentifier
        {
            get { return requestIdentifier; }
            set { requestIdentifier = value; }
        }
        #endregion

        #region Result
        /// <summary>
        /// The outcome of the processing.
        /// </summary>
        [XmlAttribute("result")]
        public ResponseResult Result
        {
            get { return result; }
            set { result = value; }
        }
        #endregion
        #endregion

        #region Public methods
        #region Equals()
        /// <summary>
        /// Checks if this response is the same as another.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (obj is Response)
            {
                Response other = obj as Response;
                return string.Equals(other.requestIdentifier, requestIdentifier) &&
                    DateTime.Equals(other.Timestamp, Timestamp);
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region GetHashCode()
        /// <summary>
        /// Returns the hash code for this response.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return (requestIdentifier ?? string.Empty).GetHashCode() &
                Timestamp.GetHashCode();
        }
        #endregion

        #region ToString()
        /// <summary>
        /// Converts this request into a string.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            XmlSerializer serialiser = new XmlSerializer(this.GetType());
            StringBuilder builder = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = UTF8Encoding.UTF8;
            settings.Indent = false;
            settings.OmitXmlDeclaration = true;
            XmlWriter writer = XmlWriter.Create(builder, settings);
            serialiser.Serialize(writer, this);
            return builder.ToString();
        }
        #endregion

        #region ConcatenateErrors()
        /// <summary>
        /// Concatenates all the error messages into one string.
        /// </summary>
        /// <returns></returns>
        public virtual string ConcatenateErrors()
        {
            List<string> errorMessages = new List<string>();
            foreach (ErrorMessage error in ErrorMessages)
            {
                errorMessages.Add(error.Message);
            }
            return string.Join(Environment.NewLine, errorMessages.ToArray());
        }
        #endregion
        #endregion
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.