Example #1
0
        public async Task UploadFile(LocalFileInfo file, IApiClient apiClient, CancellationToken cancellationToken)
        {
            using (var mediaLibrary = new MediaLibrary())
            {
                var picture = mediaLibrary.Pictures.FirstOrDefault(x => (x.Album == null || x.Album.Name == file.Album) && x.Name == file.Name);

                if (picture != null)
                {
                    Log.Info("Uploading file '{0}'", file.Id);
                    using (var stream = picture.GetImage())
                    {
                        try
                        {
                            await apiClient.UploadFile(stream, file, cancellationToken);
                        }
                        catch (HttpException ex)
                        {
                            Log.ErrorException("Uploadfile(" + file.Id + ")", ex);
                        }
                    }
                }
            }
        }
Example #2
0
        public void AddCameraUpload(string deviceId, LocalFileInfo file)
        {
            var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json");
            Directory.CreateDirectory(Path.GetDirectoryName(path));

            lock (_syncLock)
            {
                ContentUploadHistory history;

                try
                {
                    history = _json.DeserializeFromFile<ContentUploadHistory>(path);
                }
                catch (IOException)
                {
                    history = new ContentUploadHistory
                    {
                        DeviceId = deviceId
                    };
                }

                history.DeviceId = deviceId;
                history.FilesUploaded.Add(file);

                _json.SerializeToFile(history, path);
            }
        }
Example #3
0
 public Task UploadFile(LocalFileInfo file, IApiClient apiClient, CancellationToken cancellationToken = default(CancellationToken))
 {
     return apiClient.UploadFile(File.OpenRead(file.Id), file, cancellationToken);
 }
Example #4
0
        public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file)
        {
            var device = GetDevice(deviceId);
            var path = GetUploadPath(device);

            if (!string.IsNullOrWhiteSpace(file.Album))
            {
                path = Path.Combine(path, _fileSystem.GetValidFilename(file.Album));
            }

            path = Path.Combine(path, file.Name);
            path = Path.ChangeExtension(path, MimeTypes.ToExtension(file.MimeType) ?? "jpg");

            _libraryMonitor.ReportFileSystemChangeBeginning(path);

            _fileSystem.CreateDirectory(Path.GetDirectoryName(path));

            try
            {
                using (var fs = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    await stream.CopyToAsync(fs).ConfigureAwait(false);
                }

                _repo.AddCameraUpload(deviceId, file);
            }
            finally
            {
                _libraryMonitor.ReportFileSystemChangeComplete(path, true);
            }

            if (CameraImageUploaded != null)
            {
                EventHelper.FireEventIfNotNull(CameraImageUploaded, this, new GenericEventArgs<CameraImageUploadInfo>
                {
                    Argument = new CameraImageUploadInfo
                    {
                        Device = device,
                        FileInfo = file
                    }
                }, _logger);
            }
        }
Example #5
0
        public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file)
        {
            var path = GetUploadPath(deviceId);

            if (!string.IsNullOrWhiteSpace(file.Album))
            {
                path = Path.Combine(path, _fileSystem.GetValidFilename(file.Album));
            }

            Directory.CreateDirectory(path);

            path = Path.Combine(path, file.Name);

            _libraryMonitor.ReportFileSystemChangeBeginning(path);

            try
            {
                using (var fs = _fileSystem.GetFileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    await stream.CopyToAsync(fs).ConfigureAwait(false);
                }

                _repo.AddCameraUpload(deviceId, file);
            }
            finally
            {
                _libraryMonitor.ReportFileSystemChangeComplete(path, true);
            }
        }