/// <summary> /// Checks if the license is about to expire and corresponding warning /// should be shown to the user. /// </summary> /// <param name="username">The name of the user the license was issued for.</param> /// <param name="license">The license to be checked.</param> /// <param name="currentDate">The current date to check license for.</param> /// <returns>True if and only if the license is about to expire and /// expiration warning should be shown to the user.</returns> public bool RequiresExpirationWarning( string username, License license, DateTime?currentDate) { if (string.IsNullOrEmpty(username)) { return(false); } var daysLeft = _GetDaysLeft(license, currentDate); if (daysLeft == null) { return(false); } Debug.Assert(license != null); if (daysLeft > FIRST_EXPIRATION_WARNING_END) { return(false); } var licenseCache = _licenseCacheStorage.Load(); LicenseCacheEntry cacheEntry = null; licenseCache.Entries.TryGetValue(username, out cacheEntry); if (daysLeft > FIRST_EXPIRATION_WARNING_START) { var showWarning = cacheEntry == null || cacheEntry.License != license || !cacheEntry.LicenseExpirationWarningWasShown; if (showWarning) { licenseCache.Entries[username] = new LicenseCacheEntry() { LicenseExpirationWarningWasShown = true, License = license, }; _licenseCacheStorage.Save(licenseCache); return(true); } return(false); } if (daysLeft <= FIRST_EXPIRATION_WARNING_START) { return(true); } return(false); }
/// <summary> /// Implements license retrieval. /// </summary> /// <param name="getLicense">The function to be used for license retrival.</param> /// <param name="userName">The user name to be used to authenticate within /// license service.</param> /// <param name="password">The password to be used to authenticate within /// license service.</param> /// <returns>License object for the free single vehicle role.</returns> /// <exception cref="T:ESRI.ArcLogistics.LicenseException"> /// <list type="bullet"> /// <item> /// <description>License service failed processing request.</description> /// </item> /// <item> /// <description>Specified credentials are invalid.</description> /// </item> /// <item> /// <description>There is no license for the user with the specified /// credentials or all licenses have expired.</description> /// </item> /// </list></exception> /// <exception cref="T:ESRI.ArcLogistics.CommunicationError">Failed to /// communicate with the License service.</exception> private LicenseInfo _GetLicense( Func<string, string, LicenseInfo> getLicense, string userName, string password) { var licenseCache = _licenseCacheStorage.Load(); LicenseCacheEntry cacheEntry = null; licenseCache.Entries.TryGetValue(userName, out cacheEntry); LicenseInfo licenseInfo = null; // get license try { licenseInfo = getLicense(userName, password); _license = licenseInfo.License; _licenseValidationDate = licenseInfo.LicenseValidationDate; } catch (LicenseException ex) { if (ex.ErrorCode == LicenseError.LicenseExpired && cacheEntry != null) { Licenser.ExpiredLicense = cacheEntry.License; } throw; } // set new account if (RequireAuthentication) _licAccount = new NetworkCredential(userName, password); // notify clients _NotifyLicenseActivated(); // We need to store license in cache in order to display it's routes // number (and probably other info) when it expires. However, if // the license is a free single vehicle one we should not store it // in the cache to not overwrite a "real" license info. if (_license.PermittedRouteNumber > 1) { var licenseExpirationWarningWasShown = false; if (cacheEntry != null && cacheEntry.License == _license) { licenseExpirationWarningWasShown = cacheEntry.LicenseExpirationWarningWasShown; } cacheEntry = new LicenseCacheEntry() { LicenseExpirationWarningWasShown = licenseExpirationWarningWasShown, License = _license, }; licenseCache.Entries[userName] = cacheEntry; _licenseCacheStorage.Save(licenseCache); } return licenseInfo; }
/// <summary> /// Implements license retrieval. /// </summary> /// <param name="getLicense">The function to be used for license retrival.</param> /// <param name="userName">The user name to be used to authenticate within /// license service.</param> /// <param name="password">The password to be used to authenticate within /// license service.</param> /// <returns>License object for the free single vehicle role.</returns> /// <exception cref="T:ESRI.ArcLogistics.LicenseException"> /// <list type="bullet"> /// <item> /// <description>License service failed processing request.</description> /// </item> /// <item> /// <description>Specified credentials are invalid.</description> /// </item> /// <item> /// <description>There is no license for the user with the specified /// credentials or all licenses have expired.</description> /// </item> /// </list></exception> /// <exception cref="T:ESRI.ArcLogistics.CommunicationError">Failed to /// communicate with the License service.</exception> private LicenseInfo _GetLicense( Func <string, string, LicenseInfo> getLicense, string userName, string password) { var licenseCache = _licenseCacheStorage.Load(); LicenseCacheEntry cacheEntry = null; licenseCache.Entries.TryGetValue(userName, out cacheEntry); LicenseInfo licenseInfo = null; // get license try { licenseInfo = getLicense(userName, password); _license = licenseInfo.License; _licenseValidationDate = licenseInfo.LicenseValidationDate; } catch (LicenseException ex) { if (ex.ErrorCode == LicenseError.LicenseExpired && cacheEntry != null) { Licenser.ExpiredLicense = cacheEntry.License; } throw; } // set new account if (RequireAuthentication) { _licAccount = new NetworkCredential(userName, password); } // notify clients _NotifyLicenseActivated(); // We need to store license in cache in order to display it's routes // number (and probably other info) when it expires. However, if // the license is a free single vehicle one we should not store it // in the cache to not overwrite a "real" license info. if (_license.PermittedRouteNumber > 1) { var licenseExpirationWarningWasShown = false; if (cacheEntry != null && cacheEntry.License == _license) { licenseExpirationWarningWasShown = cacheEntry.LicenseExpirationWarningWasShown; } cacheEntry = new LicenseCacheEntry() { LicenseExpirationWarningWasShown = licenseExpirationWarningWasShown, License = _license, }; licenseCache.Entries[userName] = cacheEntry; _licenseCacheStorage.Save(licenseCache); } return(licenseInfo); }