public void CacheProvider_NoCacheProgress() { var pt1 = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles); pt1.Path = typeof(BasicCacheDataProvider).FullName; pt1.ProcessTaskType = ProcessTaskType.DataProvider; pt1.Name = "Cache1"; pt1.SaveToDatabase(); var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); var pipeAssembler = new TestDataPipelineAssembler("CacheProvider_Normal", CatalogueRepository); pipeAssembler.ConfigureCacheProgressToUseThePipeline(_cp); try { var ex = Assert.Throws <InvalidOperationException>(() => _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); Assert.AreEqual("Caching has not begun for this CacheProgress (" + _cp.ID + "), so there is nothing to load and this strategy should not be used.", ex.Message); } finally { _cp.Pipeline_ID = null; pipeAssembler.Destroy(); projDir.RootPath.Delete(true); } }
public ExecuteCommandCreateNewFileBasedProcessTask(IBasicActivateItems activator, ProcessTaskType taskType, LoadMetadata loadMetadata, LoadStage loadStage, FileInfo file = null) : base(activator) { _taskType = taskType; _loadMetadata = loadMetadata; _loadStage = loadStage; try { _LoadDirectory = new LoadDirectory(_loadMetadata.LocationOfFlatFiles); } catch (Exception) { SetImpossible("Could not construct LoadDirectory"); } if (!(taskType == ProcessTaskType.SQLFile || taskType == ProcessTaskType.Executable)) { SetImpossible("Only SQLFile and Executable task types are supported by this command"); } if (!ProcessTask.IsCompatibleStage(taskType, loadStage)) { SetImpossible("You cannot run " + taskType + " in " + loadStage); } _file = file; }
public void MEFCompatibleType_NoArgs() { var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true); try { _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _task.ProcessTaskType = ProcessTaskType.Attacher; _task.LoadStage = LoadStage.Mounting; _task.Path = typeof(AnySeparatorFileAttacher).FullName; _task.SaveToDatabase(); var ex = Assert.Throws <ArgumentException>(() => _checker.Check(new ThrowImmediatelyCheckNotifier() { ThrowOnWarning = true })); Assert.AreEqual(@"Class AnySeparatorFileAttacher has a Mandatory property 'Separator' marked with DemandsInitialization but no corresponding argument was provided in ArgumentCollection", ex.Message); } finally { //delete everything for real projDir.RootPath.Delete(true); } }
public ExecuteCommandCreateNewProcessTask(IActivateItems activator, ProcessTaskType taskType, LoadMetadata loadMetadata, LoadStage loadStage, FileInfo file = null) : base(activator) { _taskType = taskType; _loadMetadata = loadMetadata; _loadStage = loadStage; try { _LoadDirectory = new LoadDirectory(_loadMetadata.LocationOfFlatFiles); } catch (Exception) { SetImpossible("Could not construct LoadDirectory"); } if (taskType == ProcessTaskType.SQLFile) { _image = activator.CoreIconProvider.GetImage(RDMPConcept.SQL, OverlayKind.Add); } else if (taskType == ProcessTaskType.Executable) { _image = new IconOverlayProvider().GetOverlayNoCache(CatalogueIcons.Exe, OverlayKind.Add); } else { SetImpossible("Only SQLFile and Executable task types are supported by this command"); } if (!ProcessTask.IsCompatibleStage(taskType, loadStage)) { SetImpossible("You cannot run " + taskType + " in " + loadStage); } _file = file; }
public void CreateArchiveWithNoFiles_ShouldThrow() { var directoryHelper = new TestDirectoryHelper(GetType()); directoryHelper.SetUp(); var testDir = directoryHelper.Directory.CreateSubdirectory("CreateArchiveWithNoFiles_ShouldThrow"); var archiveFiles = new ArchiveFiles(new HICLoadConfigurationFlags()); var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "dataset"); var job = Mock.Of <IDataLoadJob>(j => j.DataLoadInfo == Mock.Of <IDataLoadInfo>()); job.LoadDirectory = loadDirectory; try { archiveFiles.Run(job, new GracefulCancellationToken()); foreach (FileInfo fileInfo in loadDirectory.ForArchiving.GetFiles("*.zip")) { Console.WriteLine("About to throw SetUp because of zip file:" + fileInfo.FullName); } Assert.IsFalse(loadDirectory.ForArchiving.GetFiles("*.zip").Any(), "There should not be any zip files in the archive directory!"); } finally { directoryHelper.TearDown(); } }
public void ConnectToServer() { var hicProjDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "MDFAttacherTest", true); var db = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase("MyImaginaryDB_RAW"); Assert.IsFalse(db.Exists()); var mdf = new MDFAttacher(); mdf.Initialize(hicProjDir, db); try { var memory = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); mdf.Check(memory); Assert.IsTrue(memory.Messages.Any(m => m.Message.Contains("Found server DATA folder") && m.Result == CheckResult.Success)); } catch (Exception e) { if (!e.Message.Contains("Proposed server DATA folder (that we will copy mdf/ldf files to) was not found"))//this message is allowed too if the SQL server is remote and not localhost then it is quite likely that the DATA path is inaccessible from the unit test server { throw; } } var memory2 = new ToMemoryCheckNotifier(new ThrowImmediatelyCheckNotifier()); mdf.OverrideMDFFileCopyDestination = TestContext.CurrentContext.WorkDirectory; mdf.Check(memory2); Assert.IsTrue(memory2.Messages.Any(m => Regex.IsMatch(m.Message, @"Found server DATA folder .*" + Regex.Escape(TestContext.CurrentContext.WorkDirectory)) && m.Result == CheckResult.Success)); hicProjDir.RootPath.Delete(true); }
public void TestFactory() { var workingDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); var testDir = workingDir.CreateSubdirectory("MDFAttacherTests_TestFactory"); var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "TestFactory", true); try { var attacher = CatalogueRepository.MEF.CreateA <IAttacher>(typeof(MDFAttacher).FullName); attacher.Initialize(loadDirectory, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); Assert.IsNotNull(attacher); Assert.IsInstanceOf <MDFAttacher>(attacher); } finally { try { testDir.Delete(true); } catch (IOException e) { Console.WriteLine(e); } } }
public MainWindow() { this.Closing += MainWindow_Closing; string SelectedCollectionName = AskCollectionName(); // Если пользователь не выбрал коллекцию, выход if (SelectedCollectionName == null) { this.Close(); return; } // Показать основное окно InitializeComponent(); _CollectionFolder = new CollectionFolder(); LoadDatabase(SelectedCollectionName); SetGropStyle(); this.DataContext = this; _Instance = this; LoadDirectoryDialog = new LoadDirectory(LoadDirectoryToCollection); LoadDirectoryDialog.IsVisibleChanged += LoadDirectoryDialog_IsVisibleChanged; AllowMultiSelection(views); _AudioExtentions = Properties.Settings.Default.AudioFiles.Split(';'); _VideoExtentions = Properties.Settings.Default.VideoFiles.Split(';'); _ImageExtentions = Properties.Settings.Default.ImageFiles.Split(';'); _DocsExtentions = Properties.Settings.Default.Documents.Split(';'); selectedItems = new List <CollectionFolder>(); }
public void CreateTask() { _lmd = new LoadMetadata(CatalogueRepository); _dir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "ProcessTaskCheckingTests")); _dir.Create(); var hicdir = LoadDirectory.CreateDirectoryStructure(_dir, "ProjDir", true); _lmd.LocationOfFlatFiles = hicdir.RootPath.FullName; _lmd.SaveToDatabase(); Catalogue c = new Catalogue(CatalogueRepository, "c"); CatalogueItem ci = new CatalogueItem(CatalogueRepository, c, "ci"); TableInfo t = new TableInfo(CatalogueRepository, "t"); t.Server = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.Name; t.Database = "mydb"; t.SaveToDatabase(); ColumnInfo col = new ColumnInfo(CatalogueRepository, "col", "bit", t); ci.SetColumnInfo(col); c.LoadMetadata_ID = _lmd.ID; c.SaveToDatabase(); _task = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles); _checker = new ProcessTaskChecks(_lmd); }
protected override void SetUp() { base.SetUp(); var workingDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); parentDir = workingDir.CreateSubdirectory("FlatFileAttacherTests"); DirectoryInfo toCleanup = parentDir.GetDirectories().SingleOrDefault(d => d.Name.Equals("Test_CSV_Attachment")); if (toCleanup != null) { toCleanup.Delete(true); } LoadDirectory = LoadDirectory.CreateDirectoryStructure(parentDir, "Test_CSV_Attachment"); // create a separate builder for setting an initial catalog on (need to figure out how best to stop child classes changing ServerICan... as this then causes TearDown to fail) _database = GetCleanedServer(DatabaseType.MicrosoftSQLServer); using (var con = _database.Server.GetConnection()) { con.Open(); var cmdCreateTable = _database.Server.GetCommand("CREATE Table " + _database.GetRuntimeName() + "..Bob([name] [varchar](500),[name2] [varchar](500))", con); cmdCreateTable.ExecuteNonQuery(); } _table = _database.ExpectTable("Bob"); }
public void ExecuteSqlFileRuntimeTask_BasicScript(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object [] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); FileInfo f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bob.sql")); File.WriteAllText(f.FullName, @"UPDATE Fish Set Lawl = 1"); var pt = Mock.Of <IProcessTask>(x => x.Path == f.FullName); var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(new IArgument[0], new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); IDataLoadJob job = Mock.Of <IDataLoadJob>(); task.Run(job, new GracefulCancellationToken()); Assert.AreEqual(1, tbl.GetDataTable().Rows[0][0]); tbl.Drop(); }
public IDataLoadJob Create(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, HICDatabaseConfiguration configuration) { var description = _loadMetadata.Name; var LoadDirectory = new LoadDirectory(_loadMetadata.LocationOfFlatFiles); return(new DataLoadJob(repositoryLocator, description, _logManager, _loadMetadata, LoadDirectory, listener, configuration)); }
private LoadDirectory CreateLoadDirectoryForTest(string directoryName) { var loadDirectory = LoadDirectory.CreateDirectoryStructure(_parentDir, directoryName, true); _dirsToCleanUp.Push(loadDirectory.RootPath); return(loadDirectory); }
protected override void SetUp() { base.SetUp(); RepositoryLocator.CatalogueRepository.MEF.AddTypeToCatalogForTesting(typeof(TestDataWriter)); RepositoryLocator.CatalogueRepository.MEF.AddTypeToCatalogForTesting(typeof(TestDataInventor)); _lmd = new LoadMetadata(CatalogueRepository, "Ive got a lovely bunch o' coconuts"); _LoadDirectory = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), @"EndToEndCacheTest", true); _lmd.LocationOfFlatFiles = _LoadDirectory.RootPath.FullName; _lmd.SaveToDatabase(); Clear(_LoadDirectory); _cata = new Catalogue(CatalogueRepository, "EndToEndCacheTest"); _cata.LoadMetadata_ID = _lmd.ID; _cata.SaveToDatabase(); _lp = new LoadProgress(CatalogueRepository, _lmd); _cp = new CacheProgress(CatalogueRepository, _lp); _lp.OriginDate = new DateTime(2001, 1, 1); _lp.SaveToDatabase(); _testPipeline = new TestDataPipelineAssembler("EndToEndCacheTestPipeline" + Guid.NewGuid(), CatalogueRepository); _testPipeline.ConfigureCacheProgressToUseThePipeline(_cp); _cp.CacheFillProgress = DateTime.Now.AddDays(-NumDaysToCache); _cp.SaveToDatabase(); _cp.SaveToDatabase(); }
public void CacheProvider_NoPipeline() { var pt1 = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles); pt1.Path = typeof(TestCachedFileRetriever).FullName; pt1.ProcessTaskType = ProcessTaskType.DataProvider; pt1.Name = "Cache1"; pt1.SaveToDatabase(); _cp.CacheFillProgress = new DateTime(1999, 1, 1); _cp.Name = "MyTestCp"; _cp.SaveToDatabase(); pt1.CreateArgumentsForClassIfNotExists <TestCachedFileRetriever>(); var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); try { var ex = Assert.Throws <Exception>(() => _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener())); Assert.AreEqual("CacheProgress MyTestCp does not have a Pipeline configured on it", ex.Message); } finally { projDir.RootPath.Delete(true); } }
private void CopyToBin(LoadDirectory projDir, string file) { string testFileLocation = Path.Combine(TestContext.CurrentContext.TestDirectory, "DataLoad", "Engine", "Resources", file); Assert.IsTrue(File.Exists(testFileLocation)); File.Copy(testFileLocation, projDir.ForLoading.FullName + Path.DirectorySeparatorChar + file, true); }
private LoadDirectory SetupLoadDirectory(LoadMetadata lmd) { var projectDirectory = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "MyLoadDir", true); lmd.LocationOfFlatFiles = projectDirectory.RootPath.FullName; lmd.SaveToDatabase(); return(projectDirectory); }
public override SMIDataChunk DoGetChunk(ICacheFetchRequest request, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken) { listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"ProcessBasedCacheSource version is {typeof(ProcessBasedCacheSource).Assembly.GetName().Version}. Assembly is {typeof(ProcessBasedCacheSource).Assembly} ")); // Where we are putting the files var cacheDir = new LoadDirectory(Request.CacheProgress.LoadProgress.LoadMetadata.LocationOfFlatFiles).Cache; var cacheLayout = new SMICacheLayout(cacheDir, new SMICachePathResolver("ALL")); Chunk = new SMIDataChunk(Request) { FetchDate = Request.Start, Modality = "ALL", Layout = cacheLayout }; var workingDirectory = cacheLayout.GetLoadCacheDirectory(listener); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Working directory is:" + workingDirectory)); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Fetch Start is:" + request.Start)); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Fetch End is:" + request.End)); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Command is:" + Command)); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Args template is:" + Args)); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Datetime format is:" + TimeFormat)); string args = Args .Replace("%s", request.Start.ToString(TimeFormat)) .Replace("%e", request.End.ToString(TimeFormat)) .Replace("%d", workingDirectory.FullName); listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Args resolved is:" + args)); using (var p = new Process()) { p.StartInfo.FileName = Command; p.StartInfo.Arguments = args; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.OutputDataReceived += (sender, a) => listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, a.Data)); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); listener.OnNotify(this, new NotifyEventArgs(p.ExitCode == 0 ? ProgressEventType.Information : ProgressEventType.Warning, "Process exited with code " + p.ExitCode)); if (p.ExitCode != 0 && ThrowOnNonZeroExitCode) { throw new Exception("Process exited with code " + p.ExitCode); } } return(Chunk); }
protected override ScheduledDataLoadJob CreateImpl(IRDMPPlatformRepositoryServiceLocator repositoryLocator, IDataLoadEventListener listener, HICDatabaseConfiguration configuration) { var LoadDirectory = new LoadDirectory(LoadMetadata.LocationOfFlatFiles); return(new ScheduledDataLoadJob(repositoryLocator, JobDescription, LogManager, LoadMetadata, LoadDirectory, listener, configuration) { LoadProgress = _loadProgress, DatesToRetrieve = _jobDateGenerationStrategy.GetDates(OverrideNumberOfDaysToLoad ?? _loadProgress.DefaultNumberOfDaysToLoadEachTime, false) }); }
public void ExecuteSqlRuntimeTask_InvalidID(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); TableInfo ti; ColumnInfo[] cols; Import(tbl, out ti, out cols); string sql = @"UPDATE {T:0} Set {C:0} = 1"; IRuntimeTask task; IProcessTask pt; var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var sqlArg = new IArgument[] { Mock.Of <IArgument>(x => x.Name == "Sql" && x.Value == sql && x.GetValueAsSystemType() == sql) }; var args = new RuntimeArgumentCollection(sqlArg, new StageArgs(LoadStage.AdjustRaw, db, dir)); pt = Mock.Of <IProcessTask>(x => x.Path == typeof(ExecuteSqlMutilation).FullName && x.GetAllArguments() == sqlArg ); task = new MutilateDataTablesRuntimeTask(pt, args, CatalogueRepository.MEF); task.Check(new ThrowImmediatelyCheckNotifier()); HICDatabaseConfiguration configuration = new HICDatabaseConfiguration(db.Server); var job = new ThrowImmediatelyDataLoadJob(); job.RegularTablesToLoad = new List <ITableInfo> { ti }; job.LookupTablesToLoad = new List <ITableInfo>(); job.Configuration = configuration; var ex = Assert.Throws <Exception>(() => task.Run(job, new GracefulCancellationToken())); StringAssert.Contains("Mutilate failed", ex.Message); StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.InnerException.Message); task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); }
public void ExecuteSqlFileRuntimeTask_ValidID_CustomNamer(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); var tableName = "AAAAAAA"; TableInfo ti; ColumnInfo[] cols; Import(tbl, out ti, out cols); FileInfo f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bob.sql")); File.WriteAllText(f.FullName, @"UPDATE {T:" + ti.ID + "} Set {C:" + cols[0].ID + "} = 1"); tbl.Rename(tableName); //we renamed the table to simulate RAW, confirm TableInfo doesn't think it exists Assert.IsFalse(ti.Discover(DataAccessContext.InternalDataProcessing).Exists()); var pt = Mock.Of <IProcessTask>(x => x.Path == f.FullName); var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(new IArgument[0], new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); //create a namer that tells the user var namer = RdmpMockFactory.Mock_INameDatabasesAndTablesDuringLoads(db, tableName); HICDatabaseConfiguration configuration = new HICDatabaseConfiguration(db.Server, namer); IDataLoadJob job = Mock.Of <IDataLoadJob>(x => x.RegularTablesToLoad == new List <ITableInfo> { ti } && x.LookupTablesToLoad == new List <ITableInfo>() && x.Configuration == configuration); task.Run(job, new GracefulCancellationToken()); Assert.AreEqual(1, tbl.GetDataTable().Rows[0][0]); tbl.Drop(); }
public void MEFCompatibleType_Passes() { var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "DelMeProjDir", true); try { _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _task.ProcessTaskType = ProcessTaskType.Attacher; _task.LoadStage = LoadStage.Mounting; _task.Path = typeof(AnySeparatorFileAttacher).FullName; _task.SaveToDatabase(); //create the arguments var args = ProcessTaskArgument.CreateArgumentsForClassIfNotExists <AnySeparatorFileAttacher>(_task); var tblName = (ProcessTaskArgument)args.Single(a => a.Name.Equals("TableName")); tblName.Value = "MyExcitingTable"; tblName.SaveToDatabase(); var filePattern = (ProcessTaskArgument)args.Single(a => a.Name.Equals("FilePattern")); filePattern.Value = "*.csv"; filePattern.SaveToDatabase(); var separator = (ProcessTaskArgument)args.Single(a => a.Name.Equals("Separator")); separator.Value = ","; separator.SaveToDatabase(); var results = new ToMemoryCheckNotifier(); _checker.Check(results); foreach (var msg in results.Messages) { Console.WriteLine("(" + msg.Result + ")" + msg.Message); if (msg.Ex != null) { Console.WriteLine(ExceptionHelper.ExceptionToListOfInnerMessages(msg.Ex)); } } Assert.AreEqual(CheckResult.Success, results.GetWorst()); } finally { //delete everything for real projDir.RootPath.Delete(true); } }
public void Test_MDFFile_AlreadyExists() { var workingDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory); var data = workingDir.CreateSubdirectory("data"); var testDir = workingDir.CreateSubdirectory("MDFAttacherTests"); var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "TestNoMDFFileFoundException", true); try { // create mdf and ldf files (in ForLoading File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "MyFile.mdf"), "fish"); File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "MyFile_log.ldf"), "fish"); //create an already existing file in the 'data' directory (immitates the copy to location) File.WriteAllText(Path.Combine(data.FullName, "MyFile.mdf"), "fish"); var attacher = new MDFAttacher(); attacher.OverrideMDFFileCopyDestination = data.FullName; attacher.Initialize(loadDirectory, GetCleanedServer(FAnsi.DatabaseType.MicrosoftSQLServer)); //should be a warning since overwritting is default behaviour var ex = Assert.Throws <Exception>(() => attacher.Attach( new ThrowImmediatelyDataLoadJob(new ThrowImmediatelyDataLoadEventListener() { ThrowOnWarning = true }) , new GracefulCancellationToken()) ); StringAssert.Contains("mdf already exists", ex.Message); } finally { try { testDir.Delete(true); } catch (IOException e) { Console.WriteLine(e); } } }
public void LoadProgress_JobFactory_NoDates() { var lp = WhenIHaveA <LoadProgress>(); lp.OriginDate = new DateTime(2001, 1, 1); // We are fully up-to-date lp.DataLoadProgress = DateTime.Now; lp.Check(new ThrowImmediatelyCheckNotifier()); var stratFactory = new JobDateGenerationStrategyFactory(new AnyAvailableLoadProgressSelectionStrategy(lp.LoadMetadata)); var strat = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener()); var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.WorkDirectory), "LoadProgress_JobFactory_NoDates", true); var lmd = lp.LoadMetadata; lmd.LocationOfFlatFiles = dir.RootPath.FullName; foreach (var cata in lmd.GetAllCatalogues()) { cata.LoggingDataTask = "ff"; cata.SaveToDatabase(); } lmd.SaveToDatabase(); var jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null); var ex = Assert.Throws <Exception>(() => jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null)); Assert.AreEqual("DatesToRetrieve was empty for load 'MyLoad'. Possibly the load is already up to date?", ex.Message); // We have 1 day to load (date is the last fully loaded date) lp.DataLoadProgress = DateTime.Now.AddDays(-2); lp.SaveToDatabase(); strat = stratFactory.Create(lp, new ThrowImmediatelyDataLoadEventListener()); jobFactory = new SingleScheduledJobFactory(lp, strat, 999, lp.LoadMetadata, null); var job = jobFactory.Create(RepositoryLocator, new ThrowImmediatelyDataLoadEventListener(), null); Assert.AreEqual(1, ((ScheduledDataLoadJob)job).DatesToRetrieve.Count); }
public void TestWithEcho() { var source = new ProcessBasedCacheSource(); if (IsLinux) { source.Command = "/bin/echo"; source.Args = "Hey Thomas go get %s and store in %d"; } else { source.Command = "cmd.exe"; source.Args = "/c echo Hey Thomas go get %s and store in %d"; } source.TimeFormat = "dd/MM/yy"; source.ThrowOnNonZeroExitCode = true; // What dates to load var cp = WhenIHaveA <CacheProgress>(); cp.CacheFillProgress = new DateTime(2001, 12, 24); cp.SaveToDatabase(); // Where to put files var lmd = cp.LoadProgress.LoadMetadata; var dir = new DirectoryInfo(TestContext.CurrentContext.WorkDirectory); var loadDir = LoadDirectory.CreateDirectoryStructure(dir, "blah", true); lmd.LocationOfFlatFiles = loadDir.RootPath.FullName; lmd.SaveToDatabase(); source.PreInitialize(new CacheFetchRequestProvider(cp), new ThrowImmediatelyDataLoadEventListener()); source.PreInitialize(cp.CatalogueRepository, new ThrowImmediatelyDataLoadEventListener()); source.PreInitialize(new PermissionWindow(cp.CatalogueRepository), new ThrowImmediatelyDataLoadEventListener()); var toMem = new ToMemoryDataLoadEventListener(true); var fork = new ForkDataLoadEventListener(toMem, new ThrowImmediatelyDataLoadEventListener() { WriteToConsole = true }); source.GetChunk(fork, new GracefulCancellationToken()); Assert.Contains($"Hey Thomas go get 24/12/01 and store in {Path.Combine(loadDir.Cache.FullName,"ALL")}", toMem.GetAllMessagesByProgressEventType()[ProgressEventType.Information].Select(v => v.Message).ToArray()); }
public ExecuteCommandPacsFetch(IBasicActivateItems activator, string start, string end, string remoteAeUri, int remotePort, string remoteAeTitle, string localAeUri, int localPort, string localAeTitle, string outDir, int maxRetries) : base(activator) { var startDate = DateTime.Parse(start); var endDate = DateTime.Parse(end); // Make something that kinda looks like a valid DLE load var memory = new MemoryCatalogueRepository(); var lmd = new LoadMetadata(memory); var dir = Directory.CreateDirectory(outDir); var results = LoadDirectory.CreateDirectoryStructure(dir, "out", true); lmd.LocationOfFlatFiles = results.RootPath.FullName; lmd.SaveToDatabase(); var lp = new LoadProgress(memory, lmd); var cp = new CacheProgress(memory, lp); //Create the source component only and a valid request range to fetch _source = new PACSSource { RemoteAEUri = new Uri("http://" + remoteAeUri), RemoteAEPort = remotePort, RemoteAETitle = remoteAeTitle, LocalAEUri = new Uri("http://" + localAeUri), LocalAEPort = localPort, LocalAETitle = localAeTitle, TransferTimeOutInSeconds = 50000, Modality = "ALL", MaxRetries = maxRetries }; //<- rly? its not gonna pass without an http!? _request = new BackfillCacheFetchRequest(BasicActivator.RepositoryLocator.CatalogueRepository, startDate) { ChunkPeriod = endDate.Subtract(startDate), CacheProgress = cp }; //Initialize it _source.PreInitialize(BasicActivator.RepositoryLocator.CatalogueRepository, new ThrowImmediatelyDataLoadEventListener { WriteToConsole = true }); _source.PreInitialize(this, new ThrowImmediatelyDataLoadEventListener { WriteToConsole = true }); }
public void CacheProvider_Normal() { var pt1 = new ProcessTask(CatalogueRepository, _lmd, LoadStage.GetFiles); pt1.Path = typeof(BasicCacheDataProvider).FullName; pt1.ProcessTaskType = ProcessTaskType.DataProvider; pt1.Name = "Cache1"; pt1.SaveToDatabase(); _cp.CacheFillProgress = new DateTime(2010, 1, 1); _cp.SaveToDatabase(); var projDir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "delme", true); _lmd.LocationOfFlatFiles = projDir.RootPath.FullName; _lmd.SaveToDatabase(); var pipeAssembler = new TestDataPipelineAssembler("CacheProvider_Normal", CatalogueRepository); pipeAssembler.ConfigureCacheProgressToUseThePipeline(_cp); try { var strategy = _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener()); Assert.AreEqual(typeof(SingleScheduleCacheDateTrackingStrategy), strategy.GetType()); var dates = strategy.GetDates(10, false); Assert.AreEqual(0, dates.Count); //zero dates to load because no files in cache File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-02.zip"), "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-03.zip"), "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); File.WriteAllText(Path.Combine(projDir.Cache.FullName, "2001-01-05.zip"), "bobbobbobyobyobyobbzzztproprietarybitztreamzippy"); strategy = _factory.Create(_lp, new ThrowImmediatelyDataLoadEventListener()); Assert.AreEqual(typeof(SingleScheduleCacheDateTrackingStrategy), strategy.GetType()); dates = strategy.GetDates(10, false); Assert.AreEqual(3, dates.Count); //zero dates to load because no files in cache } finally { _cp.Pipeline_ID = null; pipeAssembler.Destroy(); projDir.RootPath.Delete(true); } }
private void btnOk_Click(object sender, EventArgs e) { if (rbCreateNew.Checked) { try { var dir = new DirectoryInfo(tbCreateNew.Text); if (!dir.Exists) { dir.Create(); } Result = LoadDirectory.CreateDirectoryStructure(dir.Parent, dir.Name).RootPath.FullName; DialogResult = DialogResult.OK; this.Close(); } catch (Exception exception) { ExceptionViewer.Show(exception); } } if (rbUseExisting.Checked) { try { var dir = new LoadDirectory(tbUseExisting.Text); Result = dir.RootPath.FullName; DialogResult = DialogResult.OK; this.Close(); } catch (Exception exception) { if (Activator.YesNo($"Path is invalid, use anyway? ({exception.Message})", "Invalid Path")) { Result = tbUseExisting.Text; DialogResult = DialogResult.OK; this.Close(); } } } }
public void ExecuteSqlFileRuntimeTask_InvalidID(DatabaseType dbType) { var dt = new DataTable(); dt.Columns.Add("Lawl"); dt.Rows.Add(new object[] { 2 }); var db = GetCleanedServer(dbType, true); var tbl = db.CreateTable("Fish", dt); TableInfo ti; ColumnInfo[] cols; Import(tbl, out ti, out cols); FileInfo f = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Bob.sql")); File.WriteAllText(f.FullName, @"UPDATE {T:0} Set {C:0} = 1"); var pt = Mock.Of <IProcessTask>(x => x.Path == f.FullName); var dir = LoadDirectory.CreateDirectoryStructure(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), "ExecuteSqlFileRuntimeTaskTests", true); var task = new ExecuteSqlFileRuntimeTask(pt, new RuntimeArgumentCollection(new IArgument[0], new StageArgs(LoadStage.AdjustRaw, db, dir))); task.Check(new ThrowImmediatelyCheckNotifier()); HICDatabaseConfiguration configuration = new HICDatabaseConfiguration(db.Server); IDataLoadJob job = Mock.Of <IDataLoadJob>(x => x.RegularTablesToLoad == new List <ITableInfo> { ti } && x.LookupTablesToLoad == new List <ITableInfo>() && x.Configuration == configuration); var ex = Assert.Throws <ExecuteSqlFileRuntimeTaskException>(() => task.Run(job, new GracefulCancellationToken())); StringAssert.Contains("Failed to find a TableInfo in the load with ID 0", ex.Message); task.LoadCompletedSoDispose(Core.DataLoad.ExitCodeType.Success, new ThrowImmediatelyDataLoadEventListener()); }
public void AttemptToLoadDataWithFilesInForLoading_AgreementBetweenForLoadingAndCache() { var tempDirPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var tempDir = Directory.CreateDirectory(tempDirPath); try { // File in cache is the same file as in ForLoading (20160101.zip) var loadDirectory = LoadDirectory.CreateDirectoryStructure(tempDir, "CachedFileRetriever"); var cachedFilePath = Path.Combine(loadDirectory.Cache.FullName, "2016-01-01.zip"); File.WriteAllText(cachedFilePath, ""); File.WriteAllText(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip"), ""); // Set up retriever var cacheLayout = new ZipCacheLayoutOnePerDay(loadDirectory.Cache, new NoSubdirectoriesCachePathResolver()); var retriever = new TestCachedFileRetriever() { ExtractFilesFromArchive = false, LoadProgress = _lpMock, Layout = cacheLayout }; // Set up job var job = CreateTestJob(loadDirectory); job.DatesToRetrieve = new List <DateTime> { new DateTime(2016, 01, 01) }; // Should complete successfully, the file in ForLoading matches the job specification retriever.Fetch(job, new GracefulCancellationToken()); // And ForLoading should still have the file in it (i.e. it hasn't mysteriously disappeared) Assert.IsTrue(File.Exists(Path.Combine(loadDirectory.ForLoading.FullName, "2016-01-01.zip"))); } finally { tempDir.Delete(true); } }