123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- namespace Wayne.Lib.AsyncManager
- {
-
-
-
- public class IntAsyncManager : AsyncManager<int>
- {
- private int currentValue;
- private readonly int maxValue;
- private readonly int wrapTo;
-
-
-
-
-
-
- public IntAsyncManager(int id, IIdentifiableEntity parentEntity)
- : this(id, parentEntity, ServiceContainerFactory.Create(), 0, int.MaxValue, 0)
- {
- }
-
-
-
-
-
-
-
-
-
- public IntAsyncManager(int id, IIdentifiableEntity parentEntity, IServiceLocator serviceLocator, int initialValue, int maxValue)
- : this(id, parentEntity, serviceLocator, initialValue, maxValue, initialValue)
- {
- }
-
-
-
-
-
-
-
-
-
-
- public IntAsyncManager(int id, IIdentifiableEntity parentEntity, IServiceLocator serviceLocator, int initialValue, int maxValue, int wrapTo)
- : this(id, parentEntity, serviceLocator, initialValue, maxValue, wrapTo, TimeSpan.FromHours(1))
- {
- }
-
-
-
-
-
-
-
-
-
-
-
-
- public IntAsyncManager(int id, IIdentifiableEntity parentEntity, IServiceLocator serviceLocator, int initialValue, int maxValue, int wrapTo, TimeSpan? cleanOutstandingOperationsOlderThan)
- : base(id, parentEntity, serviceLocator, cleanOutstandingOperationsOlderThan)
- {
- if (initialValue > maxValue)
- throw new ArgumentException("The initialValue may not be greater than the maxValue!");
- if (wrapTo > maxValue)
- throw new ArgumentException("The wrapTo may not be greater than the maxValue!");
- currentValue = initialValue;
- this.maxValue = maxValue;
- this.wrapTo = wrapTo;
- }
-
-
-
-
- protected override int CreateNextOperationId()
- {
- int value = currentValue;
- long nextLong = (long)currentValue + 1;
- if (nextLong > maxValue)
- nextLong = wrapTo;
- currentValue = (int)nextLong;
- return value;
- }
-
-
-
- public override string EntitySubType
- {
- get { return "int"; }
- }
- }
- }
|