Exemplo n.º 1
0
        private void ProcessStatusRequest(string commandParam, out int responseCode, out byte[] responseBytes, out bool responseCompressed)
        {
            string status;

            if (string.IsNullOrEmpty(commandParam))
            {
                responseBytes      = encoding.GetBytes(_node.GetComponentsDescription());
                responseCompressed = false;
                responseCode       = 400;
                return;
            }

            ComponentRuntimeInfo componentStatus = _node.GetComponentRuntimeInfo(commandParam);

            if (componentStatus != null)
            {
                status = componentStatus.GetRuntimeInfoAsString() ?? String.Empty;
            }
            else
            {
                status = String.Format("No status found for component '{0}'", commandParam);
            }


            responseBytes = encoding.GetBytes(status);

            if (responseBytes.Length > compressionThreshold)
            {
                responseBytes      = compressor.Compress(responseBytes, true, MySpace.Common.IO.CompressionImplementation.ManagedZLib);
                responseCompressed = true;
            }
            else
            {
                responseCompressed = false;
            }

            responseCode = 200;
        }
		/// <summary>
		/// Writes the given <see cref="ComponentRuntimeInfo"/> list to a <see cref="Stream"/>.
		/// </summary>
		/// <param name="runtimeInfo">The given <see cref="ComponentRuntimeInfo"/>.</param>
		/// <returns>Returns a <see cref="Stream"/> containing the <see cref="ComponentRuntimeInfo"/> list.</returns>
		public static Stream WriteRuntimeInfo(ComponentRuntimeInfo[] runtimeInfo)
		{
			MemoryStream stream = new MemoryStream();
			BinaryFormatter bf = new BinaryFormatter();
			bf.Serialize(stream, runtimeInfo);
			stream.Seek(0, SeekOrigin.Begin);
			return stream;
		}