public ActionResult Create(string project) { if (!string.IsNullOrEmpty(project)) { repositories.CreateRepository(project); } return(RedirectToAction("Index")); }
public ActionResult CreateRepository(string cat, string subcat, string project) { if (!string.IsNullOrEmpty(project)) { repositories.CreateRepository(cat, subcat, project); } return(RedirectToAction("Index", new { cat, subcat })); }
public ActionResult Create(string project) { if (!AuthService.IsAdmin(HttpContext.User.Identity.Name) || !HttpContext.User.Identity.IsAuthenticated) { return(new HttpUnauthorizedResult()); } if (!string.IsNullOrEmpty(project)) { repositories.CreateRepository(project); } return(RedirectToAction("Index")); }
public ActionResult New(string store, string project) { repositories = new RepositoryService(new AppSettings() { RepositoriesDirectory = repositories.GetRepositoriesStoreDirectory(store), }); if (!string.IsNullOrWhiteSpace(project) && !string.IsNullOrWhiteSpace(store)) { repositories.CreateRepository(store, project); } return(RedirectToAction("List", new { store = repositories.GetRepositoriesStoreDirectory(store).Name, })); }
public IActionResult Create(string name, string remoteurl, string description) { LibGit2Sharp.Repository result = null; name = name.Trim(); var username = HttpContext.User.Identity.Name; var reps = _repository.List(r => r.UserName == username).ToList(); if (reps.Count > 9) { return(View(new { error = "已超过10个限制" })); } if (reps.Exists(r => r.Name == name)) { return(View(new { error = "已存在仓库" })); } if (!string.IsNullOrEmpty(name) && string.IsNullOrEmpty(remoteurl)) { result = RepositoryService.CreateRepository(Path.Combine(username, name)); } else if (!string.IsNullOrEmpty(remoteurl)) { remoteurl = remoteurl.Trim(); result = RepositoryService.CreateRepository(Path.Combine(username, name), remoteurl); } if (result != null) { var rep = new Repository() { Name = name, Description = description, CreationDate = DateTime.Now, DefaultBranch = "master", UserName = username, UpdateTime = DateTime.Now }; _repository.Add(rep); return(Redirect("/")); } return(View()); }
public void TestNullDataInRepositoryCreation() { var httpresponse = new HttpResponseMessage(HttpStatusCode.Created); var mock = new Mock <IRequestSender>(); var url = $"/{UrlConstants.UsersUrlPart}/{UrlConstants.RepositoriesUrlPart}"; var mockResponse = new ClientResponse <string>() { Message = MessagesHelper.StandartSuccessMessage, Status = OperationStatus.Susseess }; mock.Setup(sender => sender.SendGetRequestToGitHubApiAsync(url)) .ReturnsAsync(httpresponse); mock.Setup(sender => sender.ProcessHttpResponse <string>(httpresponse, MessagesHelper.StandartNotFoundMessage)) .ReturnsAsync(mockResponse); RepositoryService repoService = new RepositoryService(mock.Object); ClientResponse <string> testResponse = repoService.CreateRepository(null).GetAwaiter().GetResult(); Assert.Equal(MessagesHelper.EmptyDataMessage, testResponse.Message); Assert.Equal(OperationStatus.EmptyData, testResponse.Status); }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("IMPORT JSON TEXT AND APPARATUS\n"); Console.ResetColor(); Console.WriteLine( $"Text dir: {_txtFileDir}\n" + $"Text mask: {_txtFileMask}\n" + $"Apparatus dir: {_appFileDir}\n" + $"Profile file: {_profilePath}\n" + $"Database: {_database}\n" + $"Dry run: {_dry}\n"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("IMPORT JSON TEXT AND APPARATUS"); if (!_dry) { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profilePath); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, profile); Console.WriteLine("Database created."); Log.Information("Database created."); } } else { if (!File.Exists(_profilePath)) { string error = "Profile path not found: " + _profilePath; Console.WriteLine(error); Log.Error(error); return(Task.CompletedTask); } } ICadmusRepository repository = _repositoryService.CreateRepository(_database); JsonImporter importer = new JsonImporter(repository) { Logger = loggerFactory.CreateLogger("json-importer"), IsDry = _dry }; int inputFileCount = 0; // 1) import text string[] files = FileEnumerator.Enumerate( _txtFileDir, _txtFileMask, _regexMask).ToArray(); HashSet <string> fileNames = new HashSet <string>(); Console.WriteLine($"Importing text from {files.Length} file(s)..."); foreach (string txtFilePath in files) { fileNames.Add( StripFileNameNr( Path.GetFileNameWithoutExtension(txtFilePath))); Console.WriteLine(txtFilePath); inputFileCount++; using (Stream stream = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportText(stream); } } // 2) import apparatus Console.WriteLine("Importing apparatus..."); foreach (string fileName in fileNames) { Console.WriteLine(fileName); foreach (string appFilePath in Directory.EnumerateFiles( _appFileDir, fileName + "-app_*.json")) { Console.WriteLine(" " + appFilePath); using (Stream stream = new FileStream(appFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportApparatus(stream); } } } return(Task.CompletedTask); }
public Task Run() { Console.WriteLine("IMPORT DATABASE\n" + $"Input directory: {_inputDir}\n" + $"Database: {_database}\n" + $"Profile file: {_profileText}\n" + $"Preflight: {(_preflight? "yes" : "no")}"); Serilog.Log.Information("IMPORT DATABASE: " + $"Input directory: {_inputDir}, " + $"Database: {_database}, " + $"Profile file: {_profileText}, " + $"Preflight: {_preflight}"); try { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profileText); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); _profile = serializer.Read(profileContent); if (!_preflight) { if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Serilog.Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, _profile); Console.WriteLine("Database created."); Serilog.Log.Information("Database created."); } } Console.WriteLine("Creating repository..."); Serilog.Log.Information("Creating repository..."); ICadmusRepository repository = _repositoryService.CreateRepository(_database); foreach (string lexFile in Directory.GetFiles(_inputDir, "??.xml").OrderBy(s => s)) { XDocument doc = XDocument.Load(lexFile, LoadOptions.PreserveWhitespace); if (doc.Root == null) { continue; } foreach (XElement itemElement in doc.Root.Elements("item")) { // read essential metadata string id = itemElement.Attribute("id").Value; string sid = itemElement.Attribute("sid").Value; string lemma = itemElement.Element("lemma").Value; int hom = GetHomographNumber(itemElement); int flags = itemElement.ReadOptionalAttribute("flags", 0); // TODO parent... // item Item item = new Item { Id = id, Title = BuildWordKey(lemma, hom), Description = BuildItemDescription(itemElement), FacetId = "facet-lex-word", SortKey = sid, UserId = USERID, Flags = flags }; Console.WriteLine(item.Title); // read parts // first remove all the _bm so we don't accidentally include metatext XElement filtered = XElement.Parse(itemElement.ToString(SaveOptions.DisableFormatting), LoadOptions.PreserveWhitespace); foreach (XElement bm in filtered.Descendants("_bm").ToList()) { bm.Remove(); } ReadParts(filtered, item); if (!_preflight) { repository.AddItem(item, false); foreach (IPart part in item.Parts) { repository.AddPart(part, false); } } } } Console.WriteLine(" completed."); Serilog.Log.Information("Import completed"); return(Task.FromResult(0)); } catch (Exception ex) { Serilog.Log.Error(ex, ex.Message); throw; } }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("SEED DATABASE\n"); Console.ResetColor(); Console.WriteLine($"Database: {_database}\n" + $"Profile file: {_profilePath}\n" + $"Count: {_count}\n" + $"Dry run: {_dry}\n" + $"History: {_history}\n"); Serilog.Log.Information("SEED DATABASE: " + $"Database: {_database}, " + $"Profile file: {_profilePath}, " + $"Count: {_count}, " + $"Dry: {_dry}, " + $"History: {_history}"); if (!_dry) { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profilePath); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Serilog.Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, profile); Console.WriteLine("Database created."); Serilog.Log.Information("Database created."); } } Console.WriteLine("Creating repository..."); Serilog.Log.Information("Creating repository..."); ICadmusRepository repository = _dry ? null : _repositoryService.CreateRepository(_database); Console.WriteLine("Seeding items"); PartSeederFactory factory = _seederService.GetFactory(_profilePath); CadmusSeeder seeder = new CadmusSeeder(factory); foreach (IItem item in seeder.GetItems(_count)) { Console.WriteLine($"{item}: {item.Parts.Count} parts"); if (!_dry) { repository.AddItem(item, _history); foreach (IPart part in item.Parts) { repository.AddPart(part, _history); } } } Console.WriteLine("Completed."); return(Task.CompletedTask); }