Skip to content
Snippets Groups Projects
Commit 88e737d0 authored by Georgios Diamantopoulos's avatar Georgios Diamantopoulos
Browse files

support multiple json files

parent 79c6319e
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,10 @@ namespace MasterDevs.ChromeDevTools.ProtocolGenerator
[JsonProperty("experimental")]
public bool IsExperimental { get; set; }
[JsonProperty("deprecated")]
public bool IsDeprecated { get; set; }
public string[] Dependencies { get; set; }
public Command GetCommand(string name)
......
......@@ -28,16 +28,20 @@ namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
// At this point in time, we only process the most recent Chrome
// and iOS (Safari) protocols.
Dictionary<string, string> protocolFiles = new Dictionary<string, string>();
Dictionary<string, string[]> protocolFiles = new Dictionary<string, string[]>
{
{"Chrome", new [] { "js_protocol.json", "browser_protocol.json" } },
{"iOS", new [] { "Inspector-iOS-9.3.json" } }
};
//protocolFiles.Add("Chrome-0.1", "Inspector-0.1.json");
//protocolFiles.Add("Chrome-1.0", "Inspector-1.0.json");
//protocolFiles.Add("Chrome", "Inspector-1.1.json");
protocolFiles.Add("Chrome", "browser_protocol.json");
protocolFiles.Add("ChromeJS", "js_protocol.json");
//protocolFiles.Add("iOS-7.0", "Inspector-iOS-7.0.json");
//protocolFiles.Add("iOS-8.0", "Inspector-iOS-8.0.json");
//protocolFiles.Add("iOS-9.0", "Inspector-iOS-9.0.json");
protocolFiles.Add("iOS", "Inspector-iOS-9.3.json");
Collection<Protocol> protocols = new Collection<Protocol>();
......
......@@ -5,57 +5,27 @@ namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
public class Protocol
{
public Protocol()
{
this.Compatible = new Collection<string>();
this.Domains = new Collection<Domain>();
}
public Collection<string> Compatible { get; set; } = new Collection<string>();
public Collection<string> Compatible
{
get;
set;
}
public Version Version
{
get;
set;
}
public Version Version { get; set; }
public Collection<Domain> Domains
{
get;
set;
}
public Collection<Domain> Domains { get; set; } = new Collection<Domain>();
public string SourceFile
{
get;
set;
}
public string[] SourceFiles { get; set; }
public string Alias
{
get;
set;
}
public string Alias { get; set; }
public Domain GetDomain(string name)
{
return this.Domains.SingleOrDefault(d => string.Equals(d.Name, name, System.StringComparison.OrdinalIgnoreCase));
return Domains.SingleOrDefault(d => string.Equals(d.Name, name, System.StringComparison.OrdinalIgnoreCase));
}
public override string ToString()
{
if(this.SourceFile != null)
{
return $"{this.Alias} ({this.SourceFile})";
}
else
{
return this.Alias;
}
if (SourceFiles?.Any() == true)
return $"{Alias} ({string.Join(", ", SourceFiles)})";
return Alias;
}
}
}
......@@ -3,8 +3,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MasterDevs.ChromeDevTools.ProtocolGenerator
{
......@@ -82,22 +80,39 @@ namespace MasterDevs.ChromeDevTools.ProtocolGenerator
property.TypeReference = explicitMappings[fullReferenceName];
}
}
else if(property.Items != null)
else if (property.Items != null)
{
ResolveTypeReferences(protocol, domain, property.Items, explicitMappings);
}
}
public static Protocol LoadProtocol(string path, string alias)
public static Protocol LoadProtocol(string[] paths, string alias)
{
string json = File.ReadAllText(path);
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.MissingMemberHandling = MissingMemberHandling.Error;
settings.MetadataPropertyHandling = MetadataPropertyHandling.Ignore;
if (paths == null || paths.Length < 1)
throw new ArgumentException("Must specify at least one path", nameof(paths));
JsonSerializerSettings settings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Error,
MetadataPropertyHandling = MetadataPropertyHandling.Ignore
};
string json = File.ReadAllText(paths[0]);
Protocol p = JsonConvert.DeserializeObject<Protocol>(json, settings);
p.SourceFile = path;
p.SourceFiles = paths;
p.Alias = alias;
if (paths.Length > 1)
{
foreach (var path in paths.Skip(1))
{
json = File.ReadAllText(path);
Protocol partial = JsonConvert.DeserializeObject<Protocol>(json, settings);
foreach (var domain in partial.Domains)
p.Domains.Add(domain);
}
}
foreach (var domain in p.Domains)
{
foreach (var command in domain.Commands)
......
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