我有MyItem类有3个属性如下:
class MyItem
{
private string _name;
private int _value
private DateTime _TimeStamp;
public MyItem(string name, int value, string timeStamp)
{
this._name = name;
this._value = value;
this._timeStamp = DateTime.Parse(timeStamp);
}
public string Name
{ get {return this_name; } }
public int Value
{ get {return this._value; } }
public DateTime TimeStamp
{ get {return this._timeStamp; } }
// ...
}
Run Code Online (Sandbox Code Playgroud)
我也有一个MyItem列表如下:
var myItems = new List<MyItem>() {
new MyItem("A", 123, "23/02/2012"),
new MyItem("A", 323, "22/02/2012"),
new MyItem("B", 432, "23/02/2012"), …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码向我的SQLite db文件编写自定义PRAGMA:
using (var db = GetNewConnection())
{
var version = "1234";
var query = string.Format("PRAGMA user_version={0}", version);
db.ExecuteSql(query);
}
Run Code Online (Sandbox Code Playgroud)
哪个成功地将PRAGMA写入文件,我可以通过执行以下命令使用SQLite Expert或LINQPad来检查:
PRAGMA user_version
Run Code Online (Sandbox Code Playgroud)
但是如何使用OrmLite v3.9.71从DB文件中读取PRAGMA的值?
我已经尝试过以下但它无法解析SQL,因为它无法找到"FROM":
db.Select<object>("PRAGMA user_version");
Run Code Online (Sandbox Code Playgroud)
我也试过以下,没有一个工作:
db.Select<dynamic>("PRAGMA user_version");
db.Select<string>("PRAGMA user_version");
db.Select<int>("PRAGMA user_version");
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
鉴于 WMI仅适用于Windows ,并且Linux和Mac等操作系统没有注册表,如何获取.NET Core中的处理器名称?
我打算使以下方法(使用注册表)跨平台:
private static string GetProcessorName()
{
var key = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DESCRIPTION\System\CentralProcessor\0\");
return key?.GetValue("ProcessorNameString").ToString() ?? "Not Found";
}
Run Code Online (Sandbox Code Playgroud)
您可以假设我可以在运行时知道我正在运行什么操作系统。
我有以下javascript对象:
Person1.Name = "John";
Person1.Age = 12;
Person2.Name = "Joe";
Person2.Age = 5;
Run Code Online (Sandbox Code Playgroud)
然后我有一系列的人,如何根据人的年龄找到最小/最大?
Javascript或Jquery中的任何解决方案都是可以接受的.
非常感谢您的帮助.
我有 3 个课程,如下所示:
public class A
{
public string Id {get; set;}
public string Name {get; set;}
public string Age {get; set;}
public bool IsEmployed {get; set;}
public int RoleId {get; set;}
}
public class B
{
public string Id {get; set;}
public string Name {get; set;}
public string Age {get; set;}
public int RoleId {get; set;}
}
public class Roles
{
public int Id {get; set;}
public string RoleName {get; set;}
...
}
Run Code Online (Sandbox Code Playgroud)
假设这些类在 DBMS 上有自己的表。
我目前有一个 SQL 查询,我想用 …
我有一个总是被阻止的任务,我有一个 CancellationToken 传递给它,用于取消任务。然而,设置为在任务取消时执行的继续任务永远不会执行。代码是:
_tokenSrc = new CancellationTokenSource();
var cnlToken = _tokenSrc.Token;
Task.Run(() =>
// _stream.StartStream() blocks forever
_stream.StartStream(), cnlToken)
.ContinueWith(ant =>
{
_logger.Warn("Stream task cancellation requested, stopping the stream");
_stream.StopStream();
_stream = null;
_logger.Warn("Stream stopped and task cancelled");
}, TaskContinuationOptions.OnlyOnCanceled);
Run Code Online (Sandbox Code Playgroud)
稍后在代码中的其他地方......
_tokenSrc.Cancel();
Run Code Online (Sandbox Code Playgroud)
我不得不为 _stream.StartStream() 使用 Task 的原因是这个调用永远阻塞(一个我无法控制的 api,请注意 _stream 指的是一个第三方 Api,它从 web 服务流数据)所以我不得不调用它在另一个线程上。
取消任务的最佳方法是什么?
我们有一个服务于Aurelia静态文件和API的Web服务器,服务器受NTLM保护(在OWIN上使用集成Windows身份验证).
使用Aurelia Fetch Client时,我们可以成功点击API而不会出现问题.这是我们使用的配置:
constructor(private http: HttpClient){
http.configure(config => {
config
.withBaseUrl('api/')
.useStandardConfiguration();
});
Run Code Online (Sandbox Code Playgroud)
但是,当我们使用Aurelia Fetch Client时,我们得到了401 (Unauthorized)(似乎缺少授权标头)
constructor(private client: HttpClient) {
client.configure(cfg => {
cfg
.withBaseUrl('http://localhost:80/api/someEndpoint')
.withDefaults({
headers: {
'Accept' : 'application/json',
'X-Requested-With': 'Fetch'
}
})
Run Code Online (Sandbox Code Playgroud)
关于如何解决这个问题的任何想法都非常感谢.
aurelia aurelia-fetch-client aurelia-http-client aurelia-framework
我正在研究Aurelia Sample应用程序,并希望将构建输出(vendor-bundle.js和app-bundle.js)部署到www-root\scripts默认scripts目录而不是默认目录.所以我尝试修改aurelia.json看起来像:
...
"testFramework": {
"id": "jasmine",
"displayName": "Jasmine"
},
"build": {
"targets": [
{
"id": "web",
"displayName": "Web",
"output": "www-root\\scripts"
}
],
"loader": {
...
Run Code Online (Sandbox Code Playgroud)
这确实导致捆绑文件输出到,www-root\scripts但是因为我为我的apllication 定义了HTTP.SYS别名,例如登陆URL是:http:// localhost/MyAlias /当我尝试浏览它试图加载的应用程序时app-bundle.js来自:http://localhost/MyAlias/www-root/scripts/app-bundle.js而不是http://localhost/MyAlias/scripts/app-bundle.js.
但是,vendor-bundle.js可以从以下位置正确下载:http://localhost/MyAlias/scripts/vendor-bundle.js
我无法找出要修改的内容,以便从正确的路径获取app-bundle.js.
很感谢任何形式的帮助.
我有以下代码:
static void Main(string[] args)
{
const string RegXPattern = @"/api/(?<controller>\w+)/(?<action>\w+)/?$";
var regex = new Regex(RegXPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
const string InputToMatch = "/api/person/load";
regex.IsMatch(InputToMatch); // Warmup
var sw = Stopwatch.StartNew();
for (int i = 0; i < 10000000; i++)
{
var match = regex.IsMatch(InputToMatch);
}
sw.Stop();
Console.WriteLine(sw.Elapsed.ToString());
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
在Releae下的我的机器上运行以上操作,在大约18秒内完成并移除RegexOptions.Compiled使其在13秒内运行.
我的理解是,包含此标志会使匹配更快,但在我的示例中,它会导致性能降低约30%.
我在这里错过了什么?
我有一个已由des.exe加密的文件。
\n\n可以使用以下命令对文件进行加密和解密:
\n\ndes -E -k "foo" sample.txt sample.txt.enc\ndes -D -k "foo" sample.txt.enc sample.txt.dec\nRun Code Online (Sandbox Code Playgroud)\n\n我尝试使用以下方法解密:
\n\npublic byte[] Decrypt(FileInfo file, string key)\n{\n byte[] keyAsBytes = LibDesPasswordConvertor.PasswordToKey(key);\n byte[] initializationVector = keyAsBytes;\n\n var cryptoProvider = new DESCryptoServiceProvider(); \n cryptoProvider.Mode = CipherMode.CBC;\n cryptoProvider.Padding = PaddingMode.None; \n\n using (FileStream fs = file.OpenRead())\n using (var memStream = new MemoryStream())\n using (var decryptor = cryptoProvider.CreateDecryptor(keyAsBytes, initializationVector))\n using (var cryptoStream = new CryptoStream(memStream, decryptor, CryptoStreamMode.Write))\n {\n fs.CopyTo(cryptoStream);\n fs.Flush();\n cryptoStream.FlushFinalBlock();\n\n return memStream.ToArray();\n }\n}\n\npublic static …Run Code Online (Sandbox Code Playgroud) c# ×7
.net ×4
aurelia ×2
linq ×2
.net-core ×1
aurelia-cli ×1
cryptography ×1
des ×1
encryption ×1
javascript ×1
jquery ×1
performance ×1
regex ×1
sqlite ×1