using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tor.Controller
{
///
/// A class containing the command used to set the value of a configuration.
///
internal sealed class SetConfCommand : Command
{
private readonly string name;
private readonly string value;
///
/// Initializes a new instance of the class.
///
/// The name of the configuration to set.
/// The value of the configuration.
public SetConfCommand(string name, string value)
{
this.name = name;
this.value = value;
}
#region Tor.Controller.Command<>
///
/// Dispatches the command to the client control port and produces a response result.
///
/// The control connection where the command should be dispatched.
///
/// A object instance containing the response data.
///
protected override Response Dispatch(Connection connection)
{
if (name == null || value == null)
return new Response(false);
if (connection.Write("setconf {0}={1}", name, value.Contains(" ") ? string.Format("\"{0}\"", value) : value))
{
ConnectionResponse response = connection.Read();
return new Response(response.Success);
}
return new Response(false);
}
#endregion
}
}