private void InitializeTestSettings()
 {
     _settingManager.ChangeSettingForApplication(EmailSettingNames.DefaultFromAddress, "*****@*****.**");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.DefaultFromDisplayName, "");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.Host, "100.101.102.103");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.UserName, "myuser");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.Password, SimpleStringCipher.Instance.Encrypt("123456"));
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.Domain, "mydomain");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.EnableSsl, "true");
     _settingManager.ChangeSettingForApplication(EmailSettingNames.Smtp.UseDefaultCredentials, "false");
 }
Esempio n. 2
0
 public void SetMaxUserMembershipCount(long?tenantId, int value)
 {
     if (tenantId.HasValue)
     {
         _settingManager.ChangeSettingForTenant(tenantId.Value, AbpZeroSettingNames.OrganizationUnits.MaxUserMembershipCount, value.ToString());
     }
     else
     {
         _settingManager.ChangeSettingForApplication(AbpZeroSettingNames.OrganizationUnits.MaxUserMembershipCount, value.ToString());
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Changes setting for tenant with fallback to application
        /// </summary>
        /// <param name="name">Setting name</param>
        /// <param name="value">Setting value</param>
        public static void ChangeSetting(this ISettingManager manager, string name, string value)
        {
            var session = StaticContext.IocManager.Resolve <IAbpSession>();

            if (session.TenantId.HasValue)
            {
                manager.ChangeSettingForTenant(session.TenantId.Value, name, value);
            }
            else
            {
                manager.ChangeSettingForApplication(name, value);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the default language for a tenant or the host.
        /// </summary>
        /// <param name="tenantId">Tenant Id of null for host</param>
        /// <param name="languageName">Name of the language.</param>
        public virtual void SetDefaultLanguage(long?tenantId, string languageName)
        {
            var cultureInfo = CultureInfo.GetCultureInfo(languageName);

            if (tenantId.HasValue)
            {
                _settingManager.ChangeSettingForTenant(tenantId.Value, LocalizationSettingNames.DefaultLanguage, cultureInfo.Name);
            }
            else
            {
                _settingManager.ChangeSettingForApplication(LocalizationSettingNames.DefaultLanguage, cultureInfo.Name);
            }
        }
        public MainWindowViewModel()
        {
            // resolve dependencies
            _settingManager = IocManager.Instance.Resolve <ISettingManager>();
            _authService    = IocManager.Instance.Resolve <IPortalAuthenticationService>();

            try
            {
                _serviceController = new ServiceController("LicenseMonitoringSystem");
                if (_serviceController == null)
                {
                    ServiceInstalled = false;
                    ServiceStatus    = "Program not installed.";
                }
                else
                {
                    ServiceInstalled = true;
                    ServiceStatus    = _serviceController.Status.ToString();
                }
            }
            catch (Exception ex)
            {
                ServiceInstalled = false;
                ServiceStatus    = ex.Message;
            }

            // set initial values
            AccountId = _authService.GetAccount();
            DeviceId  = _authService.GetDevice();

            // listen for changes
            this.Changed(p => p.AccountId)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .ObserveOnDispatcher()
            .Subscribe(accountId =>
            {
                IsBusy = true;

                if (_canChangeAccountId)
                {
                    var prev = _authService.GetAccount();
                    if (prev != AccountId)
                    {
                        PendingChanges = true;
                    }
                }

                Debug.WriteLine($"Account ID: {accountId}");
                _settingManager.ChangeSettingForApplication(AppSettingNames.AutotaskAccountId, accountId.ToString());

                IsBusy = false;
                _canChangeAccountId = true;
            })
            .DisposeWith(_disposable);

            this.Changed(p => p.DeviceId)
            .Throttle(TimeSpan.FromMilliseconds(500))
            .ObserveOnDispatcher()
            .Subscribe(deviceId =>
            {
                IsBusy = true;
                if (_canChangeDeviceId)
                {
                    var prev = _authService.GetDevice();
                    if (prev != DeviceId)
                    {
                        PendingChanges = true;
                    }
                }

                Debug.WriteLine($"Device ID: {deviceId}");
                _settingManager.ChangeSettingForApplication(AppSettingNames.CentrastageDeviceId, deviceId.ToString());

                IsBusy             = false;
                _canChangeDeviceId = true;
            })
            .DisposeWith(_disposable);

            PendingChanges = false;
        }
        public async Task Save_Test()
        {
            LoginAsHostAdmin();
            try
            {
                using (var uow = _unitOfWorkManager.Begin())
                {
                    var nhuow   = uow as NhUnitOfWork;
                    var session = nhuow?.GetSession();

                    var testSetting = _settingManager.GetSettingValue("TestSetting");
                    testSetting.ShouldNotBeNull();

                    _settingManager.ChangeSettingForApplication("TestSetting", "2");
                    session.Flush();

                    session.CreateSQLQuery("select count(1) from AbpSettings where Name = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(1);
                    session.CreateSQLQuery(
                        "select count(1) from AbpEntityPropertyChanges where EntityChangeId in (select id from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(1);
                    session.CreateSQLQuery("select count(1) from AbpEntityChanges where EntityId = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(1);
                    session.CreateSQLQuery("select count(1) from AbpEntityChangeSets where id in (select EntityChangeSetId from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(1);
                }
                using (var uow = _unitOfWorkManager.Begin())
                {
                    var nhuow   = uow as NhUnitOfWork;
                    var session = nhuow?.GetSession();

                    var testSetting = _settingManager.GetSettingValue("TestSetting");
                    testSetting.ShouldNotBeNull();

                    _settingManager.ChangeSettingForApplication("TestSetting", "3");
                    session.Flush();
                    session.CreateSQLQuery("select count(1) from AbpSettings where Name = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(1);
                    session.CreateSQLQuery(
                        "select count(1) from AbpEntityPropertyChanges where EntityChangeId in (select id from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(2);
                    session.CreateSQLQuery("select count(1) from AbpEntityChanges where EntityId = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(2);
                    session.CreateSQLQuery("select count(1) from AbpEntityChangeSets where id in (select EntityChangeSetId from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(2);
                }
                using (var uow = _unitOfWorkManager.Begin())
                {
                    var nhuow   = uow as NhUnitOfWork;
                    var session = nhuow?.GetSession();

                    var testSetting = _settingManager.GetSettingValue("TestSetting");
                    testSetting.ShouldNotBeNull();

                    _settingManager.ChangeSettingForApplication("TestSetting", "1");
                    session.Flush();
                    session.CreateSQLQuery("select count(1) from AbpSettings where Name = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(0);
                    session.CreateSQLQuery(
                        "select count(1) from AbpEntityPropertyChanges where EntityChangeId in (select id from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(3);
                    session.CreateSQLQuery("select count(1) from AbpEntityChanges where EntityId = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(3);
                    session.CreateSQLQuery("select count(1) from AbpEntityChangeSets where id in (select EntityChangeSetId from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(3);
                }
                using (var uow = _unitOfWorkManager.Begin())
                {
                    var nhuow   = uow as NhUnitOfWork;
                    var session = nhuow?.GetSession();

                    var testSetting = _settingManager.GetSettingValue("TestSetting");
                    testSetting.ShouldNotBeNull();

                    _settingManager.ChangeSettingForApplication("TestSetting", "2");
                    session.Flush();
                    session.CreateSQLQuery("select count(1) from AbpSettings where Name = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(1);
                    session.CreateSQLQuery(
                        "select count(1) from AbpEntityPropertyChanges where EntityChangeId in (select id from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(4);
                    session.CreateSQLQuery("select count(1) from AbpEntityChanges where EntityId = 'TestSetting'")
                    .UniqueResult <int>().ShouldBe(4);
                    session.CreateSQLQuery("select count(1) from AbpEntityChangeSets where id in (select EntityChangeSetId from AbpEntityChanges where EntityId = 'TestSetting')")
                    .UniqueResult <int>().ShouldBe(4);
                }
            }
            finally
            {
                using (var uow = _unitOfWorkManager.Begin())
                {
                    var nhuow   = uow as NhUnitOfWork;
                    var session = nhuow?.GetSession();

                    // delete temporary values
                    var entityChangeSetId =
                        session.CreateSQLQuery("select EntityChangeSetId from AbpEntityChanges where EntityId = 'TestSetting'")
                        .List <Int64>();

                    session.CreateSQLQuery("delete from AbpEntityPropertyChanges where EntityChangeId in (select id from AbpEntityChanges where EntityId = 'TestSetting')")
                    .ExecuteUpdate();
                    session.CreateSQLQuery("delete from AbpEntityChanges where EntityId = 'TestSetting'")
                    .ExecuteUpdate();
                    foreach (var id in entityChangeSetId)
                    {
                        session.CreateSQLQuery($"delete from AbpEntityChangeSets where id = {id}")
                        .ExecuteUpdate();
                    }
                    session.CreateSQLQuery($"delete from AbpSettings where Name = 'TestSetting'")
                    .ExecuteUpdate();

                    session.Flush();
                }
            }
        }