Ejemplo n.º 1
0
 public void Dispose()
 {
     safeFileHandle?.Dispose();
     fileStream?.Dispose();
     StandardOutput?.Dispose();
     FreeConsole();
 }
Ejemplo n.º 2
0
        public void Close()
        {
            if (_IsClosing)
            {
                return;
            }
            _IsClosing = true;

            try
            {
                foreach (var usbInterface in _UsbInterfaces)
                {
                    usbInterface.Dispose();
                }

                _UsbInterfaces.Clear();

                _DeviceHandle?.Dispose();
                _DeviceHandle = null;
            }
            catch (Exception)
            {
                //TODO: Logging
            }

            _IsClosing = false;
        }
        public override void Close()
        {
            _DeviceHandle?.Dispose();
            _DeviceHandle = null;

            base.Close();
        }
Ejemplo n.º 4
0
        public void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            GC.SuppressFinalize(this);
            _options.IoMetrics.FileClosed(_filename);
            _readHandle?.Dispose();
            _readHandle = null;
            _handle?.Dispose();
            _handle = null;
            if (_nativeOverlapped != null)
            {
                NativeMemory.Free((byte *)_nativeOverlapped, sizeof(NativeOverlapped));
                _nativeOverlapped = null;
            }

            if (DeleteOnClose)
            {
                try
                {
                    File.Delete(_filename);
                }
                catch (Exception)
                {
                    // if we can't delete, nothing that we can do here.
                }
            }
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            Disposed = true;
            GC.SuppressFinalize(this);
            _readHandle?.Dispose();
            _handle.Dispose();
            if (_nativeOverlapped != null)
            {
                Marshal.FreeHGlobal((IntPtr)_nativeOverlapped);
                _nativeOverlapped = null;
            }
            if (_segments != null)
            {
                Marshal.FreeHGlobal((IntPtr)_segments);
                _segments = null;
            }

            if (DeleteOnClose)
            {
                try
                {
                    File.Delete(_filename);
                }
                catch (Exception)
                {
                    // if we can't delete, nothing that we can do here.
                }
            }
        }
Ejemplo n.º 6
0
 void Dispose(bool disposing)
 {
     if (disposing)
     {
         ReadSide?.Dispose();
         WriteSide?.Dispose();
     }
 }
Ejemplo n.º 7
0
        public Win32FileJournalWriter(StorageEnvironmentOptions options, VoronPathSetting filename, long journalSize,
                                      Win32NativeFileAccess access   = Win32NativeFileAccess.GenericWrite,
                                      Win32NativeFileShare shareMode = Win32NativeFileShare.Read)
        {
            try
            {
                _options  = options;
                _filename = filename;
                _handle   = Win32NativeFileMethods.CreateFile(filename.FullPath,
                                                              access, shareMode, IntPtr.Zero,
                                                              Win32NativeFileCreationDisposition.OpenAlways,
                                                              options.WinOpenFlags, IntPtr.Zero);

                if (_handle.IsInvalid)
                {
                    throw new IOException("When opening file " + filename, new Win32Exception(Marshal.GetLastWin32Error()));
                }

                var length = new FileInfo(filename.FullPath).Length;
                if (length < journalSize)
                {
                    try
                    {
                        Win32NativeFileMethods.SetFileLength(_handle, journalSize);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            _handle?.Dispose();
                            _handle = null;
                            File.Delete(_filename.FullPath);
                        }
                        catch (Exception)
                        {
                            // there's nothing we can do about it
                        }

                        throw;
                    }

                    length = journalSize;
                }

                NumberOfAllocated4Kb = (int)(length / (4 * Constants.Size.Kilobyte));

                _nativeOverlapped = (NativeOverlapped *)NativeMemory.AllocateMemory(sizeof(NativeOverlapped));

                _nativeOverlapped->InternalLow  = IntPtr.Zero;
                _nativeOverlapped->InternalHigh = IntPtr.Zero;
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Ejemplo n.º 8
0
 protected override void DisposeInternal()
 {
     _fileStream?.Dispose();
     _handle?.Dispose();
     if (DeleteOnClose)
     {
         _fileInfo?.Delete();
     }
 }
Ejemplo n.º 9
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         channel?.Dispose();
         fs?.Close();
         fs?.Dispose();
     }
 }
