我必须开发一个程序,它在本地PC上作为服务运行,为服务器提供几个用户状态.一开始我必须检测用户登录和注销.
我的想法是使用ManagementEventWatcher该类并查询Win32_LogonSession是否有更改的通知.
我的第一个测试运行良好,这是代码部分(这将作为服务的线程执行):
private readonly static WqlEventQuery qLgi = new WqlEventQuery("__InstanceCreationEvent", new TimeSpan(0, 0, 1), "TargetInstance ISA \"Win32_LogonSession\"");
public EventWatcherUser() {
}
public void DoWork() {
ManagementEventWatcher eLgiWatcher = new ManagementEventWatcher(EventWatcherUser.qLgi);
eLgiWatcher.EventArrived += new EventArrivedEventHandler(HandleEvent);
eLgiWatcher.Start();
}
private void HandleEvent(object sender, EventArrivedEventArgs e)
{
ManagementBaseObject f = (ManagementBaseObject)e.NewEvent["TargetInstance"];
using (StreamWriter fs = new StreamWriter("C:\\status.log", true))
{
fs.WriteLine(f.Properties["LogonId"].Value);
}
}
Run Code Online (Sandbox Code Playgroud)
但我有一些理解问题,我不确定这是否是解决该任务的常用方法.
如果我查询Win32_LogonSession我得到几个与同一用户相关联的记录.例如,我得到这个ID 7580798和7580829,如果我查询
ASSOCIATORS OF {Win32_LogonSession.LogonId = X} WHERE …
我阅读并测试了很多,以找到加密和部署app.config到不同机器的最佳实践.通常,我希望保护来自第三方的连接字符串的内容,并将应用程序部署到不同的计算机上.我不会手动配置每台机器.
我知道有几种方式:
Aspnet_Regiis(RSAProtectedConfigurationProvider,DPAPIProtectedConfigurationProvider)绑定到计算机,用户或自定义.RSA加密密钥.
System.Security.Cryptography.ProtectedData 绑定到机器或用户.
app.config在第一次执行时加密.哪个不安全.
您建议什么或app.config通过设置或复制和粘贴来加密和向不同机器提供应用程序的最佳做法是什么?
我想在我的Javascript代码中添加一个小骰子滚动效果.我认为一个好方法是使用该setInterval()方法.我的想法是遵循代码(仅用于测试):
function roleDice() {
var i = Math.floor((Math.random() * 25) + 5);
var j = i;
var test = setInterval(function(){
i--;
document.getElementById("dice").src = "./images/dice/dice" + Math.floor((Math.random() * 6) + 1) + ".png";
if(i < 1) {
clearInterval(test);
}
}, 50);
}
Run Code Online (Sandbox Code Playgroud)
现在我想等待setInterval,直到完成.所以我添加了一个setTimeout.
setTimeout(function(){alert("test")}, (j + 1) * 50);
Run Code Online (Sandbox Code Playgroud)
这段代码工作得很好.但在我的主代码中,该roleDice()函数返回一个值.现在我不知道我怎么能处理那个...我无法从那里回来setTimeout().如果我在函数末尾添加一个返回值,则返回将提升为快速.有没有人有想法,我怎么能解决这个问题?
编辑 嗯,好吧,我明白回调剂量是什么,我想我知道它是如何工作的,但我仍然有问题.我认为这更像是一个"界面"问题......我的代码:
function startAnimation(playername, callback) {
var i = Math.floor((Math.random() * 25) + 5);
var int = setInterval(function() {
i--;
var number = Math.floor((Math.random() * …Run Code Online (Sandbox Code Playgroud) 我在这里有一个小问题,动态生成按钮及其在asp.net中的事件处理程序.我为特殊用户生成一个带有附加按钮的灵活表.按钮将动态生成,工作正常.但我不能让事件处理程序工作.
以下是我的代码中的一些部分:构建按钮(在自己的函数中).
…
Button ButtonChange = new Button();
ButtonChange.Text = "Change";
ButtonChange.ID = "change_" + i.ToString();
ButtonChange.Font.Size = FontUnit.Point(7);
ButtonChange.ControlStyle.CssClass = "button";
ButtonChange.Click += new EventHandler(test);
…
Run Code Online (Sandbox Code Playgroud)
和
void test(object sender, EventArgs e)
{
// Do some stuff
}
Run Code Online (Sandbox Code Playgroud)
我Page_Load是空的.
但是,如果我点击按钮,程序将不会跳转到测试.出了什么问题?
编辑!!! 问题是我一开始不知道从sql查询中得到多少行.对于每一行,我将添加删除和更改按钮.我在我的程序中调用了一个将结果构建为表的方法.在这个方法中,我检查当前用户是否是AdminUser,如果是,我将调用buildAdminButtons函数.在这里,我为每一行创建一个新列中的按钮.我怎么能在OnLoad中得到这个?
private void buildAdminButtons(TableRow tempRow, int i)
{
Button ButtonDelete = new Button();
Button ButtonChange = new Button();
TableCell change = new TableCell();
TableCell delete = new TableCell();
ButtonChange.Text = "Change";
ButtonChange.ID = "change_" + i.ToString(); …Run Code Online (Sandbox Code Playgroud) 我想更改JIRA的通知行为,并为某些问题事件添加其他接收器.我知道我可以注册EventPublisher并捕获所有必要的事件.
public class MyIssueCreatedResolvedListenerImpl implements InitializingBean, DisposableBean {
private final EventPublisher eventPublisher;
public MyIssueCreatedResolvedListenerImpl(EventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
@Override
public void afterPropertiesSet() throws Exception {
eventPublisher.register(this);
}
@Override
public void destroy() throws Exception {
eventPublisher.unregister(this);
}
@EventListener
public void onIssueEvent(IssueEvent issueEvent) {
// Process the issue events. I'm using the code presented below.
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,onIssueEvent我想重用JIRA中现有的电子邮件模板,并将它们与SMTPMailServer对象一起发送给其他接收者.目前我正在使用以下代码来读取和填充速度模板.
ApplicationProperties ap = ComponentAccessor.getApplicationProperties();
String baseUrl = ap.getString(APKeys.JIRA_BASEURL);
String webworkEncoding = ap.getString(APKeys.JIRA_WEBWORK_ENCODING);
VelocityManager vm = ComponentAccessor.getVelocityManager(); …Run Code Online (Sandbox Code Playgroud) 我使用文档中的模板创建了一个 Identity 4 应用程序服务器。我定义数据库最初将填充 2 个标准用户。但是,当我尝试使用任何以前创建的用户登录时,页面会刷新并且没有任何反应。所以我调试了它,看起来这部分返回 null,而它应该返回用户数据。
代码:
var context = await _interaction.GetAuthorizationContextAsync(returnUrl);。
存在于
_IIdentityServerInteractionService 的交互依赖注入 returnUrl = "/grants";
我想创建一个小函数,它应该在控制台中以百分比显示当前状态.该函数应仅显示行中的当前值.所以我必须删除最后一个输出.那可能吗?最好的情况是一些ANSI C的东西,该程序应该适用于Linux和Windows.
我找到了一些类似的转义序列"\033[J",但它不起作用.
编辑
好吧,我尝试过:
void PrintProcessBar(int i, int n) {
float ratio = i / (float)n;
printf("%.3d\b\b", (int)(ratio * 100));
fflush(stdout);
}
Run Code Online (Sandbox Code Playgroud)
但它只打印了很多零...出了什么问题?如果我用三个,\b我什么也得不到.
解
float ratio = (i / (float)n) * 100;
printf("\b\b\b\b");
fflush(stdout);
printf("%.3d%c", (int)ratio, 37);
fflush(stdout);
Run Code Online (Sandbox Code Playgroud)
i =当前位置.n =最大运行.
我使用4 \b因为,在第一次调用函数时它将删除4个空格.
格尔茨.
我对mssql的数据库查询有一个恼人的问题.如果结果包含像德语'ä'这样的特殊字符,我就不能使用json_encode将结果正确地作为json.
json_last_error返回5,等于JSON_ERROR_UTF8.我猜数据库不会返回UTF-8编码的值.数据库集合是*Latin1_General_CI_AS*,受影响的列是varchars.
php mssql.charset配置无效.
我读过mysql用户可以用来mysql_query('SET CHARACTER SET utf8');正确编码返回值.我该怎么做才能正确获取mssql的值?
提示 - 我无法更改数据库中的任何内容.
我有一个小程序,它能够在运行时加载组件.我想为这些组件编写一个小API.主程序应该识别组件中的属性,并为每个属性创建一个swing组件.我的想法是使用注释,例如:
@Property(name = "X", PropertyType.Textfield, description = "Value for X")
private int x;
Run Code Online (Sandbox Code Playgroud)
你怎么看待这件事?有什么问题吗?是否有类似的实施或其他选择?感谢您的所有建议和提示!
更新 请注意,我无法使用第三方库.
更新 我想创建一个抽象类,它能够根据Conceet类的属性创建swing组件.抽象类控制演示文稿.例如(伪代码):
public class A {
/**
* Create swing component based on the concret class
* In this example class A should create a jTextField with a jLable "Cities". So I have not to create each component manuel,
* If the text field changed the attribute for cities should set (My idea was with propertyChangesSupport).
*/
}
public class B extends A { …Run Code Online (Sandbox Code Playgroud) 我想通过本机 java 接口调用一个方法,该接口返回一个对象。
这是我的本地方法
public native Node getProjectionPoint(double lat, double lon);
Run Code Online (Sandbox Code Playgroud)
节点类
public class Node {
private String id;
private double latitude;
private double longitude;
}
Run Code Online (Sandbox Code Playgroud)
C头文件
JNIEXPORT jobject JNICALL Java_org_smartcar_serverdatainterface_shared_services_CppConnector_getProjectionPoint (JNIEnv *env, jobject obj, jdouble lat, jdouble lon);
Run Code Online (Sandbox Code Playgroud)
我如何创建一个对象并将其返回给java?
c# ×4
java ×3
asp.net ×2
.net ×1
annotations ×1
asp.net-core ×1
button ×1
c ×1
c++ ×1
console ×1
dynamic ×1
email ×1
encryption ×1
events ×1
identity ×1
javascript ×1
jira ×1
json ×1
logoff ×1
php ×1
printf ×1
select ×1
setinterval ×1
settimeout ×1
sql-server ×1
swing ×1
templates ×1
velocity ×1
wait ×1