本文整理汇总了C#中Validator类的典型用法代码示例。如果您正苦于以下问题:C# Validator类的具体用法?C# Validator怎么用?C# Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Validator类属于命名空间,在下文中一共展示了Validator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnOK_Click
/// <summary>
/// Sets data to database.
/// </summary>
protected void btnOK_Click(object sender, EventArgs e)
{
CheckConfigurationModification();
string errorMessage = new Validator()
.NotEmpty(txtInternalStatusDisplayName.Text.Trim(), GetString("InternalStatus_Edit.errorDisplayName"))
.NotEmpty(txtInternalStatusName.Text.Trim(), GetString("InternalStatus_Edit.errorCodeName")).Result;
if (!ValidationHelper.IsCodeName(txtInternalStatusName.Text.Trim()))
{
errorMessage = GetString("General.ErrorCodeNameInIdentificatorFormat");
}
if (errorMessage == "")
{
// Check unique name for configured site
DataSet ds = InternalStatusInfoProvider.GetInternalStatuses("InternalStatusName = '" + txtInternalStatusName.Text.Trim().Replace("'", "''") + "' AND ISNULL(InternalStatusSiteID, 0) = " + ConfiguredSiteID, null);
InternalStatusInfo internalStatusObj = null;
if (!DataHelper.DataSourceIsEmpty(ds))
{
internalStatusObj = new InternalStatusInfo(ds.Tables[0].Rows[0]);
}
// if internalStatusName value is unique
if ((internalStatusObj == null) || (internalStatusObj.InternalStatusID == mStatusid))
{
// if internalStatusName value is unique -> determine whether it is update or insert
if ((internalStatusObj == null))
{
// get InternalStatusInfo object by primary key
internalStatusObj = InternalStatusInfoProvider.GetInternalStatusInfo(mStatusid);
if (internalStatusObj == null)
{
// create new item -> insert
internalStatusObj = new InternalStatusInfo();
internalStatusObj.InternalStatusSiteID = ConfiguredSiteID;
}
}
internalStatusObj.InternalStatusEnabled = chkInternalStatusEnabled.Checked;
internalStatusObj.InternalStatusName = txtInternalStatusName.Text.Trim();
internalStatusObj.InternalStatusDisplayName = txtInternalStatusDisplayName.Text.Trim();
InternalStatusInfoProvider.SetInternalStatusInfo(internalStatusObj);
URLHelper.Redirect("InternalStatus_Edit.aspx?statusid=" + Convert.ToString(internalStatusObj.InternalStatusID) + "&saved=1&siteId=" + SiteID);
}
else
{
lblError.Visible = true;
lblError.Text = GetString("InternalStatus_Edit.InternalStatusNameExists");
}
}
else
{
lblError.Visible = true;
lblError.Text = errorMessage;
}
}
示例2: BindModel
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var form = controllerContext.HttpContext.Request.Form;
var order = new Order
{
//OrderStatusId = OrderStatus.CreatedId,
CreatedDate = DateTime.Now,
DispatchedDate = DateTime.Now
};
try
{
var validator = new Validator
{
() => UpdateOrder(order, form, bindingContext.ModelState),
() => UpdateCardContact(order, form, bindingContext.ModelState),
() => UpdateDeliveryContact(order, form, bindingContext.ModelState),
() => UpdateCard(order, form, bindingContext.ModelState)
};
validator.Validate();
}
catch (ValidationException)
{
//Ignore validation exceptions - they will be stored in ModelState.
}
EnsureBasketCountryId(order);
return order;
}
示例3: GetDriveName
public static string GetDriveName(string fullPath)
{
var validator = new Validator(fullPath);
var drive = new DriveParser(fullPath, validator);
validator.ThrowOnError();
return drive.AppendTo(string.Empty);
}
示例4: btnOK_Click
/// <summary>
/// Sets data to database.
/// </summary>
protected void btnOK_Click(object sender, EventArgs e)
{
string errorMessage = new Validator()
.NotEmpty(txtTimeZoneName.Text, rfvName.ErrorMessage)
.NotEmpty(txtTimeZoneDisplayName.Text, rfvDisplayName.ErrorMessage)
.NotEmpty(txtTimeZoneGMT.Text, rfvGMT.ErrorMessage)
.IsCodeName(txtTimeZoneName.Text, GetString("general.invalidcodename"))
.IsDouble(txtTimeZoneGMT.Text, rvGMTDouble.ErrorMessage)
.Result;
if (chkTimeZoneDaylight.Checked)
{
if ((!startRuleEditor.IsValid()) || (!endRuleEditor.IsValid()))
{
errorMessage = GetString("TimeZ.RuleEditor.NotValid");
}
}
if (errorMessage == "")
{
// timeZoneName must to be unique
TimeZoneInfo timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(txtTimeZoneName.Text.Trim());
// if timeZoneName value is unique
if ((timeZoneObj == null) || (timeZoneObj.TimeZoneID == zoneid))
{
// if timeZoneName value is unique -> determine whether it is update or insert
if ((timeZoneObj == null))
{
// get TimeZoneInfo object by primary key
timeZoneObj = TimeZoneInfoProvider.GetTimeZoneInfo(zoneid);
if (timeZoneObj == null)
{
// create new item -> insert
timeZoneObj = new TimeZoneInfo();
}
}
timeZoneObj.TimeZoneName = txtTimeZoneName.Text.Trim();
timeZoneObj.TimeZoneDaylight = chkTimeZoneDaylight.Checked;
timeZoneObj.TimeZoneDisplayName = txtTimeZoneDisplayName.Text.Trim();
timeZoneObj.TimeZoneRuleStartIn = ValidationHelper.GetDateTime(TimeZoneInfoProvider.CreateRuleDateTime(startRuleEditor.Rule), DateTime.Now);
timeZoneObj.TimeZoneRuleEndIn = ValidationHelper.GetDateTime(TimeZoneInfoProvider.CreateRuleDateTime(endRuleEditor.Rule), DateTime.Now);
timeZoneObj.TimeZoneRuleStartRule = startRuleEditor.Rule;
timeZoneObj.TimeZoneRuleEndRule = endRuleEditor.Rule;
timeZoneObj.TimeZoneGMT = Convert.ToDouble(txtTimeZoneGMT.Text.Trim());
TimeZoneInfoProvider.SetTimeZoneInfo(timeZoneObj);
URLHelper.Redirect("TimeZone_Edit.aspx?zoneid=" + Convert.ToString(timeZoneObj.TimeZoneID) + "&saved=1");
}
else
{
ShowError(GetString("TimeZ.Edit.TimeZoneNameExists"));
}
}
else
{
ShowError(errorMessage);
}
}
示例5: CanonicalPathBuilder
public CanonicalPathBuilder(string fullPath)
{
_fullPath = fullPath;
ThrowHelper.ThrowIfNull(fullPath, "fullPath");
if (_fullPath == null) throw new InvalidPathException("The path is empty.");
_validator = new Validator(_fullPath);
}
示例6: ButtonOK_Click
/// <summary>
/// Saves new workflow's data and redirects to Workflow_Edit.aspx.
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">Event arguments</param>
protected void ButtonOK_Click(object sender, EventArgs e)
{
// finds whether required fields are not empty
string result = new Validator().NotEmpty(txtWorkflowDisplayName.Text, GetString("Development-Workflow_New.RequiresDisplayName")).NotEmpty(txtWorkflowCodeName.Text, GetString("Development-Workflow_New.RequiresCodeName"))
.IsCodeName(txtWorkflowCodeName.Text, GetString("general.invalidcodename"))
.Result;
if (result == "")
{
WorkflowInfo wi = WorkflowInfoProvider.GetWorkflowInfo(txtWorkflowCodeName.Text);
if (wi == null)
{
int workflowId = SaveNewWorkflow();
if (workflowId > 0)
{
WorkflowStepInfoProvider.CreateDefaultWorkflowSteps(workflowId);
URLHelper.Redirect("Workflow_Edit.aspx?workflowid=" + workflowId + "&saved=1");
}
}
else
{
lblError.Visible = true;
lblError.Text = GetString("Development-Workflow_New.WorkflowExists");
}
}
else
{
lblError.Visible = true;
lblError.Text = result;
}
}
示例7: Validate_Should_Return_Error_When_Referenced_Collection_Of_Objects_Have_Errors
public void Validate_Should_Return_Error_When_Referenced_Collection_Of_Objects_Have_Errors()
{
// Arrange
var testClass =
new TestClassWithCollectionOfReferencesToAnotherClass
{
TestProperty =
new[]
{
new TestClass { TestProperty1 = "ABC", TestProperty2 = null },
new TestClass { TestProperty1 = "ABC", TestProperty2 = "ABC"},
new TestClass { TestProperty1 = null, TestProperty2 = "ABC"}
}
};
var validator = new Validator();
// Act
var errors = validator.Validate(testClass);
// Assert
Assert.IsNotNull(errors);
Assert.AreEqual(testClass, errors.Object);
Assert.AreEqual(2, errors.Errors.Length);
Assert.AreEqual("TestProperty2", errors.Errors[0].Key);
Assert.AreEqual("Error2", errors.Errors[0].Message);
Assert.AreEqual("TestProperty1", errors.Errors[1].Key);
Assert.AreEqual("Error1", errors.Errors[1].Message);
}
示例8: ButtonOK_Click
/// <summary>
/// Saves data of edited workflow from TextBoxes into DB.
/// </summary>
protected void ButtonOK_Click(object sender, EventArgs e)
{
// finds whether required fields are not empty
string result = new Validator().NotEmpty(TextBoxWorkflowDisplayName.Text, GetString("Development-Workflow_New.RequiresDisplayName"))
.NotEmpty(txtCodeName.Text, GetString("Development-Workflow_New.RequiresCodeName"))
.IsCodeName(txtCodeName.Text, GetString("general.invalidcodename"))
.Result;
if (result == "")
{
if (currentWorkflow != null)
{
// Codename must be unique
WorkflowInfo wiCodename = WorkflowInfoProvider.GetWorkflowInfo(txtCodeName.Text);
if ((wiCodename == null) || (wiCodename.WorkflowID == currentWorkflow.WorkflowID))
{
if (currentWorkflow.WorkflowDisplayName != TextBoxWorkflowDisplayName.Text)
{
// Refresh header
ScriptHelper.RefreshTabHeader(Page, null);
}
currentWorkflow.WorkflowDisplayName = TextBoxWorkflowDisplayName.Text;
currentWorkflow.WorkflowName = txtCodeName.Text;
currentWorkflow.WorkflowAutoPublishChanges = chkAutoPublish.Checked;
// Inherited from global settings
if (radSiteSettings.Checked)
{
currentWorkflow.WorkflowUseCheckinCheckout = null;
}
else
{
currentWorkflow.WorkflowUseCheckinCheckout = radYes.Checked;
}
// Save workflow info
WorkflowInfoProvider.SetWorkflowInfo(currentWorkflow);
lblInfo.Visible = true;
lblInfo.Text = GetString("General.ChangesSaved");
}
else
{
lblError.Visible = true;
lblError.Text = GetString("Development-Workflow_New.WorkflowExists");
}
}
else
{
lblError.Visible = true;
lblError.Text = GetString("Development-Workflow_General.WorkflowDoesNotExists");
}
}
else
{
lblError.Visible = true;
lblError.Text = result;
}
}
示例9: ButtonOK_Click
/// <summary>
/// Saves new relationship name's data and redirects to RelationshipName_Edit.aspx.
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">Event arguments</param>
protected void ButtonOK_Click(object sender, EventArgs e)
{
// finds whether required fields are not empty
string result = new Validator().NotEmpty(txtRelationshipNameDisplayName.Text, GetString("General.RequiresDisplayName")).NotEmpty(txtRelationshipNameCodeName.Text, GetString("General.RequiresCodeName"))
.IsCodeName(txtRelationshipNameCodeName.Text, GetString("general.invalidcodename"))
.Result;
if (result == string.Empty)
{
RelationshipNameInfo rni = RelationshipNameInfoProvider.GetRelationshipNameInfo(txtRelationshipNameCodeName.Text);
if (rni == null)
{
int relationshipNameId = SaveNewRelationshipName();
if (relationshipNameId > 0)
{
URLHelper.Redirect("RelationshipName_Edit.aspx?relationshipnameid=" + relationshipNameId + "&saved=1");
}
}
else
{
ShowError(GetString("RelationshipNames.RelationshipNameAlreadyExists"));
}
}
else
{
ShowError(result);
}
}
示例10: Save
private void Save()
{
string validationResult = new Validator()
.NotEmpty(txtServerName.Text, rfvServerName.ErrorMessage)
.Result;
if (!string.IsNullOrEmpty(validationResult))
{
ShowError(validationResult);
return;
}
try
{
SMTPServerPriorityEnum priority = (SMTPServerPriorityEnum)Enum.Parse(typeof(SMTPServerPriorityEnum), ddlPriorities.SelectedValue);
SMTPServerInfo smtpServer =
SMTPServerInfoProvider.CreateSMTPServer(txtServerName.Text, txtUserName.Text, txtPassword.Text, chkUseSSL.Checked, priority);
if (chkAssign.Checked && currentSite != null)
{
SMTPServerSiteInfoProvider.AddSMTPServerToSite(smtpServer.ServerID, currentSite.SiteID);
}
URLHelper.Redirect(string.Format("Frameset.aspx?smtpserverid={0}&saved=1", smtpServer.ServerID));
}
catch (Exception e)
{
ShowError(e.Message);
return;
}
}
示例11: btnOK_Click
/// <summary>
/// Handles btnOK's OnClick event - Update resource info.
/// </summary>
protected void btnOK_Click(object sender, EventArgs e)
{
// Check if input is valid
string cultureCode = txtUICultureCode.Text.Trim();
string result = new Validator()
.NotEmpty(txtUICultureName.Text, rfvUICultureName.ErrorMessage)
.NotEmpty(cultureCode, rfvUICultureCode.ErrorMessage)
.Result;
// Check if requested culture exists
try
{
CultureInfo obj = new CultureInfo(cultureCode);
}
catch
{
result = GetString("UICulture.ErrorNoGlobalCulture");
}
if (!string.IsNullOrEmpty(result))
{
ShowError(result);
}
else
{
SaveUICulture(cultureCode);
}
}
示例12: nameElem_Click
void nameElem_Click(object sender, EventArgs e)
{
// Code name validation
string err = new Validator().IsIdentificator(nameElem.CodeName, GetString("general.erroridentificatorformat")).Result;
if (err != String.Empty)
{
lblError.Visible = true;
lblError.Text = err;
return;
}
// Checking for duplicate items
DataSet ds = AlternativeFormInfoProvider.GetAlternativeForms("FormName='" + SqlHelperClass.GetSafeQueryString(nameElem.CodeName, false) +
"' AND FormClassID=" + classId, null);
if (!DataHelper.DataSourceIsEmpty(ds))
{
lblError.Visible = true;
lblError.Text = GetString("general.codenameexists");
return;
}
// Create new info object
AlternativeFormInfo afi = new AlternativeFormInfo();
afi.FormID = 0;
afi.FormGUID = Guid.NewGuid();
afi.FormClassID = classId;
afi.FormName = nameElem.CodeName;
afi.FormDisplayName = nameElem.DisplayName;
AlternativeFormInfoProvider.SetAlternativeFormInfo(afi);
URLHelper.Redirect("AlternativeForms_Frameset.aspx?classid=" + classId + "&altformid=" + afi.FormID + "&saved=1");
}
示例13: Start
public Point2D gazeCoords; //average coordinates from tet gaze data
//init
void Start () {
//validate gaze data
gazeValidator = new Validator(30);
//listen for gaze events
GazeManager.Instance.AddGazeListener(this);
} //end function
示例14: Check_all_possible_errors_and_get_a_list_of_custom_exceptions
public void Check_all_possible_errors_and_get_a_list_of_custom_exceptions()
{
var list = new Validator().CheckThat(() => _integerToCheck)
.IsEqualTo<ArgumentException>(17,null)
.IsEqualTo<ArgumentException>(_integerToCheck, null)
.IsLessThan<ArgumentException>(17, null)
.IsLessThan<ArgumentException>(12, null)
.IsMoreThan<ArgumentException>(12, null)
.IsMoreThan<ArgumentException>(17, null)
.IsLessOrEqualTo<ArgumentException>(13, null)
.IsLessOrEqualTo<ArgumentException>(14, null)
.IsLessOrEqualTo<ArgumentException>(17, null)
.IsMoreOrEqualTo<ArgumentException>(13, null)
.IsMoreOrEqualTo<ArgumentException>(14, null)
.IsMoreOrEqualTo<ArgumentException>(17, null)
.IsBetween<ArgumentException>(3, 9,null)
.IsBetween<ArgumentException>(8, 17,null)
.IsBetween<ArgumentException>(15, 18,null)
.List();
Assert.That(list.ErrorsCollection.First().Value.Count, Is.EqualTo(7));
foreach (var exception in list.ErrorsCollection.First().Value)
{
Assert.IsInstanceOfType(typeof(ArgumentException),exception);
}
}
示例15: btnOK_Click
protected void btnOK_Click(object sender, EventArgs e)
{
// Check valid input
string errMsg = new Validator().
NotEmpty(this.txtName.Text, GetString("img.errors.filename")).
IsFolderName(this.txtName.Text, GetString("img.errors.filename")).
Result;
// Prepare the path
string path = filePath;
if (!newFile)
{
path = Path.GetDirectoryName(path);
}
path += "/" + txtName.Text + extension;
// Check the file name for existence
if (!this.txtName.Text.Equals(fileName, StringComparison.InvariantCultureIgnoreCase))
{
if (File.Exists(path))
{
errMsg = GetString("general.fileexists");
}
}
if (!String.IsNullOrEmpty(errMsg))
{
this.lblError.Text = errMsg;
this.lblError.Visible = true;
}
else
{
try
{
if (!newFile && !path.Equals(filePath, StringComparison.InvariantCultureIgnoreCase))
{
// Move the file to the new location
File.WriteAllText(filePath, this.txtContent.Text);
File.Move(filePath, path);
}
else
{
// Create the file or write into it
File.WriteAllText(path, this.txtContent.Text);
}
string script = "wopener.SetRefreshAction(); window.close()";
this.ltlScript.Text = ScriptHelper.GetScript(script);
}
catch (Exception ex)
{
this.lblError.Text = ex.Message;
this.lblError.Visible = true;
// Log the exception
EventLogProvider.LogException("FileSystemSelector", "SAVEFILE", ex);
}
}
}