public void DeleteUser(Guid id) { if (IsSystemUser(id)) { return; } SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser); if (id == CoreContext.TenantManager.GetCurrentTenant().OwnerId) { throw new InvalidOperationException("Can not remove tenant owner."); } var doRefreshLicense = false; var u = userService.GetUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, id); if (u.Status == EmployeeStatus.Active && CoreContext.Configuration.Standalone) { doRefreshLicense = true; } userService.RemoveUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, id); if (doRefreshLicense) { LicenseClient.RefreshLicense(); } }
private static void GetLicense(LicenseCategory licenseCategory) { LicenseClient licenseClient = new LicenseClient(LicenseClient.PublicKeyXmlFromAssembly(Assembly.GetExecutingAssembly())); try { LicensePublisherResponse response = licenseClient.GetLicense( Product, Assembly.GetExecutingAssembly().GetName().Version, s_licenseKeys[(int)licenseCategory], licenseCategory.ToString(), "Test User", "Test Company", "*****@*****.**", MachineLicense.LocalMachineData); License license = response.License; if (license == null) { Console.WriteLine("ERROR: " + response.ErrorMessage); } else { File.WriteAllText(Assembly.GetExecutingAssembly().Location + ".lic", license.SignedString); LicenseManager.Reset(); } licenseClient.Close(); } catch (CommunicationException exception) { Console.WriteLine("EXCEPTION: " + exception.Message); licenseClient.Abort(); } }
public License GetDistributableLicense(string assemblyData) { LicenseClient client = new LicenseClient(_publicKeyXml); try { { LicensePublisherResponse response = client.GetLicense(CultureInfo.CurrentCulture, Product, Version, _licenseEntry.LicenseKey, GetLicenseCategory(LicenseType.Distributable), LicenseEntry.Name, LicenseEntry.Company, LicenseEntry.Email, assemblyData); client.Close(); if (!CheckLicense(response)) { return(null); } else { return(response.License); } } } catch (CommunicationException ex) { LastErrorMessage = ex.Message; client.Abort(); return(null); } }
public UserInfo SaveUserInfo(UserInfo u, bool isVisitor = false) { if (IsSystemUser(u.ID)) { return(systemUsers[u.ID]); } if (u.ID == Guid.Empty) { SecurityContext.DemandPermissions(Constants.Action_AddRemoveUser); } else { SecurityContext.DemandPermissions(new UserSecurityProvider(u.ID), Constants.Action_EditUser); } if (u.Status == EmployeeStatus.Active) { var q = CoreContext.TenantManager.GetTenantQuota(CoreContext.TenantManager.GetCurrentTenant().TenantId); if (q.ActiveUsers < GetUsersByGroup(Constants.GroupUser.ID).Length) { throw new TenantQuotaException(string.Format("Exceeds the maximum active users ({0})", q.ActiveUsers)); } } var doRefreshLicense = false; if (CoreContext.Configuration.Standalone && !isVisitor) { var curUser = dbUserService.GetUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, u.ID); if (u.Status == EmployeeStatus.Active) { if (curUser == null || curUser.Equals(Constants.LostUser) || curUser.Status != EmployeeStatus.Active) { //new doRefreshLicense = true; } else if (!curUser.FirstName.Equals(u.FirstName) || !curUser.LastName.Equals(u.LastName)) { //rename doRefreshLicense = true; } } else if (curUser.Status == EmployeeStatus.Active) { //delete doRefreshLicense = true; } } var newUser = userService.SaveUser(CoreContext.TenantManager.GetCurrentTenant().TenantId, u); if (doRefreshLicense) { LicenseClient.RefreshLicense(); } return(newUser); }
public App(IOptions <AppSettings> settings, ILogger <App> logger, LicenseClient client, LicenseService service, DbConnection db) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings)); _client = client ?? throw new ArgumentNullException(nameof(client)); _service = service ?? throw new ArgumentNullException(nameof(service)); _db = db ?? throw new ArgumentNullException(nameof(db)); }
public bool RefreshLicense() { if (!CoreContext.Configuration.Standalone) { return(false); } LicenseClient.RefreshLicense(); return(true); }
public AboutWindow(string title, Assembly assembly) { InitializeComponent(); LicenseClient client = new LicenseClient(); FileInfo licenseFile = client.LicenseFile; License license = License.DecodeSignedLicense(licenseFile); VersionText.Text = string.Format("Version {0}", assembly.GetName().Version); string year = DateTime.Today.Year.ToString(); string status = "Unknown"; string licenseExpires = "Unknown"; string supportExpires = "Unknown"; string customerName = "Unknown"; string customerId = "Unknown"; string licenseType = "Unknown"; string machineId = Licensing.Id.MachineId.GetMachineId(); if (license != null) { status = license.VerifyLicense(assembly).ToString(); licenseExpires = license.ExpirationDate.ToString(); supportExpires = license.SupportExpirationDate.ToString(); customerName = license.CustomerName; customerId = license.CustomerId; string typeString = license.Type.ToString(); if (license.Type == LicenseType.Enterprise) { licenseType = typeString; } else if (license.Type == LicenseType.Machine) { licenseType = string.Format("{0} ({1})", typeString, license.LicenseeMachineId); } else if (license.Type == LicenseType.User) { licenseType = string.Format("{0} ({1})", typeString, license.LicenseeEmail); } } Title = $"About {title}"; titleBlock.Text = title; AboutDetailsText.Text = string.Format(c_aboutTextFormat, year, status, licenseType, licenseExpires, supportExpires, customerName, customerId, machineId); }
/// <summary> /// Create a new instance of the GroupShare API v1 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GroupShareClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Project = new ProjectClient(apiConnection); User = new UserClient(apiConnection); Organization = new OrganizationClient(apiConnection); Authenticate = new AuthenticateClient(apiConnection); Role = new RoleClient(apiConnection); Permission = new PermissionClient(apiConnection); ModuleClient = new ModuleClient(apiConnection); License = new LicenseClient(apiConnection); TranslationMemories = new TranslationMemoriesClient(apiConnection); Terminology = new TerminologyClient(apiConnection); }
private void DoCtrlClick(object sender, RoutedEventArgs e) { var worker = new BackgroundWorker(); BusyIndicator.BusyContent = LocalizedStrings.ObtainingLicense; AuthenticationClient.Instance.Credentials.Login = LoginCtrl.Text; AuthenticationClient.Instance.Credentials.Password = PasswordCtrl.Password.To <SecureString>(); worker.DoWork += (o, ea) => { using (var client = new LicenseClient()) { var lic = client.GetFullLicense(); lic.Save(); } }; worker.RunWorkerCompleted += (o, ea) => { BusyIndicator.IsBusy = false; if (ea.Error == null) { new MessageBoxBuilder() .Owner(this) .Text(LocalizedStrings.Str3028Params.Put(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "StockSharp"))) .Info() .Show(); } else { new MessageBoxBuilder() .Owner(this) .Text(ea.Error.Message) .Error() .Show(); } }; BusyIndicator.IsBusy = true; worker.RunWorkerAsync(); }
private void Generate_OnClick(object sender, RoutedEventArgs e) { var worker = new BackgroundWorker(); BusyIndicator.BusyContent = LocalizedStrings.ObtainingLicense; AuthenticationClient.Instance.Credentials.Login = LoginCtrl.Text; AuthenticationClient.Instance.Credentials.Password = PasswordCtrl.Password.To<SecureString>(); worker.DoWork += (o, ea) => { using (var client = new LicenseClient()) { var lic = client.GetFullLicense(); lic.Save(); } }; worker.RunWorkerCompleted += (o, ea) => { BusyIndicator.IsBusy = false; if (ea.Error == null) { new MessageBoxBuilder() .Owner(this) .Text(LocalizedStrings.Str3028Params.Put(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "StockSharp"))) .Info() .Show(); } else { new MessageBoxBuilder() .Owner(this) .Text(ea.Error.Message) .Error() .Show(); } }; BusyIndicator.IsBusy = true; worker.RunWorkerAsync(); }
private bool SetProductLicense(LicenseKey licenseKey, string userName, string company, string email, string designTimeLicenseCategory, string runtimeLicenseCategory) { Debug.Assert(!string.IsNullOrEmpty(runtimeLicenseCategory)); License designTimeLicense = null; License runtimeLicense; LicenseClient client = new LicenseClient(_publicKeyXml); try { LicensePublisherResponse response; if (!string.IsNullOrEmpty(designTimeLicenseCategory)) { response = client.GetLicense(CultureInfo.CurrentCulture, Product, Version, licenseKey, designTimeLicenseCategory, userName, company, email, MachineLicense.LocalMachineData); if (!CheckLicense(response)) { client.Close(); return(false); } designTimeLicense = response.License; } response = client.GetLicense(CultureInfo.CurrentCulture, Product, Version, licenseKey, runtimeLicenseCategory, userName, company, email, MachineLicense.LocalMachineData); client.Close(); if (!CheckLicense(response)) { return(false); } runtimeLicense = response.License; } catch (CommunicationException exception) { LastErrorMessage = exception.Message; client.Abort(); return(false); } string designTimeLicenseString = designTimeLicense == null ? string.Empty : designTimeLicense.SignedString; string runtimeLicenseString = runtimeLicense == null ? string.Empty : runtimeLicense.SignedString; SaveProductLicense(licenseKey, userName, company, email, designTimeLicenseString, runtimeLicenseString); return(true); }
public object ActivateLicenseKey(string licenseKey) { if (!CoreContext.Configuration.Standalone) { throw new NotSupportedException(); } if (string.IsNullOrEmpty(licenseKey)) { throw new ArgumentNullException("licenseKey", UserControlsCommonResource.LicenseKeyNotFound); } MessageService.Send(HttpContext.Current.Request, MessageAction.LicenseKeyUploaded); try { TariffSettings.LicenseAccept = true; var licenseKeys = licenseKey.Split('|'); LicenseClient.SetLicenseKeys(licenseKeys[0], licenseKeys.Length > 1 ? licenseKeys[1] : null); return(new { Status = 1 }); } catch (BillingNotConfiguredException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseKeyNotCorrect }); } catch (BillingNotFoundException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseKeyNotCorrect }); } catch (BillingException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseException }); } catch (Exception ex) { return(new { Status = 0, Message = ex.Message }); } }
public object SaveData(string email, string pwd, string lng, string promocode, string licenseKey) { try { var tenant = CoreContext.TenantManager.GetCurrentTenant(); var settings = SettingsManager.Instance.LoadSettings <WizardSettings>(tenant.TenantId); if (settings.Completed) { throw new Exception("Wizard passed."); } if (tenant.OwnerId == Guid.Empty) { Thread.Sleep(TimeSpan.FromSeconds(6)); // wait cache interval tenant = CoreContext.TenantManager.GetTenant(tenant.TenantId); if (tenant.OwnerId == Guid.Empty) { LogManager.GetLogger("ASC.Web.FirstTime").Error(tenant.TenantId + ": owner id is empty."); } } var currentUser = CoreContext.UserManager.GetUsers(CoreContext.TenantManager.GetCurrentTenant().OwnerId); var cookie = SecurityContext.AuthenticateMe(currentUser.ID); CookiesManager.SetCookies(CookiesType.AuthKey, cookie); if (!UserManagerWrapper.ValidateEmail(email)) { throw new Exception(Resource.EmailAndPasswordIncorrectEmail); } UserManagerWrapper.SetUserPassword(currentUser.ID, pwd); email = email.Trim(); if (currentUser.Email != email) { currentUser.Email = email; currentUser.ActivationStatus = EmployeeActivationStatus.NotActivated; } CoreContext.UserManager.SaveUserInfo(currentUser); if (!string.IsNullOrWhiteSpace(promocode)) { try { CoreContext.PaymentManager.ActivateKey(promocode); } catch (Exception err) { LogManager.GetLogger("ASC.Web.FirstTime").Error("Incorrect Promo: " + promocode, err); throw new Exception(Resource.EmailAndPasswordIncorrectPromocode); } } if (Enterprise) { if (string.IsNullOrEmpty(licenseKey)) { throw new ArgumentNullException("licenseKey", UserControlsCommonResource.LicenseKeyNotFound); } TariffSettings.LicenseAccept = true; var licenseKeys = licenseKey.Split('|'); MessageService.Send(HttpContext.Current.Request, MessageAction.LicenseKeyUploaded); LicenseClient.SetLicenseKeys(licenseKeys[0], licenseKeys.Length > 1 ? licenseKeys[1] : null); } settings.Completed = true; SettingsManager.Instance.SaveSettings(settings, tenant.TenantId); TrySetLanguage(tenant, lng); FirstTimeTenantSettings.SetDefaultTenantSettings(); FirstTimeTenantSettings.SendInstallInfo(currentUser); return(new { Status = 1, Message = Resource.EmailAndPasswordSaved }); } catch (BillingNotConfiguredException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseKeyNotCorrect }); } catch (BillingNotFoundException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseKeyNotCorrect }); } catch (BillingException) { return(new { Status = 0, Message = UserControlsCommonResource.LicenseException }); } catch (Exception ex) { return(new { Status = 0, Message = ex.Message }); } }