Beispiel #1
0
        /// <summary>
        /// Uploads the specified file into the specified path saving it with the specified
        /// filename
        /// </summary>
        /// <param name="file">The file to upload
        /// A <see cref="File"/>
        /// </param>
        /// <param name="directory">The path where the file should be uploaded to
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="filename">The filename to save the file as on the filesystem
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>An object representing the file on the camera
        /// A <see cref="File"/>
        /// </returns>
        public File Upload(File file, string directory, string filename)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("filename cannot be null or empty");
            }

            if (!Contains(directory))
            {
                CreateDirectory(directory);
            }

            string fullPath = CombinePath(BaseDirectory, directory);

            // First put the actual file data on the camera
            using (LibGPhoto2.CameraFile data = new LibGPhoto2.CameraFile())
            {
                data.SetName(filename);
                data.SetFileType(LibGPhoto2.CameraFileType.Normal);
                data.SetDataAndSize(System.IO.File.ReadAllBytes(Path.Combine(file.Path, file.Filename)));
                data.SetMimeType(file.MimeType);
                camera.Device.PutFile(fullPath, data, camera.Context);
            }

            // Then put the metadata on camera.
            using (LibGPhoto2.CameraFile meta = new LibGPhoto2.CameraFile())
            {
                meta.SetName(filename);
                meta.SetFileType(LibGPhoto2.CameraFileType.MetaData);
                meta.SetDataAndSize(System.Text.Encoding.UTF8.GetBytes(file.MetadataToXml()));
                camera.Device.PutFile(fullPath, meta, camera.Context);
            }

            // Then return the user a File object referencing the file on the camera
            // FIXME: Hack to copy the metadata correctly. Libgphoto returns null
            // metadata until the device refreshes it's database. Workaround is to manually
            // copy the metadata over from the old file.
            File returnFile = GetFileInternal(directory, filename);

            returnFile.Metadata.Clear();
            foreach (KeyValuePair <string, string> kp in file.Metadata)
            {
                returnFile.Metadata.Add(kp.Key, kp.Value);
            }

            // FIXME: This is another hack to fix the above issue
            returnFile.Size = file.Size;
            return(returnFile);
        }
Beispiel #2
0
        /// <summary>
        /// Synchronises the file metadata with the camera
        /// </summary>
        public void Update()
        {
            if (LocalFile)
            {
                throw new InvalidOperationException("Cannot update metadata on a local file");
            }

            if (!IsDirty)
            {
                return;
            }

            string metadata = MetadataToXml();

            using (LibGPhoto2.CameraFile file = new  LibGPhoto2.CameraFile())
            {
                file.SetFileType(LibGPhoto2.CameraFileType.MetaData);
                file.SetName(Filename);
                file.SetDataAndSize(System.Text.Encoding.UTF8.GetBytes(metadata));
                camera.Device.PutFile(FileSystem.CombinePath(filesystem.BaseDirectory, path), file, camera.Context);
            }
            dirty = false;
        }
Beispiel #3
0
        /// <summary>
        /// Synchronises the file metadata with the camera
        /// </summary>
        public void Update()
        {
            if(LocalFile)
                throw new InvalidOperationException("Cannot update metadata on a local file");

            if (!IsDirty)
                return;

            string metadata = MetadataToXml();
            using (LibGPhoto2.CameraFile file = new  LibGPhoto2.CameraFile())
            {
                file.SetFileType( LibGPhoto2.CameraFileType.MetaData);
                file.SetName(Filename);
                file.SetDataAndSize(System.Text.Encoding.UTF8.GetBytes(metadata));
                camera.Device.PutFile(FileSystem.CombinePath(filesystem.BaseDirectory, path), file, camera.Context);
            }
            dirty = false;
        }
Beispiel #4
0
        /// <summary>
        /// Uploads the specified file into the specified path saving it with the specified
        /// filename
        /// </summary>
        /// <param name="file">The file to upload
        /// A <see cref="File"/>
        /// </param>
        /// <param name="directory">The path where the file should be uploaded to
        /// A <see cref="System.String"/>
        /// </param>
        /// <param name="filename">The filename to save the file as on the filesystem
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>An object representing the file on the camera
        /// A <see cref="File"/>
        /// </returns>
        public File Upload(File file, string directory, string filename)
        {
            if (file == null)
                throw new ArgumentNullException("file");

            if (string.IsNullOrEmpty(filename))
                throw new ArgumentException("filename cannot be null or empty");

            if(!Contains(directory))
                CreateDirectory(directory);

            string fullPath = CombinePath(BaseDirectory, directory);

            // First put the actual file data on the camera
            using (LibGPhoto2.CameraFile data = new LibGPhoto2.CameraFile())
            {
                data.SetName(filename);
                data.SetFileType(LibGPhoto2.CameraFileType.Normal);
                data.SetDataAndSize(System.IO.File.ReadAllBytes(Path.Combine(file.Path, file.Filename)));
                data.SetMimeType(file.MimeType);
                camera.Device.PutFile(fullPath, data, camera.Context);
            }

            // Then put the metadata on camera.
            using (LibGPhoto2.CameraFile meta = new LibGPhoto2.CameraFile())
            {
                meta.SetName(filename);
                meta.SetFileType(LibGPhoto2.CameraFileType.MetaData);
                meta.SetDataAndSize(System.Text.Encoding.UTF8.GetBytes(file.MetadataToXml()));
                camera.Device.PutFile(fullPath, meta, camera.Context);
            }

            // Then return the user a File object referencing the file on the camera
            // FIXME: Hack to copy the metadata correctly. Libgphoto returns null
            // metadata until the device refreshes it's database. Workaround is to manually
            // copy the metadata over from the old file.
            File returnFile = GetFileInternal(directory, filename);
            returnFile.Metadata.Clear();
            foreach (KeyValuePair<string, string> kp in file.Metadata)
                returnFile.Metadata.Add(kp.Key, kp.Value);

            // FIXME: This is another hack to fix the above issue
            returnFile.Size = file.Size;
            return returnFile;
        }