public Context(IGraph graph, INode documentNode) : base(graph) { Graph = graph; DocumentNode = documentNode; LocalNamespace = DocumentNode is IUriNode uri?UriTools.ComposeUri(uri.Uri, XmlRdfProcessor.LocalNamespace) : null; }
private string CreateSchemeHandler(IntPtr configuration) { string host = null; if (string.IsNullOrWhiteSpace(config.ExternalHost)) { const string scheme = "spidereye"; host = UriTools.GetRandomResourceUrl(scheme); IntPtr handlerClass = ObjC.AllocateClassPair(ObjC.GetClass("NSObject"), "SchemeHandler" + count, IntPtr.Zero); ObjC.AddProtocol(handlerClass, ObjC.GetProtocol("WKURLSchemeHandler")); ObjC.AddMethod( handlerClass, ObjC.RegisterName("webView:startURLSchemeTask:"), uriSchemeStartDelegate, "v@:@@"); ObjC.AddMethod( handlerClass, ObjC.RegisterName("webView:stopURLSchemeTask:"), uriSchemeStopDelegate, "v@:@@"); ObjC.RegisterClassPair(handlerClass); IntPtr handler = ObjC.Call(handlerClass, "new"); ObjC.Call(configuration, "setURLSchemeHandler:forURLScheme:", handler, NSString.Create(scheme)); } return(host); }
public override Uri ResolveUri(Uri baseUri, string relativeUri) { if (relativeUri.IndexOf("//", StringComparison.Ordinal) > 0 && !new Uri(relativeUri, UriKind.RelativeOrAbsolute).IsAbsoluteUri) { return(UriTools.CreatePublicId(relativeUri)); } return(base.ResolveUri(baseUri, relativeUri)); }
public Uri FindNamespace(string prefix) { if (String.IsNullOrEmpty(prefix)) { return(LocalNamespace); } return(UriTools.VerifyNamespacePrefix(Graph.NamespaceMap.GetNamespaceUri(prefix))); }
public void NavigateToFile(string url) { if (string.IsNullOrWhiteSpace(config.ExternalHost)) { var uri = webview.BuildLocalStreamUri("spidereye", url); webview.NavigateToLocalStreamUri(uri, streamResolver); } else { var uri = UriTools.Combine(config.ExternalHost, url); webview.Navigate(uri); } }
public string FindPrefix(Uri ns) { if (UriComparer.Equals(ns, LocalNamespace)) { return(""); } try { return(Graph.NamespaceMap.GetPrefix(UriTools.GetNamespacePrefix(ns))); }catch (RdfException) { return(null); } }
public void BuildRequestUriTest(MapData mapData) { Uri result; if (mapData.baseUri == null) { result = UriTools.BuildRequestUri(mapData.baseString, mapData.parameters); } else { result = UriTools.BuildRequestUri(mapData.baseUri, mapData.parameters); } Assert.Equal(mapData.expUri, result); }
public WinFormsWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); webview = new WebView2(); InitializeWebView(); webview.WebMessageReceived += Webview_WebMessageReceived; webview.NavigationStarting += Webview_NavigationStarting; webview.CoreWebView2InitializationCompleted += WebViewInitializationCompleted; customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme)); }
public EdgiumWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); const string scheme = "http"; customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); webview = new WebView2(); webview.NavigationStarting += Webview_NavigationStarting; webview.NavigationCompleted += Webview_NavigationCompleted; webview.WebMessageReceived += Webview_WebMessageReceived; InitWebview().RunSyncWithPump(); }
public GtkWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); scriptCallbacks = new ConcurrentDictionary <Guid, GAsyncReadyDelegate>(); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; uriSchemeCallback = UriSchemeCallback; manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } using (GLibString initScript = Resources.GetInitScript("Linux")) { var script = WebKit.Manager.CreateScript(initScript, WebKitInjectedFrames.AllFrames, WebKitInjectionTime.DocumentStart, IntPtr.Zero, IntPtr.Zero); WebKit.Manager.AddScript(manager, script); WebKit.Manager.UnrefScript(script); } Handle = WebKit.CreateWithUserContentManager(manager); settings = WebKit.Settings.Get(Handle); inspector = WebKit.Inspector.Get(Handle); GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); customHost = new Uri(UriTools.GetRandomResourceUrl(CustomScheme)); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = CustomScheme) { WebKit.Context.RegisterUriScheme(context, gscheme, uriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } }
void IXmlNodeProcessor <INode> .ProcessDocumentType(string publicId, string systemId, string internalSubset, bool useAsNamespace, INode baseNode, ref INode defaultNamespace) { INode baseType = null; if (publicId != null) { var publicNode = rdf.CreateUriNode(UriTools.CreatePublicId(publicId)); rdf.HandleTriple(publicNode, label, rdf.CreateLiteralNode(publicId, xpublic)); if (systemId != null) { rdf.HandleTriple(publicNode, isDefinedBy, MakeAbsoluteNode(baseNode, systemId)); } if (useAsNamespace && UseDtdAsDefaultNamespace) { defaultNamespace = defaultNamespace ?? publicNode; } baseType = publicNode; } else if (systemId != null) { var systemNode = MakeAbsoluteNode(baseNode, systemId); baseType = BlankNode("doctype"); rdf.HandleTriple(baseType, isDefinedBy, systemNode); //if(useAsNamespace && UseDtdAsDefaultNamespace) defaultNamespace = defaultNamespace ?? systemNode; } INode subsetType = null; if (!String.IsNullOrWhiteSpace(internalSubset)) { subsetType = rdf.CreateBlankNode("dtd"); rdf.HandleTriple(subsetType, value, rdf.CreateLiteralNode(internalSubset)); if (baseType != null) { rdf.HandleTriple(subsetType, subClassOf, baseType); } baseType = subsetType; } if (baseType != null) { rdf.HandleTriple(baseNode, a, baseType); } }
private string GetBaseUri(string path) { switch (BaseUri) { case null: return(ResolveUri(path)?.AbsoluteUri); case "": return(null); case "tag:": return(UriTools.GenerateTagUri().AbsoluteUri); case "urn:uuid:": return("urn:uuid:" + Guid.NewGuid().ToString("D")); default: return(BaseUri); } }
public GtkWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } Handle = WebKit.CreateWithUserContentManager(manager); settings = WebKit.Settings.Get(Handle); inspector = WebKit.Inspector.Get(Handle); GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); const string scheme = "spidereye"; customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = scheme) { WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } }
public void NavigateToFile(string url) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (customHost != null) { url = UriTools.Combine(customHost, url).ToString(); } else { url = UriTools.Combine(config.ExternalHost, url).ToString(); } using (GLibString gurl = url) { WebKit.LoadUri(Handle, gurl); } }
public void NavigateToFile(string url) { if (url == null) { throw new ArgumentNullException(nameof(url)); } if (customHost != null) { url = UriTools.Combine(customHost, url).ToString(); } else { url = UriTools.Combine(config.ExternalHost, url).ToString(); } IntPtr nsUrl = Foundation.Call("NSURL", "URLWithString:", NSString.Create(url)); IntPtr request = Foundation.Call("NSURLRequest", "requestWithURL:", nsUrl); ObjC.Call(Handle, "loadRequest:", request); }
public async static Task <ContestGame> CreateGameAsync(APIClient api, string hookUri) { var contest = new ContestGame(); var worldKey = Guid.NewGuid().ToString(); contest.Hook = Hook.Default; await UriTools.PatchAsync(hookUri, contest.Hook); contest.WorldKey = worldKey; contest.ArenaURL = (await api.World.PutWorldAsync(worldKey, contest.Hook)); Console.WriteLine($"world create returned: {contest.ArenaURL}"); contest.ArenaURL = "ws://" + contest.ArenaURL.Replace(worldKey, string.Empty); Console.WriteLine($"final: {contest.ArenaURL}"); contest.API = new API.Client.APIClient(new Uri(contest.ArenaURL)) { Token = api.Token }; return(contest); }
public async void MapDataTest(ApiData apiData) { // FIXME: Need a test base class or somewhere else generic to setup // logging!! AppLog.ConfigureLogging(); log.Info($"--- Running test: {apiData.testReasoning}..."); // FIXME: move client creation to general setup method. client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("X-AA-ApiKey", apiKey); Uri requestUri = UriTools.BuildRequestUri(AltitudeAngelApi.mapDataUri, apiData.parameters); log.Info($"xxx - requestUri: {requestUri}"); HttpResponseMessage response = await client.GetAsync(requestUri); // String responseContentString = await response.Content.ReadAsStringAsync(); // log.Info($"xxx - response: {response}"); Assert.Equal(apiData.expStatusCode, response.StatusCode); }
public CocoaWebview(WebviewBridge bridge) { this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); IntPtr configuration = WebKit.Call("WKWebViewConfiguration", "new"); IntPtr manager = ObjC.Call(configuration, "userContentController"); callbackClass = CallbackClassDefinition.CreateInstance(this); schemeHandler = SchemeHandlerDefinition.CreateInstance(this); const string scheme = "spidereye"; customHost = new Uri(UriTools.GetRandomResourceUrl(scheme)); ObjC.Call(configuration, "setURLSchemeHandler:forURLScheme:", schemeHandler.Handle, NSString.Create(scheme)); ObjC.Call(manager, "addScriptMessageHandler:name:", callbackClass.Handle, NSString.Create("external")); IntPtr script = WebKit.Call("WKUserScript", "alloc"); ObjC.Call( script, "initWithSource:injectionTime:forMainFrameOnly:", NSString.Create(Resources.GetInitScript("Mac")), IntPtr.Zero, IntPtr.Zero); ObjC.Call(manager, "addUserScript:", script); Handle = WebKit.Call("WKWebView", "alloc"); ObjC.Call(Handle, "initWithFrame:configuration:", CGRect.Zero, configuration); ObjC.Call(Handle, "setNavigationDelegate:", callbackClass.Handle); IntPtr boolValue = Foundation.Call("NSNumber", "numberWithBool:", false); ObjC.Call(Handle, "setValue:forKey:", boolValue, NSString.Create("drawsBackground")); ObjC.Call(Handle, "addObserver:forKeyPath:options:context:", callbackClass.Handle, NSString.Create("title"), IntPtr.Zero, IntPtr.Zero); preferences = ObjC.Call(configuration, "preferences"); }
private string GetDtdSubset(INode documentNode, Context context) { using (var nullWriter = CreateNullWriter()) { foreach (var value in GetValues(documentNode)) { if (WriteValue(nullWriter, value, context)) { break; } } var sb = new StringBuilder(); sb.AppendLine(); foreach (var pair in context.Entities) { var key = pair.Key; var name = pair.Value; var pubId = UriTools.ExtractPublicId(pair.Key); if (pubId != null) { var sysId = graph.FindObject(graph.CreateUriNode(key), isDefinedBy).OfType <IUriNode>().FirstOrDefault()?.Uri; if (sysId == null) { sysId = key; } sb.AppendLine($"<!ENTITY {name} PUBLIC \"{pubId}\" \"{sysId.GetString()}\">"); } else { sb.AppendLine($"<!ENTITY {name} SYSTEM \"{key.GetString()}\">"); } } return(sb.ToString()); } }
public GtkWebview(WindowConfiguration config, IContentProvider contentProvider, WebviewBridge bridge) { this.config = config ?? throw new ArgumentNullException(nameof(config)); this.contentProvider = contentProvider ?? throw new ArgumentNullException(nameof(contentProvider)); this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge)); // need to keep the delegates around or they will get garbage collected scriptDelegate = ScriptCallback; loadFailedDelegate = LoadFailedCallback; loadDelegate = LoadCallback; contextMenuDelegate = ContextMenuCallback; closeDelegate = CloseCallback; titleChangeDelegate = TitleChangeCallback; if (config.EnableScriptInterface) { manager = WebKit.Manager.Create(); GLib.ConnectSignal(manager, "script-message-received::external", scriptDelegate, IntPtr.Zero); using (GLibString name = "external") { WebKit.Manager.RegisterScriptMessageHandler(manager, name); } Handle = WebKit.CreateWithUserContentManager(manager); } else { Handle = WebKit.Create(); } GLib.ConnectSignal(Handle, "load-failed", loadFailedDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "load-changed", loadDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "context-menu", contextMenuDelegate, IntPtr.Zero); GLib.ConnectSignal(Handle, "close", closeDelegate, IntPtr.Zero); if (config.UseBrowserTitle) { GLib.ConnectSignal(Handle, "notify::title", titleChangeDelegate, IntPtr.Zero); } if (string.IsNullOrWhiteSpace(config.ExternalHost)) { const string scheme = "spidereye"; customHost = UriTools.GetRandomResourceUrl(scheme); IntPtr context = WebKit.Context.Get(Handle); using (GLibString gscheme = scheme) { WebKit.Context.RegisterUriScheme(context, gscheme, UriSchemeCallback, IntPtr.Zero, IntPtr.Zero); } } var bgColor = new GdkColor(config.BackgroundColor); WebKit.SetBackgroundColor(Handle, ref bgColor); if (enableDevTools) { var settings = WebKit.Settings.Get(Handle); WebKit.Settings.SetEnableDeveloperExtras(settings, true); var inspector = WebKit.Inspector.Get(Handle); WebKit.Inspector.Show(inspector); } }
/** * https://developers.altitudeangel.com/docs#apis_mapdata * GET /v2/mapdata/geojson?n=51.46227963315035&e=-0.9569686575500782&s=51.450125805383585&w=-0.9857433958618458 HTTP/1.1 * Authorization: X-AA-ApiKey YOUR_API_KEYGET * * Request Details * /v2/mapdata/geojson * * This endpoint will return data for the area specified by a bounding box, subject to maximum queryable area limits as defined above. * * Querystring parameter Description * n The north coordinate of the bounding box in degrees * e The east coordinate of the bounding box in degrees * s The south coordinate of the bounding box in degrees * w The west coordinate of the bounding box in degrees */ public async Task <MapData> GetMapData(double north, double east, double south, double west) { // TODO: Separate out: request building, external request/response, // response verification, JSON extraction from response. // Request Building. Dictionary <string, string> parameters = new Dictionary <string, string> { { "n", north.ToString() }, { "e", east.ToString() }, { "s", south.ToString() }, { "w", west.ToString() } }; Uri requestUri = UriTools.BuildRequestUri(mapDataUri, parameters); log.Info($"xxx - requestUri: {requestUri}"); // External Request/Response. HttpResponseMessage response; try { response = await client.GetAsync(requestUri); } catch (HttpRequestException e) { log.Info($" Request to: {requestUri}, failed with message: {e.Message}"); throw e; } // TODO return JSON/GeoJSON, or have a separate function that // parses the JSON from the HttpResponseMessage along with // verification's? // Response Verification. if (!response.IsSuccessStatusCode) { int sCode = (int)response.StatusCode; // Non-200 status code, so need to do some failure paths. if (sCode >= 300 && sCode <= 399) { log.Info($"TODO: add HTTP Redirection code to retry request. Status Code: {sCode}"); } else if (sCode == 400) { log.Info($"TODO: add HTTP Bad Request (Missing Parameters) code. Give up request. Status Code: {sCode}"); } else if (sCode == 401) { log.Info($"TODO: add HTTP Missing Authentication code. Give up request. Status Code: {sCode}"); } else if (sCode == 404) { log.Info($"TODO: add HTTP Not Found (path) code. Give up request. Status Code: {sCode}"); String responseContentString = await response.Content.ReadAsStringAsync(); log.Info($"--- response: {response}"); log.Info($"--- response.ReasonPhrase: {response.ReasonPhrase}"); log.Info($"--- response.Content: {responseContentString}"); } else if (sCode >= 500 && sCode <= 599) { log.Info($"TODO: add HTTP Server Error code. Give up request. Status Code: {sCode}"); } else { log.Info($"TODO: No specific handler path. add HTTP code?? Give up request. Status Code: {sCode}"); } } // JSON Extraction From Response. String responseJsonString = await response.Content.ReadAsStringAsync(); // log.Info($"xxx - responseJsonString: {responseJsonString}"); MapData responseJson = JsonConvert.DeserializeObject <MapData>(responseJsonString); return(responseJson); }
public void NavigateToFile(string url) { var uri = UriTools.Combine(hostAddress, url); webview.Navigate(uri); }
public override bool MoveToId(string id) { return(SetCursor(CreateRootCursor(graph, graph.CreateUriNode(UriTools.ComposeUri(cursor.BaseUri, "#" + id))))); }
protected async override Task ExecuteAsync() { if (StartupDelay > 0) { await Task.Delay(StartupDelay); } ConfigurableContextBotConfig config = null; Type robotType = null; if (Url != null || File != null) { string text = null; if (File != null) { text = System.IO.File.ReadAllText(Path.GetFullPath(File)); } if (Url != null) { using (var webClient = new WebClient()) text = await webClient.DownloadStringTaskAsync(Url); } config = JsonConvert.DeserializeObject <ConfigurableContextBotConfig>(text); if (config.RobotType != null) { robotType = Type.GetType(config.RobotType); } } if (TypeName != null) { robotType = Type.GetType(TypeName); } if (robotType == null) { if (config?.RobotType != null) { robotType = Type.GetType(config.RobotType); } } if (robotType == null) { robotType = typeof(ContextTurret); } if (Name == null && config?.Name != null) { Name = config.Name; } if (Name == null) { Name = "robot"; } if (Sprite == null && config?.Sprite != null) { Sprite = config.Sprite; } if (Sprite == null) { Sprite = "ship_red"; } if (Color == null && config?.Color != null) { Color = config.Color; } if (Color == null) { Color = "red"; } async Task <Robot> CreateRobot(Type innerRobotType = null, string worldKey = null, APIClient apiClient = null) { var robot = Activator.CreateInstance(innerRobotType ?? robotType) as Robot; robot.AutoSpawn = true; if (robot is ConfigurableContextBot configBot) { configBot.ConfigurationFileName = File; configBot.ConfigurationFileUrl = Url; configBot.InitializeConfiguration(); } if (robot is ConfigurableTreeBot configtBot) { configtBot.ConfigurationFileName = File; } robot.AutoFire = Firing; robot.Color = Color; robot.Name = Name; robot.Target = Target; robot.Sprite = Sprite; var connection = await(apiClient ?? API) .Player.ConnectAsync(worldKey ?? World); robot.Connection = connection; return(robot); } if (Scenario != null) { var scenario = await UriTools.LoadAsync <ScenarioConfiguration>(Scenario); var tasks = new List <Task>(); var contest = await ContestGame.CreateGameAsync(API, scenario.HookURL); foreach (var robotName in scenario.Robots.Keys) { var robot = await ConfigurableContextBot.Load(scenario.Robots[robotName]); robot.Name = robotName; robot.DuelingProtocol = true; robot.Connection = await contest.API.Player.ConnectAsync(contest.WorldKey); tasks.Add(robot.StartAsync()); } await Task.WhenAll(tasks); } if (Evolve) { /* * var controller = new RobotEvolutionController(); * var ga = controller.CreateGA(async (chromosome) => * { * var contest = await ContestGame.CreateGameAsync(API); * * contest.Hook = Hook.Default; * if (EvolveHook != null) * JsonConvert.PopulateObject( * await System.IO.File.ReadAllTextAsync(EvolveHook), * contest.Hook * ); * * contest.TestRobot = await CreateRobot( * worldKey: contest.WorldKey, * apiClient: contest.API * ) as ConfigurableContextBot; * if (contest.TestRobot == null) * throw new Exception("Failed to create robot or it isn't derived from ConfigurableContextBot"); * * contest.ChallengeRobot = await CreateRobot( * worldKey: contest.WorldKey, * apiClient: contest.API, * innerRobotType: typeof(ConfigTurret) * ) as ConfigurableContextBot; * contest.ChallengeRobot.ConfigurationFileName = EvolveChallengeConfig; * if (contest.ChallengeRobot == null) * throw new Exception("Failed to create robot or it isn't derived from ConfigurableContextBot"); * * return contest; * }, new RobotEvolutionConfiguration * { * BehaviorCount = 9, * FitnessDuration = 60000 * 10 * }); * ga.Start(); */ } else { var tasks = new List <Task>(); for (int i = 0; i < Replicas; i++) { var robot = await CreateRobot(); tasks.Add(robot.StartAsync()); } ; await Task.WhenAll(tasks); foreach (var task in tasks) { if (task.IsFaulted) { Console.WriteLine($"Robot Crashed: {task.Exception}"); } } } }
public XDocumentType GetDocumentType(string root) { var classes = FindObject(DocumentNode, a); foreach (var cls in classes) { if (FindObject(cls, subClassOf).FirstOrDefault() is IUriNode publicNode) { if (UriTools.ExtractPublicId(publicNode.Uri) is string pubId) { if (FindObject(publicNode, isDefinedBy).FirstOrDefault() is IUriNode systemNode) { var subset = FindObject(cls, value).OfType <ILiteralNode>().FirstOrDefault(); return(new XDocumentType(root, pubId, systemNode.Uri.GetString(), subset?.Value)); } } } } foreach (var cls in classes) { if (FindObject(cls, subClassOf).FirstOrDefault() is IUriNode publicNode) { if (UriTools.ExtractPublicId(publicNode.Uri) is string pubId) { var subset = FindObject(cls, value).OfType <ILiteralNode>().FirstOrDefault(); return(new XDocumentType(root, pubId, null, subset?.Value)); } } } foreach (var cls in classes.OfType <IUriNode>()) { if (UriTools.ExtractPublicId(cls.Uri) is string pubId) { if (FindObject(cls, isDefinedBy).FirstOrDefault() is IUriNode systemNode) { return(new XDocumentType(root, pubId, systemNode.Uri.GetString(), null)); } } } foreach (var cls in classes.OfType <IUriNode>()) { if (UriTools.ExtractPublicId(cls.Uri) is string pubId) { return(new XDocumentType(root, pubId, null, null)); } } foreach (var cls in classes) { var subset = FindObject(cls, value).OfType <ILiteralNode>().FirstOrDefault(); if (subset != null) { return(new XDocumentType(root, null, null, subset.Value)); } } return(null); }
private void WriteDocumentType(XmlWriter writer, INode documentNode, Context context) { var root = GetRootType(documentNode); if (root == null) { return; } var classes = graph.FindObject(documentNode, a); var entitySubset = GetDtdSubset(documentNode, context); foreach (var cls in classes) { if (graph.FindObject(cls, subClassOf).FirstOrDefault() is IUriNode publicNode) { if (UriTools.ExtractPublicId(publicNode.Uri) is string pubId) { if (graph.FindObject(publicNode, isDefinedBy).FirstOrDefault() is IUriNode systemNode) { var subset = GetValues(cls).OfType <ILiteralNode>().FirstOrDefault(); writer.WriteDocType(root, pubId, systemNode.Uri.GetString(), subset?.Value + entitySubset); return; } } } } foreach (var cls in classes) { if (graph.FindObject(cls, subClassOf).FirstOrDefault() is IUriNode publicNode) { if (UriTools.ExtractPublicId(publicNode.Uri) is string pubId) { var subset = GetValues(cls).OfType <ILiteralNode>().FirstOrDefault(); writer.WriteDocType(root, pubId, null, subset?.Value + entitySubset); return; } } } foreach (var cls in classes.OfType <IUriNode>()) { if (UriTools.ExtractPublicId(cls.Uri) is string pubId) { if (graph.FindObject(cls, isDefinedBy).FirstOrDefault() is IUriNode systemNode) { writer.WriteDocType(root, pubId, systemNode.Uri.GetString(), entitySubset); return; } } } foreach (var cls in classes.OfType <IUriNode>()) { if (UriTools.ExtractPublicId(cls.Uri) is string pubId) { writer.WriteDocType(root, pubId, null, entitySubset); return; } } foreach (var cls in classes) { var subset = GetValues(cls).OfType <ILiteralNode>().FirstOrDefault(); if (subset != null) { writer.WriteDocType(root, null, null, subset.Value + entitySubset); return; } } if (!String.IsNullOrEmpty(entitySubset)) { writer.WriteDocType(root, null, null, entitySubset); } }
protected Uri GetFullUri(XmlQualifiedName xmlName) { return(xmlName != null?UriTools.ComposeUri(new Uri(xmlName.Namespace), xmlName.Name) : null); }