public override void Execute()
        {
            base.Execute();

            if (TypeText("Permission Window Name", "Enter name for the PermissionWindow e.g. 'Nightly Loads'", 1000, null, out string name))
            {
                var newWindow = new PermissionWindow(BasicActivator.RepositoryLocator.CatalogueRepository);
                newWindow.Name = name;
                newWindow.SaveToDatabase();

                if (_cacheProgressToSetOnIfAny != null)
                {
                    new ExecuteCommandSetPermissionWindow(BasicActivator, _cacheProgressToSetOnIfAny).SetTarget(newWindow).Execute();
                }

                Publish(newWindow);
                Activate(newWindow);
            }
        }
        public override void Execute()
        {
            base.Execute();

            TypeTextOrCancelDialog dialog = new TypeTextOrCancelDialog("Permission Window Name", "Enter name for the PermissionWindow e.g. 'Nightly Loads'", 1000);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string windowText = dialog.ResultText;
                var    newWindow  = new PermissionWindow(Activator.RepositoryLocator.CatalogueRepository);
                newWindow.Name = windowText;
                newWindow.SaveToDatabase();

                if (_cacheProgressToSetOnIfAny != null)
                {
                    new ExecuteCommandSetPermissionWindow(Activator, _cacheProgressToSetOnIfAny).SetTarget(newWindow).Execute();
                }

                Publish(newWindow);
                Activate(newWindow);
            }
        }
Beispiel #3
0
        public void CacheHostOutwithPermissionWindow()
        {
            var rootDir = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
            var testDir = rootDir.CreateSubdirectory("C");

            if (testDir.Exists)
            {
                Directory.Delete(testDir.FullName, true);
            }

            var loadDirectory = LoadDirectory.CreateDirectoryStructure(testDir, "Test");


            var cp           = WhenIHaveA <CacheProgress>();
            var loadMetadata = cp.LoadProgress.LoadMetadata;

            loadMetadata.LocationOfFlatFiles = loadDirectory.RootPath.FullName;

            // This feels a bit nasty, but quick and much better than having the test wait for an arbitrary time period.
            var listener = new ExpectedNotificationListener("Download not permitted at this time, sleeping for 60 seconds");

            cp.CacheFillProgress   = DateTime.Now.AddDays(-1);
            cp.PermissionWindow_ID = 1;


            var permissionWindow = new PermissionWindow(Repository);

            permissionWindow.RequiresSynchronousAccess = true;
            permissionWindow.ID   = 1;
            permissionWindow.Name = "Test Permission Window";


            //Create a time period that we are outwith (1 hour ago to 30 minutes ago).
            TimeSpan start = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 1, 0, 0));
            TimeSpan stop  = DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 0, 30, 0));

            permissionWindow.SetPermissionWindowPeriods(new List <PermissionWindowPeriod>(new []
            {
                new PermissionWindowPeriod(
                    (int)DateTime.Now.DayOfWeek,
                    start,
                    stop)
            }));
            permissionWindow.SaveToDatabase();

            cp.PermissionWindow_ID = permissionWindow.ID;
            cp.SaveToDatabase();

            var dataFlowPipelineEngine = Mock.Of <IDataFlowPipelineEngine>();

            // set up a factory stub to return our engine mock
            var cacheHost = new CachingHost(Repository)
            {
                CacheProgressList = new List <ICacheProgress> {
                    cp
                }
            };

            var stopTokenSource   = new CancellationTokenSource();
            var abortTokenSource  = new CancellationTokenSource();
            var cancellationToken = new GracefulCancellationToken(stopTokenSource.Token, abortTokenSource.Token);

            var task = Task.Run(() => cacheHost.Start(listener, cancellationToken), cancellationToken.CreateLinkedSource().Token);

            // Don't want to cancel before the DownloadUntilFinished loop starts and we receive the first "Download not permitted at this time, sleeping for 60 seconds" message
            listener.ReceivedMessage += abortTokenSource.Cancel;

            try
            {
                task.Wait();
            }
            catch (AggregateException e)
            {
                Assert.AreEqual(1, e.InnerExceptions.Count);
                Assert.IsInstanceOf(typeof(TaskCanceledException), e.InnerExceptions[0], e.InnerExceptions[0].Message);
            }
            finally
            {
                testDir.Delete(true);
            }
        }