// Execute a command and wait for a response. No more interaction
        public override void ExecuteSyncCommand(string commandDescription, string commandText, out string commandOutput, int timeout, out int exitCode)
        {
            int    exit   = -1;
            string output = string.Empty;

            var settings = new DockerExecSettings(TransportSettings, commandText, runInShell: false, makeInteractive: false);
            var runner   = GetCommandRunner(settings, true);

            string dockerCommand = "{0} {1}".FormatInvariantWithArgs(settings.Command, settings.CommandArgs);
            string waitMessage   = StringResources.WaitingOp_ExecutingCommand.FormatCurrentCultureWithArgs(commandDescription);
            string errorMessage;

            VS.VSOperationWaiter.Wait(waitMessage, true, (cancellationToken) =>
            {
                if (OuterConnection != null)
                {
                    exit = OuterConnection.ExecuteCommand(dockerCommand, timeout, out output, out errorMessage);
                }
                else
                {
                    //local exec command
                    exit = ExecuteCommand(commandText, timeout, out output, out errorMessage);
                }
            });

            exitCode      = exit;
            commandOutput = output;
        }
        public override void CopyFile(string sourcePath, string destinationPath)
        {
            DockerCopySettings settings;
            string             tmpFile = null;

            if (!Directory.Exists(sourcePath) && !File.Exists(sourcePath))
            {
                throw new ArgumentException(StringResources.Error_CopyFile_SourceNotFound.FormatCurrentCultureWithArgs(sourcePath), nameof(sourcePath));
            }

            if (OuterConnection != null)
            {
                tmpFile = "/tmp" + "/" + StringResources.CopyFile_TempFilePrefix + Guid.NewGuid();
                OuterConnection.CopyFile(sourcePath, tmpFile);
                settings = new DockerCopySettings(TransportSettings, tmpFile, destinationPath);
            }
            else
            {
                settings = new DockerCopySettings(TransportSettings, sourcePath, destinationPath);
            }

            ICommandRunner runner = GetCommandRunner(settings);

            ManualResetEvent resetEvent = new ManualResetEvent(false);
            int exitCode = -1;

            runner.Closed += (e, args) =>
            {
                exitCode = args;
                resetEvent.Set();
                try
                {
                    if (OuterConnection != null && !string.IsNullOrEmpty(tmpFile))
                    {
                        string output;
                        string errorMessage;
                        // Don't error on failing to remove the temporary file.
                        int exit = OuterConnection.ExecuteCommand("rm " + tmpFile, 5000, out output, out errorMessage);
                        Debug.Assert(exit == 0, FormattableString.Invariant($"Removing file exited with {exit} and message {output}. {errorMessage}"));
                    }
                }
                catch (Exception ex) // don't error on cleanup
                {
                    Debug.Fail("Exception thrown while cleaning up temp file. " + ex.Message);
                }
            };

            runner.Start();

            bool complete = resetEvent.WaitOne(Timeout.Infinite);

            if (!complete || exitCode != 0)
            {
                throw new CommandFailedException(StringResources.Error_CopyFileFailed);
            }
        }
Exemple #3
0
        public override void ExecuteSyncCommand(string commandDescription, string commandText, out string commandOutput, int timeout, out int exitCode)
        {
            int    exit   = -1;
            string output = string.Empty;

            if (OuterConnection != null)
            {
                string dockerCommand = string.Format(CultureInfo.InvariantCulture, StringResources.DockerExecCommandFormat, _containerName, commandText);
                string waitMessage   = string.Format(CultureInfo.InvariantCulture, StringResources.WaitingOp_ExecutingCommand, commandDescription);
                VS.VSOperationWaiter.Wait(waitMessage, true, () =>
                {
                    exit = OuterConnection.ExecuteCommand(dockerCommand, timeout, out output);
                });
            }
            else
            {
                //local exec command
                exit = ExecuteCommand(commandText, timeout, out output);
            }

            exitCode      = exit;
            commandOutput = output;
        }
Exemple #4
0
 override public void EnlistTransaction(SysTx.Transaction transaction)
 {
     OuterConnection.Open_EnlistTransaction(transaction);
 }
Exemple #5
0
 override public void ChangeDatabase(string value)
 {
     OuterConnection.Open_ChangeDatabase(value);
 }
Exemple #6
0
 internal OdbcTransaction BeginOdbcTransaction(IsolationLevel isolevel)
 {
     return(OuterConnection.Open_BeginTransaction(isolevel));
 }
Exemple #7
0
        override public void EnlistTransaction(SysTx.Transaction transaction)
        {
#if !COREFX
            OuterConnection.Open_EnlistTransaction(transaction);
#endif
        }