Ejemplo n.º 10
0
 public void Dispose()
 {
     if (!_isDisposed)
     {
         _isDisposed = true;
         _readHandle?.Dispose();
         _writeHandle?.Dispose();
         ClosePseudoConsole(_ptyHandle);
     }
 }
    protected virtual void Dispose(bool disposing)
    {
      if (_disposed) return;

      // Dispose of managed resources here.
      if (disposing) _safeFileHandle?.Dispose();

      // Dispose of any unmanaged resources not wrapped in safe handles.

      _disposed = true;  
    }
 public void Dispose()
 {
     handle?.Dispose();
     afsluiten?.Dispose();
     reboot?.Dispose();
     taskmananger?.Dispose();
     vergrendel?.Dispose();
     kladblok?.Dispose();
     cpuCounter?.Dispose();
     ramCounter.Dispose();
 }
Ejemplo n.º 13
0
        public void Close()
        {
            foreach (var usbInterface in UsbInterfaces)
            {
                usbInterface.Dispose();
            }

            UsbInterfaces.Clear();

            _DeviceHandle?.Dispose();
            _DeviceHandle = null;
        }
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _safeHandle?.Dispose();
            }

            _disposed = true;
        }
Ejemplo n.º 15
0
        public override void Dispose()
        {
            IsInitialized = false;

            foreach (var usbInterface in _UsbInterfaces)
            {
                usbInterface.Dispose();
            }
            _UsbInterfaces.Clear();

            _DeviceHandle?.Dispose();

            base.Dispose();
        }
Ejemplo n.º 16
0
        private static void InternalCreatePipe(
            out SafeFileHandle parentHandle, out SafeFileHandle childHandle,
            bool parentInputs)
        {
            var securityAttributesParent = new Interop.SecurityAttributes();

            securityAttributesParent.bInheritHandle = Interop.BOOL.TRUE;

            SafeFileHandle hTmp = null;

            try
            {
                if (parentInputs)
                {
                    CreatePipeWithSecurityAttributes(
                        out childHandle, out hTmp,
                        ref securityAttributesParent, 0);
                }
                else
                {
                    CreatePipeWithSecurityAttributes(
                        out hTmp, out childHandle,
                        ref securityAttributesParent, 0);
                }

                // Duplicate the parent handle to be non-inheritable so that the child process
                // doesn't have access. This is done for correctness sake, exact reason is unclear.
                // One potential theory is that child process can do something brain dead like
                // closing the parent end of the pipe and there by getting into a blocking situation
                // as parent will not be draining the pipe at the other end anymore.
                SafeProcessHandle currentProcHandle = Kernel32.GetCurrentProcess();

                if (!Kernel32.DuplicateHandle(
                        currentProcHandle, hTmp,
                        currentProcHandle, out parentHandle,
                        0, false, HandleOptions.DuplicateSameAccess))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                if (hTmp != null && !hTmp.IsInvalid)
                {
                    hTmp.Dispose();
                }
            }
        }
Ejemplo n.º 17
0
        // Take reference, so we may easily add multiple interface support in the future
        internal void ReturnHandle(SafeWinUsbInterfaceHandle handle)
        {
            if (activeWinUsbHandle != handle)
            {
                throw new InvalidOperationException("Returning handle is not equal to active handle");
            }

            if (Interlocked.Decrement(ref referenceCount) == 0)
            {
                activeWinUsbHandle.Dispose();
                activeFileHandle.Dispose();

                activeWinUsbHandle = null;
                activeFileHandle   = null;
            }
        }
Ejemplo n.º 18
0
        public bool Open()
        {
            device = new SafeFileHandle(NativeMethods.CreateFile(@"\\.\" + id,
                                                                 FileAccess.GENERIC_READ | FileAccess.GENERIC_WRITE, 0, IntPtr.Zero,
                                                                 CreationDisposition.OPEN_EXISTING, FileAttributes.FILE_ATTRIBUTE_NORMAL,
                                                                 IntPtr.Zero), true);

            if (device.IsInvalid)
            {
                device.Close();
                device.Dispose();
                device = null;
            }

            return(device != null);
        }
        public override void Dispose()
        {
            if (Disposed)
            {
                return;
            }

            base.Dispose();

            _fileStream?.Dispose();
            _handle?.Dispose();
            if (DeleteOnClose)
            {
                _fileInfo?.Delete();
            }
        }
Ejemplo n.º 20
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                handle.Dispose();
                pin         = null;
                console     = null;
                excludeList = null;
            }

            disposed = true;
        }
Ejemplo n.º 21
0
        public override void Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;

            if (_ReadSafeFileHandle != null)
            {
                _ReadSafeFileHandle.Dispose();
                _ReadSafeFileHandle = new SafeFileHandle((IntPtr)0, true);
            }

            base.Dispose();
        }
