From 0fe8f726c126ad8eb1e34bf0dc9929e878601f33 Mon Sep 17 00:00:00 2001 From: Scordo Date: Thu, 21 Sep 2017 22:10:17 +0200 Subject: [PATCH] #17 Fixed DeployServerSnapshot method of QueryRunner --- .../CommandHandling/Command.cs | 5 +++++ .../CommandHandling/CommandParameter.cs | 6 ++++-- .../CommandHandling/CommandParameterGroupList.cs | 11 ++++++++--- TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/TS3QueryLib.Core.Silverlight/CommandHandling/Command.cs b/TS3QueryLib.Core.Silverlight/CommandHandling/Command.cs index b2afacd..e168608 100644 --- a/TS3QueryLib.Core.Silverlight/CommandHandling/Command.cs +++ b/TS3QueryLib.Core.Silverlight/CommandHandling/Command.cs @@ -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); diff --git a/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameter.cs b/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameter.cs index b1d7322..d8aaf57 100644 --- a/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameter.cs +++ b/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameter.cs @@ -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 @@ -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 @@ -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 diff --git a/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameterGroupList.cs b/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameterGroupList.cs index 2623252..c6c16b1 100644 --- a/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameterGroupList.cs +++ b/TS3QueryLib.Core.Silverlight/CommandHandling/CommandParameterGroupList.cs @@ -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); @@ -39,7 +44,7 @@ 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; @@ -47,9 +52,9 @@ public void AddParameter(string name, string value, uint? groupIndex) 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) diff --git a/TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs b/TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs index fc79835..12acf56 100644 --- a/TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs +++ b/TS3QueryLib.Core.Silverlight/Server/QueryRunner.cs @@ -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.Parse(SendCommand(command)); }