Class Metered

Class Metered

Namespace: Aspose.Note
Assembly: Aspose.Note.dll (25.6.0)

Provides methods to set metered key.

public class Metered
{
    private readonly double _usage;
    private readonly DateTime _lastReset;
    private const int MinutesPerDay = 1440;
    public Metered(double usage, DateTime lastReset)
    {
        _usage = usage;
        _lastReset = lastReset;
    }
    public bool HasExpired()
    {
        var elapsedMinutes = (DateTime.Now - _lastReset).TotalMinutes;
        return elapsedMinutes >= MinutesPerDay;
    }
    public void Reset(DateTime newDate)
    {
        if (_usage > 0 && !HasExpired())
            throw new ArgumentException("Cannot reset meter if it has expired or still in use.");
        _lastReset = newDate;
        _usage = 0;
    }
}

Inheritance

object Metered

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

In this example, an attempt will be made to set metered public and private key

Metered metered = new Metered();
   metered.SetMeteredKey("PublicKey", "PrivateKey");
Dim metered As Metered = New Metered
metered.SetMeteredKey("PublicKey", "PrivateKey")

Shows how to set metered license.

Metered meterded = new Metered();
      meterded.SetMeteredKey("MyPublicKey", "MyPrivateKey");
      Console.WriteLine($"Credit before operation: {Metered.GetConsumptionCredit():F2}");
      Console.WriteLine($"Consumption quantity before operation: {Metered.GetConsumptionQuantity():F2}");
      string dataDir = RunExamples.GetDataDir_Pages();
      Document document = new Document(Path.Combine(dataDir, "Aspose.one"));
      document.Save(Path.Combine(dataDir, "MeteredLicense.pdf"));
      Console.WriteLine($"Credit before operation: {Metered.GetConsumptionCredit():F2}");
      Console.WriteLine($"Consumption quantity before operation: {Metered.GetConsumptionQuantity():F2}");

Constructors

Metered()

public Metered()
   {
   }

Methods

GetConsumptionCredit()

Gets consumption credit.

public static decimal GetConsumptionCredit()
   {
      decimal consumptionAmount = 0m;
      if (_consumedUnits > _minimumConsumptionThreshold)
      {
         consumptionAmount = CalculateConsumptionAmount(_consumedUnits, _rate);
      }
      return consumptionAmount;
   }

Returns

decimal

Returns the number of consumed credit points.

GetConsumptionQuantity()

Gets consumption file size.

public static decimal GetConsumptionQuantity()
    {
    }

Returns

decimal

Returns the number of consumed bytes.

ResetMeteredKey()

Removes previously setup license.

public void ResetMeteredKey()
   {
   }

SetMeteredKey(string, string)

Sets metered public and private keys.

public void SetMeteredKey(
    string publicKey,
    string privateKey)
{
}

Parameters

publicKey string

The public key.

privateKey string

The private key.

Examples

Shows how to set metered license.

Metered metered = new Metered();
   metered.SetMeteredKey("MyPublicKey", "MyPrivateKey");
   Console.WriteLine($"Credit before operation: {Metered.GetConsumptionCredit():F2}");
   Console.WriteLine($"Consumption quantity before operation: {Metered.GetConsumptionQuantity():F2}");
   string dataDir = RunExamples.GetDataDir_Pages();
   Document document = new Document(Path.Combine(dataDir, "Aspose.one"));
   document.Save(Path.Combine(dataDir, "MeteredLicense.pdf"));
   Console.WriteLine($"Credit before operation: {Metered.GetConsumptionCredit():F2}");
   Console.WriteLine($"Consumption quantity before operation: {Metered.GetConsumptionQuantity():F2}");

Remarks

If you purchase metered license, this API should be called on application startup, normally, this is enough.However, if metered fails to upload consumption data during 24 hours period, the license will be set to evaluation status. To avoid such case, you should regularly check the license status If it is evaluation status, call this API again.

 English