Aspose 许可证对象如何工作?它会永远持续下去吗?

发布于 2024-08-24 13:14:40 字数 663 浏览 8 评论 0原文

我正在使用 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");

pdfLicensewordLicense 变量从未在任何地方使用过,但 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酷到爆炸 2024-08-31 13:14:40

如果您阅读产品文档,你会看到这一行:

在对文档进行任何操作之前,您需要设置许可证。只需每个应用程序(或进程)设置一次许可证

因此它是以流程为中心的。

If you read the product documentation, you will see this line:

You need to set a license before performing any operations with documents. It is only required to set a license once per application (or process).

Hence it is process-centric.

待"谢繁草 2024-08-31 13:14:40

来检查许可证是否已设置

License.isLicenseSet();

在 Java 版本的 Aspose 中,您可以通过调用返回布尔值 。请注意,这是一个静态方法。

In the Java version of Aspose you can check if the license was set by calling

License.isLicenseSet();

which returns a boolean. Notice that this is a static method.

娜些时光,永不杰束 2024-08-31 13:14:40

我尝试创建一个 Spring bean 来执行此操作(如下所示),但它不起作用。 Spring似乎想调用License.setLicense(Reader)而不是License.setLicense(String)。我收到的错误是无法将类型“java.lang.String”的属性值转换为属性“license”所需的类型“java.io.Reader”

<bean id="asposeLicense" class="com.aspose.cells.License">
    <property name="license" value="Aspose.Cells.lic" />
</bean>

然而,我确实得到了这个更通用的(Java)解决方案:

web.xml:

<!-- does things needing doing when application starts or stops -->
<listener>
    <listener-class>
        com.xyz.listener.ApplicationStartupListener
    </listener-class>
</listener>

ApplicationStartupListener.java (new class):

package com.xyz.listener;

import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aspose.cells.License;

public class ApplicationStartupListener implements ServletContextListener {
    protected final Log logger = LogFactory.getLog(getClass());

    @Override
    public void contextInitialized(ServletContextEvent event) {
    logger.info("Initializing application context...");

    try {
        // set license for Aspose.Cells (the Excel API)
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excel/Aspose.Cells.lic");
        License license = new License();
        license.setLicense(inputStream);
        logger.info("Aspose.Cells license set? " + License.isLicenseSet());
    } catch (Exception e) {
        logger.error("Error encountered trying to set Aspose.Cells license!", e);
    }

    logger.info("Application context initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

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'.

<bean id="asposeLicense" class="com.aspose.cells.License">
    <property name="license" value="Aspose.Cells.lic" />
</bean>

I did however get this more generic (Java) solution to work:

web.xml:

<!-- does things needing doing when application starts or stops -->
<listener>
    <listener-class>
        com.xyz.listener.ApplicationStartupListener
    </listener-class>
</listener>

ApplicationStartupListener.java (new class):

package com.xyz.listener;

import java.io.InputStream;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.aspose.cells.License;

public class ApplicationStartupListener implements ServletContextListener {
    protected final Log logger = LogFactory.getLog(getClass());

    @Override
    public void contextInitialized(ServletContextEvent event) {
    logger.info("Initializing application context...");

    try {
        // set license for Aspose.Cells (the Excel API)
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("excel/Aspose.Cells.lic");
        License license = new License();
        license.setLicense(inputStream);
        logger.info("Aspose.Cells license set? " + License.isLicenseSet());
    } catch (Exception e) {
        logger.error("Error encountered trying to set Aspose.Cells license!", e);
    }

    logger.info("Application context initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文