Skip to content

Commit

Permalink
All ObjectPath elements displayed in action tree #36. Partially rewri…
Browse files Browse the repository at this point in the history
…tten parsing #22. API prepared for merged actions #34.
  • Loading branch information
dstarkowski committed Aug 1, 2016
1 parent 86da95d commit 64ce01a
Show file tree
Hide file tree
Showing 24 changed files with 368 additions and 415 deletions.
95 changes: 0 additions & 95 deletions CsomInspector/CsomInspector.Core/Actions/Action.cs

This file was deleted.

77 changes: 77 additions & 0 deletions CsomInspector/CsomInspector.Core/Actions/ActionBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Xml.Linq;

namespace CsomInspector.Core.Actions
{
public abstract class ActionBase : IObjectTreeNode, INotifyPropertyChanged
{
protected ActionBase()
{
MergedActions = new List<ActionBase>();
}

protected const String _elementNamespace = "http://schemas.microsoft.com/sharepoint/clientquery/2009";

public event PropertyChangedEventHandler PropertyChanged;

public virtual IEnumerable<IObjectTreeNode> Children => Enumerable.Empty<IObjectTreeNode>();

public Int32 Id { get; protected set; }

public Boolean IsHighlighted { get; private set; }

public Int32 ObjectPathId { get; protected set; }

public List<ActionBase> MergedActions { get; }
public List<Result> Results { get; internal set; }

public static ActionBase FromXml(XElement actionElement)
{
if (actionElement == null)
{
throw new ArgumentNullException(nameof(actionElement));
}

var name = actionElement.Name;
if (actionElement.Name.NamespaceName != _elementNamespace)
{
throw new ArgumentException("Specified element does not match CSOM request namespace.", nameof(actionElement));
}

var idAttribute = actionElement.Attribute(XName.Get("Id"));
var objectPathAttribute = actionElement.Attribute(XName.Get("ObjectPathId"));

var action = CreateAction(actionElement);
action.Id = Convert.ToInt32(idAttribute.Value);
action.ObjectPathId = Convert.ToInt32(objectPathAttribute.Value);

return action;
}

public void Highlight(Boolean isHighlighted)
{
IsHighlighted = isHighlighted;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsHighlighted)));
}

private static ActionBase CreateAction(XElement element)
{
var name = element.Name.LocalName;

switch (name)
{
case "Query":
return QueryAction.FromXml(element);
case "Method":
return MethodAction.FromXml(element);
case "SetProperty":
return SetPropertyAction.FromXml(element);
default:
return GenericAction.FromXml(element);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CsomInspector.Core.Actions
{
public class ChildItemQuery
{
}
namespace CsomInspector.Core.Actions
{
public class ChildItemQueryAction
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace CsomInspector.Core.Actions
{
public class ExceptionHandlingScope : Action
public class ExceptionHandlingScope : ActionBase
{
protected ExceptionHandlingScope() : base("ExceptionHandlingScope")
protected ExceptionHandlingScope()
{
}

Expand All @@ -15,7 +15,7 @@ protected ExceptionHandlingScope() : base("ExceptionHandlingScope")
};

public static ExceptionHandlingScope FromXml() =>
new ExceptionHandlingScope();
new ExceptionHandlingScope();

public override String ToString() => "ExceptionHandlingScope";
}
Expand Down
18 changes: 11 additions & 7 deletions CsomInspector/CsomInspector.Core/Actions/GenericAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@

namespace CsomInspector.Core.Actions
{
public class GenericAction : Action
public class GenericAction : ActionBase
{
private GenericAction(String name, IEnumerable<IObjectTreeNode> attributes, IEnumerable<IObjectTreeNode> elements) : base(name)
private String _name;

private GenericAction(String name, IEnumerable<IObjectTreeNode> attributes, IEnumerable<IObjectTreeNode> elements)
{
_name = name;

Children = attributes
.Concat(elements)
.ToList();
}

public override IEnumerable<IObjectTreeNode> Children { get; }

public override String ToString() => $"{Name} (?)";
public override String ToString() => $"{_name} (?)";

internal static GenericAction FromXml(XElement actionElement)
internal static new GenericAction FromXml(XElement actionElement)
{
var name = actionElement.Name.LocalName;

Expand All @@ -37,11 +41,11 @@ internal static GenericAction FromXml(XElement actionElement)
}

var value = actionElement.Value;

if (!String.IsNullOrWhiteSpace(value))
{
var valueNode = new[] {
new ObjectTreeNode($"Value = {value}", Enumerable.Empty<IObjectTreeNode>())
};
var valueNode = new[] { new ObjectTreeNode($"Value = {value}", Enumerable.Empty<IObjectTreeNode>()) };

return new GenericAction(name, attributes, valueNode);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
using System;
using System.Collections.Generic;
using System.Xml.Linq;

using System.Xml.Linq;

namespace CsomInspector.Core.Actions
{
public class Method : Action
{
private Method(ObjectPaths.Method method)
: base("Method")
{
_method = method;
}

private ObjectPaths.Method _method;

public override IEnumerable<IObjectTreeNode> Children => _method.Children;

public override String ToString() => _method.ToString();

internal static Method FromXml(XElement actionElement)
{
var nameAttribute = actionElement.Attribute(XName.Get("Name"));
var parametersElement = actionElement.Element(XName.Get("Parameters"));
var method = ObjectPaths.Method.FromXml(actionElement);

return new Method(method);
}
{
public class MethodAction : ActionBase
{
private MethodAction(ObjectPaths.Method method)
{
_method = method;
}

private ObjectPaths.Method _method;

public override IEnumerable<IObjectTreeNode> Children => _method.Children;

public override String ToString() => _method.ToString();

internal static new MethodAction FromXml(XElement actionElement)
{
var nameAttribute = actionElement.Attribute(XName.Get("Name"));
var parametersElement = actionElement.Element(XName.Get("Parameters"));
var method = ObjectPaths.Method.FromXml(actionElement);

return new MethodAction(method);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace CsomInspector.Core.Actions
{
public class ObjectIdentityQuery
{
}
namespace CsomInspector.Core.Actions
{
public class ObjectIdentityQueryAction
{
}
}
29 changes: 0 additions & 29 deletions CsomInspector/CsomInspector.Core/Actions/ObjectPathAction.cs

This file was deleted.

Loading

0 comments on commit 64ce01a

Please sign in to comment.