protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults) { ICreateViewPageModel pageModel = currentTarget as ICreateViewPageModel; if (pageModel != null && pageModel.ValidateExistingFileExtension != null) { string physicalPath = string.Empty; if (pageModel.ProjectItem != null) { physicalPath = pageModel.ProjectItem.ItemPath; } else { physicalPath = pageModel.ModuleProject.ProjectPath; } string moduleViewsProjectPath = (pageModel.CreateViewFolder) ? Path.Combine(physicalPath, objectToValidate) : physicalPath; string viewFileName = String.Format(CultureInfo.CurrentCulture, "{0}.{1}", objectToValidate, pageModel.ValidateExistingFileExtension); string viewExistsMessage = (pageModel.IsWpfView) ? Resources.YouCantAddWpfViewIfFormsViewExists : Resources.YouCantAddFormsViewIfWpfViewExists; Validator <string> _viewViewFileValidator = new FileNotExistsValidator( moduleViewsProjectPath, String.Format(CultureInfo.CurrentCulture, viewExistsMessage, Path.Combine(moduleViewsProjectPath, viewFileName))); _viewViewFileValidator.Validate(viewFileName, validationResults); } }
protected override void DoValidate(string objectToValidate, object currentTarget, string key, ValidationResults validationResults) { ICreateViewPageBaseModel pageModel = currentTarget as ICreateViewPageBaseModel; if (pageModel != null) { string physicalPath = string.Empty; if (pageModel.WebFolder != null) { physicalPath = pageModel.WebFolder.ItemPath; } else { physicalPath = pageModel.WebProject.ProjectPath; } string viewFileName = String.Format(CultureInfo.CurrentCulture, "{0}.{1}", objectToValidate, pageModel.ViewFileExtension); string viewExistsMessage = DefaultFailureMessage; string pathToValidate = String.Empty; try { pathToValidate = Path.Combine(physicalPath, viewFileName); } catch (ArgumentException ex) { validationResults.AddResult(new ValidationResult(ex.Message, objectToValidate, key, "Bad file name", this)); return; } Validator <string> _viewViewFileValidator = new FileNotExistsValidator( physicalPath, String.Format(CultureInfo.CurrentCulture, viewExistsMessage, pathToValidate)); _viewViewFileValidator.Validate(viewFileName, validationResults); } }