dlech.SshAgentLib.CygwinSocket.TestFile C# (CSharp) Method

TestFile() public static method

Tests a file to see if it looks like a Cygwin socket file
public static TestFile ( string path ) : bool
path string The path to the file.
return bool
        public static bool TestFile(string path)
        {
            var test = new Regex(@"!<socket >\d+ s (?:[0-9A-Fa-f]{8}-?){4}");
              return test.Match(File.ReadAllText(path)).Success;
        }

Usage Example

Beispiel #1
0
 /// <summary>
 /// Starts a cygwin style socket that can be used by the ssh program
 /// that comes with cygwin.
 /// </summary>
 /// <param name="path">The path to the socket file that will be created.</param>
 public void StartCygwinSocket(string path)
 {
     if (disposed)
     {
         throw new ObjectDisposedException("PagentAgent");
     }
     if (cygwinSocket != null)
     {
         return;
     }
     // only overwrite a file if it looks like a CygwinSocket file.
     // TODO: Might be good to test that there are not network sockets using
     // the port specified in this file.
     if (File.Exists(path) && CygwinSocket.TestFile(path))
     {
         File.Delete(path);
     }
     cygwinSocket = new CygwinSocket(path);
     cygwinSocket.ConnectionHandler = connectionHandler;
 }