We just bought the Aspose.Words plugin (.Net) to utilize the power of the Compare method.
We recieved a License-file along side with an email stating a public and private key.
After some emailing with the sales team I was told to use the Metered setup, where the method SetMeteredKey(pub,private) is used.
After this, a call to Metered.IsMeteredLicense() returns true. (as expected )
But when I then use the new Document(MemoryStream, HtmlLoadOptions) I get the dreeded “Evaluation Only…” message on my document ?!
If I call the “GetProductName()” I get : “Aspose.Words Document Comparer for .NET " Which seems correct ?
If I call IsMeteredLicensed() it returns true – again seems correct
If I call GetConsumptionQuantity() – I always get 0 ? odd ‘ive tried several times today… (worked on this issue all day in fact…
) ?
I’ve checked that I’m able to connect to https://purchase.aspose.com to ensure its not a connectivity issue.
We’ve bought the : “Aspose.Words Document Comparer for .NET - Metered OEM” product.
Here are some code snippets to understand what I have tried so far… (including some debug console.writes…)
This is the method I call at startup and again before we use the compare functionality (to ensure the Metered license is “on”)
public bool ApplyLicenseToAspose()
{
try
{
var license = new Aspose.Words.Metered();
if (Metered.IsMeteredLicensed())
{
var credit = Metered.GetConsumptionQuantity();
Console.WriteLine(credit + "consumption");
return true;
}
var assembly = Assembly.GetExecutingAssembly();
using (var stream = assembly.GetManifestResourceStream("License.Aspose.lic"))
{
if (stream is not null)
{
string content;
using (StreamReader reader = new StreamReader(stream, true))
{
content = reader.ReadToEnd();
}
var xmlDoc = System.Xml.Linq.XDocument.Parse(content);
var publicKey = xmlDoc.Element("SubscriptionApiKeys")?.Element("PublicKey")?.Value;
var privateKey = xmlDoc.Element("SubscriptionApiKeys")?.Element("PrivateKey")?.Value;
license.SetMeteredKey(publicKey, privateKey);
var productName = license.GetProductName();
return Metered.IsMeteredLicensed();
}
}
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to apply Aspose license.");
}
return false;
}
And here is how I ensure the license is applied when using the compare functionality. :
public IHtmlContent? CompareHtml(IHtmlContent? oldContent, IHtmlContent? newContent)
{
if (oldContent is null) return newContent;
if (newContent is null) return oldContent;
var licensOk = _asposeLicenseService.ApplyLicenseToAspose();
if(!licensOk)
{
_logger.LogWarning("Aspose license not applied, comparison may be limited.");
}
var loadOptions = new HtmlLoadOptions()
{
LoadFormat = LoadFormat.Html,
ResourceLoadingCallback = _resourceLoading,
BaseUri = ""
};
var oldHtmlBytes = Raw(oldContent);
using var msOld = new MemoryStream(oldHtmlBytes);
var oldDoc = new Document(msOld, loadOptions);
var newHtmlBytes = Raw(newContent);
using var msNew = new MemoryStream(newHtmlBytes);
var newDoc = new Document(msNew, loadOptions);
return DoCompare(oldDoc, newDoc, licensOk);
}
private IHtmlContent DoCompare(Document oldDoc, Document newDoc, bool licensOk)
{
var compared = (Document)oldDoc.Clone(true);
compared.Compare(newDoc, "diffUser", DateTime.Now,
new CompareOptions { IgnoreFormatting = true, Granularity = Granularity.WordLevel });
var save = new HtmlSaveOptions(SaveFormat.Html)
{
HtmlVersion = HtmlVersion.Html5,
ExportImagesAsBase64 = true,
ExportRoundtripInformation = false,
ExportListLabels = ExportListLabels.ByHtmlTags,
PrettyFormat = false,
};
using var ms = new MemoryStream();
compared.Save(ms, save);
ms.Position = 0;
var html = new StreamReader(ms, Encoding.UTF8).ReadToEnd();
//…….. This html contains the "EVALUATION" message ?!?!?!
Thanks in advance for any ideas to help with this issue.
/Christian