Ejemplo n.º 1
0
        public DbScriptsToRunSelection GetSelectedScriptsToRun(Guid deploymentId, string[] sourceScriptsList)
        {
            _internalApiWebClient.CollectScriptsToRun(deploymentId, sourceScriptsList);

            var pollStartTime = DateTime.UtcNow;
            DbScriptsToRunSelectionResult scriptsToRunSelection;

            while (true)
            {
                PostDiagnosticMessage("Waiting for script selection...", DiagnosticMessageType.Trace);

                lock (_collectedScriptsByDeploymentId)
                {
                    if (_collectedScriptsByDeploymentId.TryGetValue(deploymentId, out scriptsToRunSelection))
                    {
                        break;
                    }
                }

                Thread.Sleep(1000);

                if (DateTime.UtcNow - pollStartTime > new TimeSpan(0, 0, _maxWaitTimeInSeconds))
                {
                    PostDiagnosticMessage("No scripts were selected in the alloted time slot - we'll time out.", DiagnosticMessageType.Trace);

                    break;
                }
            }

            if (scriptsToRunSelection != null && scriptsToRunSelection.Canceled)
            {
                PostDiagnosticMessage("Canceled selection of scripts to run - we'll not continue.", DiagnosticMessageType.Trace);

                return(new DbScriptsToRunSelection());
            }

            if (scriptsToRunSelection == null || scriptsToRunSelection.DbScriptsToRunSelection.SelectedScripts == null || scriptsToRunSelection.DbScriptsToRunSelection.SelectedScripts.Length == 0)
            {
                _internalApiWebClient.OnCollectScriptsToRunTimedOut(deploymentId);

                throw new TimeoutException("Given up waiting for scripts selection.");
            }

            PostDiagnosticMessage("Scripts to run were provided - we'll continue.", DiagnosticMessageType.Trace);

            return(scriptsToRunSelection.DbScriptsToRunSelection);
        }