Browse Source

使用定时器TimerX替代计划任务;

干掉MEF
v1.4
大石头 9 years ago
parent
commit
33f90165df
  1. 1
      GitCandy/Controllers/AccountController.cs
  2. 4
      GitCandy/Controllers/CandyControllerBase.cs
  3. 5
      GitCandy/Controllers/GitController.cs
  4. 5
      GitCandy/Controllers/RepositoryController.cs
  5. 3
      GitCandy/Data/RepositoryService.cs
  6. 30
      GitCandy/Git/Cache/GitCacheAccessor.cs
  7. 28
      GitCandy/Git/GitService.cs
  8. 8
      GitCandy/GitCandy.csproj
  9. 4
      GitCandy/Global.asax.cs

1
GitCandy/Controllers/AccountController.cs

@ -14,7 +14,6 @@ using UserX = NewLife.GitCandy.Entity.User;
namespace GitCandy.Controllers
{
[Export(typeof(AccountController))]
public class AccountController : CandyControllerBase
{
[Administrator]

4
GitCandy/Controllers/CandyControllerBase.cs

@ -1,5 +1,4 @@
using System;
using System.Composition;
using System.Threading;
using System.Web;
using System.Web.Caching;
@ -18,8 +17,7 @@ namespace GitCandy.Controllers
private Token _token;
[Import]
public MembershipService MembershipService { get; set; }
public MembershipService MembershipService { get; set; } = new MembershipService();
public Token Token
{

5
GitCandy/Controllers/GitController.cs

@ -1,5 +1,4 @@
using System;
using System.Composition;
using System.Globalization;
using System.IO;
using System.IO.Compression;
@ -13,11 +12,9 @@ using LibGit2Sharp;
namespace GitCandy.Controllers
{
[Export(typeof(GitController))]
public class GitController : CandyControllerBase
{
[Import]
public RepositoryService RepositoryService { get; set; }
public RepositoryService RepositoryService { get; set; } = new RepositoryService();
[SmartGit]
public ActionResult Smart(string project, string service, string verb)

5
GitCandy/Controllers/RepositoryController.cs

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Net;
using System.Web;
using System.Web.Mvc;
@ -17,11 +16,9 @@ using NewLife.Log;
namespace GitCandy.Controllers
{
[Export(typeof(RepositoryController))]
public class RepositoryController : CandyControllerBase
{
[Import]
public RepositoryService RepositoryService { get; set; }
public RepositoryService RepositoryService { get; set; } = new RepositoryService();
public ActionResult Index()
{

3
GitCandy/Data/RepositoryService.cs

@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
using GitCandy.Base;
using GitCandy.Models;
using NewLife.Data;
using NewLife.GitCandy.Entity;
using XCode;
namespace GitCandy.Data
{
[Export(typeof(RepositoryService))]
public class RepositoryService
{
public Repository Create(RepositoryModel model, long managerID, out bool badName)

30
GitCandy/Git/Cache/GitCacheAccessor.cs

@ -7,9 +7,9 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Threading.Tasks;
using GitCandy.Configuration;
using GitCandy.Extensions;
using GitCandy.Schedules;
using LibGit2Sharp;
using NewLife.Log;
using NewLife.Threading;
namespace GitCandy.Git.Cache
{
@ -39,8 +39,7 @@ namespace GitCandy.Git.Cache
};
}
public static T Singleton<T>(T accessor)
where T : GitCacheAccessor
public static T Singleton<T>(T accessor) where T : GitCacheAccessor
{
Contract.Requires(accessor != null);
@ -91,7 +90,7 @@ namespace GitCandy.Git.Cache
File.WriteAllLines(filename, expectation);
Scheduler.Instance.AddJob(new SingleJob(() =>
new TimerX(s =>
{
var dirs = Directory.GetDirectories(cachePath, "*.del");
foreach (var dir in dirs)
@ -99,7 +98,7 @@ namespace GitCandy.Git.Cache
XTrace.WriteLine("Delete cache directory {0}", dir);
Directory.Delete(dir, true);
}
}, JobType.LongRunning));
}, null, 10000, 10 * 60 * 1000);
enabled = true;
}
@ -117,17 +116,12 @@ namespace GitCandy.Git.Cache
public static void Delete(string project)
{
Scheduler.Instance.AddJob(new SingleJob(() =>
var cachePath = UserConfiguration.Current.CachePath.GetFullPath();
for (int i = 0; i < accessors.Length; i++)
{
var cachePath = UserConfiguration.Current.CachePath.GetFullPath();
for (int i = 0; i < accessors.Length; i++)
{
var path = Path.Combine(cachePath, (i + 1).ToString(), project);
if (Directory.Exists(path))
Directory.Delete(path, true);
}
}, JobType.LongRunning));
var path = Path.Combine(cachePath, (i + 1).ToString(), project);
if (Directory.Exists(path)) Directory.Delete(path, true);
}
}
protected void RemoveFromRunningPool()
@ -150,8 +144,7 @@ namespace GitCandy.Git.Cache
try
{
Calculate();
if (enabled)
Save();
if (enabled) Save();
}
catch (Exception ex)
{
@ -171,7 +164,8 @@ namespace GitCandy.Git.Cache
}
else if (IsAsync)
{
Scheduler.Instance.AddJob(new SingleJob(task));
//Scheduler.Instance.AddJob(new SingleJob(task));
Task.Run(() => task.Start());
}
else
{

28
GitCandy/Git/GitService.cs

@ -1,15 +1,16 @@
using GitCandy.Base;
using GitCandy.Configuration;
using GitCandy.Extensions;
using GitCandy.Git.Cache;
using GitCandy.Models;
using LibGit2Sharp;
using System;
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GitCandy.Base;
using GitCandy.Configuration;
using GitCandy.Extensions;
using GitCandy.Git.Cache;
using GitCandy.Models;
using LibGit2Sharp;
namespace GitCandy.Git
{
@ -385,11 +386,9 @@ namespace GitCandy.Git
public string GetArchiveFilename(string path, string newline, out string referenceName)
{
var commit = GetCommitByPath(ref path, out referenceName);
if (commit == null)
return null;
if (commit == null) return null;
if (referenceName == null)
referenceName = commit.Sha;
if (referenceName == null) referenceName = commit.Sha;
var accessor = GitCacheAccessor.Singleton(new ArchiverAccessor(_repoId, _repository, commit, newline, CpToEncoding(commit.Encoding), _i18n.Value));
@ -754,17 +753,18 @@ namespace GitCandy.Git
args += " --advertise-refs";
args += " \"" + _repositoryPath + "\"";
var info = new System.Diagnostics.ProcessStartInfo(Path.Combine(UserConfiguration.Current.GitCorePath.GetFullPath(), "git.exe"), args)
var cfg = UserConfiguration.Current;
var info = new ProcessStartInfo(Path.Combine(cfg.GitCorePath.GetFullPath(), "git.exe"), args)
{
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = Path.GetDirectoryName(UserConfiguration.Current.RepositoryPath.GetFullPath()),
WorkingDirectory = Path.GetDirectoryName(cfg.RepositoryPath.GetFullPath()),
};
using (var process = System.Diagnostics.Process.Start(info))
using (var process = Process.Start(info))
{
inStream.CopyTo(process.StandardInput.BaseStream);
process.StandardInput.Close();

8
GitCandy/GitCandy.csproj

@ -381,9 +381,7 @@
<Compile Include="App_Start\AppInfomation.cs" />
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\MefConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\ScheduleConfig.cs" />
<Compile Include="App_Start\SshServerConfig.cs" />
<Compile Include="Areas\GitCandy\Controllers\TeamController.cs" />
<Compile Include="Areas\GitCandy\Controllers\RepositoryController.cs" />
@ -489,12 +487,6 @@
<Compile Include="Models\UserListModel.cs" />
<Compile Include="Models\UserModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Schedules\IJob.cs" />
<Compile Include="Schedules\JobContext.cs" />
<Compile Include="Schedules\JobType.cs" />
<Compile Include="Schedules\Runner.cs" />
<Compile Include="Schedules\Scheduler.cs" />
<Compile Include="Schedules\SingleJob.cs" />
<Compile Include="Security\Token.cs" />
<Compile Include="Ssh\Algorithms\CipherInfo.cs" />
<Compile Include="Ssh\Algorithms\CipherModeEx.cs" />

4
GitCandy/Global.asax.cs

@ -29,8 +29,8 @@ namespace GitCandy
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
MefConfig.RegisterMef();
ScheduleConfig.RegisterScheduler();
//MefConfig.RegisterMef();
//ScheduleConfig.RegisterScheduler();
GitCacheAccessor.Initialize();
SshServerConfig.StartSshServer();

Loading…
Cancel
Save