public virtual string GetLicenseLocation(LicenseMode licenseMode) { try { var entryAssembly = AssemblyHelper.GetEntryAssembly(); var companyName = _applicationIdService.CompanyName; if (string.IsNullOrWhiteSpace(companyName)) { companyName = entryAssembly.Company(); } var productName = _applicationIdService.ProductName; if (string.IsNullOrWhiteSpace(productName)) { productName = entryAssembly.Product(); } if (licenseMode == LicenseMode.CurrentUser) { return(Path.Combine(_appDataService.GetApplicationDataDirectory(Catel.IO.ApplicationDataTarget.UserRoaming), "LicenseInfo.xml")); } // Keep using static path return(Path.Combine(Catel.IO.Path.GetApplicationDataDirectoryForAllUsers(companyName, productName), "LicenseInfo.xml")); } catch (Exception ex) { Log.Warning(ex, $"Failed to get license location for license mode '{licenseMode}', probably access is denied"); return(null); } }
public bool IsLicenseModeAvailable(LicenseMode licenseMode) { var licenseLocation = _licenseLocationService.GetLicenseLocation(licenseMode); if (string.IsNullOrWhiteSpace(licenseLocation)) { return(false); } try { var checkLocation = $"{licenseLocation}.tmp"; if (!_fileService.CanOpenWrite(checkLocation)) { return(false); } _fileService.Delete(checkLocation); return(true); } catch (Exception ex) { Log.Debug(ex, $"Failed to access location @ '{licenseLocation}', assuming license mode '{licenseMode}' is not available"); return(false); } }
public virtual string GetLicenseLocation(LicenseMode licenseMode) { var entryAssembly = AssemblyHelper.GetEntryAssembly(); var companyName = _applicationIdService.CompanyName; if (string.IsNullOrWhiteSpace(companyName)) { companyName = entryAssembly.Company(); } var productName = _applicationIdService.ProductName; if (string.IsNullOrWhiteSpace(productName)) { productName = entryAssembly.Product(); } if (licenseMode == LicenseMode.CurrentUser) { return(Path.Combine(Catel.IO.Path.GetApplicationDataDirectory(companyName, productName), "LicenseInfo.xml")); } return(Path.Combine(Catel.IO.Path.GetApplicationDataDirectoryForAllUsers(companyName, productName), "LicenseInfo.xml")); }
protected void OnLicenseModeChanged(LicenseMode oldValue) { if (oldValue != LicenseMode.Lifetime) { ExpireHour = 999; } }
/// <summary> /// Saves the license. /// </summary> /// <param name="license">The license key that will be saved to <c>Catel.IO.Path.GetApplicationDataDirectory</c> .</param> /// <param name="licenseMode"></param> /// <returns>Returns only true if the license is valid.</returns> /// <exception cref="ArgumentException">The <paramref name="license" /> is <c>null</c> or whitespace.</exception> public void SaveLicense(string license, LicenseMode licenseMode = LicenseMode.CurrentUser) { Argument.IsNotNullOrWhitespace("license", license); try { var licenseObject = License.Load(license); var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); using (var xmlWriter = XmlWriter.Create(xmlFilePath)) { licenseObject.Save(xmlWriter); xmlWriter.Flush(); xmlWriter.Close(); } Log.Info("License saved"); } catch (Exception ex) { Log.Error(ex, "Failed to save license"); throw; } }
public LicenseMode GetLicenseFromXml(string xmlLicense) { XmlDocument doc = new XmlDocument(); doc.Load(xmlLicense); XmlNode node = doc.DocumentElement.FirstChild; string licenseValue = node.InnerText; LicenseFile = licenseValue; license.LicenseCode = licenseValue; LicenseMode licenseMode = LicenseMode.Unavailable; if (license.Status == LicenseStatus.Valid) { string licenseType = GetDataField("LicenseType"); switch (licenseType.ToLower()) { case "lite": licenseMode = LicenseMode.Lite; break; case "enterprise": licenseMode = LicenseMode.Enterprise; break; default: break; } } return(licenseMode); }
public string LoadLicense(LicenseMode licenseMode) { var fileName = GetLicenseLocation(licenseMode); Log.Debug("Loading license from '{0}'", fileName); return(File.ReadAllText(fileName)); }
public string LoadLicense(LicenseMode licenseMode) { var fileName = GetLicenseLocation(licenseMode); Log.Debug("Loading license from '{0}'", fileName); return File.ReadAllText(fileName); }
public static LicenseMode ToOpposite(this LicenseMode licenseMode) { if (licenseMode == LicenseMode.CurrentUser) { return(LicenseMode.MachineWide); } return(LicenseMode.CurrentUser); }
private void LoadAndApplyLicense() { var licenseText = _licenseService.LoadLicense(LicenseMode); if (string.IsNullOrWhiteSpace(licenseText)) { licenseText = _licenseService.LoadLicense(LicenseMode.ToOpposite()); } ApplyLicense(licenseText); }
/// <summary> /// Removes the license if exists. /// </summary> /// <param name="licenseMode"></param> public void RemoveLicense(LicenseMode licenseMode = LicenseMode.CurrentUser) { var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); if (File.Exists(xmlFilePath)) { File.Delete(xmlFilePath); } Log.Info("The '{0}' License has been removed", licenseMode); }
public static string ToDescriptionText(this LicenseMode licenseMode) { var descriptionAttribute = typeof(LicenseMode) .GetField(licenseMode.ToString()) .GetCustomAttributes(typeof(DescriptionAttribute), false) .FirstOrDefault() as DescriptionAttribute; return(descriptionAttribute != null ? descriptionAttribute.Description : licenseMode.ToString()); }
protected override async Task <bool> SaveAsync() { var licenseExists = _licenseService.LicenseExists(LicenseMode); var oppositeLicenseMode = LicenseMode.ToOpposite(); var oppositeLicenseExists = _licenseService.LicenseExists(oppositeLicenseMode); if (licenseExists && !oppositeLicenseExists) { return(true); } if (string.IsNullOrWhiteSpace(LicenseInfo.Key)) { return(false); } var validationContext = _licenseValidationService.ValidateLicense(LicenseInfo.Key); if (validationContext.HasErrors) { return(false); } try { _licenseService.SaveLicense(LicenseInfo.Key, LicenseMode); } catch (Exception ex) { Log.Error(ex, $"Failed to save license using '{LicenseMode}'"); await _messageService.ShowErrorAsync(_languageService.GetString("FailedToSaveLicense")); return(false); } if (oppositeLicenseExists) { var messageResult = await _messageService.ShowAsync(string.Format("The license for {0} has been successfully created, would you like to remove license for {1}?", LicenseMode.ToDescriptionText(), oppositeLicenseMode.ToDescriptionText()), "Remove license confirmation", MessageButton.YesNo); if (messageResult == MessageResult.Yes) { _licenseService.RemoveLicense(oppositeLicenseMode); } } return(true); }
/// <summary> /// Check if the license exists. /// </summary> /// <returns>returns <c>true</c> if exists else <c>false</c></returns> public bool LicenseExists(LicenseMode licenseMode = LicenseMode.CurrentUser) { var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); if (File.Exists(xmlFilePath)) { Log.Debug("License exists"); return(true); } Log.Debug("License does not exist"); return(false); }
/// <summary> /// Removes the license if exists. /// </summary> /// <param name="licenseMode"></param> public void RemoveLicense(LicenseMode licenseMode = LicenseMode.CurrentUser) { var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); try { _fileService.Delete(xmlFilePath); Log.Info("The '{0}' license has been removed", licenseMode); } catch (Exception ex) { Log.Error(ex, $"Failed to delete the license @ '{xmlFilePath}'"); } }
/* * CryptoLicense license; * * private void InitializeLicense(ITracingService tracingService) * { * tracingService.Trace("Before license = new CryptoLicense"); * license = new CryptoLicense(); * // Get by Pressing Ctrl+K in Crypto License Generator * tracingService.Trace("Before license.ValidationKey"); * try * { * license.ValidationKey = "AMAAMADYLN6qRVjvUEWSzEw0UL1lN8bnWzRVTeB0YCgvKtr8mYotNNvZhpqRF0Ij/cKUN1MDAAEAAQ=="; * } * catch (LicenseServiceException ex) * { * throw new InvalidPluginExecutionException(ex.Message); * } * catch (System.Exception ex) * { * throw new InvalidPluginExecutionException(ex.Message); * } * * * tracingService.Trace("After license.ValidationKey"); * } * * private LicenseMode GetLicenseFromXml(string xmlLicense, ITracingService tracingService) * { * XmlDocument doc = new XmlDocument(); * doc.Load(xmlLicense); * * tracingService.Trace("License Loaded to XmlDocument"); * * XmlNode node = doc.DocumentElement.FirstChild; * string licenseValue = node.InnerText; * tracingService.Trace("License Value: {0}", licenseValue); * * license.LicenseCode = licenseValue; * * LicenseMode licenseMode = LicenseMode.Unavailable; * if (license.Status == LicenseStatus.Valid) * { * string licenseType = GetDataField("LicenseType"); * switch (licenseType.ToLower()) * { * case "lite": * licenseMode = LicenseMode.Lite; * break; * case "enterprise": * licenseMode = LicenseMode.Enterprise; * break; * default: * break; * } * } * * return licenseMode; * } * * private string GetDataField(string fieldName) * { * Hashtable data = license.ParseUserData("#"); * string rc = data[fieldName].ToString(); * * return rc; * } * */ private void GetLicenseMode() { string licenseType = "lite"; // "%%watermark0%%"; switch (licenseType.ToLower()) { case "lite": licenseMode = LicenseMode.Lite; break; case "enterprise": licenseMode = LicenseMode.Enterprise; break; default: break; } }
public static LicenseMode ValidateLicense(out string error) { bool rc = false; LicenseMode license = LicenseMode.Unavailable; error = ""; bool isLicenseValid = ValidateKey(License.LicenseKey); if (!isLicenseValid) { DateTime today = DateTime.UtcNow; long todayTicks = today.Ticks; if (!string.IsNullOrEmpty(License.ExpirationDateTick)) { long expDateTicks = long.MinValue; bool isInt64 = long.TryParse(License.ExpirationDateTick, out expDateTicks); if (isInt64) { if (expDateTicks > todayTicks) { rc = true; } } else { } } } else { rc = true; } if (!isLicenseValid) { license = LicenseMode.Unavailable; } else { license = LicenseMode.Enterprise; } return(license); // rc; }
public void CreateEntityLogic(string entityLogicalName, Guid entityId, LicenseMode license) { tracing.Trace("Entering CreateEntityLogic function"); EntityCollection autonumbers = RetrieveAutoNumberSettings(entityLogicalName); if (autonumbers.Entities.Count > 0) { foreach (Entity autonumber in autonumbers.Entities) { Guid autoNumberId = autonumber.Id; string entityName = autonumber.Attributes["xrm_entityname"].ToString(); string attributeName = autonumber.Attributes["xrm_fieldname"].ToString(); UpdateAutoNumber(autonumber, entityLogicalName, attributeName, entityId, entityName); } } }
/// <summary> /// Loads the license. /// </summary> /// <returns>The license from <c>Catel.IO.Path.GetApplicationDataDirectory</c> unless it failed to load then it returns an empty string</returns> public string LoadLicense(LicenseMode licenseMode = LicenseMode.CurrentUser) { try { var licenseString = _licenseLocationService.LoadLicense(licenseMode); var licenseObject = License.Load(licenseString); CurrentLicense = licenseObject; Log.Debug("License loaded: {0}", licenseObject.ToString()); return(licenseObject.ToString()); } catch (Exception ex) { Log.Debug(ex, "Failed to load the license, returning empty string"); return(string.Empty); } }
public string LoadLicense(LicenseMode licenseMode) { try { var fileName = GetLicenseLocation(licenseMode); if (!string.IsNullOrWhiteSpace(fileName) && _fileService.Exists(fileName)) { Log.Debug($"Loading license from '{fileName}'"); return(_fileService.ReadAllText(fileName)); } } catch (Exception ex) { Log.Error(ex, $"Failed to load license for license mode '{licenseMode}'"); } return(null); }
/// <summary> /// Check if the license exists. /// </summary> /// <returns>returns <c>true</c> if exists else <c>false</c></returns> public bool LicenseExists(LicenseMode licenseMode = LicenseMode.CurrentUser) { var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); try { if (!string.IsNullOrWhiteSpace(xmlFilePath) && _fileService.Exists(xmlFilePath)) { Log.Debug("License exists"); return(true); } } catch (Exception ex) { Log.Warning(ex, $"Failed to check whether the license exists @ '{xmlFilePath}'"); } Log.Debug("License does not exist"); return(false); }
public virtual string GetLicenseLocation(LicenseMode licenseMode) { var entryAssembly = AssemblyHelper.GetEntryAssembly(); var companyName = _applicationIdService.CompanyName; if (string.IsNullOrWhiteSpace(companyName)) { companyName = entryAssembly.Company(); } var productName = _applicationIdService.ProductName; if (string.IsNullOrWhiteSpace(productName)) { productName = entryAssembly.Product(); } if (licenseMode == LicenseMode.CurrentUser) { return Path.Combine(Catel.IO.Path.GetApplicationDataDirectory(companyName, productName), "LicenseInfo.xml"); } return Path.Combine(Catel.IO.Path.GetApplicationDataDirectoryForAllUsers(companyName, productName), "LicenseInfo.xml"); }
/// <summary> /// Joins and generates the data for the full report page. /// </summary> /// <param name="Debug"></param> /// <param name="Severities"></param> /// <param name="License"></param> /// <returns></returns> private IQueryable <RawReportFull> GetDebugData(IQueryable <CalculationDebugDataEntity> Debug, IEnumerable <SeverityEntity> Severities, LicenseMode License) { var organs = new LinqMetaData().Organ; var fu = Debug.ToArray() .Where(x => x.IsFiltered) .Join(Debug.ToArray() .Where(y => !y.IsFiltered), x => x.FingerSector, y => y.FingerSector, (x, y) => new FilteredUnfiltered { OrganComponent = x.OrganComponent, FingerSector = x.FingerSector, FilteredLRRank = x.LRRank, FilteredLRScaledScore = (int)Math.Round(x.LRScaledScore), FilteredEPICRank = x.EPICRank, FilteredEPICScaledScore = (int)Math.Round(x.EPICScaledScore), // fill in report score below FilteredEPICBaseScore = x.EPICBaseScore, FilteredEPICBonusScore = x.EPICBonusScore, FilteredEPICScore = x.EPICScore, UnfilteredLRRank = y.LRRank, UnfilteredLRScaledScore = (int)Math.Round(y.LRScaledScore), UnfilteredEPICRank = y.EPICRank, UnfilteredEPICScaledScore = (int)Math.Round(y.EPICScaledScore), // fill in report score below UnfilteredEPICBaseScore = y.EPICBaseScore, UnfilteredEPICBonusScore = y.EPICBonusScore, UnfilteredEPICScore = y.EPICScore, }); var joined = organs .LeftOuterJoin(fu.Where(y => y.FingerSector.Contains("L")), x => x.LComp, y => y.FingerSector, (y, x) => new RawReportFull { LComp = x != null ? x.FingerSector : "", RComp = y.RComp, OrganId = y.OrganId, Organ = y.Description.Replace(" - Left", "").Replace(" - Right", ""), OrganSystemOrgan = y.OrganSystemOrgans.First(z => z.LicenseOrganSystem.LicenseMode == License), FingerSector = (x != null ? x.FingerSector : ""), LFilteredLRRank = x != null ? x.FilteredLRRank.ToString(CultureInfo.InvariantCulture) : "", LFilteredLRScaledScore = x != null ? x.FilteredLRScaledScore.ToString(CultureInfo.InvariantCulture) : "", LFilteredEPICRank = x != null ? x.FilteredEPICRank.ToString(CultureInfo.InvariantCulture) : "", LFilteredEPICScaledScore = x != null ? x.FilteredEPICScaledScore.ToString(CultureInfo.InvariantCulture) : "", // fill in report score below LFilteredEPICBaseScore = x != null ? x.FilteredEPICBaseScore.ToString(CultureInfo.InvariantCulture) : "", LFilteredEPICBonusScore = x != null ? x.FilteredEPICBonusScore.ToString(CultureInfo.InvariantCulture) : "", LFilteredEPICScore = x != null ? x.FilteredEPICScore.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredLRRank = x != null ? x.UnfilteredLRRank.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredLRScaledScore = x != null ? x.UnfilteredLRScaledScore.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredEPICRank = x != null ? x.UnfilteredEPICRank.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredEPICScaledScore = x != null ? x.UnfilteredEPICScaledScore.ToString(CultureInfo.InvariantCulture) : "", // fill in report score below LUnfilteredEPICBaseScore = x != null ? x.UnfilteredEPICBaseScore.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredEPICBonusScore = x != null ? x.UnfilteredEPICBonusScore.ToString(CultureInfo.InvariantCulture) : "", LUnfilteredEPICScore = x != null ? x.UnfilteredEPICScore.ToString(CultureInfo.InvariantCulture) : "", }) // join right sides .LeftOuterJoin(fu.Where(y => y.FingerSector.Contains("R")), x => x.RComp, y => y.FingerSector, (y, x) => { y.FingerSector = y.FingerSector + (!String.IsNullOrEmpty(y.FingerSector) && x != null ? "/" : "") + (x != null ? x.FingerSector : ""); y.RFilteredLRRank = x != null ? x.FilteredLRRank.ToString(CultureInfo.InvariantCulture) : ""; y.RFilteredLRScaledScore = x != null ? x.FilteredLRScaledScore.ToString(CultureInfo.InvariantCulture) : ""; y.RFilteredEPICRank = x != null ? x.FilteredEPICRank.ToString(CultureInfo.InvariantCulture) : ""; y.RFilteredEPICScaledScore = x != null ? x.FilteredEPICScaledScore.ToString(CultureInfo.InvariantCulture) : ""; // fill in report score below y.RFilteredEPICBaseScore = x != null ? x.FilteredEPICBaseScore.ToString(CultureInfo.InvariantCulture) : ""; y.RFilteredEPICBonusScore = x != null ? x.FilteredEPICBonusScore.ToString(CultureInfo.InvariantCulture) : ""; y.RFilteredEPICScore = x != null ? x.FilteredEPICScore.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredLRRank = x != null ? x.UnfilteredLRRank.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredLRScaledScore = x != null ? x.UnfilteredLRScaledScore.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredEPICRank = x != null ? x.UnfilteredEPICRank.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredEPICScaledScore = x != null ? x.UnfilteredEPICScaledScore.ToString(CultureInfo.InvariantCulture) : ""; // fill in report score below y.RUnfilteredEPICBaseScore = x != null ? x.UnfilteredEPICBaseScore.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredEPICBonusScore = x != null ? x.UnfilteredEPICBonusScore.ToString(CultureInfo.InvariantCulture) : ""; y.RUnfilteredEPICScore = x != null ? x.UnfilteredEPICScore.ToString(CultureInfo.InvariantCulture) : ""; return(y); }); var report = joined .Join(Severities, x => x.OrganId, y => y.OrganId, (x, y) => { x.PhysicalLeft = y != null && y.PhysicalLeft.HasValue ? y.PhysicalLeft.Value.ToString(CultureInfo.InvariantCulture) : ""; x.PhysicalRight = y != null && y.PhysicalRight.HasValue ? y.PhysicalRight.Value.ToString(CultureInfo.InvariantCulture) : ""; x.MentalLeft = y != null && y.MentalLeft.HasValue ? y.MentalLeft.Value.ToString(CultureInfo.InvariantCulture) : ""; x.MentalRight = y != null && y.MentalRight.HasValue ? y.MentalRight.Value.ToString(CultureInfo.InvariantCulture) : ""; return(x); }); return(report.AsQueryable()); }
/// <summary> /// Check if the license exists. /// </summary> /// <returns>returns <c>true</c> if exists else <c>false</c></returns> public bool LicenseExists(LicenseMode licenseMode = LicenseMode.CurrentUser) { var xmlFilePath = _licenseLocationService.GetLicenseLocation(licenseMode); if (File.Exists(xmlFilePath)) { Log.Debug("License exists"); return true; } Log.Debug("License does not exist"); return false; }
/// <summary> /// Loads the license. /// </summary> /// <returns>The license from <c>Catel.IO.Path.GetApplicationDataDirectory</c> unless it failed to load then it returns an empty string</returns> public string LoadLicense(LicenseMode licenseMode = LicenseMode.CurrentUser) { try { var licenseString = _licenseLocationService.LoadLicense(licenseMode); var licenseObject = License.Load(licenseString); CurrentLicense = licenseObject; //Log.Debug("License loaded: {0}", licenseObject.ToString()); return licenseObject.ToString(); } catch (Exception ex) { Log.Debug(ex, "Failed to load the license, returning empty string"); return string.Empty; } }