public (int fileId, string fileName) SaveConsumerEmployeeFile(SystemUser user, int id, string fileData, string fileName, int?fileId = null) { bool isNew = fileId == null; FileMetaDataModel model = isNew ? new FileMetaDataModel() : FileDataService.GetFileMetadata(_context, fileId.Value); if (isNew) { model.CreatedOn = DateTime.UtcNow; model.AddedById = user.UserId; } else { model.UpdatedOn = DateTime.UtcNow; model.UpdatedById = user.UserId; } model.ParentEntityId = id; model.ParentEntityTypeId = (int)EntityTypes.ConsumerEmployee; var fileInfo = Utils.GetFileDataFromBase64String(fileData); model.FileContentType = fileInfo.FileType; model.FileDisplayName = fileName; var filePath = IOFileService.GetEmployeeConsumerFilePath(string.Format("{0}.{1}", GetFileNameBasedOnId(id), fileInfo.Extension)); model.FilePath = filePath; IOFileService.SaveBase64File(filePath, fileData); var savedFile = FileDataService.SaveFileMetaData(_context, model); return(fileId : savedFile.Id, fileName : model.FileDisplayName); }
/// <summary> /// Called when this instance is loaded. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void OnLoaded(object sender, RoutedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(this)) { return; } this.Cursor = Cursors.Wait; this.IsEnabled = false; this.employee = null; using (IDataService service = new FileDataService()) { this.employee = await service.GetEmployeeByIdAsync(this.EmployeeId); } this.Cursor = Cursors.None; this.IsEnabled = true; if (this.employee == null) { return; } this.DataContext = this.employee; }
public void FDService_get_observable_data_first_element_equals_csharp() { var fdrMock = new Mock <IFileDataRepository>(); fdrMock .Setup(svc => svc.GetAllData()) .Returns(new FileData("sysName") { new List <string>() { "csharp", "rocks" } }); var fdrFactoryMock = new Mock <IRepositoryFactory>(); fdrFactoryMock .Setup(fry => fry.GetFileDataRepository(It.IsAny <FileSpecs>())) .Returns(fdrMock.Object); var fds = new FileDataService(fdrFactoryMock.Object); fds.LoadData(new FileSpecs { Name = "sysName" }); var fdoList = fds.GetObservableData("sysName"); Assert.IsTrue(fdoList[0][0] == "csharp"); }
/// <summary> /// Called when the user requests save data. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void OnSave(object sender, RoutedEventArgs e) { this.IsEnabled = false; // TODO: Validate input... etc... this.employee.FirstName = this.FirstNameTextBox.Text; this.employee.LastName = this.LastNameTextBox.Text; this.employee.Title = this.TitleTextBox.Text; this.employee.BirthDate = this.BirthDateDatePicker.SelectedDate; this.employee.HireDate = this.HireDateDatePicker.SelectedDate; this.employee.Address = this.AddressTextBox.Text; this.employee.City = this.CityTextBox.Text; this.employee.State = this.StateTextBox.Text; this.employee.Country = this.CountryTextBox.Text; this.employee.PostalCode = this.PostalCodeTextBox.Text; this.employee.Phone = this.PhoneTextBox.Text; this.employee.Fax = this.FaxTextBox.Text; using (IDataService service = new FileDataService()) { await service.SaveEmployeeAsync(this.employee); } this.IsEnabled = true; }
/// <summary> /// Initilize the ViewModel /// </summary> /// <param name="file">File that needs to be loaded. Leave empty for a new document</param> public async void Initialize(StorageFile file = null) { if (file != null) { LoadDataModel model = await FileDataService.LoadWithoutPrompt(file); if (model.LoadSuccessful == true) { Data = model.TextModel; PreviousData = model.TextModel; File = model.File; RefreshTitlebarTitle(); } else // If loading fails fall back by preparing a new, empty document instead { PrepareNewDocument(); } } else if (_data == null) { PrepareNewDocument(); } // Set UI and UX stuff ZoomFactor = 1; //UIZoomFactorVisibility = true; // Shown on purpose. Gets hidden in 3 seconds after launch _isInAlwaysOnTopMode = false; UIAppBarDisplayMode = AppBarClosedDisplayMode.Compact; UITitlebarDetailsVisibility = true; SetEditedFalse(); CheckDeviceCapabilities(); SetUXToggles(); UpdateZoomFactorPercentage(); }
// Save private async Task <bool> SaveFile() { if (File == null) { return(await SaveFileAs()); } else { bool success = await FileDataService.Save(Data, File); if (success == true) { // Show Save Successful Notification Debug.WriteLine("Save File: Saving Successful"); ShowUXMessage(1); SetEditedFalse(); return(true); } else { // Show Save Failed Notification Debug.WriteLine("Save File: Saving Failed"); ShowUXMessage(2); return(false); } } }
public BaseController() { inventoryService = new InventoryService() { CurrentEmployee = GetCurrentEmployee() }; deliveryService = new DeliveryService() { CurrentEmployee = GetCurrentEmployee() }; storeService = new StoreService() { CurrentEmployee = GetCurrentEmployee() }; employeeService = new EmployeeService() { CurrentEmployee = GetCurrentEmployee() }; mapRuleService = new MapRuleService() { CurrentEmployee = GetCurrentEmployee() }; carrierService = new CarrierService() { CurrentEmployee = GetCurrentEmployee() }; fileDataService = new FileDataService() { CurrentEmployee = GetCurrentEmployee() }; epacketService = new EpacketService() { CurrentEmployee = GetCurrentEmployee() }; }
public void GetAppropriateActionTestVersion() { // Arrange Mock <FileDetails> fileDetailsMock = new Mock <FileDetails>(); IFileDataService service = new FileDataService(fileDetailsMock.Object); String[] arr = { "-v", "fileSiz.txt" }; Mock <IFileDataService> fileDataMock = new Mock <IFileDataService>(); string returnValue = ""; Assert.IsTrue(arr.Length == 2); fileDataMock.Setup(x => x.GetAppropriateAction(arr[0], arr[1])).Callback <string, string>((x, y) => { if (service.IsSizeTask(x)) { returnValue = "GetSize"; // fileDetailsMock.Object.Size(y); } else if (service.IsVersonTask(x)) { returnValue = "GetVersion"; //fileDetailsMock.Setup(a => a.Version(y)).Returns(""); fileDetailsMock.Object.Version(y); } }); // Act fileDataMock.Object.GetAppropriateAction(arr[0], arr[1]); // Assert Assert.IsTrue(returnValue == "GetVersion"); Assert.IsFalse(returnValue == "GetSize"); }
/// <summary> /// Initilize the ViewModel /// </summary> /// <param name="file">File that needs to be loaded. Leave empty for a new document</param> public async void Initialize(StorageFile file = null) { if (file != null) { LoadDataModel model = await FileDataService.LoadWithoutPrompt(file); if (model.LoadSuccessful == true) { Data = model.TextModel; PreviousData = model.TextModel; File = model.File; RefreshTitlebarTitle(); } else // If loading fails fall back by preparing a new, empty document instead { PrepareNewDocument(); } } else if (_data == null) { PrepareNewDocument(); } // Set UI and UX stuff SetEditedFalse(); CheckDeviceCapabilities(); SetUXToggles(); }
// Save As private async Task <bool> SaveFileAs() { // #TODO: Check whether the user cancelled the action or it has actually failed StorageFile tempFile = await FileDataService.SaveAs(_data); if (tempFile != null) { File = tempFile; // Create a temp TextDataModel to make the changes in TextDataModel data = new TextDataModel(); data.Text = Data.Text; data.DocumentTitle = File.DisplayName + File.FileType; // Write the changes back to the Data property since it doesn't register single changed items otherwise Data = data; PreviousData = data; RefreshTitlebarTitle(); // Show Save Successful Notification Debug.WriteLine("Save File As File: Saving Successful"); ShowUXMessage(1); SetEditedFalse(); return(true); } else { // Show Save Failed Notification Debug.WriteLine("Save File As: Saving Failed"); ShowUXMessage(2); return(false); } }
public static void Main(string[] args) { try { // We will be using Unity IoC container to inject dependency - IDataModel // We used contructor injection in FileDataService. IUnityContainer unitycontainer = new UnityContainer(); // Here we are registering IDataModel as FileDataModel object // because we want to read Hello World from a file // We can register it with any class implementing IDataModel interface // ex- DataBaseDataModel, XMLDataModel, etc. unitycontainer.RegisterType <IDataModel, FileDataModel>(); // We are resolving dependency FileDataService service = unitycontainer.Resolve <FileDataService>(); // service instance is reading data from the file and storing in the model service.ReadData(); // we are displaying stored data in the model as output // In our case its a string - "Hello World from the file" Console.WriteLine(service.DisplayData()); Console.ReadLine(); } catch (ResolutionFailedException res_ex) { LoggingService.WriteLog("main console app", res_ex); } catch (Exception ex) { LoggingService.WriteLog("main console app", ex); } }
public FileDataServiceTests() { var optionsBuilder = new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()); _context = new SqlContext(optionsBuilder.Options); _fileDataService = new FileDataService(_context); }
public void Load() { var dataService = new FileDataService(); foreach (var friend in dataService.GetAllFriends()) { Friends.Add(friend); } }
public ExerciseServiceTests() { var optionsBuilder = new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new SqlContext(optionsBuilder.Options); _fileDataService = new FileDataService(context); _categoryService = new CategoryService(context); _exerciseService = new ExerciseService(context, _fileDataService); _authorService = new AuthorService(context); }
public ProblemServiceTests() { var optionsBuilder = new DbContextOptionsBuilder().UseInMemoryDatabase(Guid.NewGuid().ToString()); var context = new SqlContext(optionsBuilder.Options); var problemLibraryAssembly = Assembly.Load("ProblemLibrary"); _fileDataService = new FileDataService(context); _problemService = new ProblemService(context, _fileDataService); _authorService = new AuthorService(context); }
/// <summary> /// Called when the user requests save data. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void OnSave(object sender, RoutedEventArgs e) { this.IsEnabled = false; using (IDataService service = new FileDataService()) { await service.SaveEmployeeAsync(this.employee); } this.IsEnabled = true; }
/// <summary> /// Called when the user requests save data. /// </summary> private async void OnSave() { this.IsEnabled = false; using (IDataService service = new FileDataService()) { await service.SaveEmployeeAsync(this.Employee); } this.IsEnabled = true; }
public LocalFileService(FileDataService dataService, IOptions <ServerPaths> pathOptions, ILogger <LocalFileService> logger) { _dataService = dataService; _fileStorage = pathOptions.Value.FileStorage; if (!Directory.Exists(_fileStorage)) { Directory.CreateDirectory(_fileStorage); } _logger = logger; }
public void GetFileWithValidFormatTest() { // Arrange const string validFormatName = "I am in the correct format, but I do not exist."; Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act string fileContents = fileService.GetLocalFileContents(validFormatName); // Assert }
public void SaveFileWithNullContentTest() { // Arrange const string validFormatName = "This file does not exist."; Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act string fileContents = fileService.SaveLocalFile(validFormatName, null); // Assert }
/// <summary> /// Loads an employee. /// </summary> public async void LoadEmployee() { this.IsEnabled = false; this.Employee = null; using (IDataService service = new FileDataService()) { this.Employee = await service.GetEmployeeByIdAsync(this.EmployeeId); } this.IsEnabled = true; }
public void GetFileWithNullTest() { // Arrange Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act fileService.GetLocalFileContents(null); // Assert }
public void SaveFileWithNullNameTest() { // Arrange const string testContent = "contents"; Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act fileService.SaveLocalFile(null, testContent); // Assert }
public void GetFileWithValidNameTest() { const string validFormatName = "CardSet00.json"; Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act string fileContents = fileService.GetLocalFileContents(validFormatName); // Assert Assert.IsNotNull(fileContents); }
public void GetFileWithInvalidFormatTest() { // Arrange const string invalidName = "<>:\"/\\|?*0.."; Mock <ILoggingAdapter <FileDataService> > myLogger = new Mock <ILoggingAdapter <FileDataService> >(); myLogger.Setup(logger => logger.LogError(It.IsAny <Exception>(), It.IsAny <string>())).Verifiable(); FileDataService fileService = new FileDataService(myLogger.Object); // Act fileService.GetLocalFileContents(invalidName); // Assert }
/// <summary> /// 构造函数 /// </summary> /// <param name="_setting"></param> /// <param name="env"></param> /// <param name="_dataService"></param> /// <param name="_fileDataService"></param> /// <param name="_tempDataService"></param> /// <param name="_templateDataService"></param> /// <param name="_groupDataService"></param> /// <param name="_systemLogDataService"></param> public MeetingController(IOptions <AppSettings> _setting, IHostingEnvironment env, MeetingDataService _dataService, FileDataService _fileDataService, TempDataService _tempDataService, TemplateDataService _templateDataService, GroupDataService _groupDataService, SystemLogDataService _systemLogDataService) { this.setting = _setting; this.hostingEnv = env; this.dataService = _dataService; this.fileDataService = _fileDataService; this.tempDataService = _tempDataService; this.templateDataService = _templateDataService; this.groupDataService = _groupDataService; this.systemLogDataService = _systemLogDataService; }
public async void TestListElementIds() { await FileService.TemporarilyUpload(Configuration.RemoteRevitFileUrl, Configuration.RemoteRevitFileName, async file => { Assert.NotNull(file); Assert.NotNull(file.FileId); var translate = await TranslateService.EnsureTranslated(file); Assert.NotNull(translate); var elements = await FileDataService.ListElementIds(new ListFileElementIdsParameter(file.FileId.Value)); Assert.NotNull(elements); }); }
public void Load() { Friends.Clear(); var dataService = new FileDataService(); foreach (var friend in _dataProvider.GetAllFriends()) { Friends.Add( new NavigationItemViewModel( friend.Id, friend.DisplayMember, _eventAggregator)); } }
// Save // #TODO: Build this correctly and make sure changes are saved without additional file dialogs public async Task <bool> SaveFile() { if (File == null) { bool success = await SaveFileAs(); return(success); } else { bool success = await FileDataService.Save(_data, _file); return(success); } }
public ActionResult AddOrUpdateConsumerFile() { FileMetaDataModelView inputModel = RequestManager.GetModelFromJsonRequest <FileMetaDataModelView>(HttpContext.Request); if (inputModel == null) { return(null); } inputModel.ParentEntityTypeId = (int)EntityTypes.Consumer; FileDataService.UpdateFileMetaData(inputModel, CurrentUser.UserId); var result = FileDataService.SaveFileDataWithFile(_context, inputModel, inputModel.FileData); var returnData = CustomMapper.MapEntity <FileMetaDataModelView>(result); return(Json(new { status = "ok", model = returnData }, JsonRequestBehavior.AllowGet)); }