Esempio n. 1
0
        private static void RegisterDownloads(ContainerBuilder builder)
        {
            builder.Register(
                c =>
            {
                var ctx = c.Resolve <IComponentContext>();
                DownloadDataFromRemoteEndpoints func =
                    (endpoint, token, filePath, timeout) =>
                {
                    var handler = ctx.Resolve <IDirectIncomingData>();
                    var result  = handler.ForwardData(endpoint, filePath, timeout);

                    var layer    = ctx.Resolve <IProtocolLayer>();
                    var msg      = new DataDownloadRequestMessage(layer.Id, token);
                    var response = layer.SendMessageAndWaitForResponse(
                        endpoint,
                        msg,
                        CommunicationConstants.DefaultMaximuNumberOfRetriesForMessageSending,
                        timeout);
                    return(Task <FileInfo> .Factory.StartNew(
                               () =>
                    {
                        Task.WaitAll(result, response);
                        return result.Result;
                    }));
                };

                return(func);
            })
            .SingleInstance();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestCommands"/> class.
        /// </summary>
        /// <param name="download">The delegate used to download data from a remote endpoint.</param>
        /// <param name="onEcho">The function called when an echo command is executed.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="download"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="onEcho"/> is <see langword="null" />.
        /// </exception>
        public TestCommands(DownloadDataFromRemoteEndpoints download, Action <EndpointId, string> onEcho)
        {
            {
                Lokad.Enforce.Argument(() => download);
                Lokad.Enforce.Argument(() => onEcho);
            }

            m_Download = download;
            m_OnEcho   = onEcho;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginLoadingAssemblyResolver"/> class.
        /// </summary>
        /// <param name="hostCommands">The object that provides the commands registered with the application.</param>
        /// <param name="layer">The object that handles the communication with the remote host.</param>
        /// <param name="fileSystem">The object that virtualizes the file system.</param>
        /// <param name="hostId">The ID of the host endpoint.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostCommands"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="layer"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostId"/> is <see langword="null" />.
        /// </exception>
        public PluginLoadingAssemblyResolver(
            ISendCommandsToRemoteEndpoints hostCommands,
            DownloadDataFromRemoteEndpoints layer,
            IFileSystem fileSystem,
            EndpointId hostId)
        {
            {
                Lokad.Enforce.Argument(() => hostCommands);
                Lokad.Enforce.Argument(() => layer);
                Lokad.Enforce.Argument(() => fileSystem);
                Lokad.Enforce.Argument(() => hostId);
            }

            m_HostCommands = hostCommands;
            m_Layer        = layer;
            m_FileSystem   = fileSystem;
            m_HostId       = hostId;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginLoadingAssemblyResolver"/> class.
        /// </summary>
        /// <param name="hostCommands">The object that provides the commands registered with the application.</param>
        /// <param name="layer">The object that handles the communication with the remote host.</param>
        /// <param name="fileSystem">The object that virtualizes the file system.</param>
        /// <param name="hostId">The ID of the host endpoint.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostCommands"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="layer"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostId"/> is <see langword="null" />.
        /// </exception>
        public PluginLoadingAssemblyResolver(
            ISendCommandsToRemoteEndpoints hostCommands,
            DownloadDataFromRemoteEndpoints layer,
            IFileSystem fileSystem,
            EndpointId hostId)
        {
            {
                Lokad.Enforce.Argument(() => hostCommands);
                Lokad.Enforce.Argument(() => layer);
                Lokad.Enforce.Argument(() => fileSystem);
                Lokad.Enforce.Argument(() => hostId);
            }

            m_HostCommands = hostCommands;
            m_Layer = layer;
            m_FileSystem = fileSystem;
            m_HostId = hostId;
        }
Esempio n. 5
0
        public void LocatePluginAssemblyDownloadFail()
        {
            var token    = new UploadToken();
            var commands = new Mock <IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny <AssemblyName>()))
                .Returns(
                    Task <UploadToken> .Factory.StartNew(
                        () =>
                {
                    return(token);
                }));
            }

            var commandContainer = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor <IHostApplicationCommands>(It.IsAny <EndpointId>()))
                .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, u, file) => Task <FileInfo> .Factory.StartNew(
                () =>
            {
                Assert.AreSame(token, u);
                throw new FileNotFoundException();
            });

            var fileSystem = new Mock <IFileSystem>();
            {
                fileSystem.Setup(f => f.Path)
                .Returns(new MockPath());
                fileSystem.Setup(f => f.File)
                .Returns(new MockFile(new Dictionary <string, string>()));
            }

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);

            Assert.IsNull(resolver.LocatePluginAssembly(new object(), new ResolveEventArgs("a")));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StoreTestReportDataCommands"/> class.
        /// </summary>
        /// <param name="fileSystem">The object that provides access to the file system.</param>
        /// <param name="configuration">The object that provides access to the application configuration.</param>
        /// <param name="activeTests">The object that stores information about all the active tests.</param>
        /// <param name="dataDownload">The function that handles the download of data from a remote endpoint.</param>
        /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param>
        public StoreTestReportDataCommands(
            IFileSystem fileSystem,
            IConfiguration configuration,
            IStoreActiveTests activeTests,
            DownloadDataFromRemoteEndpoints dataDownload,
            SystemDiagnostics diagnostics)
        {
            {
                Lokad.Enforce.Argument(() => fileSystem);
                Lokad.Enforce.Argument(() => configuration);
                Lokad.Enforce.Argument(() => activeTests);
                Lokad.Enforce.Argument(() => dataDownload);
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_FileSystem = fileSystem;
            m_Configuration = configuration;
            m_ActiveTests = activeTests;
            m_DataDownload = dataDownload;
            m_Diagnostics = diagnostics;
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetApplicationCommands"/> class.
        /// </summary>
        /// <param name="dataDownload">The object that handles the communication with remote endpoints.</param>
        /// <param name="datasetLock">The function that handles downloading data from the remote endpoint.</param>
        /// <param name="closeAction">The action that closes the application.</param>
        /// <param name="loadAction">The action that is used to load the dataset from a given file path.</param>
        /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataDownload"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="datasetLock"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="closeAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="loadAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown is <paramref name="systemDiagnostics"/> is <see langword="null"/>
        /// </exception>
        public DatasetApplicationCommands(
            DownloadDataFromRemoteEndpoints dataDownload,
            ITrackDatasetLocks datasetLock,
            Action closeAction,
            Action <FileInfo> loadAction,
            SystemDiagnostics systemDiagnostics,
            TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => dataDownload);
                Enforce.Argument(() => closeAction);
                Enforce.Argument(() => loadAction);
                Enforce.Argument(() => systemDiagnostics);
            }

            m_DataDownload = dataDownload;
            m_DatasetLock  = datasetLock;
            m_CloseAction  = closeAction;
            m_LoadAction   = loadAction;
            m_Diagnostics  = systemDiagnostics;
            m_Scheduler    = scheduler ?? TaskScheduler.Default;
        }
