예제 #1
0
    public void ForNonSeekable(string input, params string[] lines)
    {
        using (var s = new AnonymousPipeServerStream())
        using (var c = new AnonymousPipeClientStream(s.GetClientHandleAsString()))
        {
            var bytes = Encoding.ASCII.GetBytes(input);
            s.Write(bytes, 0, bytes.Length);
            s.Close();

            var skipLF = false;
            foreach (var line in lines)
            {
                Assert.Equal(line, c.ReadProtocolLineWithEnd(skipLF));
                skipLF = (line.Last() == '\r');
            }
        }

        using (var s = new AnonymousPipeServerStream())
        using (var c = new AnonymousPipeClientStream(s.GetClientHandleAsString()))
        {
            var bytes = Encoding.ASCII.GetBytes(input);
            s.Write(bytes, 0, bytes.Length);
            s.Close();

            var skipLF = false;
            foreach (var line in lines)
            {
                Assert.Equal(line.TrimEnd(LineEnds), c.ReadProtocolLine(skipLF));
                skipLF = (line.Last() == '\r');
            }
        }
    }
예제 #2
0
		Stream OpenOutput(string gitExe, string fileName, string blobHash)
		{
			if (!File.Exists(fileName))
				return null;
			if (blobHash == null)
				return null;
			
			AnonymousPipeServerStream pipe = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
			
			StartupInfo startupInfo = new GitVersionProvider.StartupInfo();
			startupInfo.dwFlags = STARTF_USESTDHANDLES;
			startupInfo.hStdOutput = pipe.ClientSafePipeHandle;
			startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
			startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
			startupInfo.cb = 16;
			
			PROCESS_INFORMATION procInfo;
			
			string commandLine = "\"" + gitExe + "\" cat-file blob " + blobHash;
			string workingDir = Path.GetDirectoryName(fileName);
			Debug.WriteLine(workingDir + "> " + commandLine);
			const uint CREATE_NO_WINDOW = 0x08000000;
			if (!CreateProcess(null, commandLine,
			                   IntPtr.Zero, IntPtr.Zero, true, CREATE_NO_WINDOW, IntPtr.Zero, workingDir, ref startupInfo,
			                   out procInfo)) {
				pipe.DisposeLocalCopyOfClientHandle();
				pipe.Close();
				return null;
			}
			
			pipe.DisposeLocalCopyOfClientHandle();
			
			return pipe;
		}
예제 #3
0
        static void Relaunch()
        {
            var tempdir = Path.Combine( Path.GetTempPath(), Path.GetRandomFileName() );
            Directory.CreateDirectory( tempdir );
            var xcopy_args = String.Format( "/E \"{0}\" \"{1}\\\"", Path.GetDirectoryName(OriginalPath).Replace("file:\\",""), tempdir );
            var pcopy = Process.Start( "xcopy", xcopy_args );
            if (!pcopy.WaitForExit(10000)) throw new InvalidOperationException("Relaunch copy hanged!");
            Win32.MoveFileEx( tempdir, null, Win32.MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT) ;
            var newexe = Path.Combine( tempdir, Path.GetFileName(OriginalPath) );

            if ( Connection != null && Connection.Socket.Connected ) {
                var pipe = new AnonymousPipeServerStream( PipeDirection.Out, HandleInheritability.Inheritable );
                var pipename = pipe.GetClientHandleAsString();
                var pcloneinfo = new ProcessStartInfo( newexe, string.Format( "--original={0} --pipe={1}", OriginalPath, pipename ) );
                pcloneinfo.UseShellExecute = false;
                var pclone = Process.Start(pcloneinfo);
                var sockinfo = Connection.Socket.DuplicateAndClose(pclone.Id).ProtocolInformation;
                pipe.Write( sockinfo, 0, sockinfo.Length );
                pipe.WaitForPipeDrain();
                pipe.Close();
            } else {
                var pclone = Process.Start( newexe, string.Format( "--original={0}", OriginalPath ) );
            }
        }
		Stream OpenOutput(string fileName, string blobHash)
		{
			if (blobHash == null)
				return null;
			
			AnonymousPipeServerStream pipe = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
			
			StartupInfo startupInfo = new GitVersionProvider.StartupInfo();
			startupInfo.dwFlags = STARTF_USESTDHANDLES;
			startupInfo.hStdOutput = pipe.ClientSafePipeHandle;
			startupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
			startupInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE);
			startupInfo.cb = 16;
			
			PROCESS_INFORMATION procInfo;
			
			if (!CreateProcess(null, string.Format("cmd /c git cat-file blob {0}", blobHash),
			                   IntPtr.Zero, IntPtr.Zero, true, 0, IntPtr.Zero, Path.GetDirectoryName(fileName), ref startupInfo,
			                   out procInfo)) {
				pipe.DisposeLocalCopyOfClientHandle();
				pipe.Close();
				return null;
			}
			
			pipe.DisposeLocalCopyOfClientHandle();
			
			return pipe;
		}