在我们的主要产品中,我们已经有一个功能请求已经存在了几年,现在已经被要求了很多次.它在技术上易于实现,问题在于它将从根本上改变工具的概念,并且可能会导致更多错误报告,因为人们误用新功能来匹配新概念(我们将无法做到)解决方法).我们有一个单独的功能可以很好地解决这个问题,但我们仍然需要实现新的功能.
我们应该吗
我有一个包含大量标签的大型xhtml文档.我观察到一些未闭合的开头段落标签不必要地重复,我想删除它们或用空格替换它们.我只想编码识别未封闭的段落标签并删除它们.
这是一个小样本,以显示我的意思:
<p><strong>Company Registration No.1</strong> </p>
<p><strong>Company Registration No.2</strong></p>
<p> <!-- extra tag -->
<p> <!-- extra tag -->
<hr/>
<p><strong> HALL WOOD (LEEDS) LIMITED</strong><br/></p>
<p><strong>REPORT AND FINANCIAL STATEMENTS </strong></p>
Run Code Online (Sandbox Code Playgroud)
有人可以给我控制台应用程序的代码,只是为了删除这些未封闭的段落标签.
我正在尝试调试在windows phone 7模拟器中运行的应用程序,但我无法从visual studio连接到它 - Attach to Process- >选择Windows Phone 7 Emulator传输显示错误:
"无法连接到'Windows Phone 7模拟器'.未实现"
我错过了什么?
我可以使用FileStream构造函数来确保一次只有一个进程访问文件吗?以下代码是否有效?
public static IDisposable AcquireFileLock() {
IDisposable lockObj;
do {
// spinlock - continually try to open the file until we succeed
lockObj = TryOpenLockFile();
// sleep for a little bit to let someone else have a go if we fail
if (lockObj == null) Thread.Sleep(100);
}
while (lockObj == null);
return lockObj;
}
private static FileStream TryOpenLockFile() {
try {
return new FileStream(s_LockFileName, FileMode.Create, FileAccess.Read, FileShare.None);
}
catch (IOException) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
特别是,FileMode.Create原子WRT …
我想编写一个TSQL存储过程,它创建一个具有指定名称的数据库,并使用一些模式预先填充它.
所以我使用了很多EXEC语句:
EXEC('CREATE TABLE ' + @dbName + '.dbo.MyTable (...)');
Run Code Online (Sandbox Code Playgroud)
等等,与一些一起CREATE PROCEDURE,CREATE FUNCTION等等.然而,问题来自于当我想创建一个类型,CREATE TYPE语句中指定的数据库不能有,你不能USE @dbName在存储过程中.
如何在存储过程中的另一个数据库中创建类型?
我有这个方法(这是我原来问题的简化):
public List<AbstractMap.SimpleEntry<String, List<?>>> method(List<?> list) {
return Collections.singletonList(new AbstractMap.SimpleEntry<>("", list));
}
Run Code Online (Sandbox Code Playgroud)
但是,这会导致编译错误:
Run Code Online (Sandbox Code Playgroud)Console.java:40: error: incompatible types return Collections.singletonList(new AbstractMap.SimpleEntry<>("", list)); ^ required: List<SimpleEntry<String,List<?>>> found: List<SimpleEntry<String,List<CAP#1>>> where CAP#1 is a fresh type-variable: CAP#1 extends Object from capture of ? 10 errors
如果我尝试在顶级方法上指定类型实例化:
return Collections.<AbstractMap.SimpleEntry<String, List<?>>>singletonList(new AbstractMap.SimpleEntry<>("", list));
Run Code Online (Sandbox Code Playgroud)
我得到一个不同的错误:
Run Code Online (Sandbox Code Playgroud)Console.java:40: error: method singletonList in class Collections cannot be applied to given types; return Collections.<AbstractMap.SimpleEntry<String, List<?>>>singletonList(new AbstractMap.SimpleEntry<>("", list)); ^ required: T found: SimpleEntry<String,List<CAP#1>> reason: actual argument SimpleEntry<String,List<CAP#1>> cannot be converted to SimpleEntry<String,List<?>> …
我有一个 node.js + express web 服务器,我正在用 Mocha 进行测试。我在测试工具中启动 Web 服务器,并连接到 mongodb 以查找输出:
describe("Api", function() {
before(function(done) {
// start server using function exported from another js file
// connect to mongo db
});
after(function(done) {
// shut down server
// close mongo connection
});
beforeEach(function(done) {
// empty mongo collection
});
describe("Events", function() {
it("Test1", ...);
it("Test2", ...);
it("Test3", ...);
it("Test4", ...);
it("Test5", ...);
});
});
Run Code Online (Sandbox Code Playgroud)
如果 Mocha 一次运行超过 4 个测试,则会超时:
4 passing (2s)
1 failing
1) Api Test5:
Error: …Run Code Online (Sandbox Code Playgroud) SpliteratorConsumer在其tryAdvance和forEachRemaining方法中采用任意函数.
如果消费者抛出异常,分裂者的状态应该是什么?如果消费者传递给forEachRemaining10个项目之后抛出异常(然后传播并捕获),tryAdvance那么分裂器中的下一个调用是否应返回第11个项目,或者该分裂器是否应该被视为死亡和无效?
javadocs在这一点上含糊不清; 他们只是说任何例外情况都会传播出去,而没有提到分裂者在那之后的状态
我试图让我的http api服务器中的错误处理正常工作,我不明白节点的错误处理行为.
我已经定义了我自己的错误对象,如下所示:
function ServerError(statusCode, err, message) {
this.status = statusCode;
if (err != undefined) {
this.err = err;
if (message != undefined) {
this.message = message;
}
else {
this.message = err.message || err;
}
}
}
ServerError.prototype = new Error();
Run Code Online (Sandbox Code Playgroud)
我在中间件或处理程序中使用这样的对象:
function forceError() {
return function(req, res, next) {
next(new ServerError(500, "Internal error!"));
}
}
Run Code Online (Sandbox Code Playgroud)
如果未定义任何处理程序,则会将此错误打印到控制台并在响应正文中返回.这种事情TypeErrors和我自己的错误一样.这很糟糕,因为它包含堆栈跟踪和文件名/路径.
为什么快递返回堆栈跟踪?我认为默认行为只是崩溃,因此不会将服务器上的任何信息泄露给客户端.
我有一个返回泛型类型的方法,有没有办法检索值<T>而不必通过参数给出这个?
public <T> T getObject(String location, String method)
{
// ! Here I want to retrieve the class of T
Class<?> requestedClass = getMeTheClassThatWasRequested();
return requestedClass;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
java ×3
express ×2
generics ×2
node.js ×2
.net ×1
c# ×1
crash ×1
database ×1
file-locking ×1
filestream ×1
html ×1
java-8 ×1
mocha.js ×1
mongodb ×1
reflection ×1
regex ×1
spliterator ×1
t-sql ×1
xhtml ×1
xml ×1