private async void SaveButton_Click(object sender, RoutedEventArgs e) { if (!AreSamePasswords()) { FieldValidation.WriteMessage(ErrorLabel, language.PasswordsDontMatch); return; } if (IsValidForm()) { LocalAccount localAccount = new LocalAccount() { IdLocalAccount = localAccountViewModel.IdLocalAccount, FullName = FullNameBox.Text, Email = EmailBox.Text, PasswordHash = PasswordBox.Password, }; ObservableCollection <RoleViewModel> roles = RolesComboBox.SelectedItems as ObservableCollection <RoleViewModel>; localAccount.SetRoles(roles.Select(x => Mapping.Mapper.Map <Role>(x)).ToList()); DbStatus status = await localAccountService.Update(localAccount); OperationStatus = StatusHandler.Handle(OperationType.Edit, status); Close(); } else { FieldValidation.WriteMessage(ErrorLabel, language.SelectValues); } }
public LocalAccount CreateLocalAccount(int userId, string password, bool requireConfirmationToken) { if (string.IsNullOrEmpty(password)) { throw new ArgumentException(T(SecurityConstants.ErrorPasswordRequired)); } string hashedPassword = EncryptionExtensions.Encrypt(KeyConfiguration.PublishKey, password); if (string.IsNullOrEmpty(hashedPassword)) { throw new ArgumentException(T(SecurityConstants.ErrorConfigKey).Text); } var token = requireConfirmationToken ? GenerateToken() : null; var localAccount = new LocalAccount { UserId = userId, Password = hashedPassword, IsConfirmed = !requireConfirmationToken, ConfirmationToken = token, PasswordFailuresSinceLastSuccess = 0 }; localAccountRepository.Insert(localAccount); return(localAccount); }
private async Task <CustomIdentity> GetUserPrincipal() { LocalAccount localAccount = await userAuthenticationService.ValidateUser(UsernameBox.Text, PasswordBox.Password); if (localAccount == null) { Error.Text = language.WrongPasswordOrEmail; Error.Visibility = Visibility.Visible; return(new AnonymousIdentity()); } List <Role> roleNames = localAccount.GetRoles(); if (roleNames == null) { Error.Text = language.NoKnownRoles; Error.Visibility = Visibility.Visible; return(new AnonymousIdentity()); } Error.Visibility = Visibility.Collapsed; string[] accountRoles = roleNames.Select(x => x.RoleName).ToArray(); CustomIdentity customIdentity = new CustomIdentity(localAccount.FullName, localAccount.Email, accountRoles, localAccount.PasswordHash); return(customIdentity); }
private void DeleteOrUpdateRoles(LocalAccount currentAccount, LocalAccount localAccount, List <string> commandsToExecute, MySqlConnection connection) { var rolesToDelete = currentAccount.GetRoles().Except(localAccount.GetRoles()); var rolesToAdd = localAccount.GetRoles().Except(currentAccount.GetRoles()); foreach (var role in rolesToDelete) { LocalAccountRole lr = new LocalAccountRole() { IdLocalAccount = currentAccount.IdLocalAccount, IdRole = role.IdRole }; commandsToExecute.Add(new DeleteCommand <LocalAccountRole>().GetCommand(connection, lr.GetAssociatedDbTableName(), lr).CommandText); } foreach (var role in rolesToAdd) { LocalAccountRole lr = new LocalAccountRole() { IdRole = role.IdRole, IdLocalAccount = currentAccount.IdLocalAccount, Deleted = 0 }; commandsToExecute.Add(new InsertOrUpdateCommand <LocalAccountRole>().GetCommand(connection, lr.GetAssociatedDbTableName(), lr).CommandText); } }
private async Task <LoginResult> PrivateLogin(string host, bool rememberMe, LocalAccount localAccount) { var identity = await _identityService.GetIdentityAsync(localAccount.IdentityId); var expiration = DateTimeOffset.UtcNow.AddHours(1); if (rememberMe) { expiration = DateTimeOffset.UtcNow.AddMonths(1); } var claims = await GetClaimsForIdentityAsync(identity, host, rememberMe, expiration); var authenticationProperties = new AuthenticationProperties() { AllowRefresh = true, ExpiresUtc = expiration, IsPersistent = rememberMe, IssuedUtc = DateTimeOffset.UtcNow, }; var principal = new ClaimsPrincipal(new ClaimsIdentity(claims, "RinsenPassword")); await _httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, authenticationProperties); return(LoginResult.Success(principal, localAccount.LoginId)); }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { LocalAccount localAccount = new LocalAccount() { FullName = FullNameBox.Text, Email = EmailBox.Text, PasswordHash = PasswordBox.Password, IdLocalAccount = localAccountViewModel.IdLocalAccount }; ObservableCollection <RoleViewModel> roles = selectedItems.SelectedItems as ObservableCollection <RoleViewModel>; localAccount.SetRoles(roles.Select(x => Mapping.Mapper.Map <Role>(x)).ToList()); DbStatus status = await localAccountService.Update(localAccount); if (status == DbStatus.SUCCESS) { WindowHelper.WriteMessage(language.UpdatingSuccess, MessageLabel, true); } else if (status == DbStatus.NOT_FOUND) { WindowHelper.WriteMessage(language.EntityNotFound, MessageLabel, false); } else { WindowHelper.WriteMessage(language.DatabaseError, MessageLabel, false); } }
protected InterestRate(LocalAccount account, List <Operation> incomingOperations, List <Operation> outgoingOperations) { this.account = account; this.incomingOperations = incomingOperations; this.outgoingOperations = outgoingOperations; }
public void GetSendType_OrderTest() { LocalAccount account = new LocalAccount(); account.IsConfigByV3 = true; Guid accountId = new Guid("4C5E9CC7-02A8-44B8-9520-81C84DC0A2C3"); BusinessType type = BusinessType.OrderExecuted; BusinessParameter parameter = new BusinessParameter(account, null, accountId, type); SendType result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.None, result,"when orderstate not assign shoud be none"); parameter = new BusinessParameter(account, null, accountId, type, FaxAndEmail.Repository.Model.OrderState.Deleted); result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.Fax, result,"shoud from v3 deleteOrderSendType"); parameter = new BusinessParameter(account, null, accountId, type, FaxAndEmail.Repository.Model.OrderState.Executed); result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.Fax, result,"shoud from v3 ExecutedOrderSendType"); account.IsConfigByV3 = false; account.OrderOption = OrderConfirmationEnum.None; parameter = new BusinessParameter(account, null, accountId, type); result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.None, result,"when not configed by v3 ,shoud be the same with account.OrderOption"); }
private async void YesButton_Click(object sender, RoutedEventArgs e) { LocalAccount localAccount = Mapping.Mapper.Map <LocalAccount>(localAccountViewModel); DbStatus status = await localAccountService.Delete(localAccount); this.Close(); }
public Transfer(Customer customer, Bank bank, LocalAccount fromAccount, string toAccountNumber, Money amount) { this.Bank = bank; this.customer = customer; FromAccount = fromAccount; this.ToAccountNumber = toAccountNumber; Money = amount; FromAccount.OutgoingOperations.Add(this); }
private void execute(OpenAccount operation) { var newAccount = new LocalAccount( operation.customer, operation.bank.generateAccountNumber(), operation.Money ?? new Money() ); operation.bank.addAccount(newAccount); newAccount.OtherOperations.Add(operation); }
public void GetSendType_AlertOptionTest() { LocalAccount account = new LocalAccount(); account.IsConfigByV3 = false; account.AlertOption = AlertOptionEnum.Fax; Guid accountId = new Guid("4C5E9CC7-02A8-44B8-9520-81C84DC0A2C3"); BusinessType type = BusinessType.RiskLevelChanged; BusinessParameter parameter = new BusinessParameter(account, null, accountId, type); SendType result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.Email, result); }
void Awake() { if (!localAccount) { localAccount = this; DontDestroyOnLoad(gameObject); } else { Destroy(this); } // 인게임 씬 테스트용 코드 NewAccount(); }
private void execute(Transfer operation) { LocalAccount localAccount = (LocalAccount)operation.FromAccount; //check if account belongs to this bank if (localAccount == null || !operation.Bank.getAccounts().Contains(localAccount)) { throw new Exception("This account does not belong to our bank."); } else { if (operation.Money <= 0) { throw new Exception("Amount has to be greater than 0."); } if (localAccount.AccountNumber == operation.ToAccountNumber) { throw new Exception("Transfer has to be between different accounts."); } if (!localAccount.hasSufficientBalance(operation.Money)) { throw new Exception("Insufficient account balance."); } if (operation.ToAccountNumber.StartsWith(operation.Bank.accountPrefix)) { //it's an internal transfer var recipientsAccount = operation.Bank.getAccounts().Find(a => a.AccountNumber == operation.ToAccountNumber); if (recipientsAccount == null) { throw new Exception("Recipient's account not found"); } localAccount.decreaseBalance(operation.Money); recipientsAccount.increaseBalance(operation.Money); recipientsAccount.IncomingOperations.Add(operation); operation.Status = Operation.OperationStatus.Completed; } else { //it's an external transfer operation.Status = Operation.OperationStatus.PendingCompletion; localAccount.decreaseBalance(operation.Money); localAccount.OutgoingOperations.Add(operation); operation.Bank.IBPA.performInterBankTransfer(operation); } } }
public void GetSendType_BalanceTest() { LocalAccount account = new LocalAccount(); account.IsConfigByV3 = true; Guid accountId = new Guid("4C5E9CC7-02A8-44B8-9520-81C84DC0A2C3"); BusinessType type = BusinessType.Balance; BusinessParameter parameter = new BusinessParameter(account, null, accountId, type); SendType result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.Fax, result,"When config by v3"); account.IsConfigByV3 = false; account.BalanceOption = BalanceOptionEnum.None; parameter = new BusinessParameter(account, null, accountId, type); result = BusinessHelper.GetSendType(parameter); Assert.AreEqual(SendType.None, result,"When not config by v3"); }
public async Task <DbStatus> AddOrUpdate(LocalAccount localAccount) { List <string> commandsToExecute = new List <string>(); IConnector connector = ConnectorFactory.CreateConnector(); MySqlConnection connection = connector.CreateConnection(); await connector.OpenConnection(connection); LocalAccount currentAccount = await GetByUniqueIdentifiers(new string[] { "Email" }, localAccount, false); DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection); commandsToExecute.Add(new InsertOrUpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText); DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray()); DbStatus status = await transactionProcedure.Execute(); return(status); }
public async Task <LocalAccount> GetByUniqueIdentifiers(string[] propertyNames, LocalAccount localAccount, bool?deleted = null) { var list = await ServiceHelper <LocalAccount> .ExecuteSelectCommand(new SelectWithAttributeValuesCommand <LocalAccount>(propertyNames, deleted), localAccount); LocalAccount dbAccount = list.Count != 0 ? list[0] : null; if (dbAccount == null) { return(null); } else { IList <Role> roles = await localAccountRoleService.GetAllRolesFor(dbAccount.IdLocalAccount); dbAccount.SetRoles(roles as List <Role>); return(dbAccount); } }
public async Task <LocalAccount> GetByPrimaryKey(LocalAccount localAccount) { var list = await ServiceHelper <LocalAccount> .ExecuteSelectCommand(new SelectWithPrimaryKeyCommand <LocalAccount>(), localAccount); LocalAccount account = list.Count != 0 ? list[0] : null; if (account == null) { return(null); } else { IList <Role> roles = await localAccountRoleService.GetAllRolesFor(localAccount.IdLocalAccount); account.SetRoles(roles as List <Role>); return(account); } }
public async Task <LocalAccount> ValidateUser(string email, string password) { LocalAccount localAccount = new LocalAccount() { Email = email }; localAccount = await localAccountService.GetByUniqueIdentifiers(new string[] { "Email" }, localAccount); if (localAccount == null) { return(null); } // bool passwordConfirmed = ValidatePassword(password, localAccount.PasswordHash); bool passwordConfirmed = password == localAccount.PasswordHash; return(!passwordConfirmed ? null : localAccount); }
public void CreateUser(string username, string password) { using (var repository = new SnizPrestizRepository(true)) { var localAccount = new LocalAccount() { Password = BCrypt.HashPassword(password, BCrypt.GenerateSalt()), Username = username }; var account = new Account() { LocalAccount = localAccount, Flags = (int)AccountFlags.None }; repository.Add(account); repository.SaveChanges(); } }
private void SetUserDefault() { try { var user = service.GetUser(Constants.DefaultUserName); if (user == null) { using (var transaction = new TransactionScope()) { user = new User { Id = 0, UserName = Constants.DefaultUserName, FullName = Constants.DefaultFullName, Email = Constants.DefaultEmail, SuperUser = true, CreateDate = DateTime.UtcNow }; userRepository.Insert(user); string hashedPassword = EncryptionExtensions.Encrypt(KeyConfiguration.PublishKey, Constants.DefaultPassword); if (string.IsNullOrEmpty(hashedPassword)) { throw new ArgumentException(SecurityConstants.ErrorConfigKey); } var localAccount = new LocalAccount { UserId = user.Id, IsConfirmed = true, Password = hashedPassword }; localAccountRepository.Insert(localAccount); transaction.Complete(); } } } catch (Exception) { } }
public async Task <DbStatus> Update(LocalAccount localAccount) { List <string> commandsToExecute = new List <string>(); IConnector connector = ConnectorFactory.CreateConnector(); MySqlConnection connection = connector.CreateConnection(); await connector.OpenConnection(connection); LocalAccount currentAccount = await GetByPrimaryKey(localAccount); if (currentAccount == null) { return(DbStatus.NOT_FOUND); } DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection); commandsToExecute.Add(new UpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText); DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray()); DbStatus status = await transactionProcedure.Execute(); return(status); }
private async Task <CustomIdentity> GetUserPrincipal() { LocalAccount localAccount = await userAuthenticationService.ValidateUser(EmailBox.Text, PasswordBox.Password); if (localAccount == null) { WindowHelper.WriteMessage(language.WrongPasswordOrEmail, ErrorLabel, false); return(new AnonymousIdentity()); } var roleNames = localAccount.GetRoles(); if (roleNames == null) { WindowHelper.WriteMessage(language.NoKnownRoles, ErrorLabel, false); return(new AnonymousIdentity()); } string[] accountRoles = roleNames.Select(x => x.RoleName).ToArray(); CustomIdentity customIdentity = new CustomIdentity(localAccount.FullName, localAccount.Email, accountRoles, localAccount.PasswordHash); return(customIdentity); }
public async Task <DbStatus> Delete(LocalAccount localAccount) { List <string> commandsToExecute = new List <string>(); IConnector connector = ConnectorFactory.CreateConnector(); MySqlConnection connection = connector.CreateConnection(); await connector.OpenConnection(connection); foreach (var role in localAccount.GetRoles()) { LocalAccountRole lr = new LocalAccountRole() { IdLocalAccount = localAccount.IdLocalAccount, IdRole = role.IdRole }; commandsToExecute.Add(new DeleteCommand <LocalAccountRole>().GetCommand(connection, lr.GetAssociatedDbTableName(), lr).CommandText); } commandsToExecute.Add(new DeleteCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText); DbTransactionProcedure transactionProcedure = new DeleteDbTransactionProcedure(commandsToExecute.ToArray()); DbStatus status = await transactionProcedure.Execute(); return(status); }
public async Task <DbStatus> Add(LocalAccount localAccount) { List <string> commandsToExecute = new List <string>(); IConnector connector = ConnectorFactory.CreateConnector(); MySqlConnection connection = connector.CreateConnection(); await connector.OpenConnection(connection); LocalAccount currentAccount = await GetByUniqueIdentifiers(new string[] { "Email" }, localAccount); if (currentAccount != null && currentAccount.Deleted == 0) { return(DbStatus.EXISTS); } else if (currentAccount != null && currentAccount.Deleted == 1) { DeleteOrUpdateRoles(currentAccount, localAccount, commandsToExecute, connection); commandsToExecute.Add(new InsertOrUpdateCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText); } else { commandsToExecute.Add(new InsertCommand <LocalAccount>().GetCommand(connection, localAccount.GetAssociatedDbTableName(), localAccount).CommandText); foreach (var role in localAccount.GetRoles()) { LocalAccountRole lr = new LocalAccountRole() { IdRole = role.IdRole }; commandsToExecute.Add(new InsertIntoConnectionTableCommand <LocalAccountRole>("IdLocalAccount").GetCommand(connection, lr.GetAssociatedDbTableName(), lr).CommandText); } } DbTransactionProcedure transactionProcedure = new UpdateDbTransactionProcedure(commandsToExecute.ToArray()); DbStatus status = await transactionProcedure.Execute(); return(status); }
protected async override Task <object> Execute(MySqlCommand command) { List <LocalAccount> localAccounts = new List <LocalAccount>(); DataTable dataTable = new DataTable(); using (MySqlDataAdapter dataAdapter = new MySqlDataAdapter(command)) { await dataAdapter.FillAsync(dataTable); } foreach (DataRow row in dataTable.Rows) { LocalAccount localAccount = new LocalAccount() { IdLocalAccount = (int)row["IdLocalAccount"], FullName = (string)row["FullName"], Deleted = (sbyte)row["Deleted"], Email = (string)row["Email"], PasswordHash = (string)row["PasswordHash"] }; localAccount.SetRoleNames((string)row["Roles"]); localAccounts.Add(localAccount); } return(localAccounts); }
public void Setup() { account = new LocalAccount(new Customer("", ""), "A01", new Money(99999)); operation = new Mock <Operation>(); operation.SetupGet(o => o.Money).Returns(new Money(1)); }
public InterestRateRich(LocalAccount account, List <Operation> incomingOperations, List <Operation> outgoingOperations) : base(account, incomingOperations, outgoingOperations) { }
static void RunOptions(Options options) { Unattend unattendObject = new Unattend(); Settings windowsPESettings = new Settings(); Settings oobeSettings = new Settings(); Settings specializeSettings = new Settings(); windowsPESettings.Pass = "******"; oobeSettings.Pass = "******"; specializeSettings.Pass = "******"; /// SETUP UI COMPONENT SetupUIComponent setupUIComponent = new SetupUIComponent(); setupUIComponent.SetupUILanguage.UILanguage = options.language; setupUIComponent.InputLocale = options.locale; setupUIComponent.SystemLocale = options.language; setupUIComponent.UILanguage = options.language; setupUIComponent.UserLocale = options.language; /// SETUP DISK COMPONENT SetupDiskComponent setupDiskComponent = new SetupDiskComponent(); Disk disk = new Disk(); disk.Action = "add"; disk.DiskID = "0"; disk.WillWipeDisk = "true"; CreatePartition primaryPartition = new CreatePartition(); CreatePartition efiPartition = new CreatePartition(); CreatePartition msrPartition = new CreatePartition(); CreatePartition windowsPartition = new CreatePartition(); primaryPartition.Order = "1"; primaryPartition.Size = "450"; primaryPartition.Type = "Primary"; efiPartition.Order = "2"; efiPartition.Size = "100"; efiPartition.Type = "EFI"; msrPartition.Order = "3"; msrPartition.Size = "16"; msrPartition.Type = "MSR"; windowsPartition.Order = "4"; windowsPartition.Extend = "true"; windowsPartition.Type = "Primary"; disk.createPartition(primaryPartition); disk.createPartition(efiPartition); disk.createPartition(msrPartition); disk.createPartition(windowsPartition); /// Setup Modify partitions ModifyPartition primaryModifyPartition = new ModifyPartition(); ModifyPartition efiModifyPartition = new ModifyPartition(); ModifyPartition msrModifyPartition = new ModifyPartition(); ModifyPartition windowsModifyPartition = new ModifyPartition(); primaryModifyPartition.Format = "NTFS"; primaryModifyPartition.Label = "WinRE"; primaryModifyPartition.Order = "1"; primaryModifyPartition.PartitionID = "1"; primaryModifyPartition.TypeID = "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC"; efiModifyPartition.Format = "FAT32"; efiModifyPartition.Label = "System"; efiModifyPartition.Order = "2"; efiModifyPartition.PartitionID = "2"; msrModifyPartition.Order = "3"; msrModifyPartition.PartitionID = "3"; windowsModifyPartition.Format = "NTFS"; windowsModifyPartition.Label = "Windows"; windowsModifyPartition.Letter = "C"; windowsModifyPartition.Order = "4"; windowsModifyPartition.PartitionID = "4"; disk.modifyPartition(primaryModifyPartition); disk.modifyPartition(efiModifyPartition); disk.modifyPartition(msrModifyPartition); disk.modifyPartition(windowsModifyPartition); setupDiskComponent.DiskConfiguration.Disk = disk; //SETUP USER DATA UserData userData = new UserData(); userData.AcceptEula = "true"; userData.Organization = options.organization; userData.setProductKey(options.productkey); setupDiskComponent.UserData = userData; //SETUP IMAGE INSTALL ImageInstall imageInstall = new ImageInstall(); InstallTo installTo = new InstallTo(); installTo.DiskID = "0"; installTo.PartitionID = "4"; imageInstall.setInstallTo(installTo); setupDiskComponent.ImageInstall = imageInstall; //SETUP OOBE OobeUIComponent oobeUIComponent = new OobeUIComponent(); oobeUIComponent.InputLocale = options.locale; oobeUIComponent.SystemLocale = options.language; oobeUIComponent.UILanguage = options.language; oobeUIComponent.UserLocale = options.language; //SETUP USER ACCOUNT OobeAccountsComponent oobeAccountsComponent = new OobeAccountsComponent(); oobeAccountsComponent.AutoLogon.Enabled = "true"; oobeAccountsComponent.AutoLogon.LogonCount = "1"; oobeAccountsComponent.AutoLogon.Username = "******"; Password defaultAdminPassword = new Password(); defaultAdminPassword.Value = "password"; defaultAdminPassword.PlainText = "true"; oobeAccountsComponent.AutoLogon.Password = defaultAdminPassword; oobeAccountsComponent.Name = "Microsoft-Windows-Shell-Setup"; oobeAccountsComponent.ProcessorArchitecture = "amd64"; oobeAccountsComponent.PublicKeyToken = "31bf3856ad364e35"; oobeAccountsComponent.Language = "neutral"; oobeAccountsComponent.VersionScope = "nonSxS"; UserAccounts userAccounts = new UserAccounts(); LocalAccounts localAccounts = new LocalAccounts(); LocalAccount localAccount = new LocalAccount(); AdministratorPassword administratorPassword = new AdministratorPassword(); administratorPassword.Value = "password"; administratorPassword.PlainText = "true"; userAccounts.AdministratorPassword = administratorPassword; localAccount.Action = "add"; localAccount.Description = "Local admin account"; localAccount.DisplayName = options.username; localAccount.Group = "Administrators"; localAccount.Name = options.username; Password password = new Password(); password.Value = options.password; password.PlainText = "true"; localAccount.Password = password; localAccounts.LocalAccount = localAccount; userAccounts.LocalAccounts = localAccounts; oobeAccountsComponent.UserAccounts = userAccounts; OOBE oOBE = new OOBE(); oOBE.HideEULAPage = "true"; oOBE.HideLocalAccountScreen = "true"; oOBE.NetworkLocation = "Home"; oOBE.HideOEMRegistrationScreen = "true"; oOBE.HideOnlineAccountScreens = "true"; oOBE.ProtectYourPC = "1"; oOBE.HideWirelessSetupInOOBE = "true"; oobeAccountsComponent.OOBE = oOBE; //SETUP SYSTEM INFORMATION SystemInformationComponent systemInformationComponent = new SystemInformationComponent(); systemInformationComponent.Name = "Microsoft-Windows-Shell-Setup"; systemInformationComponent.ProcessorArchitecture = "amd64"; systemInformationComponent.PublicKeyToken = "31bf3856ad364e35"; systemInformationComponent.VersionScope = "nonSxS"; systemInformationComponent.ComputerName = options.computername; //SETUP TERMINAL SERVICES & FIREWALL (ENABLE RDP) TerminalServicesComponent terminalServicesComponent = new TerminalServicesComponent(); terminalServicesComponent.Name = "Microsoft-Windows-TerminalServices-LocalSessionManager"; terminalServicesComponent.ProcessorArchitecture = "amd64"; terminalServicesComponent.PublicKeyToken = "31bf3856ad364e35"; terminalServicesComponent.Language = "neutral"; terminalServicesComponent.VersionScope = "nonSxS"; terminalServicesComponent.FDenyTSConnections = "false"; NetworkingMPSSVCComponent networkingMPSSVCComponent = new NetworkingMPSSVCComponent(); networkingMPSSVCComponent.Name = "Networking-MPSSVC-Svc"; networkingMPSSVCComponent.PublicKeyToken = "31bf3856ad364e35"; networkingMPSSVCComponent.ProcessorArchitecture = "amd64"; networkingMPSSVCComponent.Language = "neutral"; networkingMPSSVCComponent.VersionScope = "nonSxS"; FirewallGroups firewallGroups = new FirewallGroups(); FirewallGroup firewallGroup = new FirewallGroup(); firewallGroup.Action = "add"; firewallGroup.KeyValue = "RemoteDesktop"; firewallGroup.Active = "true"; firewallGroup.Group = "@FirewallAPI.dll,-28752"; firewallGroup.Profile = "all"; firewallGroups.FirewallGroup = firewallGroup; networkingMPSSVCComponent.FirewallGroups = firewallGroups; //SETTING FOR ENABLE/DISABLE NLA RdpExtensionComponent rdpExtensionComponent = new RdpExtensionComponent(); rdpExtensionComponent.UserAuthentication = "0"; //Add components to settings windowsPESettings.Component.Add(setupUIComponent); windowsPESettings.Component.Add(setupDiskComponent); // oobeSettings.Component.Add(oobeUIComponent); oobeSettings.Component.Add(oobeAccountsComponent); specializeSettings.Component.Add(systemInformationComponent); specializeSettings.Component.Add(terminalServicesComponent); specializeSettings.Component.Add(networkingMPSSVCComponent); specializeSettings.Component.Add(rdpExtensionComponent); unattendObject.Settings = new System.Collections.Generic.List <Settings>(); unattendObject.Settings.Add(windowsPESettings); unattendObject.Settings.Add(specializeSettings); unattendObject.Settings.Add(oobeSettings); new XmlSerializer(typeof(WindowsUnattendObject.Unattend)).Serialize(Console.Out, unattendObject); }
public void Run() { try { var connectionString = ConfigurationManager.ConnectionStrings[CMSConfigurationSection.Instance.Data.SettingConnectionString].ConnectionString; var connecttion = new SqlConnection { ConnectionString = connectionString }; try { var filePath = System.AppDomain.CurrentDomain.BaseDirectory + @"SqlScript\sp_default.sql"; string script = File.ReadAllText(filePath); string[] splitter = new string[] { "\r\nGO\r\n" }; IEnumerable <string> commandStrings = script.Split(splitter, StringSplitOptions.RemoveEmptyEntries); connecttion.Open(); foreach (string commandString in commandStrings) { if (commandString.Trim() != "") { using (var command = new SqlCommand(commandString, connecttion)) { command.ExecuteNonQuery(); } } } connecttion.Close(); } catch (Exception ex) { if (connecttion.State == ConnectionState.Open) { connecttion.Close(); } throw new Exception(ex.Message); } var user = userRepository.Table.FirstOrDefault(x => x.UserName == Constants.DefaultUserName); if (user == null) { using (var transaction = new TransactionScope()) { user = new User { Id = 0, UserName = Constants.DefaultUserName, Email = Constants.DefaultUserName + "@yourdomain.com", SuperUser = true, CreateDate = DateTime.UtcNow }; userRepository.Insert(user); string hashedPassword = EncryptionExtensions.Encrypt(KeyConfiguration.PublishKey, Constants.DefaultPassword); if (string.IsNullOrEmpty(hashedPassword)) { throw new ArgumentException(SecurityConstants.ErrorConfigKey); } var localAccount = new LocalAccount { UserId = user.Id, IsConfirmed = true, Password = hashedPassword }; localAccountRepository.Insert(localAccount); transaction.Complete(); } } } catch (Exception ex) { } }