//****************************************************************************************************** // ServiceResponse.cs - Gbtc // // Copyright © 2012, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 08/29/2006 - Pinal C. Patel // Generated original version of source code. // 09/30/2008 - J. Ritchie Carroll // Converted to C#. // 03/09/2009 - Pinal C. Patel // Edited code comments. // 09/14/2009 - Stephen C. Wills // Added new header and license agreement. // 12/20/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Security; namespace GSF.ServiceProcess { /// /// Represents a response sent by the to a from the . /// /// /// /// [Serializable] public class ServiceResponse : ISerializable { #region [ Members ] // Fields private string m_type; private string m_message; private readonly List m_attachments; #endregion #region [ Constructors ] /// /// Creates a new from serialization parameters. /// /// The with populated with data. /// The source for this deserialization. protected ServiceResponse(SerializationInfo info, StreamingContext context) { // Deserialize client request fields m_type = info.GetOrDefault("type", ""); m_message = info.GetOrDefault("message", ""); m_attachments = new List(); int attachmentCount = info.GetOrDefault("attachmentCount", 0); for (int i = 0; i < attachmentCount; i++) { m_attachments.Add(info.GetOrDefault("attachment" + i, null as object)); } } /// /// Initializes a new instance of the class. /// public ServiceResponse() : this("UNDETERMINED") { } /// /// Initializes a new instance of the class. /// /// Type of the in plain text. public ServiceResponse(string type) : this(type, "") { } /// /// Initializes a new instance of the class. /// /// Type of the in plain-text. /// Message associated with the . public ServiceResponse(string type, string message) { m_type = type.ToUpper(); m_message = message; m_attachments = new List(); } #endregion #region [ Properties ] /// /// Gets or sets the plain-text type of the . /// /// The value being assigned is either a null or empty string. public string Type { get { return m_type; } set { if (string.IsNullOrEmpty(value)) throw new ArgumentNullException("value"); m_type = value.ToUpper(); } } /// /// Gets or sets the plain-text message associated with the . /// public string Message { get { return m_message; } set { m_message = value; } } /// /// Gets a list of serializable attachments of the . /// public List Attachments { get { return m_attachments; } } #endregion #region [ Methods ] /// /// Populates a with the data needed to serialize the target object. /// /// The to populate with data. /// The destination (see ) for this serialization. /// The caller does not have the required permission. public void GetObjectData(SerializationInfo info, StreamingContext context) { // Serialize client request fields info.AddValue("type", m_type); info.AddValue("message", m_message); info.AddValue("attachmentCount", m_attachments.Count); for (int i = 0; i < m_attachments.Count; i++) { info.AddValue("attachment" + i, m_attachments[i]); } } #endregion } }