Esempio n. 8
0
        public void LocatePluginAssemblyWithUnknownAssemblyOnHost()
        {
            var commands = new Mock <IHostApplicationCommands>();
            {
                commands.Setup(c => c.PreparePluginContainerForTransfer(It.IsAny <AssemblyName>()))
                .Returns(
                    Task <UploadToken> .Factory.StartNew(
                        () =>
                {
                    throw new FileNotFoundException();
                }));
            }

            var commandContainer = new Mock <ISendCommandsToRemoteEndpoints>();
            {
                commandContainer.Setup(c => c.CommandsFor <IHostApplicationCommands>(It.IsAny <EndpointId>()))
                .Returns(commands.Object);
            }

            DownloadDataFromRemoteEndpoints layer = (id, token, file) =>
            {
                Assert.Fail();
                return(Task <FileInfo> .Factory.StartNew(() => new FileInfo(file)));
            };

            var fileSystem = new Mock <IFileSystem>();

            var endpoint = new EndpointId("a");
            var resolver = new PluginLoadingAssemblyResolver(
                commandContainer.Object,
                layer,
                fileSystem.Object,
                endpoint);

            Assert.IsNull(resolver.LocatePluginAssembly(new object(), new ResolveEventArgs("a")));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransferTestReportDataCommands"/> class.
        /// </summary>
        /// <param name="fileSystem">The object that provides access to the file system.</param>
        /// <param name="dataDownload">The function that handles the download of data from a remote endpoint.</param>
        /// <param name="remoteCommands">The object that sends commands to remote endpoints.</param>
        /// <param name="uploads">The object that stores links to all the files that should be uploaded.</param>
        /// <param name="testInformation">The object that stores information about the currently active test.</param>
        /// <param name="hostInformation">The object that stores information about the host.</param>
        /// <param name="storageDirectory">The directory in which all the report files are stored.</param>
        /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="fileSystem"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataDownload"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="remoteCommands"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="uploads"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="testInformation"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostInformation"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="storageDirectory"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="diagnostics"/> is <see langword="null" />.
        /// </exception>
        public TransferTestReportDataCommands(
            IFileSystem fileSystem,
            DownloadDataFromRemoteEndpoints dataDownload,
            ISendCommandsToRemoteEndpoints remoteCommands,
            IStoreUploads uploads,
            ActiveTestInformation testInformation,
            HostInformationStorage hostInformation,
            string storageDirectory,
            SystemDiagnostics diagnostics)
        {
            {
                Lokad.Enforce.Argument(() => fileSystem);
                Lokad.Enforce.Argument(() => dataDownload);
                Lokad.Enforce.Argument(() => remoteCommands);
                Lokad.Enforce.Argument(() => uploads);
                Lokad.Enforce.Argument(() => testInformation);
                Lokad.Enforce.Argument(() => hostInformation);
                Lokad.Enforce.Argument(() => storageDirectory);
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_FileSystem = fileSystem;
            m_DataDownload = dataDownload;
            m_RemoteCommands = remoteCommands;
            m_Uploads = uploads;
            m_TestInformation = testInformation;
            m_HostInformation = hostInformation;
            m_StorageDirectory = storageDirectory;
            m_Diagnostics = diagnostics;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TestStepExecutionCommands"/> class.
        /// </summary>
        /// <param name="fileSystem">The object that provides access to the file system.</param>
        /// <param name="layer">The object that provides methods for sending and receiving data from remote endpoints.</param>
        /// <param name="remoteCommands">The object that sends commands to remote endpoints.</param>
        /// <param name="remoteNotifications">The object that provides notifications from remote endpoints.</param>
        /// <param name="dataDownload">The function that is used to download data streams from remote endpoints.</param>
        /// <param name="executionEvents">The object that handles sending test execution events to the Sherlock master.</param>
        /// <param name="sectionBuilders">The function that returns a new test section builder.</param>
        /// <param name="configuration">The configuration object.</param>
        /// <param name="testInformation">The object that stores information about the currently active test.</param>
        /// <param name="hostInformation">The object that stores information about the host.</param>
        /// <param name="storageDirectory">The directory in which all the report files are stored.</param>
        /// <param name="diagnostics">The object that provides the diagnostics methods for the application.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="fileSystem"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="layer"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="remoteCommands"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="remoteNotifications"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataDownload"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="executionEvents"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="sectionBuilders"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="configuration"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="testInformation"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="hostInformation"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="storageDirectory"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="diagnostics"/> is <see langword="null" />.
        /// </exception>
        public TestStepExecutionCommands(
            IFileSystem fileSystem,
            ICommunicationLayer layer,
            ISendCommandsToRemoteEndpoints remoteCommands,
            INotifyOfRemoteEndpointEvents remoteNotifications,
            DownloadDataFromRemoteEndpoints dataDownload,
            ITestExecutionNotificationsInvoker executionEvents,
            Func<string, ITestSectionBuilder> sectionBuilders,
            IConfiguration configuration,
            ActiveTestInformation testInformation,
            HostInformationStorage hostInformation,
            string storageDirectory,
            SystemDiagnostics diagnostics)
        {
            {
                Lokad.Enforce.Argument(() => fileSystem);
                Lokad.Enforce.Argument(() => layer);
                Lokad.Enforce.Argument(() => remoteCommands);
                Lokad.Enforce.Argument(() => remoteNotifications);
                Lokad.Enforce.Argument(() => dataDownload);
                Lokad.Enforce.Argument(() => executionEvents);
                Lokad.Enforce.Argument(() => sectionBuilders);
                Lokad.Enforce.Argument(() => configuration);
                Lokad.Enforce.Argument(() => testInformation);
                Lokad.Enforce.Argument(() => hostInformation);
                Lokad.Enforce.Argument(() => storageDirectory);
                Lokad.Enforce.Argument(() => diagnostics);
            }

            m_FileSystem = fileSystem;
            m_Layer = layer;
            m_RemoteCommands = remoteCommands;
            m_RemoteNotifications = remoteNotifications;
            m_DataDownload = dataDownload;
            m_TestExecutionEvents = executionEvents;
            m_SectionBuilders = sectionBuilders;
            m_Configuration = configuration;
            m_TestInformation = testInformation;
            m_HostInformation = hostInformation;
            m_StorageDirectory = storageDirectory;
            m_Diagnostics = diagnostics;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetApplicationCommands"/> class.
        /// </summary>
        /// <param name="dataDownload">The object that handles the communication with remote endpoints.</param>
        /// <param name="datasetLock">The function that handles downloading data from the remote endpoint.</param>
        /// <param name="closeAction">The action that closes the application.</param>
        /// <param name="loadAction">The action that is used to load the dataset from a given file path.</param>
        /// <param name="systemDiagnostics">The object that provides the diagnostics methods for the system.</param>
        /// <param name="scheduler">The scheduler that is used to run the tasks.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="dataDownload"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="datasetLock"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="closeAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="loadAction"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Thrown is <paramref name="systemDiagnostics"/> is <see langword="null"/>
        /// </exception>
        public DatasetApplicationCommands(
            DownloadDataFromRemoteEndpoints dataDownload,
            ITrackDatasetLocks datasetLock,
            Action closeAction,
            Action<FileInfo> loadAction,
            SystemDiagnostics systemDiagnostics,
            TaskScheduler scheduler = null)
        {
            {
                Enforce.Argument(() => dataDownload);
                Enforce.Argument(() => closeAction);
                Enforce.Argument(() => loadAction);
                Enforce.Argument(() => systemDiagnostics);
            }

            m_DataDownload = dataDownload;
            m_DatasetLock = datasetLock;
            m_CloseAction = closeAction;
            m_LoadAction = loadAction;
            m_Diagnostics = systemDiagnostics;
            m_Scheduler = scheduler ?? TaskScheduler.Default;
        }