From 2c72fb3c00ab30d2fc945c244bf762e4507e35c4 Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Wed, 8 Oct 2014 11:40:12 +0200 Subject: [PATCH] ready for 1.3.0 Signed-off-by: Emmanuel Mathot --- .gitmodules | 3 - Terradue.OpenSearch | 1 - Terradue.OpenSearch.Client.nuspec | 27 +-- Terradue.OpenSearch.Client.sln | 6 - .../Properties/AssemblyInfo.cs | 6 +- .../Terradue.OpenSearch.Client.csproj | 23 +- .../Client}/OpenSearchClient.cs | 215 ++++++++++-------- .../Client}/OpenSearchResultFilters.cs | 0 Terradue.OpenSearch.Client/packages.config | 4 + 9 files changed, 149 insertions(+), 136 deletions(-) delete mode 160000 Terradue.OpenSearch rename Terradue.OpenSearch.Client/Terradue/{Air => OpenSearch/Client}/OpenSearchClient.cs (75%) rename Terradue.OpenSearch.Client/Terradue/{Air => OpenSearch/Client}/OpenSearchResultFilters.cs (100%) diff --git a/.gitmodules b/.gitmodules index 065e2b49..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "Terradue.OpenSearch"] - path = Terradue.OpenSearch - url = git://github.com/Terradue/DotNetOpenSearch diff --git a/Terradue.OpenSearch b/Terradue.OpenSearch deleted file mode 160000 index 8ea99f3a..00000000 --- a/Terradue.OpenSearch +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8ea99f3a32a2bcdfdb85d70c969cb003a2d32cee diff --git a/Terradue.OpenSearch.Client.nuspec b/Terradue.OpenSearch.Client.nuspec index b82795be..63ecbd01 100644 --- a/Terradue.OpenSearch.Client.nuspec +++ b/Terradue.OpenSearch.Client.nuspec @@ -1,31 +1,26 @@ - OpenSearchClient - 1.2 + Terradue.OpenSearch.Client + 1.3.0 Terradue Terradue - https://www.gnu.org/copyleft/gpl.html - https://github.com/Terradue/OpenSearchClient + https://github.com/Terradue/DotNetOpenSearchClient/blob/master/LICENSE + https://github.com/Terradue/DotNetOpenSearchClient false - Package description - Summary of changes made in this release of the package. + Generic OpenSearch Client Copyright 2014 OpenSearch - - - - - - + + + + + - - - - + \ No newline at end of file diff --git a/Terradue.OpenSearch.Client.sln b/Terradue.OpenSearch.Client.sln index d894400c..88b79f5f 100644 --- a/Terradue.OpenSearch.Client.sln +++ b/Terradue.OpenSearch.Client.sln @@ -1,8 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terradue.OpenSearch", "Terradue.OpenSearch\Terradue.OpenSearch\Terradue.OpenSearch.csproj", "{997A44FD-EE4A-490A-855B-88305E0CD269}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terradue.OpenSearch.Client", "Terradue.OpenSearch.Client\Terradue.OpenSearch.Client.csproj", "{1FB59AA7-3878-47CD-4267-F179F56C6470}" EndProject Global @@ -15,10 +13,6 @@ Global {1FB59AA7-3878-47CD-4267-F179F56C6470}.Debug|x86.Build.0 = Debug|x86 {1FB59AA7-3878-47CD-4267-F179F56C6470}.Release|x86.ActiveCfg = Release|x86 {1FB59AA7-3878-47CD-4267-F179F56C6470}.Release|x86.Build.0 = Release|x86 - {997A44FD-EE4A-490A-855B-88305E0CD269}.Debug|x86.ActiveCfg = Debug|Any CPU - {997A44FD-EE4A-490A-855B-88305E0CD269}.Debug|x86.Build.0 = Debug|Any CPU - {997A44FD-EE4A-490A-855B-88305E0CD269}.Release|x86.ActiveCfg = Release|Any CPU - {997A44FD-EE4A-490A-855B-88305E0CD269}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution StartupItem = Terradue.OpenSearch.Client\Terradue.OpenSearch.Client.csproj diff --git a/Terradue.OpenSearch.Client/Properties/AssemblyInfo.cs b/Terradue.OpenSearch.Client/Properties/AssemblyInfo.cs index c5f1343e..55ae1f60 100644 --- a/Terradue.OpenSearch.Client/Properties/AssemblyInfo.cs +++ b/Terradue.OpenSearch.Client/Properties/AssemblyInfo.cs @@ -4,7 +4,7 @@ // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. [assembly: AssemblyTitle("OpenSearchClient")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Generic OpenSearch Client")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] @@ -14,8 +14,8 @@ // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.2.*")] -[assembly: AssemblyInformationalVersion("1.2")] +[assembly: AssemblyVersion("1.3.0.*")] +[assembly: AssemblyInformationalVersion("1.3.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. //[assembly: AssemblyDelaySign(false)] diff --git a/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj b/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj index a61766cf..4c04576e 100644 --- a/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj +++ b/Terradue.OpenSearch.Client/Terradue.OpenSearch.Client.csproj @@ -22,7 +22,7 @@ true x86 false - -f Rdf -p time:start=1995-10-11T14:54:10.000Z -p time:end=1995-10-11T14:55:12.000Z -p eop:wrsLongitudeGrid=125 -p time:relation=equals http://cci-ice-velocity.terradue.int/catalogue/search/ICESHEET_CCI_SLC/description + -f rdf -p time:start=1995-10-11T14:54:10.000Z -p time:end=1996-10-11T14:55:12.000Z -p eop:wrsLongitudeGrid=125 http://cci-ice-velocity.terradue.int/catalogue/search/ICESHEET_CCI_SLC/description enclosure full @@ -47,20 +47,29 @@ ..\packages\Mono.Addins.1.1\lib\Mono.Addins.dll + + ..\packages\Terradue.ServiceModel.Syndication.1.0.0.0\lib\net40\Terradue.ServiceModel.Syndication.dll + + + ..\packages\Terradue.OpenSearch.1.7.0.1\lib\net40\Terradue.OpenSearch.dll + + + ..\packages\Terradue.GeoJson.1.4.0\lib\net40\Terradue.GeoJson.dll + + + ..\packages\Terradue.OpenSearch.RdfEO.1.0.1\lib\net40\Terradue.OpenSearch.RdfEO.dll + - - + - - {997A44FD-EE4A-490A-855B-88305E0CD269} - Terradue.OpenSearch - + + \ No newline at end of file diff --git a/Terradue.OpenSearch.Client/Terradue/Air/OpenSearchClient.cs b/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs similarity index 75% rename from Terradue.OpenSearch.Client/Terradue/Air/OpenSearchClient.cs rename to Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs index 7f144239..7cd17963 100755 --- a/Terradue.OpenSearch.Client/Terradue/Air/OpenSearchClient.cs +++ b/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchClient.cs @@ -11,7 +11,7 @@ using System.Reflection; using Terradue.OpenSearch; using System.Collections.Specialized; -using System.ServiceModel.Syndication; +using Terradue.ServiceModel.Syndication; using Mono.Addins; using log4net; using log4net.Repository.Hierarchy; @@ -20,6 +20,9 @@ using log4net.Appender; using Terradue.OpenSearch.Engine; using Terradue.OpenSearch.Result; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Net.Security; namespace Terradue.Shell.OpenSearch { //------------------------------------------------------------------------------------------------------------------------- @@ -31,7 +34,7 @@ public class OpenSearchClient { private static bool verbose; private static bool listOsee; private static string outputFilePathArg = null; - private static string outputFormatArg = "Atom"; + private static string queryFormatArg = null; private static List baseUrlArg = null; private static int timeout = 10000; private static int pagination = 20; @@ -41,6 +44,7 @@ public class OpenSearchClient { private List openSearchEngineExtensions; private static OpenSearchEngine ose; + public static void Main(string[] args) { if (!GetArgs(args)) { @@ -48,7 +52,9 @@ public static void Main(string[] args) { Environment.ExitCode = 1; return; } - + + + OpenSearchClient client = null; try { client = new OpenSearchClient(); @@ -67,36 +73,60 @@ public static void Main(string[] args) { Environment.ExitCode = 1; return; } - + } private void Initialize() { + + // Config log + ConfigureLog(); + + log.Debug("Initialize Addins registry."); + AddinManager.Initialize(); AddinManager.Registry.Update(null); + + log.Debug("Initialize SSL verification."); + // Override automatic validation of SSL server certificates. + System.Net.ServicePointManager.ServerCertificateValidationCallback = (s,ce,ca,p) => true; + + log.Debug("Load OpenSearch Engine."); ose = new OpenSearchEngine(); - ose.LoadPlugins(); + + LoadOpenSearchEngineExtensions(ose); + + + } + + void LoadOpenSearchEngineExtensions(OpenSearchEngine ose) { + if (queryFormatArg == null) { + ose.LoadPlugins(); + } else { + foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (typeof(IOpenSearchEngineExtension))) { + IOpenSearchEngineExtension osee = (IOpenSearchEngineExtension)node.CreateInstance(); + if (string.Compare(osee.Identifier, queryFormatArg, true) == 0) + ose.RegisterExtension(osee); + } + } } private void ListOpenSearchEngineExtensions() { - // Config log - ConfigureLog(); + // Initialize the output stream Stream outputStream = InitializeOutputStream(); StreamWriter sw = new StreamWriter(outputStream); - sw.WriteLine(string.Format("{0,-30}{1,-25}{2,-25}", "Extension Name", "Input Mime-Type", "Output Format")); - sw.WriteLine(string.Format("{0,-30}{1,-25}{2,-25}", "==============", "===============", "=============")); + sw.WriteLine(string.Format("{0,-30}{1,-40}", "Extension Id", "Mime-Type capability")); + sw.WriteLine(string.Format("{0,-30}{1,-40}", "============", "====================")); AddinManager.Initialize(); AddinManager.Registry.Update(null); foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes (typeof(IOpenSearchEngineExtension))) { IOpenSearchEngineExtension osee = (IOpenSearchEngineExtension)node.CreateInstance(); - foreach (string input in osee.GetInputFormatTransformPath()) { - sw.WriteLine(string.Format("{0,-30}{1,-25}{2,-25}", osee.Name, input, osee.Name)); - } + sw.WriteLine(string.Format("{0,-30}{1,-40}", osee.Identifier, osee.DiscoveryContentType)); } sw.Close(); @@ -104,8 +134,6 @@ private void ListOpenSearchEngineExtensions() { } private void ListOutputFormat() { - // Config log - ConfigureLog(); // Initialize the output stream Stream outputStream = InitializeOutputStream(); @@ -154,10 +182,10 @@ private void ProcessQuery() { while (totalResults > 0) { - parametersNvc = ResolveParameters(parameters, entity, outputFormatArg); + parametersNvc = ResolveParameters(parameters, entity); // Perform the query - osr = QueryOpenSearch(ose, entity, parametersNvc, outputFormatArg); + osr = QueryOpenSearch(ose, entity, parametersNvc); // Transform the result OutputResult(osr, outputStream); @@ -180,7 +208,7 @@ private void ProcessQuery() { public static bool GetArgs(string[] args) { if (args.Length == 0) return false; - + int argpos = 0; while (argpos < args.Length) { switch (args[argpos]) { @@ -198,7 +226,7 @@ public static bool GetArgs(string[] args) { case "-f": case "--format": if (argpos < args.Length - 1) { - outputFormatArg = args[++argpos]; + queryFormatArg = args[++argpos]; } else return false; break; @@ -225,7 +253,7 @@ public static bool GetArgs(string[] args) { case "--list-osee": listOsee = true; break; - + default: if (baseUrlArg == null) { baseUrlArg = args[argpos].Split(',').ToList(); @@ -251,8 +279,8 @@ public static void PrintUsage() { Console.Error.WriteLine(" -p/--parameter Specify a parameter for the query"); Console.Error.WriteLine(" -o/--output Write output to instead of stdout"); - Console.Error.WriteLine(" -f/--format Specify the output format of the query. Format available can be listed with --list-osee."); - Console.Error.WriteLine(" Default: Atom"); + Console.Error.WriteLine(" -f/--format Specify the format of the query. Format available can be listed with --list-osee."); + Console.Error.WriteLine(" By default, the client is automatic and uses the best format."); Console.Error.WriteLine(" -to/--time-out Specify query timeout (millisecond)"); Console.Error.WriteLine(" --pagination Specify the pagination number for search loops. Default: 20"); Console.Error.WriteLine(" --list-osee List the OpenSearch Engine Extensions"); @@ -331,7 +359,7 @@ private Stream InitializeOutputStream() { /// Base URL. /// Parameters nvc. Uri PrepareQueryUrl(Uri baseUrl, NameValueCollection parametersNvc) { - + throw new NotImplementedException(); } @@ -346,7 +374,7 @@ NameValueCollection PrepareQueryParameters() { // if martch is successful if (matchParamDef.Success) { // TODO filter and convert query param - if (matchParamDef.Groups[1].Value == "count" ){ + if (matchParamDef.Groups[1].Value == "count") { if (matchParamDef.Groups[2].Value == "unlimited") { nvc.Add(matchParamDef.Groups[1].Value, pagination.ToString()); totalResults = int.MaxValue; @@ -361,7 +389,7 @@ NameValueCollection PrepareQueryParameters() { nvc.Add(matchParamDef.Groups[1].Value, matchParamDef.Groups[2].Value); } - + } if (totalResults == 0) { @@ -372,9 +400,9 @@ NameValueCollection PrepareQueryParameters() { return nvc; } - private IOpenSearchResult QueryOpenSearch(OpenSearchEngine ose, IOpenSearchable entity, NameValueCollection parameters, string type) { + private IOpenSearchResult QueryOpenSearch(OpenSearchEngine ose, IOpenSearchable entity, NameValueCollection parameters) { - IOpenSearchResult osr = ose.Query(entity, parameters, type); + IOpenSearchResult osr = ose.Query(entity, parameters); return osr; @@ -388,10 +416,9 @@ void ListFormat(Stream outputStream) { void OutputResult(IOpenSearchResult osr, Stream outputStream) { - + StreamWriter sw = new StreamWriter(outputStream); if (metadataPaths == null) { - StreamWriter sw = new StreamWriter(outputStream); if (osr.Result is IOpenSearchResultCollection) { IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; rc.Items.FirstOrDefault(i => { @@ -407,84 +434,72 @@ void OutputResult(IOpenSearchResult osr, Stream outputStream) { sw.Flush(); } - if (osr.Result is SyndicationFeed) { - SyndicationFeed feed = (SyndicationFeed)osr.Result; - foreach (SyndicationItem item in feed.Items) { - sw.WriteLine(item.Id); - } + return; + } + + if (metadataPaths[0] == "enclosure") { + if (osr.Result is IOpenSearchResultCollection) { + IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; + rc.Items.FirstOrDefault(i => { + i.Links.FirstOrDefault(l => { + if (l.RelationshipType == "enclosure") { + sw.WriteLine(l.Uri.ToString()); + return true; + } else + return false; + }); + return false; + }); sw.Flush(); } - } else { + return; + } - if (metadataPaths[0] == "{}") { - if (osr.Result is IOpenSearchResultCollection) { - IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; - rc.Serialize(outputStream); - } + if (metadataPaths[0] == "{}") { + if (osr.Result is IOpenSearchResultCollection) { + IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; + rc.SerializeToStream(outputStream); + } - if (osr.Result is SyndicationFeed) { - SyndicationFeed feed = (SyndicationFeed)osr.Result; - Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed); - XmlWriter xw = XmlWriter.Create(outputStream); - atomFormatter.WriteTo(xw); - xw.Flush(); - } - } else { - StreamWriter sw = new StreamWriter(outputStream); - - if (osr.Result is IOpenSearchResultCollection) { - IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; - foreach (IOpenSearchResultItem item in rc.Items) { - string sep = ""; - foreach (var path in metadataPaths) { - foreach (XmlNode node in item.ElementExtensions) { - XmlNamespaceManager xnsm = new XmlNamespaceManager(node.OwnerDocument.NameTable); - xnsm.AddNamespace("dclite4g", "http://xmlns.com/2008/dclite4g#"); - xnsm.AddNamespace("dct", "http://purl.org/dc/terms/"); - xnsm.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); - sw.Write(sep); - XmlNode noder = node.ParentNode.SelectSingleNode(path, xnsm); - if (noder != null) { - if (noder.NodeType == XmlNodeType.Attribute) - sw.Write(noder.Value); - else - sw.Write(noder.InnerText); - } - sep = "\t"; - } - } - sw.WriteLine(); - } - sw.Flush(); - } + if (osr.Result is SyndicationFeed) { + SyndicationFeed feed = (SyndicationFeed)osr.Result; + Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed); + XmlWriter xw = XmlWriter.Create(outputStream); + atomFormatter.WriteTo(xw); + xw.Flush(); + } + return; + } - if (osr.Result is SyndicationFeed) { - SyndicationFeed feed = (SyndicationFeed)osr.Result; - foreach (SyndicationItem item in feed.Items) { - foreach (SyndicationElementExtension ext in item.ElementExtensions) { - var reader = ext.GetReader(); - XmlDocument doc = new XmlDocument(); - doc.Load(reader); - XmlNamespaceManager xnsm = new XmlNamespaceManager(doc.NameTable); - string sep = ""; - foreach (var path in metadataPaths) { - sw.Write(sep); - XmlNode node = doc.SelectSingleNode(path, xnsm); - if (node.NodeType == XmlNodeType.Attribute) - sw.Write(node.Value); - else - sw.Write(node.InnerText); - sep = "\t"; - } - } + if (osr.Result is IOpenSearchResultCollection) { + IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; + foreach (IOpenSearchResultItem item in rc.Items) { + string sep = ""; + XmlDocument doc = new XmlDocument(); + doc.Load(item.ElementExtensions.GetReaderAtExtensionWrapper()); + foreach (var path in metadataPaths) { + XmlNamespaceManager xnsm = new XmlNamespaceManager(doc.NameTable); + xnsm.AddNamespace("dclite4g", "http://xmlns.com/2008/dclite4g#"); + xnsm.AddNamespace("dct", "http://purl.org/dc/terms/"); + xnsm.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); + sw.Write(sep); + XmlNode noder = doc.SelectSingleNode(path, xnsm); + if (noder != null) { + if (noder.NodeType == XmlNodeType.Attribute) + sw.Write(noder.Value); + else + sw.Write(noder.InnerText); } - sw.Flush(); + sep = "\t"; } + sw.WriteLine(); } - + sw.Flush(); } + return; + } void SerializeXmlDocument(XmlDocument xmlDocument, Stream outputStream) { @@ -492,10 +507,9 @@ void SerializeXmlDocument(XmlDocument xmlDocument, Stream outputStream) { serializer.Serialize(outputStream, xmlDocument); } - NameValueCollection ResolveParameters(NameValueCollection nameValueCollection, IOpenSearchable entity, string resultName) { + NameValueCollection ResolveParameters(NameValueCollection nameValueCollection, IOpenSearchable entity) { - Type resultType = ose.GetTypeByExtensionName(resultName); - string contentType = entity.GetTransformFunction(ose, resultType).Item1; + string contentType = entity.DefaultMimeType; NameValueCollection osdParam = entity.GetOpenSearchParameters(contentType); NameValueCollection osdRevParams = OpenSearchFactory.ReverseTemplateOpenSearchParameters(osdParam); @@ -504,7 +518,7 @@ NameValueCollection ResolveParameters(NameValueCollection nameValueCollection, I foreach (string key in nameValueCollection.AllKeys) { if (osdRevParams[key] != null) { - foreach ( var id in osdRevParams.GetValues(key) ) + foreach (var id in osdRevParams.GetValues(key)) parameters.Set(id, nameValueCollection[key]); } else { parameters.Set(key, nameValueCollection[key]); @@ -517,7 +531,7 @@ NameValueCollection ResolveParameters(NameValueCollection nameValueCollection, I int CountResults(IOpenSearchResult osr) { if (osr.Result is IOpenSearchResultCollection) { IOpenSearchResultCollection rc = (IOpenSearchResultCollection)osr.Result; - return rc.Items.Count; + return rc.Items.Count(); } if (osr.Result is SyndicationFeed) { @@ -527,6 +541,7 @@ int CountResults(IOpenSearchResult osr) { return 0; } + } } diff --git a/Terradue.OpenSearch.Client/Terradue/Air/OpenSearchResultFilters.cs b/Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchResultFilters.cs similarity index 100% rename from Terradue.OpenSearch.Client/Terradue/Air/OpenSearchResultFilters.cs rename to Terradue.OpenSearch.Client/Terradue/OpenSearch/Client/OpenSearchResultFilters.cs diff --git a/Terradue.OpenSearch.Client/packages.config b/Terradue.OpenSearch.Client/packages.config index 85931ea9..fa30d293 100644 --- a/Terradue.OpenSearch.Client/packages.config +++ b/Terradue.OpenSearch.Client/packages.config @@ -3,4 +3,8 @@ + + + + \ No newline at end of file