mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-03 10:04:59 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
27
src/Views/Validations/BranchName.cs
Normal file
27
src/Views/Validations/BranchName.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class BranchName : ValidationRule {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-/\.]+$");
|
||||
|
||||
public Models.Repository Repo { get; set; }
|
||||
public string Prefix { get; set; } = "";
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var name = value as string;
|
||||
if (string.IsNullOrEmpty(name)) new ValidationResult(false, App.Text("EmptyBranchName"));
|
||||
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadBranchName"));
|
||||
|
||||
name = Prefix + name;
|
||||
foreach (var t in Repo.Branches) {
|
||||
if (t.Name == name) {
|
||||
return new ValidationResult(false, App.Text("DuplicatedBranchName"));
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
13
src/Views/Validations/CloneDir.cs
Normal file
13
src/Views/Validations/CloneDir.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class CloneDir : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
return Directory.Exists(value as string)
|
||||
? ValidationResult.ValidResult
|
||||
: new ValidationResult(false, App.Text("BadCloneFolder"));
|
||||
}
|
||||
}
|
||||
}
|
13
src/Views/Validations/CommitMessage.cs
Normal file
13
src/Views/Validations/CommitMessage.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class CommitMessage : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var subject = value as string;
|
||||
return string.IsNullOrWhiteSpace(subject)
|
||||
? new ValidationResult(false, App.Text("EmptyCommitMessage"))
|
||||
: ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
18
src/Views/Validations/GitURL.cs
Normal file
18
src/Views/Validations/GitURL.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
|
||||
public class GitURL : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
string url = value as string;
|
||||
bool valid = !string.IsNullOrEmpty(url)
|
||||
&& (url.StartsWith("http://", StringComparison.Ordinal)
|
||||
|| url.StartsWith("https://", StringComparison.Ordinal)
|
||||
|| url.StartsWith("git@", StringComparison.Ordinal)
|
||||
|| url.StartsWith("file://", StringComparison.Ordinal));
|
||||
return valid ? ValidationResult.ValidResult : new ValidationResult(false, App.Text("BadRemoteUri"));
|
||||
}
|
||||
}
|
||||
}
|
16
src/Views/Validations/LocalRepositoryName.cs
Normal file
16
src/Views/Validations/LocalRepositoryName.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class LocalRepositoryName : ValidationRule {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-]+$");
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var name = value as string;
|
||||
if (string.IsNullOrEmpty(name)) return ValidationResult.ValidResult;
|
||||
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadLocalName"));
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
13
src/Views/Validations/PatchFile.cs
Normal file
13
src/Views/Validations/PatchFile.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class PatchFile : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
return File.Exists(value as string)
|
||||
? ValidationResult.ValidResult
|
||||
: new ValidationResult(false, App.Text("BadPatchFile"));
|
||||
}
|
||||
}
|
||||
}
|
31
src/Views/Validations/RemoteName.cs
Normal file
31
src/Views/Validations/RemoteName.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class RemoteName : ValidationRule {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-\.]+$");
|
||||
|
||||
public Models.Repository Repo { get; set; }
|
||||
public bool IsOptional { get; set; }
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var name = value as string;
|
||||
if (string.IsNullOrEmpty(name)) {
|
||||
return IsOptional ? ValidationResult.ValidResult : new ValidationResult(false, App.Text("EmptyRemoteName"));
|
||||
}
|
||||
|
||||
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadRemoteName"));
|
||||
|
||||
if (Repo != null) {
|
||||
foreach (var t in Repo.Remotes) {
|
||||
if (t.Name == name) {
|
||||
return new ValidationResult(false, App.Text("DuplicatedRemoteName"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
17
src/Views/Validations/SubmodulePath.cs
Normal file
17
src/Views/Validations/SubmodulePath.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class SubmodulePath : ValidationRule {
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var path = value as string;
|
||||
if (string.IsNullOrEmpty(path)) return ValidationResult.ValidResult;
|
||||
|
||||
var regex = new Regex(@"^[\w\-\._/]+$");
|
||||
var succ = regex.IsMatch(path.Trim());
|
||||
return !succ ? new ValidationResult(false, App.Text("BadSubmodulePath")) : ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
26
src/Views/Validations/TagName.cs
Normal file
26
src/Views/Validations/TagName.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace SourceGit.Views.Validations {
|
||||
public class TagName : ValidationRule {
|
||||
private static readonly Regex REG_FORMAT = new Regex(@"^[\w\-\.]+$");
|
||||
|
||||
public List<Models.Tag> Tags { get; set; }
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo) {
|
||||
var name = value as string;
|
||||
if (string.IsNullOrEmpty(name)) new ValidationResult(false, App.Text("EmptyTagName"));
|
||||
if (!REG_FORMAT.IsMatch(name)) return new ValidationResult(false, App.Text("BadTagName"));
|
||||
|
||||
foreach (var t in Tags) {
|
||||
if (t.Name == name) {
|
||||
return new ValidationResult(false, App.Text("DuplicatedTagName"));
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue