protected void btnAdd_OnClick(object sender, EventArgs e) { int timeout = 0; var parseResult = Int32.TryParse(txtTimeout.Text, out timeout); if (!parseResult) { EndUserMessage = "Timeout Is Not Valid"; return; } var module = new EntityWuModule() { Name = txtDisplayName.Text, Description = txtDescription.Text, Timeout = Convert.ToInt32(txtTimeout.Text), RedirectStdOut = chkStdOut.Checked, RedirectStdError = chkStdError.Checked, SuccessCodes = txtSuccessCodes.Text, }; var result = Call.WuModuleApi.Post(module); if (!result.Success) { EndUserMessage = result.ErrorMessage; } else { EndUserMessage = "Successfully Created Windows Update Module"; Response.Redirect("~/views/modules/wumodules/general.aspx?wuModuleId=" + result.Id); } }
public DtoActionResult Post(EntityWuModule module) { var result = _wuModuleServices.AddModule(module); if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "WuModule"; auditLog.ObjectId = result.Id; auditLog.ObjectName = module.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(module); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Create; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult Put(int id, EntityWuModule module) { module.Id = id; var result = _wuModuleServices.UpdateModule(module); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } if (result.Success) { var auditLog = new EntityAuditLog(); auditLog.ObjectType = "WuModule"; auditLog.ObjectId = result.Id; auditLog.ObjectName = module.Name; auditLog.ObjectJson = JsonConvert.SerializeObject(module); auditLog.UserId = _userId; auditLog.AuditType = EnumAuditEntry.AuditType.Update; _auditLogService.AddAuditLog(auditLog); } return(result); }
public DtoActionResult UpdateModule(EntityWuModule module) { var u = GetModule(module.Id); if (u == null) { return new DtoActionResult { ErrorMessage = "Module Not Found", Id = 0 } } ; var isActiveModule = new ServiceModule().IsModuleActive(module.Id, EnumModule.ModuleType.Wupdate); if (!string.IsNullOrEmpty(isActiveModule)) { return new DtoActionResult() { ErrorMessage = isActiveModule, Id = 0 } } ; var validationResult = ValidateModule(module, false); var actionResult = new DtoActionResult(); if (validationResult.Success) { _uow.WindowsUpdateModuleRepository.Update(module, module.Id); _uow.Save(); actionResult.Success = true; actionResult.Id = module.Id; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; } return(actionResult); }
public DtoActionResult AddModule(EntityWuModule module) { var validationResult = ValidateModule(module, true); var actionResult = new DtoActionResult(); if (validationResult.Success) { _uow.WindowsUpdateModuleRepository.Insert(module); var moduleType = new EntityModule(); moduleType.ModuleType = EnumModule.ModuleType.Wupdate; moduleType.Guid = module.Guid; _uow.ModuleRepository.Insert(moduleType); _uow.Save(); actionResult.Success = true; actionResult.Id = module.Id; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; } return(actionResult); }
private DtoValidationResult ValidateModule(EntityWuModule module, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; int value; if (!int.TryParse(module.Timeout.ToString(), out value)) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Timeout"; return(validationResult); } try { if (string.IsNullOrEmpty(module.SuccessCodes)) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } if (module.SuccessCodes.Split(',').Any(code => !int.TryParse(code, out value))) { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } } catch { validationResult.Success = false; validationResult.ErrorMessage = "Invalid Success Code"; return(validationResult); } if (module.Timeout < 0) { module.Timeout = 0; } if (string.IsNullOrEmpty(module.Name) || !module.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-' || c == ' ' || c == '.')) { validationResult.Success = false; validationResult.ErrorMessage = "Module Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.WindowsUpdateModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } else { var originalModule = _uow.WindowsUpdateModuleRepository.GetById(module.Id); if (originalModule.Name != module.Name) { if (_uow.WindowsUpdateModuleRepository.Exists(h => h.Name == module.Name)) { validationResult.Success = false; validationResult.ErrorMessage = "A Module With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
private DtoActionResult CreateWindowsUpdate() { foreach (var wuModuleModule in _export.WuModules) { if (_export.Instructions.Contains("[generate-module-guid]")) { wuModuleModule.Guid = Guid.NewGuid().ToString(); } if (_uow.WindowsUpdateModuleRepository.Exists(h => h.Guid.Equals(wuModuleModule.Guid))) { return(new DtoActionResult() { ErrorMessage = "A Windows Update Module With This Guid Already Exists. " + wuModuleModule.Guid }); } var wu = new EntityWuModule(); wu.Name = wuModuleModule.DisplayName; wu.Description = "Added Via Policy Template " + _export.Name + " On " + DateTime.Now + "\r\n" + wu.Description; wu.Guid = wuModuleModule.Guid; wu.AdditionalArguments = wuModuleModule.Arguments; wu.RedirectStdError = wuModuleModule.RedirectError; wu.RedirectStdOut = wuModuleModule.RedirectOutput; wu.SuccessCodes = wuModuleModule.SuccessCodes; wu.Timeout = wuModuleModule.Timeout; if (wuModuleModule.UploadedFiles.Any()) { _policyHasInternalFiles = true; } if (wuModuleModule.ExternalFiles.Any()) { _policyHasExternalFiles = true; } if (_uow.WindowsUpdateModuleRepository.Exists(h => h.Name.Equals(wu.Name))) { for (var c = 1; c <= 100; c++) { if (c == 100) { return new DtoActionResult() { ErrorMessage = "Could Not Determine A Windows Update Name" } } ; var newName = wu.Name + "_" + c; if (!_uow.WindowsUpdateModuleRepository.Exists(h => h.Name == newName)) { wu.Name = newName; break; } } } var addResult = new ServiceWuModule().AddModule(wu); if (!addResult.Success) { return(addResult); } var policyModule = new EntityPolicyModules(); policyModule.Guid = wu.Guid; policyModule.ModuleId = addResult.Id; policyModule.ModuleType = EnumModule.ModuleType.Wupdate; policyModule.Name = wu.Name; policyModule.Order = wuModuleModule.Order; policyModule.PolicyId = _policy.Id; policyModule.ConditionFailedAction = wuModuleModule.ConditionFailedAction; policyModule.ConditionNextModule = wuModuleModule.ConditionNextOrder; var conditionId = CreateCondition(wuModuleModule.Condition); if (conditionId != 0) { policyModule.ConditionId = conditionId; } else { policyModule.ConditionId = -1; } _uow.PolicyModulesRepository.Insert(policyModule); } return(new DtoActionResult() { Success = true }); }