示例#1
0
        public static bool TryGetConnectionInfoOrDefault(
            ConnectionInfoStore store,
            string remoteTargetStringOrId,
            RetrieveMode mode,
            out StoredConnectionInfo connectionInfo)
        {
            connectionInfo = (StoredConnectionInfo)null;
            if (string.IsNullOrWhiteSpace(remoteTargetStringOrId))
            {
                return(RemoteTargetUtils.TryGetDefaultConnectionInfo(store, mode, new StoredConnectionInfo[0], out connectionInfo));
            }
            RemoteTarget result1 = (RemoteTarget)null;
            int          result2 = -1;

            if (RemoteTargetUtils.TryParseRemoteTarget(remoteTargetStringOrId, out result1))
            {
                if (!store.TryGetById(result1.Id, mode, out connectionInfo))
                {
                    return(false);
                }
            }
            else
            {
                if (!int.TryParse(remoteTargetStringOrId, out result2))
                {
                    return(store.TryGetByName(remoteTargetStringOrId, out connectionInfo));
                }
                if (!store.TryGetById(result2, out connectionInfo))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
 public static bool TryGetConnectionInfoOrDefault(
     string remoteTargetStringOrId,
     RetrieveMode mode,
     out StoredConnectionInfo connectionInfo)
 {
     return(RemoteTargetUtils.TryGetConnectionInfoOrDefault(new ConnectionInfoStore(), remoteTargetStringOrId, mode, out connectionInfo));
 }
        /// <summary>
        /// NtfsReader constructor.
        /// </summary>
        /// <param name="driveInfo">The drive you want to read metadata from.</param>
        /// <param name="include">Information to retrieve from each node while scanning the disk</param>
        /// <remarks>Streams & Fragments are expensive to store in memory, if you don't need them, don't retrieve them.</remarks>
        public NtfsReader(DriveInfo driveInfo, RetrieveMode retrieveMode)
        {
            if (driveInfo == null)
            {
                throw new ArgumentNullException("driveInfo");
            }

            DriveInfo tmpDriveInfo = driveInfo;

            //try to find if the drive is mapped on a local volume
            if (driveInfo.DriveType != DriveType.Fixed)
            {
                tmpDriveInfo = ResolveLocalMapDrive(driveInfo);
            }

            _rootPath = tmpDriveInfo.Name;

            StringBuilder builder = new StringBuilder(1024);

            GetVolumeNameForVolumeMountPoint(tmpDriveInfo.RootDirectory.Name, builder, builder.Capacity);

            _driveInfo    = driveInfo;
            _retrieveMode = retrieveMode;

            string volume = builder.ToString().TrimEnd(new char[] { '\\' });

            _volumeHandle =
                CreateFile(
                    volume,
                    FileAccess.Read,
                    FileShare.All,
                    IntPtr.Zero,
                    FileMode.Open,
                    0,
                    IntPtr.Zero
                    );

            if (_volumeHandle == null || _volumeHandle.IsInvalid)
            {
                throw new IOException(
                          string.Format(
                              "Unable to open volume {0}. Make sure it exists and that you have Administrator privileges.",
                              driveInfo
                              )
                          );
            }

            InitializeDiskInfo();

            _nodes = ProcessMft();

            //cleanup anything that isn't used anymore
            _nameIndex = null;

            GC.Collect();
        }
示例#4
0
        /// <summary>
        /// NtfsReader constructor.
        /// </summary>
        /// <param name="driveInfo">The drive you want to read metadata from.</param>
        /// <param name="include">Information to retrieve from each node while scanning the disk</param>
        /// <remarks>Streams & Fragments are expensive to store in memory, if you don't need them, don't retrieve them.</remarks>
        public NtfsReader(DriveInfo driveInfo, RetrieveMode retrieveMode)
        {
            if (driveInfo == null)
            {
                throw new ArgumentNullException(nameof(driveInfo));
            }

            _driveInfo    = driveInfo;
            _retrieveMode = retrieveMode;

            StringBuilder builder = new StringBuilder(1024);

            GetVolumeNameForVolumeMountPoint(_driveInfo.RootDirectory.Name, builder, builder.Capacity);

            string volume = builder.ToString().TrimEnd(new char[] { '\\' });

            _volumeHandle =
                CreateFile(
                    volume,
                    FileAccess.Read,
                    FileShare.All,
                    IntPtr.Zero,
                    FileMode.Open,
                    0,
                    IntPtr.Zero
                    );

            if (_volumeHandle == null || _volumeHandle.IsInvalid)
            {
                throw new IOException(
                          string.Format(
                              "Unable to open volume {0}. Make sure it exists and that you have Administrator privileges.",
                              driveInfo
                              )
                          );
            }

            using (_volumeHandle)
            {
                InitializeDiskInfo();

                _nodes = ProcessMft();
            }

            //cleanup anything that isn't used anymore
            _nameIndex    = null;
            _volumeHandle = null;

            GC.Collect();
        }
示例#5
0
 public static bool TryGetDefaultConnectionInfo(
     ConnectionInfoStore store,
     RetrieveMode mode,
     StoredConnectionInfo[] excludedConnections,
     out StoredConnectionInfo connectionInfo)
 {
     connectionInfo = (StoredConnectionInfo)null;
     if (store.Connections.Count == 0)
     {
         return(false);
     }
     StoredConnectionInfo[] connectionsByAddedDate = RemoteTargetUtils.GetAvailableConnectionsByAddedDate(store);
     connectionInfo = store.Connections.Where <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(c => !((IEnumerable <StoredConnectionInfo>)excludedConnections).Any <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(e => e.Id == c.Id)))).Where <StoredConnectionInfo>((Func <StoredConnectionInfo, bool>)(c => c.LastSuccessful != DateTime.MinValue)).DefaultIfEmpty <StoredConnectionInfo>(((IEnumerable <StoredConnectionInfo>)connectionsByAddedDate).FirstOrDefault <StoredConnectionInfo>()).FirstOrDefault <StoredConnectionInfo>();
     return(connectionInfo != null);
 }