public void Set(string key, object val) { var dictionary = new Dictionary <string, string>(); var watcherMock = new Mock <IWatcher>(); watcherMock.Setup(m => m.Properties) .Returns(dictionary); //watcherMock.Setup(r => r.Properties.Add(It.Is<string>(r => r == "key"), It.Is<string>(r => r == key))); //watcher?.Properties?.Add("key", k); var timeWatcherMock = new Mock <ITimeWatcher>(); timeWatcherMock.Setup(r => r.StartWatcher(It.IsAny <string>(), It.IsAny <bool>())) .Returns(() => watcherMock.Object); var obj = new RepositoryCache(); Assert.IsNotNull(obj); obj.Set(timeWatcherMock.Object, key, val); timeWatcherMock.Verify(foo => foo.StartWatcher("RepositoryCache.Set", It.IsAny <bool>()), Times.Once()); //watcherMock.Verify(r => r.Properties.Add(It.Is<string>(r => r == "key"), It.Is<string>(r => r == key)), Times.Once()); watcherMock.VerifyGet(r => r.Properties, Times.Once()); var b = dictionary.ContainsValue(key); Assert.IsTrue(b); //Assert.AreEqual(val,dictionary[key]); }
private void AddRepositoryContentsToCache(RepositoryReference repoSpec, IEnumerable <RepositoryContent> contentList) { foreach (var repoContent in contentList) { var subKey = new RepositoryPathReference { RepositoryOwner = repoSpec.RepositoryOwner, RepositoryName = repoSpec.RepositoryName, TreeReference = repoSpec.TreeReference, Path = repoContent.Path }; if (RepositoryCache.TryGetValue(subKey, out RepositoryContentEntry subEntry)) { subEntry.Leaf = repoContent; } else { subEntry = new RepositoryContentEntry { Leaf = repoContent } }; var subOptions = new MemoryCacheEntryOptions { Size = repoContent.Size }; RepositoryCache.Set(subKey, subEntry, subOptions); if (repoContent.Type.TryParse(out var repoContentType) && repoContentType == ContentType.File) { subEntry.Contents = new List <RepositoryContent>(capacity: 1) { repoContent } } ; } }
/// <summary> /// Add a single repository to the set that is exported by this daemon. /// <para /> /// The existence (or lack-thereof) of <code>git-daemon-export-ok</code> is /// ignored by this method. The repository is always published. /// </summary> /// <param name="name"> /// name the repository will be published under. /// </param> /// <param name="db">the repository instance. </param> public void ExportRepository(string name, Repository db) { if (!name.EndsWith(Constants.DOT_GIT_EXT)) { name = name + Constants.DOT_GIT_EXT; } Exports.Add(name, db); RepositoryCache.register(db); }
public void testCacheOpen() { RepositoryCache.FileKey loc = RepositoryCache.FileKey.exact(db.Directory); Core.Repository d2 = RepositoryCache.open(loc); Assert.AreNotSame(db, d2); Assert.AreSame(d2, RepositoryCache.open(RepositoryCache.FileKey.exact(loc.getFile()))); d2.Close(); d2.Close(); }
/// <exception cref="System.IO.IOException"></exception> private FileObjectDatabase.AlternateHandle OpenAlternate(FilePath objdir) { FilePath parent = objdir.GetParentFile(); if (RepositoryCache.FileKey.IsGitRepository(parent, fs)) { RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(parent, fs); FileRepository db = (FileRepository)RepositoryCache.Open(key); return(new FileObjectDatabase.AlternateRepository(db)); } NGit.Storage.File.ObjectDirectory db_1 = new NGit.Storage.File.ObjectDirectory(config , objdir, null, fs); return(new FileObjectDatabase.AlternateHandle(db_1)); }
public void ClearAll() { var timeWatcherMock = new Mock <ITimeWatcher>(); var watcherMock = new Mock <IWatcher>(); timeWatcherMock.Setup(r => r.StartWatcher(It.IsAny <string>(), It.IsAny <bool>())) .Returns(() => watcherMock.Object); var obj = new RepositoryCache(); Assert.IsNotNull(obj); var result = obj.ClearAll(timeWatcherMock.Object); Assert.IsTrue(result); timeWatcherMock.Verify(foo => foo.StartWatcher("RepositoryCache.ClearAll", It.IsAny <bool>()), Times.Once()); }
public virtual void TearDown() { RepositoryCache.Clear(); foreach (Repository r in toClose) { r.Close(); } toClose.Clear(); // Since memory mapping is controlled by the GC we need to // tell it this is a good time to clean up and unlock // memory mapped files. // if (useMMAP) { System.GC.Collect(); } RecursiveDelete(TestId(), trash, false, true); }
public virtual void tearDown() { RepositoryCache.clear(); foreach (Core.Repository r in toClose) { r.Dispose(); } toClose.Clear(); // Since memory mapping is controlled by the GC we need to // tell it this is a good time to clean up and unlock // memory mapped files. // if (useMMAP) { System.GC.Collect(); } recursiveDelete(testName() + " (TearDown)", trash, true); }
public void testCacheRegisterOpen() { DirectoryInfo dir = db.Directory; RepositoryCache.register(db); using (Core.Repository exact = RepositoryCache.open(RepositoryCache.FileKey.exact(dir))) { Assert.AreSame(db, exact); } Assert.IsTrue(dir.Name.EndsWith(Constants.DOT_GIT_EXT)); Assert.AreEqual(Constants.DOT_GIT, dir.Name); DirectoryInfo parent = dir.Parent; using (Core.Repository lenient = RepositoryCache.open(RepositoryCache.FileKey.lenient(parent))) { Assert.AreSame(db, lenient); } RepositoryCache.close(db); }
static void Main(string[] args) { Console.WriteLine("Migrating the database up..."); var connectionString = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=\"C:\\Users\\asuttmiller\\documents\\visual studio 2013\\Projects\\Parakeet\\Parakeet.Data\\Parakeet.mdf\";Integrated Security=True"; Runner.MigrateToLatest(connectionString); Console.WriteLine("Done migrating up..."); Console.ReadLine(); var repositoryCache = new RepositoryCache(); var peopleRepository = repositoryCache.PeopleRepository; try { peopleRepository.Add(new Person { FirstName = "Alex", LastName = "Suttmiller", Id = 10 }); } catch (Exception e) { Console.WriteLine(e); } }
private async Task <RepositoryContentEntry> CreateCachedRepositoryContentEntry(ICacheEntry entryOptions) { var entryKey = (RepositoryPathReference)entryOptions.Key; string entryPath = entryKey.Path; var entryContents = await DownloadRepositoryContents(entryKey, entryPath) .ConfigureAwait(continueOnCapturedContext: false); AddRepositoryContentsToCache(entryKey, entryContents); if (RepositoryCache.TryGetValue(entryKey, out RepositoryContentEntry entryObj)) { entryObj.Contents = entryContents; } else { entryObj = new RepositoryContentEntry { Contents = entryContents } }; entryOptions.Size = entryObj.Leaf?.Size; return(entryObj); }
private async Task <RepositoryContentEntry> GetRepositoryContentEntry(RepositoryReference repoSpec, string path) { var entryKey = new RepositoryPathReference { RepositoryOwner = repoSpec.RepositoryOwner, RepositoryName = repoSpec.RepositoryName, TreeReference = repoSpec.TreeReference, Path = path }; var entryObj = await RepositoryCache.GetOrCreateAsync( entryKey, CreateCachedRepositoryContentEntry ).ConfigureAwait(continueOnCapturedContext: false); if (entryObj.Contents is null) { var entryContents = await DownloadRepositoryContents(repoSpec, path) .ConfigureAwait(continueOnCapturedContext: false); AddRepositoryContentsToCache(repoSpec, entryContents); entryObj.Contents = entryContents; } return(entryObj); }
public void Get(string key, object val) { var dictionary = new Dictionary <string, string>(); var watcherMock = new Mock <IWatcher>(); watcherMock.Setup(m => m.Properties) .Returns(dictionary); var timeWatcherMock = new Mock <ITimeWatcher>(); timeWatcherMock.Setup(r => r.StartWatcher(It.IsAny <string>(), It.IsAny <bool>())) .Callback(() => dictionary.Clear()) .Returns(() => watcherMock.Object); var obj = new RepositoryCache(); Assert.IsNotNull(obj); obj.Set(timeWatcherMock.Object, key, val); var result = obj.Get <object>(timeWatcherMock.Object, key); timeWatcherMock.Verify(foo => foo.StartWatcher("RepositoryCache.Get", It.IsAny <bool>()), Times.Once()); Assert.AreEqual(val, result); }
private Accounts() { IAccountRepository repository = Repository.Factory.CreateAccountRepository(); _repositoryCache = new RepositoryCache <string, Account>(repository, _interval); }
internal TFSRepository(RepositoryService versionControlService, string rootPath) { this.VersionControlService = versionControlService; this.RootPath = rootPath; this.cache = new RepositoryCache(this); }
public MonsterRoleRepository(string filePath, IAsyncGetAllService <MonsterRole> asyncGetAllService) { mFilePath = filePath; mAsyncGetAllService = asyncGetAllService; mCache = new RepositoryCache <MonsterRole>(this); }
/// <exception cref="NGit.Errors.RepositoryNotFoundException"></exception> /// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception> public override Repository Open(C req, string name) { if (IsUnreasonableName(name)) { throw new RepositoryNotFoundException(name); } Repository db = exports.Get(NameWithDotGit(name)); if (db != null) { db.IncrementOpen(); return(db); } foreach (FilePath @base in exportBase) { FilePath dir = RepositoryCache.FileKey.Resolve(new FilePath(@base, name), FS.DETECTED ); if (dir == null) { continue; } try { RepositoryCache.FileKey key = RepositoryCache.FileKey.Exact(dir, FS.DETECTED); db = RepositoryCache.Open(key, true); } catch (IOException e) { throw new RepositoryNotFoundException(name, e); } try { if (IsExportOk(req, name, db)) { // We have to leak the open count to the caller, they // are responsible for closing the repository if we // complete successfully. return(db); } else { throw new ServiceNotEnabledException(); } } catch (RuntimeException e) { db.Close(); throw new RepositoryNotFoundException(name, e); } catch (IOException e) { db.Close(); throw new RepositoryNotFoundException(name, e); } catch (ServiceNotEnabledException e) { db.Close(); throw; } } if (exportBase.Count == 1) { FilePath dir = new FilePath(exportBase.Iterator().Next(), name); throw new RepositoryNotFoundException(name, new RepositoryNotFoundException(dir)); } throw new RepositoryNotFoundException(name); }
private SpecialProducts() { var repository = Repository.Factory.CreateSpecialProductRepository(); _repositoryCache = new RepositoryCache <SpecialProductType, SpecialProductView>(repository, _interval); }
public void Create() { var obj = new RepositoryCache(); Assert.IsNotNull(obj); }
public PubmedStudyReferenceRepository(MongoContext context, RepositoryCache <Guid, PubmedStudyReference> repositoryCache) : base(context, repositoryCache) { }
public IndexModel(ILogger <IndexModel> logger, IRepository repository, RepositoryCache repositoryCache) { _logger = logger; _repository = repository; _repositoryCache = repositoryCache; }
private SystemParams() { var repository = Repository.Factory.CreateSystemParamRepository(); _repositoryCache = new RepositoryCache <SystemParamType, SystemParam>(repository, _interval); }
public SummonerRepository(string filePath) { mFilePath = filePath; mAsyncGetAllService = new AsyncGetAllService <Summoner>(GetAll); mCache = new RepositoryCache <Summoner>(this); }
public BiorxivStudyReferenceRepository(MongoContext context, RepositoryCache <Guid, BiorxivStudyReference> repositoryCache) : base(context, repositoryCache) { }