Skip to content

Commit

Permalink
#17 Fixed DeployServerSnapshot method of QueryRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
Scordo committed Sep 21, 2017
1 parent 1c897d0 commit 0fe8f72
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions TS3QueryLib.Core.Silverlight/CommandHandling/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public Command(string commandName, params string[] options)

#region Public Methods

public void AddRaw(string rawText)
{
ParameterGroups.AddRaw(rawText);
}

public void AddParameter(string parameterName)
{
ParameterGroups.AddParameter(parameterName, null, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class CommandParameter
public string EncodedName { get { return Ts3Util.EncodeString(Name); } }
public string Value { get; set; }
public string EncodedValue { get { return Ts3Util.EncodeString(Value); } }
public bool EncodeNameWhenValueIsNull { get; set; }

#endregion

Expand All @@ -21,13 +22,14 @@ public CommandParameter(string name) : this(name, null)

}

public CommandParameter(string name, string value)
public CommandParameter(string name, string value, bool encodeNameWhenValueIsNull = true)
{
if (name.IsNullOrTrimmedEmpty())
throw new ArgumentException("name is null or trimmed empty", "name");

Name = name.Trim();
Value = value == null? null : value.Trim();
EncodeNameWhenValueIsNull = encodeNameWhenValueIsNull;
}

#endregion
Expand All @@ -36,7 +38,7 @@ public CommandParameter(string name, string value)

public override string ToString()
{
return Value == null ? EncodedName : string.Format("{0}={1}", Name, EncodedValue);
return Value == null ? (EncodeNameWhenValueIsNull ? EncodedName : Name) : string.Format("{0}={1}", Name, EncodedValue);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public CommandParameterGroupList(int capacity): base(capacity)

#region Public Methods

public void AddRaw(string rawText)
{
AddParameter(rawText, null, 0, false);
}

public void AddParameter(string name)
{
AddParameter(name, null);
Expand All @@ -39,17 +44,17 @@ public void AddParameter(string name, string value)
AddParameter(name, value, null);
}

public void AddParameter(string name, string value, uint? groupIndex)
public void AddParameter(string name, string value, uint? groupIndex, bool encodeNameWhenValueIsNull = true)
{
groupIndex = groupIndex ?? 0;

if (groupIndex > Count)
throw new ArgumentOutOfRangeException(string.Format("Can not add parameter '{0}' with value '{1}' to group with index '{2}', because the index is '{3}' too big.", name, value, groupIndex, Count-groupIndex));

if (groupIndex == Count)
Add(new CommandParameterGroup{new CommandParameter(name, value)});
Add(new CommandParameterGroup{new CommandParameter(name, value, encodeNameWhenValueIsNull) });
else
this[(int) groupIndex].Add(new CommandParameter(name, value));
this[(int) groupIndex].Add(new CommandParameter(name, value, encodeNameWhenValueIsNull));
}

public CommandParameter GetParameter(string name)
Expand Down
2 changes: 1 addition & 1 deletion TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ public SimpleResponse DeployServerSnapshot(string snapshotData)
throw new ArgumentException("snapshotData is null or trimmed empty", "snapshotData");

Command command = CommandName.ServerSnapshotDeploy.CreateCommand();
command.AddParameter(snapshotData);
command.AddRaw(snapshotData);

return ResponseBase<SimpleResponse>.Parse(SendCommand(command));
}
Expand Down

0 comments on commit 0fe8f72

Please sign in to comment.