Skip to content
Snippets Groups Projects
Commit 38ee3362 authored by Frederik Carlier's avatar Frederik Carlier
Browse files

Add basic DOM for deserializing the the debugger protocol into .NET objects

parent 06565759
No related branches found
No related tags found
No related merge requests found
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;
}
}
}
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;
}
}
}
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;
}
}
}
......@@ -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" />
......
......@@ -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";
......
using Newtonsoft.Json;
namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
class Property : Type
{
[JsonProperty("name")]
public override string Name
{
get;
set;
}
public bool Optional
{
get;
set;
}
}
}
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;
}
}
}
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;
}
}
}
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;
}
}
}
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}";
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment