private void AddCameraUpload(string deviceId, LocalFileInfo file) { var path = Path.Combine(GetDevicePath(deviceId), "camerauploads.json"); _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); lock (_cameraUploadSyncLock) { ContentUploadHistory history; try { history = _json.DeserializeFromFile <ContentUploadHistory>(path); } catch (IOException) { history = new ContentUploadHistory { DeviceId = deviceId }; } history.DeviceId = deviceId; var list = history.FilesUploaded.ToList(); list.Add(file); history.FilesUploaded = list.ToArray(); _json.SerializeToFile(history, path); } }
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); } }
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); } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (_deleteTempFiles && null != LocalFileInfo && LocalFileInfo.Exists) { LocalFileInfo.Delete(); LocalFileInfo = null; } }
public Stream CreateStream(RemoteFileInfo remoteFileInfo) { if (remoteFileInfo == null) { throw new ArgumentNullException("remoteFileInfo"); } LocalFileInfo localFileInfo = m_LocalFileAllocator.AllocateFile(remoteFileInfo.FileName, remoteFileInfo.FileSize); return(new FileStream(localFileInfo.FileName, FileMode.Open, FileAccess.Write)); }
public async Task AcceptCameraUpload(string deviceId, Stream stream, LocalFileInfo file) { var device = GetDevice(deviceId, false); var uploadPathInfo = GetUploadPath(device); var path = uploadPathInfo.Item1; 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"); _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); await EnsureLibraryFolder(uploadPathInfo.Item2, uploadPathInfo.Item3).ConfigureAwait(false); _libraryMonitor.ReportFileSystemChangeBeginning(path); try { using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read)) { await stream.CopyToAsync(fs).ConfigureAwait(false); } AddCameraUpload(deviceId, file); } finally { _libraryMonitor.ReportFileSystemChangeComplete(path, true); } if (CameraImageUploaded != null) { CameraImageUploaded?.Invoke(this, new GenericEventArgs <CameraImageUploadInfo> { Argument = new CameraImageUploadInfo { Device = device, FileInfo = file } }); } }
private void RefreshFilesCache(string fileName, bool isInDatabase) { bool FileExists = File.Exists(Settings.NaturalGroundingFolder + fileName); LocalFileInfo FileEntry = files.Where(f => f.FileName.Equals(fileName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (FileEntry != null) { FileEntry.IsInDatabase = isInDatabase; } if (FileExists && FileEntry == null) { files.Add(new LocalFileInfo(fileName, isInDatabase)); } else if (!FileExists && FileEntry != null) { files.Remove(FileEntry); } }
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); } }
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); } } } } }
public Task UploadFile(LocalFileInfo file, IApiClient apiClient, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException(); }
public Task UploadFile(LocalFileInfo file, IApiClient apiClient, CancellationToken cancellationToken) { return(apiClient.UploadFile(File.OpenRead(file.Id), file, cancellationToken)); }
//下载资源文件 private IEnumerator Download() { List <AssetFile> assetFiles = this.CommonResourceUtils.GetUpdateFileList(); if (assetFiles == null || assetFiles.Count == 0) { Debug.Log("<><DownloadPage2View.Download>No one file need to download"); this.StopSignal.Dispatch(false); yield break; } UpdateRecord updateRecord = this.HotUpdateUtils.ReadUpdateRecord(); if (assetFiles == null || assetFiles.Count == 0) { Debug.Log("<><DownloadPage2View.Download>Native update record is null"); this.StopSignal.Dispatch(false); yield break; } this.downloadInfo.CompleteCount = 0; this.downloadInfo.TotalCount = assetFiles.Count; bool error = false; this.InvokeRepeating("CheckOverTime", 1f, 1f); for (int i = 0; i < assetFiles.Count; i++) {//逐个下载缺失的资源文件 Debug.LogFormat("<><DownloadPage2View.Download>File: {0}", assetFiles[i]); yield return(new WaitUntil(() => !this.pause)); yield return(this.StartCoroutine(this.ResourceUtils.LoadAsset(assetFiles[i].FullPath, (obj) => { LocalFileInfo localFileInfo = updateRecord.FileList.Find(t => t.File + t.MD5 == assetFiles[i].FullPath); if (localFileInfo != null) { localFileInfo.File = assetFiles[i].FullPath; localFileInfo.MD5 = assetFiles[i].MD5; localFileInfo.Type = assetFiles[i].GetFileType(); } else { updateRecord.FileList.Add(new LocalFileInfo() { File = assetFiles[i].FullPath, MD5 = assetFiles[i].MD5, Type = assetFiles[i].GetFileType() }); } }, (failureInfo) => { if (failureInfo != null) //中断操作类错误才做处理 { Debug.LogErrorFormat("<><DownloadPage2View.Download>Error: {0}\n({1})", failureInfo.Message, assetFiles[i]); if (failureInfo.Interrupt) { error = true; } } }, true))); if (error) { break; //如果下载过程中遇到错误,退出下载页 } //更新进度条及进度文字 float percent = (float)++this.downloadInfo.CompleteCount / this.downloadInfo.TotalCount; percent = Mathf.Clamp01(percent); this.progressBar.fillAmount = percent; this.progress.text = string.Format("{0}/{1}", this.downloadInfo.CompleteCount, this.downloadInfo.TotalCount); float maxLength = this.progressBar.rectTransform.rect.width - this.progress.rectTransform.rect.width / 1.5f; this.progress.GetComponent <RectTransform>().anchoredPosition = this.originPos + new Vector2(maxLength * percent, 0); } System.GC.Collect(); this.CancelInvoke("CheckOverTime");//结束下载时(无论是正常结束还是遇到错误时异常结束)停止检测下载超时 if (error) { this.ShowNoWifiPage(); } else { AssetBundle.UnloadAllAssetBundles(true); PlayerDataManager.ResourceDownloaded = true; this.HotUpdateUtils.SaveUpdateRecord(updateRecord); this.StopSignal.Dispatch(true); } }