From 38ee33625ec780ec46461f7e7eeb6b3e5870a06e Mon Sep 17 00:00:00 2001 From: Frederik Carlier <frederik.carlier@quamotion.mobi> Date: Sun, 8 May 2016 22:46:57 +0200 Subject: [PATCH] Add basic DOM for deserializing the the debugger protocol into .NET objects --- source/ProtocolGenerator/Command.cs | 43 ++++++++++++++ source/ProtocolGenerator/Domain.cs | 45 ++++++++++++++ source/ProtocolGenerator/Event.cs | 25 ++++++++ ...vs.ChromeDevTools.ProtocolGenerator.csproj | 31 +++++++++- source/ProtocolGenerator/Program.cs | 10 ++++ source/ProtocolGenerator/Property.cs | 20 +++++++ source/ProtocolGenerator/Protocol.cs | 25 ++++++++ source/ProtocolGenerator/ProtocolItem.cs | 28 +++++++++ source/ProtocolGenerator/Type.cs | 59 +++++++++++++++++++ source/ProtocolGenerator/Version.cs | 22 +++++++ 10 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 source/ProtocolGenerator/Command.cs create mode 100644 source/ProtocolGenerator/Domain.cs create mode 100644 source/ProtocolGenerator/Event.cs create mode 100644 source/ProtocolGenerator/Property.cs create mode 100644 source/ProtocolGenerator/Protocol.cs create mode 100644 source/ProtocolGenerator/ProtocolItem.cs create mode 100644 source/ProtocolGenerator/Type.cs create mode 100644 source/ProtocolGenerator/Version.cs diff --git a/source/ProtocolGenerator/Command.cs b/source/ProtocolGenerator/Command.cs new file mode 100644 index 0000000..6a3d253 --- /dev/null +++ b/source/ProtocolGenerator/Command.cs @@ -0,0 +1,43 @@ +using System.Collections.ObjectModel; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Command : ProtocolItem + { + public Collection<Property> Returns + { + get; + set; + } + + public Property Error + { + get; + set; + } + + public Collection<string> Handlers + { + get; + set; + } + + public Collection<Property> Parameters + { + get; + set; + } + + public bool async + { + get; + set; + } + + public string Redirect + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/Domain.cs b/source/ProtocolGenerator/Domain.cs new file mode 100644 index 0000000..3e70627 --- /dev/null +++ b/source/ProtocolGenerator/Domain.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using System.Collections.ObjectModel; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Domain : ProtocolItem + { + [JsonProperty(PropertyName = "domain")] + public override string Name + { + get; + set; + } + + public Collection<Type> Types + { + get; + set; + } + + public Collection<Command> Commands + { + get; + set; + } + + public Collection<Event> Events + { + get; + set; + } + + public string Availability + { + get; + set; + } + + public string FeatureGuard + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/Event.cs b/source/ProtocolGenerator/Event.cs new file mode 100644 index 0000000..ff2b92d --- /dev/null +++ b/source/ProtocolGenerator/Event.cs @@ -0,0 +1,25 @@ +using System.Collections.ObjectModel; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Event : ProtocolItem + { + public Collection<Property> Parameters + { + get; + set; + } + + public Collection<string> Handlers + { + get; + set; + } + + public bool Deprecated + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/MasterDevs.ChromeDevTools.ProtocolGenerator.csproj b/source/ProtocolGenerator/MasterDevs.ChromeDevTools.ProtocolGenerator.csproj index 5e5798e..4a58f80 100644 --- a/source/ProtocolGenerator/MasterDevs.ChromeDevTools.ProtocolGenerator.csproj +++ b/source/ProtocolGenerator/MasterDevs.ChromeDevTools.ProtocolGenerator.csproj @@ -50,14 +50,43 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> + <Compile Include="Command.cs" /> + <Compile Include="Domain.cs" /> + <Compile Include="Event.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Property.cs" /> + <Compile Include="Protocol.cs" /> + <Compile Include="ProtocolItem.cs" /> + <Compile Include="Type.cs" /> + <Compile Include="Version.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> + <None Include="Inspector-0.1.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-1.0.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-1.1.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-iOS-7.0.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-iOS-8.0.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-iOS-9.0.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + <None Include="Inspector-iOS-9.3.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> <None Include="packages.config" /> <None Include="protocol.json"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> diff --git a/source/ProtocolGenerator/Program.cs b/source/ProtocolGenerator/Program.cs index 194d205..f418253 100644 --- a/source/ProtocolGenerator/Program.cs +++ b/source/ProtocolGenerator/Program.cs @@ -23,6 +23,16 @@ namespace MasterDevs.ChromeDevTools.ProtocolGenerator private static Dictionary<string, List<string>> _DomainEvents = new Dictionary<string, List<string>>(); private static Dictionary<string, string> _SimpleTypes = new Dictionary<string, string>(); + private static Protocol LoadProtocol(string path) + { + string json = File.ReadAllText(path); + JsonSerializerSettings settings = new JsonSerializerSettings(); + settings.MissingMemberHandling = MissingMemberHandling.Error; + settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore; + Protocol p = JsonConvert.DeserializeObject<Protocol>(json, settings); + return p; + } + private static void Main(string[] args) { var filePath = "protocol.json"; diff --git a/source/ProtocolGenerator/Property.cs b/source/ProtocolGenerator/Property.cs new file mode 100644 index 0000000..7645385 --- /dev/null +++ b/source/ProtocolGenerator/Property.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Property : Type + { + [JsonProperty("name")] + public override string Name + { + get; + set; + } + + public bool Optional + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/Protocol.cs b/source/ProtocolGenerator/Protocol.cs new file mode 100644 index 0000000..ae206ed --- /dev/null +++ b/source/ProtocolGenerator/Protocol.cs @@ -0,0 +1,25 @@ +using System.Collections.ObjectModel; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Protocol + { + public Collection<string> Compatible + { + get; + set; + } + + public Version Version + { + get; + set; + } + + public Collection<Domain> Domains + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/ProtocolItem.cs b/source/ProtocolGenerator/ProtocolItem.cs new file mode 100644 index 0000000..61bae95 --- /dev/null +++ b/source/ProtocolGenerator/ProtocolItem.cs @@ -0,0 +1,28 @@ +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + abstract class ProtocolItem + { + public virtual string Description + { + get; + set; + } + + public virtual bool Hidden + { + get; + set; + } + + public virtual string Name + { + get; + set; + } + + public override string ToString() + { + return this.Name; + } + } +} diff --git a/source/ProtocolGenerator/Type.cs b/source/ProtocolGenerator/Type.cs new file mode 100644 index 0000000..775759f --- /dev/null +++ b/source/ProtocolGenerator/Type.cs @@ -0,0 +1,59 @@ +using Newtonsoft.Json; +using System.Collections.ObjectModel; + +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Type : ProtocolItem + { + [JsonProperty(PropertyName = "Id")] + public override string Name + { + get; + set; + } + + [JsonProperty(PropertyName ="type")] + public string Kind + { + get; + set; + } + + public Collection<string> Enum + { + get; + set; + } + + public Collection<Property> Properties + { + get; + set; + } + + public Type Items + { + get; + set; + } + + public int MinItems + { + get; + set; + } + + public int MaxItems + { + get; + set; + } + + [JsonProperty("$ref")] + public string TypeReference + { + get; + set; + } + } +} diff --git a/source/ProtocolGenerator/Version.cs b/source/ProtocolGenerator/Version.cs new file mode 100644 index 0000000..b9d6dc8 --- /dev/null +++ b/source/ProtocolGenerator/Version.cs @@ -0,0 +1,22 @@ +namespace MasterDevs.ChromeDevTools.ProtocolGenerator +{ + class Version + { + public string Major + { + get; + set; + } + + public string Minor + { + get; + set; + } + + public override string ToString() + { + return $"{this.Major}.{this.Minor}"; + } + } +} -- GitLab