Ejemplo n.º 22
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                // get rid of managed resources
            }
            // get rid of unmanaged resources
            _driverHandle.Dispose();

            implementation = new Lazy <KeyboardEmulatorAPI>(() => CreateInstance(), System.Threading.LazyThreadSafetyMode.PublicationOnly);
            disposed       = true;
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Closes the serial port.
 /// </summary>
 /// <exception cref="System.ObjectDisposedException"/>
 /// <remarks>
 /// Closing the serial port invalidates actions that can be done to the serial port,
 /// but it does not prevent the serial port from being reopened
 /// </remarks>
 public void Close()
 {
     if (m_IsDisposed)
     {
         throw new ObjectDisposedException("WinNativeSerial");
     }
     if (IsOpen)
     {
         m_CommOverlappedIo.Dispose();
         m_CommOverlappedIo = null;
         m_CommState        = null;
         m_CommModemStatus  = null;
         m_ComPortHandle.Dispose();
         m_ComPortHandle = null;
     }
 }
Ejemplo n.º 24
0
 // Disposeパターン
 protected virtual void Dispose(bool disposing)
 {
     if (disposed)
     {
         return;             // Dispose has already been called.
     }
     if (disposing)
     {
         handle.Dispose();
         // マネージリソースの解放
         // ToDo
     }
     // アンマネージリソースの解放
     // ToDo
     disposed = true;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Closes the Wirekite devices.
        /// </summary>
        /// <remarks>
        /// A closed device can no longer be used. It must be disconnected and connected again,
        /// or the Wirekite service must be restarted.
        /// </remarks>
        public void Close()
        {
            if (_deviceState == DeviceState.Closed)
            {
                return;
            }

            _ports.Clear();
            _throttler.Clear();
            _pendingRequests.Clear();
            _service.RemoveDevice(this);
            WinUsb_Free(_interfaceHandle);
            _interfaceHandle = IntPtr.Zero;
            _deviceHandle.Dispose();
            _deviceHandle = null;
            _deviceState  = DeviceState.Closed;
        }
Ejemplo n.º 26
0
 public void Dispose()
 {
     if (driveHandle != null)
     {
         if (driveStream != null)
         {
             driveStream.Close();
             driveStream.Dispose();
         }
         if (!driveHandle.IsClosed)
         {
             driveHandle.Close();
         }
         driveHandle.Dispose();
         driveHandle = null;
     }
 }
Ejemplo n.º 27
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }
            if (disposing)
            {
                handle.Dispose();
                _host           = null;
                console         = null;
                client          = null;
                TunnelDestroyed = true;
            }

            disposed = true;
        }
Ejemplo n.º 28
0
        // Returns the std* handle of the current process that can be inherited by a child process.
        private static SafeFileHandle GetStdHandleForChild(int kind)
        {
            var handle = new SafeFileHandle(Kernel32.GetStdHandle(kind), false);

            // If we do not have a console window, we attach a new console to a child process.
            // In this case console pseudo handles cannot be inherited by a child process.
            // Ignore console pseudo handles and redirect from/to NUL instead, so that
            // our child processes should not stuck reading from an invisible console.
            if (handle.IsInvalid ||
                (IsConsoleHandle(handle) && !HasConsoleWindow()))
            {
                handle.Dispose();
                return(null);
            }

            return(handle);
        }
Ejemplo n.º 29
0
    protected virtual void Dispose(bool disposing)
    {
        if (disposed)
        {
            return;
        }

        // Dispose of managed resources here.
        if (disposing)
        {
            safeHandle.Dispose();
        }

        // Dispose of any unmanaged resources not wrapped in safe handles.

        disposed = true;
    }
Ejemplo n.º 30
0
        /// <summary>
        /// Closes the <see cref="UsbDevice"/> and disposes any <see cref="UsbDevice.ActiveEndpoints"/>.
        /// </summary>
        /// <returns>True on success.</returns>
        public override bool Close()
        {
            if (IsOpen)
            {
                ActiveEndpoints.Clear();
                mUsbHandle.Dispose();

                if (mSafeDevHandle != null)
                {
                    if (!mSafeDevHandle.IsClosed)
                    {
                        mSafeDevHandle.Dispose();
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 31
0
	public static int test_0_sf_dispose ()
	{
		SafeFileHandle sf = new SafeFileHandle ((IntPtr) 0x0d00d, false);
		sf.Dispose ();
		try {
			mono_xr (sf);
		} catch (ObjectDisposedException){
			return 0;
		}
		return 1;
	}