Beispiel #1
0
        /// <summary>
        /// Copies a file from the local system to a remote device.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="desktopFileName">The name of the local file to copy.</param>
        /// <param name="deviceFileName">The name of the remote destination file.</param>
        /// <param name="overwrite"><see langword="true"/> if the destination file can be overwritten; otherwise, <see langword="false"/>.</param>
        /// <param name="percentProgressCallback">Optional. A callback delegate to receive progress updates. This value can be <see langword="null"/>.</param>
        public static void CopyFileToDevice(RemoteDevice device, string desktopFileName, string deviceFileName, bool overwrite, Action <float> percentProgressCallback)
        {
            using var remoteFile = new RemoteDevice.DeviceFile(device.ISession, deviceFileName, GENERIC_WRITE, FILE_SHARE_READ, overwrite ? CREATE_ALWAYS : CREATE_NEW, FILE_ATTRIBUTE_NORMAL);
            using (var localFile = new FileStream(desktopFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                float  totalSize = localFile.Length;
                long   filepos   = 0;
                byte[] buffer    = new byte[FileBufferSize];
                int    bytesread = localFile.Read(buffer, 0, buffer.Length);
                while (bytesread > 0)
                {
                    // move remote file pointer # of bytes read
                    filepos += bytesread;

                    // write our buffer to the remote file
                    remoteFile.Write(buffer, 0, bytesread);

                    // notify of progress, if elected
                    if (percentProgressCallback != null)
                    {
                        // use BeginInvoke as a "fire and forget" notification, to help prevent deadlocks
                        percentProgressCallback.BeginInvoke(filepos / totalSize, null, null);
                    }

                    try
                    {
                        // refill the local buffer
                        bytesread = localFile.Read(buffer, 0, buffer.Length);
                    }
                    catch (Exception)
                    {
                        bytesread = 0;
                    }
                }
                remoteFile.SetEndOfFile();
            }

            remoteFile.SetFileTimes(File.GetCreationTime(desktopFileName), File.GetLastAccessTime(desktopFileName),
                                    File.GetLastWriteTime(desktopFileName));
        }
Beispiel #2
0
 /// <summary>
 /// Sets the date and time that a file was created, last accessed, or last modified for files on a remote device.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="fileName">String that specifies the name of a file.</param>
 /// <param name="creationTime">The date and time the file was created. This parameter can be NULL if the application does not need to set this information.</param>
 /// <param name="lastAccessTime">The date and time the file was last accessed. This parameter can be NULL if the application does not need to set this information.</param>
 /// <param name="lastWriteTime">The date and time the file was last modified. This parameter can be NULL if the application does not need to set this information.</param>
 internal static void SetFileTimes(RemoteDevice device, string fileName, DateTime?creationTime, DateTime?lastAccessTime, DateTime?lastWriteTime)
 {
     using RemoteDevice.DeviceFile f = new RemoteDevice.DeviceFile(device.ISession, fileName);
     f.SetFileTimes(creationTime, lastAccessTime, lastWriteTime);
 }
Beispiel #3
0
 /// <summary>
 /// Sets the file times.
 /// </summary>
 /// <param name="creationTime">The creation time.</param>
 /// <param name="lastAccessTime">The last access time.</param>
 /// <param name="lastWriteTime">The last write time.</param>
 internal void SetFileTimes(DateTime?creationTime, DateTime?lastAccessTime, DateTime?lastWriteTime)
 {
     using RemoteDevice.DeviceFile f = new RemoteDevice.DeviceFile(Device.ISession, FullPath);
     f.SetFileTimes(creationTime, lastAccessTime, lastWriteTime);
 }