public static FileLeaseManager.LeaseOperationResult GetLeaseOperation(FileLeaseManager.LeaseOperationRequest request)
 {
     FileLeaseManager.LeaseOperationResult result;
     using (FileStream fileStream = new FileStream(request.LeasePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.None))
     {
         byte[] array   = new byte[fileStream.Length];
         int    count   = fileStream.Read(array, 0, array.Length);
         string @string = Encoding.ASCII.GetString(array, 0, count);
         result = new FileLeaseManager.LeaseOperationResult(LeaseToken.Parse(@string));
     }
     return(result);
 }
        private FileLeaseManager.LeaseOperationResult SetLeaseOperation(FileLeaseManager.LeaseOperationRequest request)
        {
            string path = this.useBackupLeaseLocation ? this.backupLeaseFilePath : this.primaryLeaseFilePath;

            FileLeaseManager.LeaseOperationResult result;
            using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                byte[] bytes = Encoding.ASCII.GetBytes(request.Token.StringForm);
                fileStream.Write(bytes, 0, bytes.Length);
                fileStream.Flush();
                result = new FileLeaseManager.LeaseOperationResult();
            }
            return(result);
        }
        public static FileLeaseManager.LeaseOperationResult TryRunLeaseOperation(FileLeaseManager.LeaseOperation leaseOperation, FileLeaseManager.LeaseOperationRequest request)
        {
            Exception e = null;

            for (int i = 0; i < 10; i++)
            {
                e = null;
                if (i > 0)
                {
                    Thread.Sleep(50);
                }
                try
                {
                    return(leaseOperation(request));
                }
                catch (FileNotFoundException ex)
                {
                    e = ex;
                }
                catch (DirectoryNotFoundException ex2)
                {
                    e = ex2;
                }
                catch (IOException ex3)
                {
                    e = ex3;
                }
                catch (UnauthorizedAccessException ex4)
                {
                    e = ex4;
                }
            }
            return(new FileLeaseManager.LeaseOperationResult(e));
        }