寻找特定标签
Looking for a specific tag
我有一个 regarding a way to access a proxy card from within a web page when using Chrome. I'm now attempting to instead use a vb.Net application with an embedded CefSharp object. I have the code I need to access the proxy card (thanks to Smart Card API),但我需要一种简单的方法来表明这甚至是一个选项。我的想法是:
- 在网页上放置一个空元素(例如
<div id='smartcard' />
)
- 在 Visual Basic 中,为此
<div />
监视页面内容
- 如果找到
<div />
,请确保检测到卡 reader。如果是这样,请在其内容中添加一些文本(可能还有图像),表明可以扫描该卡
- 检测到卡片扫描后,将卡片中的值放入表单元素中,然后POST它
在我看来,我可能不得不使用 JavaScript 和 vb.net 代码的某种组合,但我对 CefSharp 太陌生了,我真的不知道在哪里开始。
在此先感谢您的帮助。
不是 C# 程序员,我查看了 CardWerk 上关于 General Usage guide many times and still didn't really understand it. That said, I think I've been able to get this project off the ground. In addition to the CefSharp project, I'm also using the non-free Smart Card API 的信息。
下面是我所做的一些片段。
VB.Net
Imports CefSharp
Imports Subsembly ' For the SmartCard namespace
Class MainWindow
Private WithEvents CardManager As SmartCard.CardTerminalManager
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
browser.Address = "https://jake-dev7.local/trainingmatrix/"
Debug.Print(SmartCard.SMARTCARDAPI.API_VERSION)
CardManager = SmartCard.CardTerminalManager.Singleton
CardManager.Startup(True)
End Sub
Private Sub browser_LoadingStateChanged(sender As Object, e As LoadingStateChangedEventArgs) Handles browser.LoadingStateChanged
Dim script As String
If Not e.IsLoading Then
If CardManager.SlotCount Then
script = "if ($('#proxcard').length) { proxcard_init() }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End If
End Sub
Protected Sub InsertedEvent(ByVal aSender As Object, ByVal aEventArgs As SmartCard.CardTerminalEventArgs) Handles CardManager.CardInsertedEvent
Dim aCard As SmartCard.CardHandle
Dim nActivationResult As SmartCard.CardActivationResult
Dim iFacilityCode As Integer
Dim iCardID As Integer
' There's a bunch of code here taken from the sample code that came
' with the SmartCard API from CardWerk to pull the facility code and
' card id out of the prox card.
If iFacilityCode <> 0 And iCardID <> 0 Then
Dim script As String
script = "if ($('#proxcard').length) { proxcard_scan(" & iFacilityCode & ", " & iCardID & ") }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End Sub
End Class
JavaScript
(这是在网页加载的.js
文件中。此页面也可以在Chrome、Firefox、IE等中加载,这些功能永远不会运行 这使得此实用程序可用于没有自定义 .exe
和卡 reader) 的计算机。
// These proxcard_* functions are called via our parent application
// (CefSharp object embeded in a vb.Net assembly)
function proxcard_init() {
$('#proxcard').html("<div class='or'>- OR -</div><div><img src='proxcard.jpg'><br>Scan your card</div>");
}
function proxcard_scan(facilityID, cardID) {
var vars = {
facilityID: facilityID,
cardID: cardID
};
if ($('form#adduser').length) {
// We're on the add user page. Check to see if this card matches somebody.
$.post('httprequest.php?type=get-emp-from-prox', vars, function(data) {
if (data && data.number) {
// Update UI and backend form fields. If everything validates, submit the form
} else {
// Clear UI and backend form fields that pertain to user ID
alert('Card not found');
}
}, 'json');
} else if ($('form#update').length) {
// Deal with the update form
}
}
在我的实际代码中,我有多个 else if
语句来处理允许扫描卡片的不同表单。它们不包括在内,以防止失控 :)。
请注意:这并不是整个项目或使用 CefSharp 处理代理卡所需的所有代码。我希望这足以帮助其他人。
我有一个
- 在网页上放置一个空元素(例如
<div id='smartcard' />
) - 在 Visual Basic 中,为此
<div />
监视页面内容- 如果找到
<div />
,请确保检测到卡 reader。如果是这样,请在其内容中添加一些文本(可能还有图像),表明可以扫描该卡 - 检测到卡片扫描后,将卡片中的值放入表单元素中,然后POST它
- 如果找到
在我看来,我可能不得不使用 JavaScript 和 vb.net 代码的某种组合,但我对 CefSharp 太陌生了,我真的不知道在哪里开始。
在此先感谢您的帮助。
不是 C# 程序员,我查看了 CardWerk 上关于 General Usage guide many times and still didn't really understand it. That said, I think I've been able to get this project off the ground. In addition to the CefSharp project, I'm also using the non-free Smart Card API 的信息。
下面是我所做的一些片段。
VB.Net
Imports CefSharp
Imports Subsembly ' For the SmartCard namespace
Class MainWindow
Private WithEvents CardManager As SmartCard.CardTerminalManager
Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
browser.Address = "https://jake-dev7.local/trainingmatrix/"
Debug.Print(SmartCard.SMARTCARDAPI.API_VERSION)
CardManager = SmartCard.CardTerminalManager.Singleton
CardManager.Startup(True)
End Sub
Private Sub browser_LoadingStateChanged(sender As Object, e As LoadingStateChangedEventArgs) Handles browser.LoadingStateChanged
Dim script As String
If Not e.IsLoading Then
If CardManager.SlotCount Then
script = "if ($('#proxcard').length) { proxcard_init() }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End If
End Sub
Protected Sub InsertedEvent(ByVal aSender As Object, ByVal aEventArgs As SmartCard.CardTerminalEventArgs) Handles CardManager.CardInsertedEvent
Dim aCard As SmartCard.CardHandle
Dim nActivationResult As SmartCard.CardActivationResult
Dim iFacilityCode As Integer
Dim iCardID As Integer
' There's a bunch of code here taken from the sample code that came
' with the SmartCard API from CardWerk to pull the facility code and
' card id out of the prox card.
If iFacilityCode <> 0 And iCardID <> 0 Then
Dim script As String
script = "if ($('#proxcard').length) { proxcard_scan(" & iFacilityCode & ", " & iCardID & ") }"
browser.GetMainFrame().ExecuteJavaScriptAsync(script)
End If
End Sub
End Class
JavaScript
(这是在网页加载的.js
文件中。此页面也可以在Chrome、Firefox、IE等中加载,这些功能永远不会运行 这使得此实用程序可用于没有自定义 .exe
和卡 reader) 的计算机。
// These proxcard_* functions are called via our parent application
// (CefSharp object embeded in a vb.Net assembly)
function proxcard_init() {
$('#proxcard').html("<div class='or'>- OR -</div><div><img src='proxcard.jpg'><br>Scan your card</div>");
}
function proxcard_scan(facilityID, cardID) {
var vars = {
facilityID: facilityID,
cardID: cardID
};
if ($('form#adduser').length) {
// We're on the add user page. Check to see if this card matches somebody.
$.post('httprequest.php?type=get-emp-from-prox', vars, function(data) {
if (data && data.number) {
// Update UI and backend form fields. If everything validates, submit the form
} else {
// Clear UI and backend form fields that pertain to user ID
alert('Card not found');
}
}, 'json');
} else if ($('form#update').length) {
// Deal with the update form
}
}
在我的实际代码中,我有多个 else if
语句来处理允许扫描卡片的不同表单。它们不包括在内,以防止失控 :)。
请注意:这并不是整个项目或使用 CefSharp 处理代理卡所需的所有代码。我希望这足以帮助其他人。