diff --git a/LINQ/TestMain/Module1.vb b/LINQ/TestMain/Module1.vb index ae852ea..e609fbb 100644 --- a/LINQ/TestMain/Module1.vb +++ b/LINQ/TestMain/Module1.vb @@ -9,6 +9,9 @@ Module Module1 Sub Main() + Dim svr As New RQL.RESTProvider + Call svr.Run() + Dim stststs = LDM.Statements.LinqStatement.TryParse( _ _ "From x As Integer In ""E:\Microsoft.VisualBasic.Parallel\trunk\LINQ\ints.txt"" Let add = x + 50 Where add > 0 Let cc = add ^ 2 let abc as double = cc mod 99 +11.025R Select abc, cc, x, add, nn = cc+ x/ add * 22 mod 5, gg = math.max(cc,add)") diff --git a/LINQ/TestMain/TestMain.vbproj b/LINQ/TestMain/TestMain.vbproj index bd045c6..6278f1a 100644 --- a/LINQ/TestMain/TestMain.vbproj +++ b/LINQ/TestMain/TestMain.vbproj @@ -150,6 +150,14 @@ {fecce1fd-e1d4-49e3-a668-60bb5e7aed99} +Microsoft.VisualBasic.Architecture.Framework + + {fbfc1455-b232-4f16-afc7-4054a8b864ab} + SMRUCC.HTTPInternal + + + {bc922a27-9bc3-4e7e-be3d-55fc03fb4160} + RQL + {0a9b9fa6-e12d-48fd-b979-9f021a591e69} Linq diff --git a/RQL/LinqAPI.vb b/RQL/LinqAPI.vb index dfef2d7..9db1b7b 100644 --- a/RQL/LinqAPI.vb +++ b/RQL/LinqAPI.vb @@ -1,4 +1,5 @@ Imports Microsoft.VisualBasic.CommandLine.Reflection +Imports Microsoft.VisualBasic.ComputingServices.TaskHost Imports SMRUCC.HTTPInternal.AppEngine Imports SMRUCC.HTTPInternal.AppEngine.APIMethods Imports SMRUCC.HTTPInternal.Platform @@ -6,33 +7,7 @@ Imports SMRUCC.HTTPInternal.Platform ''' ''' 对外部提供Linq查询服务的WebApp ''' -<[Namespace]("Linq")> -Public Class LinqAPI : Inherits WebApp +Public Class LinqAPI : Inherits LinqPool - Sub New(main As PlatformEngine) - Call MyBase.New(main) - End Sub - ''' - ''' 通过这个默认的API复写方法来执行linq查询的创建 - ''' - ''' - ''' - ''' - ''' - Public Function ExecLinq(uri As String, args As String, ByRef out As String) As Boolean - - End Function - - - <[GET](GetType(String))> - Public Function MoveNext(args As String) As String - - End Function - - Public Overrides Function Page404() As String - Return PlatformEngine.Page404 - End Function End Class diff --git a/RQL/RESTProvider.vb b/RQL/RESTProvider.vb index 3773f68..c9ba7a5 100644 --- a/RQL/RESTProvider.vb +++ b/RQL/RESTProvider.vb @@ -6,12 +6,12 @@ Imports Microsoft.VisualBasic.Serialization Imports SMRUCC.HTTPInternal.Core ''' -''' 在线查询服务提供模块 +''' 在线查询服务提供模块,在这个模块之中只负责进行url参数的解析工作 ''' Public Class RESTProvider : Inherits HttpServer Public ReadOnly Property Repository As Repository - Public ReadOnly Property LinqProvider As LinqPool = New LinqPool + Public ReadOnly Property LinqProvider As LinqAPI = New LinqAPI ''' ''' @@ -23,6 +23,10 @@ Public Class RESTProvider : Inherits HttpServer Me.Repository = repo End Sub + Sub New() + Call Me.New(80, RQL.Repository.LoadDefault) + End Sub + ''' ''' http://linq.gcmodeller.org/kegg/pathways?where=test_expr(pathway) ''' 测试条件里面的对象实例的标识符使用资源url里面的最后一个标识符为变量名 @@ -32,16 +36,26 @@ Public Class RESTProvider : Inherits HttpServer ''' ''' 返回一个网络终点IpEndPoint Public Overrides Sub handleGETRequest(p As HttpProcessor) + If p.IsWWWRoot Then + ' 返回帮助信息 + Else + Call __apiInvoke(p) + End If + End Sub + + Private Sub __apiInvoke(p As HttpProcessor) Dim url As String = p.http_url Dim pos As Integer = InStr(url, "?") Dim expr As String = "" If pos = 0 Then ' expr为空 Else - expr = Mid(url, pos + 1).Trim + expr = Mid(url, pos + 1).Trim ' 参数里面可能含有转意字符,还需要进行转意 + expr = expr.URLEscapes + url = Mid(url, 1, pos - 1) End If - Dim source = Repository.GetRepository(url, expr) ' expr为空的话,则没有where测试,则返回所有数据 + Dim source As IEnumerable = Repository.GetRepository(url, expr) ' expr为空的话,则没有where测试,则返回所有数据 Dim linq As IPEndPoint = LinqProvider.OpenQuery(source, Repository.GetType(url)) Call p.outputStream.WriteLine(linq.GetJson) End Sub diff --git a/RQL/Repository.vb b/RQL/Repository.vb index c091cb9..f1db74d 100644 --- a/RQL/Repository.vb +++ b/RQL/Repository.vb @@ -15,7 +15,7 @@ Public Class Repository : Implements ISaveHandle ''' {lower_case.url, type_info} ''' ''' - Public ReadOnly Property Models As Dictionary(Of String, EntityProvider) + Public Property Models As New Dictionary(Of String, EntityProvider) ReadOnly __types As TypeRegistry ReadOnly __api As APIProvider @@ -44,11 +44,20 @@ Public Class Repository : Implements ISaveHandle Return api.GetType End Function - Public Function LoadFile(url As String) As Repository - Return LoadJsonFile(Of Repository)(url) + Public Shared Function LoadFile(url As String) As Repository + Try + Return LoadJsonFile(Of Repository)(url) + Catch ex As Exception + ex = New Exception(url, ex) + Call App.LogException(ex) + + Dim __new As New Repository + Call __new.Save(url, Encodings.ASCII) + Return __new + End Try End Function - Public Function LoadDefault() As Repository + Public Shared Function LoadDefault() As Repository Return LoadFile(DefaultFile) End Function