#Region "Microsoft.VisualBasic::22586192046998227a38d880c5be5068, LINQ\RQL\Repository\LinqAPI.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see .
' /********************************************************************************/
' Summaries:
' Class LinqAPI
'
' Properties: Repository
'
' Constructor: (+1 Overloads) Sub New
' Function: Free, MoveNext, OpenQuery
'
'
' /********************************************************************************/
#End Region
Imports System.Collections.Specialized
Imports Microsoft.VisualBasic.Net
Imports Microsoft.VisualBasic.Scripting.Runtime
Imports Microsoft.VisualBasic.SecurityString.MD5Hash
Imports Microsoft.VisualBasic.Serialization.JSON
Imports sciBASIC.ComputingServices.TaskHost
Namespace Linq
'''
''' 对外部提供Linq查询服务的WebApp
'''
Public Class LinqAPI : Inherits LinqPool
Public ReadOnly Property Repository As Repository
'''
''' {hashCode.tolower, linq_uid}
'''
ReadOnly __uidMaps As New Dictionary(Of String, String)
Sub New(repo As Repository)
Me.Repository = repo
End Sub
'''
'''
'''
''' 数据源的引用位置
''' 查询参数
'''
Public Overloads Function OpenQuery(url As String, args As String) As LinqEntry
Dim source As IEnumerable = Repository.GetRepository(url, args) ' expr为空的话,则没有where测试,则返回所有数据
Dim type As Type = Repository.GetType(url) ' 得到元素的类型信息
Dim linq As IPEndPoint = OpenQuery(source, type)
Dim result As New LinqEntry(type) With {
.Linq = linq,
.uid = (linq.ToString & Now.ToString).GetMd5Hash.ToLower
}
Call __uidMaps.Add(result.uid, result.Linq.ToString)
Return result
End Function
'''
''' Linq数据源的MD5哈希值
'''
Const uid As String = "uid"
Const n As String = "n"
'''
'''
'''
''' uid,n
'''
Public Function MoveNext(args As NameValueCollection) As String
Dim uid As String = args(LinqAPI.uid)
Dim n As Integer = CastInteger(args(LinqAPI.n))
Dim linq As LinqProvider = GetLinq(__uidMaps(uid))
Dim source As Object = linq.Moves(n)
Dim json As String = JsonContract.GetObjectJson(source, linq.BaseType)
Return json
End Function
'''
''' 释放掉一个Linq查询的资源
'''
'''
'''
Public Overloads Function Free(args As NameValueCollection) As String
Dim uid As String = args(LinqAPI.uid)
Call MyBase.Free(__uidMaps(uid))
Call __uidMaps.Remove(uid)
Return True
End Function
End Class
End Namespace