Aspose 许可证对象如何工作?它会永远持续下去吗?
我正在使用 Aspose 来处理 PDF 和 Word 文档。每次我要对文档执行某些操作时,我都会确保这样调用:
Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense("Aspose.Total.lic");
Aspose.Words.License wordLicense = new Aspose.Words.License();
wordLicense.SetLicense("Aspose.Total.lic");
pdfLicense
和 wordLicense
变量从未在任何地方使用过,但 Aspose 正确地识别出我拥有有效的许可证。这是怎么发生的?许可证是否保存在某个秘密的单例中?如果是这样,这是否意味着它们在线程的生命周期内持续存在?
由于这是在 Web 应用程序中使用的,如果我在应用程序启动时运行上述代码,我可以在整个应用程序中安全地使用 Aspose,而不必担心许可问题吗?
目前我更加偏执并在每个使用 Aspose 的方法开始时运行该代码。这工作得很好 - 我的许可证被正确识别 - 但它有点太“巧合编程”让我感到舒服。
(我正在将 C# 与 ASP.NET 3.5 一起使用,如果这有什么区别的话。)
I'm using Aspose to handle PDFs and Word documents. Each time I'm about to do something with a document, I make sure to call this:
Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense("Aspose.Total.lic");
Aspose.Words.License wordLicense = new Aspose.Words.License();
wordLicense.SetLicense("Aspose.Total.lic");
The pdfLicense
and wordLicense
variables are never used anywhere, yet Aspose correctly recognises that I do have a valid license. How does this happen? Are the licenses being held in a secret singleton somewhere? If so, does this mean they last for the lifetime of the thread?
As this is being used in a web application, if I run the above code when the application starts up, can I then safely use Aspose throughout my application without worrying about the licensing?
At the moment I'd being more paranoid and running that code at the start of every method that uses Aspose. This works fine - my license is recognised correctly - but it's a bit too "programming-by-coincidence" for me to feel comfortable about it.
(I'm using C# with ASP.NET 3.5, if that makes any difference.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您阅读产品文档,你会看到这一行:
因此它是以流程为中心的。
If you read the product documentation, you will see this line:
Hence it is process-centric.
来检查许可证是否已设置
在 Java 版本的 Aspose 中,您可以通过调用返回布尔值 。请注意,这是一个静态方法。
In the Java version of Aspose you can check if the license was set by calling
which returns a boolean. Notice that this is a static method.
我尝试创建一个 Spring bean 来执行此操作(如下所示),但它不起作用。 Spring似乎想调用License.setLicense(Reader)而不是License.setLicense(String)。我收到的错误是无法将类型“java.lang.String”的属性值转换为属性“license”所需的类型“java.io.Reader”。
然而,我确实得到了这个更通用的(Java)解决方案:
web.xml:
ApplicationStartupListener.java (new class):
I tried creating a Spring bean that would do this (as shown below), but it did not work. Spring seemed to want to call License.setLicense(Reader) instead of License.setLicense(String). The error I get is Failed to convert property value of type 'java.lang.String' to required type 'java.io.Reader' for property 'license'.
I did however get this more generic (Java) solution to work:
web.xml:
ApplicationStartupListener.java (new class):