public ApplicationRepository() { _ctx = new AuthContext(); _userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(_ctx)); RefreshTokens = new RefreshTokenRepository(_ctx); Audiences = new AudienceRepository(_ctx); Files = new FileRepository(_ctx); }
public async Task GetFilesAsync_WhenFilesExist_ReturnsExpectedType() { //Arrange var sut = new FileRepository(new StubLoggerService()); ; //Act var result = await sut.GetFilesAsync(); //Assert Assert.IsInstanceOfType(result, typeof(IEnumerable<FileItem>)); }
public async Task GetFilesAsync_VerifyLogMethodIsCalled() { //Arrange var loggerServiceMock = new Mock<ILoggerService>(); var sut = new FileRepository(loggerServiceMock.Object); //Act var result = await sut.GetFilesAsync(); //Assert loggerServiceMock.Verify(c => c.Log(It.IsAny<string>()), Times.Once()); }
public static void InitTest(TestContext context) { Init(context); var repo = new FileRepository { DirectoryPath = Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).FullName).FullName }; repo.Initialize(); Users = repo; Templates = repo; Places = repo; Characters = repo; }
public UnitOfWork(FypDbContext db) { _context = db; Campus = new CampusRepository(_context); Department = new DepartmentRepository(_context); Batch = new BatchRepository(_context); Section = new SectionRepository(_context); Student = new StudentRepository(_context); File = new FileRepository(_context); Teacher = new TeacherRepository(_context); EnrollDep = new EnrollDepartmentRepository(_context); EnrollBatch = new EnrollBatchRepository(_context); EnrollSection = new EnrollSectionRepository(_context); Course = new CourseRepository(_context); CourseToDep = new CourseToDepRepository(_context); StudentRegistration = new StudentRegistrationRepository(_context); subjectallocate = new SubjectAllocatRepository(_context); }
public PlayersController(FileRepository repo) { _IRepo = repo; }
public override void Dispose() { FileRepository.Dispose(); base.Dispose(); }
public HomeController() { _fileRepository = new FileRepository(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Input")); }
internal void InitializeData() { Settings = FileRepository.ReadSettings(); Issues = new ObservableCollection <Issue>(FileRepository.ReadFile <Issue>("issue")); Projects = new ObservableCollection <Project>(FileRepository.ReadFile <Project>("project")); }
public void Execute(IJobExecutionContext context) { var taskId = ""; var jobDataTaskId = context.Trigger.JobDataMap["taskId"]; if (jobDataTaskId != null) { taskId = jobDataTaskId.ToString(); } FileRepository repo = new FileRepository(); FileTask task = null; while ((task = repo.GetTask(taskId)) != null) { // 修改开始执行时间 repo.StartTask(task.ID); try { if (!IsConvertFormat(task.ExtName)) { throw new Exception("未知文件类型,没有相关的转换器!"); } string viewMode = AppConfig.GetAppSettings("ViewMode"); if (viewMode != ViewModeDTO.TilePicViewer.ToString()) { string folderPath = OfficeHelper.GetFolderPath(task.ID); var pdfFilePath = Path.Combine(folderPath, task.ID + ".pdf"); var swfFilePath = Path.Combine(folderPath, task.ID + ".swf"); var snapFilePath = Path.Combine(folderPath, task.ID + ".png"); #region 1.转换PDF byte[] pdfBuffer = null; if (!string.IsNullOrEmpty(task.ExtName)) { if (task.ExtName.ToLower() == "pdf") { pdfBuffer = FileStoreHelper.GetFile(task.Name); } else if (task.ExtName.ToLower() == "docx" || task.ExtName.ToLower() == "doc") { // 获取文件 var butter = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Word2PDF(butter, pdfFilePath, task.ExtName.ToLower()); } else if (task.ExtName.ToLower() == "xlsx" || task.ExtName.ToLower() == "xls") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Excel2PDF(buffer); } else if (task.ExtName.ToLower() == "txt") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Txt2PDF(buffer); } else if (task.ExtName.ToLower() == "jpg" || task.ExtName.ToLower() == "jpeg" || task.ExtName.ToLower() == "png") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Img2PDF(buffer); } else if (task.ExtName.ToLower() == "tif" || task.ExtName.ToLower() == "tiff") { // 获取文件 var buffer = FileStoreHelper.GetFile(task.Name); pdfBuffer = FileConverter.Tif2PDF(buffer); } else { throw new Exception("未知文件类型,没有相关的转换器!"); } } else { throw new Exception("未定义文件类型!"); } if (pdfBuffer == null) { throw new Exception("PDF文件不存在!"); } #endregion #region 2.生成SWF var pdfPageCount = FileConverter.GetPageCount(pdfBuffer); if (!File.Exists(pdfFilePath)) { FileConverter.SaveFileBuffer(pdfBuffer, pdfFilePath); FileConverter.PDF2SWF(pdfFilePath, swfFilePath, pdfPageCount); } #endregion #region 3.生成缩略图 byte[] snapBuffer = FileConverter.ConvertToSnap(pdfBuffer, "pdf"); FileConverter.SaveFileBuffer(snapBuffer, snapFilePath); #endregion repo.EndTask(task.ID, ResultStatus.Success); } else { //1.获取文件 byte[] bytes = FileStoreHelper.GetFile(task.ID); string filePath = OfficeHelper.GetFolderPath(task.ID, "Files"); FileStoreHelper.SaveFileBuffer(bytes, Path.Combine(filePath, task.Name)); //2.转图 var imgDTO = OfficeHelper.InitDTO(task.Name, bytes.Length, task.ID); FileConverter fileConverter = new FileConverter(); var result = fileConverter.Exec(imgDTO); if (result == null || !result.status) { throw new Exception("转图失败!"); } //3.生成记录文件 imgDTO.Versions[0].ImageZoomLevel = 18; imgDTO.Versions[0].HighHeightUnit = result.HighHeightUnit; OfficeHelper.WriteJsonFile(imgDTO); //4.设置数据库完成 repo.EndTask(task.ID, ResultStatus.Success); //5.删除原始文件 if (File.Exists(imgDTO.Versions[0].FullPath)) { File.Delete(imgDTO.Versions[0].FullPath); } } } catch (Exception ex) { // 记录日志 repo.EndTask(task.ID, ResultStatus.Error); LogWriter.Info(string.Format(ErrInfo, DateTime.Now.ToString(), task.ID, task.Name, ex.Message, ex.StackTrace)); } } //新增处理关联word、excel进程关闭问题 2019-5-29 CloseExit(); }
public static File GetFile(this Item item, ID fieldId) { return(FileRepository.Get(item.Fields[fieldId].Value)); }
public FileService(IMapper mapper, IOptions <FilesMongoDbSettings> settings) { repository = new FileRepository(settings); this.mapper = mapper; }
public IEnumerable <FileModel> GetFiles() { return(FileRepository.GetAll()); }
public FileModel FindByHashCode(string hashCode) { var file = FileRepository.GetByHashCode(hashCode); return(file); }
public override int DoSaveData(FormCollection form, int?ID = null, List <HttpPostedFileBase> files = null) { PRODUCT saveModel; FileRepository fileRepository = new FileRepository(); if (!ID.HasValue) { saveModel = new PRODUCT(); saveModel.BUD_DT = DateTime.UtcNow.AddHours(8); saveModel.BUD_ID = UserProvider.Instance.User.ID; } else { saveModel = this.DB.PRODUCT.Where(s => s.ID == ID).FirstOrDefault(); } saveModel.TITLE = form["TITLE"]; saveModel.HOME_PAGE_DISPLAY = form["HOME_PAGE_DISPLAY"] == "on" ? true : false; saveModel.DISABLE = form["DISABLE"] == "Y" ? true : false; saveModel.SQ = form["SQ"] == null ? 1 : form["SQ"] == string.Empty ? 1 : Convert.ToInt32(form["SQ"]); saveModel.DESC = form["DESC"]; saveModel.HOME_INFO = form["HOME_INFO"]; saveModel.SPEC = form["SPEC"]; saveModel.CONTENT = form["contenttext"]; saveModel.EDIT1 = form["EDIT1"]; saveModel.EDIT1_MOBILE = form["EDIT1_MOBILE"]; saveModel.EDIT2 = form["EDIT2"]; saveModel.EDIT2_MOBILE = form["EDIT2_MOBILE"]; saveModel.EDIT3 = form["EDIT3"]; saveModel.EDIT3_MOBILE = form["EDIT3_MOBILE"]; saveModel.QA = form["QA"]; saveModel.UPT_DT = DateTime.UtcNow.AddHours(8); saveModel.UPT_ID = UserProvider.Instance.User.ID; PublicMethodRepository.FilterXss(saveModel); if (ID.HasValue) { this.DB.Entry(saveModel).State = EntityState.Modified; } else { this.DB.PRODUCT.Add(saveModel); } try { this.DB.SaveChanges(); } catch (Exception ex) { ex.AppException(); } int identityId = (int)saveModel.ID; #region FILEBASE處理 List <int> oldFileList = new List <int>(); #region 將原存在的ServerFILEBASE保留 記錄FILEBASEID //將原存在的ServerFILEBASE保留 記錄FILEBASEID foreach (var f in form.Keys) { if (f.ToString().StartsWith("FileData")) { var id = Convert.ToInt16(form[f.ToString().Split('.')[0] + ".ID"]); if (!oldFileList.Contains(id)) { oldFileList.Add(id); } } } #endregion 將原存在的ServerFILEBASE保留 記錄FILEBASEID #region 建立FILEBASE模型 FilesModel fileModel = new FilesModel() { ActionName = _actionName, ID = identityId, OldFileIds = oldFileList }; #endregion 建立FILEBASE模型 #region 若有null則是前端html的name重複於ajax formData名稱 if (files != null) { if (files.Count > 0) { files.RemoveAll(item => item == null); } } #endregion 若有null則是前端html的name重複於ajax formData名稱 #region img data binding 單筆多筆裝在不同容器 fileRepository.UploadFile(fileModel, files, identityId, _actionName); fileRepository.SaveFileToDB(fileModel); #endregion img data binding 單筆多筆裝在不同容器 #endregion FILEBASE處理 return(identityId); }
public FileService(FileRepository repository) { this.fileRepository = repository; }
public ClipboardController(IAuthService authService, FileRepository fileRepository) { this.authService = authService; this.fileRepository = fileRepository; }
public FileService() { _fileRepository = new FileRepository(); }
public FileRepositoryTest() { testSubject = new FileRepository(); }
public InstallerMessage SetRepository(string uri, string user, string password, bool replaceExisting = false) { LastException = null; try { if (RepoIsClonned()) { if (replaceExisting) { try { Directory.Delete(_repoPath, true); } catch (Exception e) { throw new Exception("Could not delete current repository. " + e.Message); } } else { if (!GitHelper.isValidLocalRepository(Path.Combine(_repoPath, @".git"))) { throw new Exception("There are files stored where the repository would be cloned. Clone canceled"); } var repo = new FileRepository(Path.Combine(_repoPath, @".git")); var c = repo.GetConfig(); var remoteUrl = c.GetString("remote", "origin", "url"); var isSameRepo = remoteUrl != uri; if (!isSameRepo) { var remotes = c.GetSubsections("remote"); foreach (var remote in remotes) { var rUrl = c.GetString("remote", remote, "url"); if (String.IsNullOrEmpty(remoteUrl)) // let's keep the first we find { remoteUrl = rUrl; } if (rUrl == uri) { isSameRepo = true; break; } } if (!isSameRepo) { if (!String.IsNullOrEmpty(remoteUrl)) { throw new Exception("There is already a repository pointing to " + remoteUrl + " where the wiki should be cloned."); } throw new Exception("There is already a repository where the wiki should be cloned."); } } return(InstallerMessage.Success); } } if (!Directory.Exists(_repoPath)) { if (!Directory.Exists(Path.Combine(_appRoot, "App_Data"))) { Directory.CreateDirectory(Path.Combine(_appRoot, "App_Data")); } Directory.CreateDirectory(_repoPath); } var cmd = new CloneCommand(); if (!String.IsNullOrEmpty(user)) { cmd.SetCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); } cmd.SetURI(uri); cmd.SetCloneSubmodules(true); cmd.SetDirectory(_repoPath); cmd.Call(); } catch (Exception e) { LastException = e; return(InstallerMessage.ExceptionThrown); } if (RepoIsClonned()) { WG.Settings.Repository = uri; return(InstallerMessage.Success); } return(InstallerMessage.UnkownFailure); }
public void DeleteFile(int id) { FileRepository.Delete(id); CacheRepository.Delete($"{FileCache}-{id}"); UnitOfWork.Save(); }
public FileService() { this.fileRepository = new FileRepository(); }
public int Count() { return(FileRepository.Count()); }
public void Checkout() { try { IRepository <Product> productRepository = new FileRepository <Product>(Path.Combine("..\\..\\Files", "product.json")); IRepository <OnSalePromotion> onSalePromotionRepository = new FileRepository <OnSalePromotion>(Path.Combine("..\\..\\Files", "onsale.json")); IRepository <GroupSalePromotion> groupSalePromotionRepository = new FileRepository <GroupSalePromotion>(Path.Combine("..\\..\\Files", "groupsale.json")); IRepository <AdditionalSalePromotion> additionalSalePromotionRepository = new FileRepository <AdditionalSalePromotion>(Path.Combine("..\\..\\Files", "additionalsale.json")); // Simple promotion data validation IPromotionValidator promotionValidator; promotionValidator = new OnSalePromotionValidator(onSalePromotionRepository.GetAll()); promotionValidator.Validate(); promotionValidator = new GroupSalePromotionValidator(groupSalePromotionRepository.GetAll()); promotionValidator.Validate(); promotionValidator = new AdditionalSalePromotionValidator(additionalSalePromotionRepository.GetAll()); promotionValidator.Validate(); // Read basket data List <Product> productsInBasket = JsonConvert.DeserializeObject <List <Product> >(File.ReadAllText(Path.Combine("..\\..\\Files", "basket.json"))); // Service Layer Facade ISaleService saleService = new SaleServiceImpl(productRepository, onSalePromotionRepository, groupSalePromotionRepository, additionalSalePromotionRepository); foreach (var item in productsInBasket) { saleService.AddProduct(item.Id); } Receipt receipt = saleService.GetReceipt(); ReceiptPrinter receiptPrinter = new ConsoleReceiptPrinter(receipt); receiptPrinter.Print(); } catch (ProductException pdex) { Console.WriteLine("=== " + pdex.Message + " ==="); } catch (PromotionException pmex) { Console.WriteLine("=== " + pmex.Message + " ==="); return; } catch (Exception ex) { Console.WriteLine("=== Woops, there's something wrong..." + ex.ToString() + " ==="); } }
public Service(FileRepository <ID, E> repository) { Repository = repository; }
/// <summary> /// Creates a new instance of the <see cref="FileController"/> class. /// </summary> /// <param name="fileRepository">The file repository.</param> public FileController(FileRepository fileRepository) { this.fileRepository = fileRepository; }
public _RefWriter_495(TestRepository <R> _enclosing, FileRepository fr, ICollection <Ref> baseArg1) : base(baseArg1) { this._enclosing = _enclosing; this.fr = fr; }
public int DoSaveData(ActivityDataModel model) { OLACT saveModel; FileRepository fileRepository = new FileRepository(); if (!model.ID.HasValue) { saveModel = new OLACT(); saveModel.BUD_ID = UserProvider.Instance.User.ID; saveModel.BUD_DT = DateTime.UtcNow.AddHours(8); } else { saveModel = this.DB.OLACT.Where(s => s.ID == model.ID).FirstOrDefault(); } saveModel.ACTITLE = model.Title; saveModel.SQ = model.Sort; saveModel.PUB_DT_STR = model.PublishDateStr; saveModel.APPLY_DATE_BEGIN = model.ApplyDateTimeBegin; saveModel.APPLY_DATE_END = model.ApplyDateTimeEnd; saveModel.ACT_CONTENT = model.contenttext; saveModel.ACT_NUM = model.ActivityNumber; saveModel.ACT_DATE_DESC = model.ActivityDateTimeDescription; saveModel.DISABLE = model.Disable; saveModel.UPD_ID = UserProvider.Instance.User.ID; saveModel.UPD_DT = DateTime.UtcNow.AddHours(8); PublicMethodRepository.FilterXss(saveModel); if (!model.ID.HasValue) { this.DB.OLACT.Add(saveModel); } else { this.DB.Entry(saveModel).State = EntityState.Modified; } try { this.DB.SaveChanges(); } catch (Exception ex) { throw ex; } int identityId = (int)saveModel.ID; #region 組別 List <OLACTGROUP> groupUpdateEntity = new List <OLACTGROUP>(); List <OLACTGROUP> groupAddEntity = new List <OLACTGROUP>(); List <int> oldIds = model.ActivityGroup.Where(o => o.GroupID > 0).Select(s => s.GroupID).ToList(); using (var transation = DB.Database.CurrentTransaction ?? DB.Database.BeginTransaction()) { var removeNotInEntities = DB.OLACTGROUP.Where(o => o.MAP_ACT_ID == identityId && !oldIds.Contains(o.ID)); if (removeNotInEntities.Count() > 0) { DB.OLACTGROUP.RemoveRange(removeNotInEntities); } foreach (var group in model.ActivityGroup) { OLACTGROUP temp = null; if (group.GroupID == 0) { temp = new OLACTGROUP(); temp.BUD_DT = DateTime.UtcNow.AddHours(8); temp.BUD_ID = UserProvider.Instance.User.ID; } else { temp = DB.OLACTGROUP.Where(o => o.ID == group.GroupID).First(); } temp.MAP_ACT_ID = identityId; temp.GROUP_NAME = group.GroupName; temp.TEAM_APPLY_LIMIT = group.GroupApplyLimit; temp.COUNT_APPLY_LIMIT = group.CountApplyLimit; temp.UPD_DT = DateTime.UtcNow.AddHours(8); temp.UPD_ID = UserProvider.Instance.User.ID; if (group.GroupID == 0) { groupAddEntity.Add(temp); } else { groupUpdateEntity.Add(temp); } } foreach (var item in groupUpdateEntity) { this.DB.Entry(item).State = EntityState.Modified; } if (groupAddEntity.Count > 0) { this.DB.OLACTGROUP.AddRange(groupAddEntity); } try { DB.SaveChanges(); transation.Commit(); } catch (Exception ex) { transation.Rollback(); throw ex; } } #endregion #region 檔案處理 FilesModel fileModel = new FilesModel() { ActionName = "Activity", ID = identityId, OldFileIds = model.OldFilesId }; fileRepository.UploadFile("Post", fileModel, model.Files, "M"); fileRepository.SaveFileToDB(fileModel); #endregion 檔案處理 return(identityId); }
public EmployeeRepository() { _fileRepository = FileRepository<Employee>.GetInstance("Employee.txt"); }
public UnitOfWork(Sowatech.ServiceLocation.IServiceLocator serviceLocator) { FileRepository = serviceLocator.GetAllInstances <IFileRepository>(Settings.Default.FileRepositoryType).Single().Value; FileRepository.Init(Settings.Default.FileRepositoryConnectionstring); }
public UploadController() { //this project stays simple hence no IoC FileRepository = new FileRepository(new HttpServerUtilityWrapper(System.Web.HttpContext.Current.Server)); }
public FileSystemRepository(FileRepository fileRepository, DirectoryRepository directoryRepository) { this.directoryRepository = directoryRepository; this.fileRepository = fileRepository; }
public void ShouldGetFile() { DataFile dataFile = new FileRepository().GetFile(2); Assert.AreEqual("name.txt", dataFile.Name); }
public JucatorFileRepository(IValidator <Jucator> Validator, string FilePath, FileRepository <int, Echipa> repoEchipa) : base(Validator, FilePath) { this.repoEchipa = repoEchipa; //ReadAllFromFile(); }
private void RunWipeDB() => LogMessage = FileRepository.WipeDatabaseModel();
public AlgorithmFileProvider(IOptions <DirectoryPathOptions> directoryPathOptions, ILogger <AlgorithmFileProvider> logger, FileRepository fileRepository, IFileStorage fileStorage, FileSystemWrapper fileSystem, IUnitOfWorkProvider unitOfWorkProvider, UserLocalFileProvider userLocalFileProvider) { _directoryPathOptions = directoryPathOptions; _logger = logger; _fileRepository = fileRepository; _fileStorage = fileStorage; _fileSystem = fileSystem; _unitOfWorkProvider = unitOfWorkProvider; _userLocalFileProvider = userLocalFileProvider; }
public UnitOfWork(string conectionString) { db = new ApplicationContext(conectionString); userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(db)); fileRepository = new FileRepository(db); }
public void CloseSession() { _session.Dispose(); _authRepository = null; _configRepository = null; _contentRepository = null; _fileRepository = null; //_session = null; }
private void RunSelectCommand() => (SelectedFile, Path) = FileRepository.OpenFile();
private void RunDBCreator() => LogMessage = FileRepository.CreateDatabaseModel();
public DepartmentRepository() { _fileRepository = FileRepository<Department>.GetInstance("Departmet.txt"); }