//****************************************************************************************************** // ClientRequest.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 Eclipse Public License -v 1.0 (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/eclipse-1.0.php // // 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 // Original version of source code generated. // 04/27/2007 - Pinal C. Patel // Added Attachments property for clients to send serializable objects as part of the request. // 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. // 10/14/2010 - Pinal C. Patel // Overrode ToString() method to provide a text representation of ClientRequest. // Recoded static Parse() method to make it more robust. // 01/24/201 - Pinal C. Patel // Modified ToString() remove leading and trailing white spaces. // 12/20/2012 - Starlynn Danyelle Gilliam // Modified Header. // //****************************************************************************************************** using System; using System.Collections.Generic; using GSF.Console; namespace GSF.ServiceProcess { /// /// Represents a request sent by to . /// /// /// [Serializable] public class ClientRequest { #region [ Members ] // Fields private string m_command; private Arguments m_arguments; private readonly List m_attachments; #endregion #region [ Constructors ] /// /// Initializes a new instance of the class. /// public ClientRequest() : this("UNDEFINED") { } /// /// Initializes a new instance of the class. /// /// Command text for the . public ClientRequest(string command) : this(command, new Arguments("")) { } /// /// Initializes a new instance of the class. /// /// Command text for the . /// for the . public ClientRequest(string command, Arguments arguments) { m_command = command.ToUpper(); m_arguments = arguments; m_attachments = new List(); } #endregion #region [ Properties ] /// /// Gets or sets the command text for the . /// /// The value being assigned is either a null or empty string. public string Command { get { return m_command; } set { if (string.IsNullOrEmpty(value)) throw new ArgumentNullException("value"); m_command = value.ToUpper(); } } /// /// Gets or sets the for the . /// public Arguments Arguments { get { return m_arguments; } set { m_arguments = value; } } /// /// Gets a list of attachments for the . /// public List Attachments { get { return m_attachments; } } #endregion #region [ Methods ] /// /// Returns the that represents the . /// /// A that represents the . public override string ToString() { return string.Format("{0} {1}", m_command, m_arguments).Trim(); } #endregion #region [ Static ] /// /// Converts to a . /// /// Text to be converted to a . /// object if parsing is successful; otherwise null. public static ClientRequest Parse(string text) { // Input text can't be null. if ((object)text == null) return null; // Input text can't be empty. text = text.Trim(); if (text == "") return null; string[] textSegments = text.Split(' '); ClientRequest request = new ClientRequest(); request.Command = textSegments[0].ToUpper(); if (textSegments.Length == 1) request.Arguments = new Arguments(""); else request.Arguments = new Arguments(text.Remove(0, text.IndexOf(' ') + 1).Trim()); return request; } #endregion } }