Skip to content

Commit

Permalink
Use Common.Command class in InnerServer too
Browse files Browse the repository at this point in the history
  • Loading branch information
skyline-gleb committed Mar 4, 2015
1 parent 3e0e7ad commit f5568ca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,34 @@

public class Command
{
#region Fields

private IDictionary<string, JToken> commandParameters = new JObject();

#endregion

#region Constructors and Destructors

public Command(string name, IDictionary<string, JToken> parameters)
{
this.Name = name;
this.Parameters = parameters;
if (parameters != null)
{
this.Parameters = parameters;
}
}

public Command(string name, string jsonParameters)
: this(name, JObject.Parse(jsonParameters))
: this(name, string.IsNullOrEmpty(jsonParameters) ? null : JObject.Parse(jsonParameters))
{
}

public Command(string name)
: this(name, new JObject())
{
this.Name = name;
}

public Command()
{
}

Expand All @@ -43,7 +56,18 @@ public Command(string name)
/// Gets the parameters of the command
/// </summary>
[JsonProperty("parameters")]
public IDictionary<string, JToken> Parameters { get; set; }
public IDictionary<string, JToken> Parameters
{
get
{
return this.commandParameters;
}

set
{
this.commandParameters = value;
}
}

/// <summary>
/// Gets the SessionID of the command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,4 @@ public JsonResponse(string sessionId, ResponseStatus responseCode, object value)

#endregion
}

public class JsonCommand
{
#region Public Properties

/// <summary>
/// Gets the command name
///
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

/// <summary>
/// Gets the parameters of the command
///
/// </summary>
[JsonProperty("parameters")]
public Dictionary<string, object> Parameters { get; set; }

/// <summary>
/// Gets the SessionID of the command
///
/// </summary>
[JsonProperty("sessionId")]
public string SessionId { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Automator(UIElement visualRoot)

public string ProcessCommand(string content)
{
var requestData = JsonConvert.DeserializeObject<JsonCommand>(content);
var requestData = JsonConvert.DeserializeObject<Command>(content);
var command = requestData.Name;
var parameters = requestData.Parameters;

Expand All @@ -50,7 +50,7 @@ public string ProcessCommand(string content)
throw new NullReferenceException("Parameters can not be NULL");
}

object elementIdObject;
JToken elementIdObject;
if (parameters.TryGetValue("ID", out elementIdObject))
{
elementId = elementIdObject.ToString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
namespace WindowsUniversalAppDriver.InnerServer.Commands
{
#region

using System;
using System.Collections.Generic;
using System.Threading;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using Windows.UI.Core;
using Windows.UI.Xaml;

using Newtonsoft.Json;

using WindowsUniversalAppDriver.Common;
using WindowsUniversalAppDriver.Common.Exceptions;
using WindowsUniversalAppDriver.InnerServer;

#endregion

internal class CommandBase
{
#region Public Properties

public Automator Automator { get; set; }

public Dictionary<string, object> Parameters { get; set; }
public IDictionary<string, JToken> Parameters { get; set; }

public string Session { get; set; }

Expand All @@ -33,7 +37,7 @@ public static void BeginInvokeSync(UIElement root, Action action)
var waitEvent = new AutoResetEvent(false);

root.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
CoreDispatcherPriority.Normal,
() =>
{
try
Expand Down Expand Up @@ -65,7 +69,7 @@ public string Do()
var response = string.Empty;
try
{
BeginInvokeSync(Automator.VisualRoot, () => { response = this.DoImpl(); });
BeginInvokeSync(this.Automator.VisualRoot, () => { response = this.DoImpl(); });
}
catch (AutomationException exception)
{
Expand All @@ -87,6 +91,9 @@ public virtual string DoImpl()
/// <summary>
/// The JsonResponse with SUCCESS status and NULL value.
/// </summary>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public string JsonResponse()
{
return JsonConvert.SerializeObject(new JsonResponse(this.Session, ResponseStatus.Success, null));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
namespace WindowsUniversalAppDriver.InnerServer.Commands
{
#region

using System;
using System.Reflection;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

using WindowsUniversalAppDriver.Common;
using WindowsUniversalAppDriver.Common.Exceptions;
using WindowsUniversalAppDriver.InnerServer.Commands.Helpers;

#endregion

internal class GetElementAttributeCommand : CommandBase
{
#region Public Properties
Expand All @@ -23,7 +28,7 @@ public override string DoImpl()
{
var element = this.Automator.WebElements.GetRegisteredElement(this.ElementId);

object value;
JToken value;
string attributeName = null;
if (this.Parameters.TryGetValue("NAME", out value))
{
Expand Down

0 comments on commit f5568ca

Please sign in to comment.