Showing the changes to Source/Libraries/GSF.ServiceProcess/ClientRequest.cs (1 of 628 files). Show all
Unified · Split
| @@ -0,0 +1,190 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// ClientRequest.cs - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright © 2010, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/eclipse-1.0.php | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 08/29/2006 - Pinal C. Patel | |
| 20 | +// Original version of source code generated. | |
| 21 | +// 04/27/2007 - Pinal C. Patel | |
| 22 | +// Added Attachments property for clients to send serializable objects as part of the request. | |
| 23 | +// 09/30/2008 - J. Ritchie Carroll | |
| 24 | +// Converted to C#. | |
| 25 | +// 03/09/2009 - Pinal C. Patel | |
| 26 | +// Edited code comments. | |
| 27 | +// 09/14/2009 - Stephen C. Wills | |
| 28 | +// Added new header and license agreement. | |
| 29 | +// 10/14/2010 - Pinal C. Patel | |
| 30 | +// Overrode ToString() method to provide a text representation of ClientRequest. | |
| 31 | +// Recoded static Parse() method to make it more robust. | |
| 32 | +// 01/24/201 - Pinal C. Patel | |
| 33 | +// Modified ToString() remove leading and trailing white spaces. | |
| 34 | +// 10/8/2012 - Danyelle Gilliam | |
| 35 | +// Modified Header | |
| 36 | +// | |
| 37 | +//****************************************************************************************************** | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | +using GSF.Console; | |
| 42 | +using System; | |
| 43 | +using System.Collections.Generic; | |
| 44 | + | |
| 45 | +namespace GSF.ServiceProcess | |
| 46 | +{ | |
| 47 | + /// <summary> | |
| 48 | + /// Represents a request sent by <see cref="ClientHelper"/> to <see cref="ServiceHelper"/>. | |
| 49 | + /// </summary> | |
| 50 | + /// <seealso cref="ClientHelper"/> | |
| 51 | + /// <seealso cref="ServiceHelper"/> | |
| 52 | + [Serializable()] | |
| 53 | + public class ClientRequest | |
| 54 | + { | |
| 55 | + #region [ Members ] | |
| 56 | + | |
| 57 | + // Fields | |
| 58 | + private string m_command; | |
| 59 | + private Arguments m_arguments; | |
| 60 | + private List<object> m_attachments; | |
| 61 | + | |
| 62 | + #endregion | |
| 63 | + | |
| 64 | + #region [ Constructors ] | |
| 65 | + | |
| 66 | + /// <summary> | |
| 67 | + /// Initializes a new instance of the <see cref="ClientRequest"/> class. | |
| 68 | + /// </summary> | |
| 69 | + public ClientRequest() | |
| 70 | + : this("UNDEFINED") | |
| 71 | + { | |
| 72 | + } | |
| 73 | + | |
| 74 | + /// <summary> | |
| 75 | + /// Initializes a new instance of the <see cref="ClientRequest"/> class. | |
| 76 | + /// </summary> | |
| 77 | + /// <param name="command">Command text for the <see cref="ClientRequest"/>.</param> | |
| 78 | + public ClientRequest(string command) | |
| 79 | + : this(command, new Arguments("")) | |
| 80 | + { | |
| 81 | + } | |
| 82 | + | |
| 83 | + /// <summary> | |
| 84 | + /// Initializes a new instance of the <see cref="ClientRequest"/> class. | |
| 85 | + /// </summary> | |
| 86 | + /// <param name="command">Command text for the <see cref="ClientRequest"/>.</param> | |
| 87 | + /// <param name="arguments"><see cref="Arguments"/> for the <paramref name="command"/>.</param> | |
| 88 | + public ClientRequest(string command, Arguments arguments) | |
| 89 | + { | |
| 90 | + m_command = command.ToUpper(); | |
| 91 | + m_arguments = arguments; | |
| 92 | + m_attachments = new List<object>(); | |
| 93 | + } | |
| 94 | + | |
| 95 | + #endregion | |
| 96 | + | |
| 97 | + #region [ Properties ] | |
| 98 | + | |
| 99 | + /// <summary> | |
| 100 | + /// Gets or sets the command text for the <see cref="ClientRequest"/>. | |
| 101 | + /// </summary> | |
| 102 | + /// <exception cref="ArgumentNullException">The value being assigned is either a null or empty string.</exception> | |
| 103 | + public string Command | |
| 104 | + { | |
| 105 | + get | |
| 106 | + { | |
| 107 | + return m_command; | |
| 108 | + } | |
| 109 | + set | |
| 110 | + { | |
| 111 | + if (string.IsNullOrEmpty(value)) | |
| 112 | + throw new ArgumentNullException("value"); | |
| 113 | + | |
| 114 | + m_command = value.ToUpper(); | |
| 115 | + } | |
| 116 | + } | |
| 117 | + | |
| 118 | + /// <summary> | |
| 119 | + /// Gets or sets the <see cref="Arguments"/> for the <see cref="Command"/>. | |
| 120 | + /// </summary> | |
| 121 | + public Arguments Arguments | |
| 122 | + { | |
| 123 | + get | |
| 124 | + { | |
| 125 | + return m_arguments; | |
| 126 | + } | |
| 127 | + set | |
| 128 | + { | |
| 129 | + m_arguments = value; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + /// <summary> | |
| 134 | + /// Gets a list of attachments for the <see cref="ClientRequest"/>. | |
| 135 | + /// </summary> | |
| 136 | + public List<object> Attachments | |
| 137 | + { | |
| 138 | + get | |
| 139 | + { | |
| 140 | + return m_attachments; | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + #endregion | |
| 145 | + | |
| 146 | + #region [ Methods ] | |
| 147 | + | |
| 148 | + /// <summary> | |
| 149 | + /// Returns the <see cref="String"/> that represents the <see cref="ClientRequest"/>. | |
| 150 | + /// </summary> | |
| 151 | + /// <returns>A <see cref="String"/> that represents the <see cref="ClientRequest"/>.</returns> | |
| 152 | + public override string ToString() | |
| 153 | + { | |
| 154 | + return string.Format("{0} {1}", m_command, m_arguments).Trim(); | |
| 155 | + } | |
| 156 | + | |
| 157 | + #endregion | |
| 158 | + | |
| 159 | + #region [ Static ] | |
| 160 | + | |
| 161 | + /// <summary> | |
| 162 | + /// Converts <see cref="string"/> to a <see cref="ClientRequest"/>. | |
| 163 | + /// </summary> | |
| 164 | + /// <param name="text">Text to be converted to a <see cref="ClientRequest"/>.</param> | |
| 165 | + /// <returns><see cref="ClientRequest"/> object if parsing is successful; otherwise null.</returns> | |
| 166 | + public static ClientRequest Parse(string text) | |
| 167 | + { | |
| 168 | + // Input text can't be null. | |
| 169 | + if (text == null) | |
| 170 | + return null; | |
| 171 | + | |
| 172 | + // Input text can't be empty. | |
| 173 | + text = text.Trim(); | |
| 174 | + if (text == "") | |
| 175 | + return null; | |
| 176 | + | |
| 177 | + string[] textSegments = text.Split(' '); | |
| 178 | + ClientRequest request = new ClientRequest(); | |
| 179 | + request.Command = textSegments[0].ToUpper(); | |
| 180 | + if (textSegments.Length == 1) | |
| 181 | + request.Arguments = new Arguments(""); | |
| 182 | + else | |
| 183 | + request.Arguments = new Arguments(text.Remove(0, text.IndexOf(' ') + 1).Trim()); | |
| 184 | + | |
| 185 | + return request; | |
| 186 | + } | |
| 187 | + | |
| 188 | + #endregion | |
| 189 | + } | |
| 190 | +} | |