private byte[] getAppropriateThumbnail(FileAsset file) { var large = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".large.thumb"); if (File.Exists(large)) { return(File.ReadAllBytes(large)); } var medium = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".medium.thumb"); if (File.Exists(medium)) { return(File.ReadAllBytes(medium)); } var small = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".small.thumb"); if (File.Exists(small)) { return(File.ReadAllBytes(small)); } var origin = Path.Combine(MyFileFolder.Photo, file.saved_path); if (File.Exists(origin)) { return(File.ReadAllBytes(origin)); } return(null); }
private byte[] getVideoThumbnail(FileAsset file) { var thumb_path = Path.Combine(MyFileFolder.Thumbs, file.file_id.ToString() + ".thumb.mp4"); if (File.Exists(thumb_path)) { File.Delete(thumb_path); } var file_path = Path.Combine(MyFileFolder.Photo, file.saved_path); var videoWidth = getVideoWidth(file_path); if (videoWidth <= 0) { return(null); } if (videoWidth > 720) { FFmpegHelper.MakeVideoThumbnail720(file_path, thumb_path); } else { FFmpegHelper.MakeVideoThumbnail(file_path, thumb_path); } return(File.ReadAllBytes(thumb_path)); }
public void SetUp() { _fileAsset = new FileAsset("file", Encoding.UTF8); _fileSystem = MockRepository.GenerateMock <IFileSystem>(); _fileSystem.Stub(arg => arg.AbsolutePath("file")).Return("file"); _resolveAssetFiles = _fileAsset.ResolveAssetFiles(_fileSystem).ToArray(); }
public void upload_not_on_cloud_file_assets() { var label = new Label { label_id = Guid.NewGuid(), seq = 500, share_proc_seq = 100 }; var file1 = new FileAsset { file_id = Guid.NewGuid() }; var file2 = new FileAsset { file_id = Guid.NewGuid(), on_cloud = false }; var file_already_on_cloud = new FileAsset { file_id = Guid.NewGuid(), on_cloud = true }; db.Setup(x => x.QueryLabelFiles(label)).Returns(new List <FileAsset> { file1, file2, file_already_on_cloud }); api.Setup(x => x.UploadAttachment(file1)).Verifiable(); api.Setup(x => x.UploadAttachment(file2)).Verifiable(); api.Setup(x => x.UploadAttachment(file_already_on_cloud)).Throws(new Exception("already uploaded")); db.Setup(x => x.UpdateFileOnCloud(file1)).Verifiable(); db.Setup(x => x.UpdateFileOnCloud(file2)).Verifiable(); task.Process(label); api.Verify(); db.Verify(); }
public static void Check(FileAsset obj) { if (obj == null) { return; } }
public static FileAsset AsFileModel(this Data2.SyncAsset asset) { var ret = new FileAsset(); ret.InjectFrom(asset); return(ret); }
public void SetUp() { _fileAsset = new FileAsset("file", Encoding.UTF8); _fileSystem = MockRepository.GenerateMock <IFileSystem>(); _tempPath = Path.GetTempFileName(); _fileSystem.Stub(arg => arg.AbsolutePath("file")).Return(_tempPath); _watcher = _fileAsset.GetFileSystemWatcher(_fileSystem); }
public IActionResult Post([FromBody] FileAsset value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } value = repo.Create(AuthMan.GetAccountId(this), value); return(CreatedAtAction("Get", value)); }
public override void handleFileEndCmd(ProtocolContext ctx, TextCommand cmd) { ctx.temp_file.EndWrite(); ctx.raiseOnFileEnding(); if (!Util.HasDuplicateFile(ctx.fileCtx, ctx.device_id)) { SavedPath saved = null; try { saved = ctx.storage.MoveToStorage(ctx.temp_file.Path, ctx.fileCtx); } catch (Exception e) { throw new IOException("Unable to move temp file to storage. temp_file:" + ctx.temp_file.Path + ", file_name: " + ctx.fileCtx.file_name, e); } var fileAsset = new FileAsset { device_id = ctx.device_id, event_time = ctx.fileCtx.datetime, file_id = Guid.NewGuid(), file_name = ctx.fileCtx.file_name, file_path = Path.Combine(ctx.fileCtx.folder, ctx.fileCtx.file_name), file_size = ctx.fileCtx.file_size, type = (int)ctx.fileCtx.type, saved_path = saved.relative_file_path, parent_folder = Path.GetDirectoryName(saved.relative_file_path), seq = Util.GetNextSeq() }; Util.SaveFileRecord(fileAsset); if (ctx.fileCtx.file_size != ctx.temp_file.BytesWritten) { log4net.LogManager.GetLogger(typeof(TransmitStartedState)).WarnFormat("{0} is expected to have {1} bytes but {2} bytes received.", ctx.fileCtx.file_name, ctx.fileCtx.file_size, ctx.temp_file.BytesWritten); } ctx.fileCtx.file_id = fileAsset.file_id; ctx.raiseOnFileReceived(); } else { ctx.temp_file.Delete(); } log4net.LogManager.GetLogger("wsproto").Debug("send back file-exist for file recv success"); ctx.Send(new TextCommand { action = "file-exist", file_name = ctx.fileCtx.file_name }); ctx.recved_files++; ctx.SetState(new TransmitInitState()); }
void Awake() { bottomLimit = -threshold; topLimit = threshold; colorEffect = this.GetComponent <TimedColorEffect>(); colorEffect.AddMaterial(FileAsset.GetMaterialOfSoundParticleByColorName("Orange")); colorEffect.AddMaterial(FileAsset.GetMaterialOfSoundParticleByColorName("Cyan")); colorEffect.AddMaterial(FileAsset.GetMaterialOfSoundParticleByColorName("Purple")); pSystem = this.GetComponent <ParticleSystem>(); }
void CreateMap(string mapName) { string[] tileInfo = ParseMap(FileAsset.GetMapTileInfo(mapName)); for (int i = 0; i < tileInfo.Length; i = i + 2) { string tileId = tileInfo[i]; string tileType = tileInfo[i + 1]; CreateTileInMap(tileId, tileType); } FitUIElementOnServerScreen(this.gameObject); }
public async Task <IActionResult> Put([FromBody] FileAsset value) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } var res = await repo.UpdateAsync(AuthMan.GetAccountId(this), value); if (res == null) { return(NotFound()); } return(Ok(value)); }
public bool ApplyUpdate(FileAsset item) { var fullPath = this.GetFullPath(item.Id); var directoryPath = Path.GetDirectoryName(fullPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } // check if file exists and if it's date is higher than the one on the server, dont update if (File.Exists(fullPath)) { var lastUpdated = File.GetLastWriteTimeUtc(fullPath); if (lastUpdated >= item.Updated) { return(false); } } using (var fs = new FileStream(fullPath, FileMode.Create)) { var byteContent = item.ByteContent; if (byteContent == null && !String.IsNullOrEmpty(item.Content)) { byteContent = Encoding.UTF8.GetBytes(item.Content); } if (byteContent != null) { fs.Write(byteContent, 0, byteContent.Length); } fs.Close(); } // preserve the date File.SetLastWriteTimeUtc(fullPath, item.Updated); if (_lastUpdated.HasValue && item.Updated > _lastUpdated) { _lastUpdated = item.Updated; } return(true); }
IEnumerator RotateThroughColors() { while (true) { if (materials == null || materials.Count == 0) { ChangeParticleSystemMaterial(FileAsset.GetMaterialOfSoundParticleByColorName("White")); } else { currentMaterial = (currentMaterial + 1) % materials.Count; ChangeParticleSystemMaterial(materials[currentMaterial]); } yield return(new WaitForSecondsRealtime(interval)); } }
public async Task <string> Handle(FileCreateCommand request, CancellationToken cancellationToken) { var file = await fileAssetRepository.FindAsync(request.MD5); if (file != null) { file.UpdateBasicInfo(request.Name, request.Description, request.FileState, identityService.GetUserId()); await fileAssetRepository.UpdateAsync(file); return(file.Id); } var url = $"/{OSSConst.AppRouteArea}/{OSSConst.ClientAssetFolder}/{request.MD5}.{request.FileExt}"; file = new FileAsset(request.Name, request.Description, request.FileExt, request.FileState, request.Size, url, identityService.GetUserId()); file.CustomizeId(request.MD5); await fileAssetRepository.AddAsync(file); return(file.Id); }
public IActionResult Post(IFormFile file) { if (file == null) { return(BadRequest(GetMessage("File not sent."))); } if (file.Length == 0) { return(BadRequest(GetMessage("File zero-length."))); } var projection = Builders <FileAsset> .Projection.Expression(z => new FileDetails(z.Id)); var fileRepository = new MongoRepository <FileAsset, FileDetails>(FileAsset.Database, FileAsset.Collection, projection); var fileAsset = new FileAsset { FileName = file.FileName, ContentType = file.ContentType, Verified = true, // This will need to be improved upon later. Prevent dick picks and other mcgubbins from being uploaded. }; var insertedId = fileRepository.Insert(fileAsset); var storagePath = GetStoragePath(); if (!Directory.Exists(storagePath)) { Directory.CreateDirectory(storagePath); } var filePath = GetFilePath(insertedId); using (var stream = System.IO.File.Open(filePath, FileMode.Create)) { file.CopyTo(stream); } return(Ok(new FileDetails(insertedId))); }
void ProcessConnectionState() { string logMessage = _insertedString; if (string.IsNullOrEmpty(logMessage)) { logMessage = "localhost"; } switch (state) { case Connection.Disconnected: state = Connection.Connecting; break; case Connection.Connecting: if (!timeoutEnd.HasValue) { TimeLogger.Log("CLIENT - connecting to {0}", logMessage); } ControlTimeOut(); break; case Connection.Connected: TimeLogger.Log("CLIENT - connected to {0}", logMessage); try{ FileAsset.SaveGameData(_insertedString); } catch (System.Exception e) { TimeLogger.Log("A problem occurred while saving game data: {0}", e.Message); } if (!string.IsNullOrEmpty(_insertedString)) { clientController.LastSucessfulIp = _insertedString; } StateEnd(); break; } }
public async Task <FileAsset> Upload() { string name = Guid.NewGuid().ToString(); FileAsset res = new FileAsset(); res.Id = GuidGen.NewGUID(); res.Name = name; res.Url = "/upload/" + name; string localPath = uploadPath + name; using (StreamWriter sw = new StreamWriter(localPath)) { var bodystream = HttpContext.Request.Body; bodystream.CopyTo(sw.BaseStream); } FileInfo fi = new FileInfo(localPath); res.Size = fi.Length; res.Md5 = Md5.CalcFile(localPath); await repo.CreateAsync(AuthMan.GetAccountId(this), res, false); return(res); }
public void GetFromDisk_AllButOneAssetsFoundOnDisk() { var stubFileCreation = typeof(Asset_Tests).GetMethod("StubFile", BindingFlags.NonPublic | BindingFlags.Instance); var fileAsset2 = new FileAsset((IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", "~/dont" }), fileBundle); fileBundle.Assets.Add(fileAsset2); fileHelper.Setup(fh => fh.Exists(It.Is<string>(s => s.Contains("dont")))) .Returns(false); fileHelper.Setup(fh => fh.Exists(It.Is<string>(s => !s.Contains("dont")))) .Returns(true); fileHelper.Setup(fh => fh.GetLastAccessTime(It.IsAny<string>())) .Returns(DateTime.Today); fileHelper.Setup(fh => fh.ReadAllText(It.IsAny<string>())) .Returns("[]"); uncachedToCachedFiles.Setup(d => d.ContainsKey(It.IsAny<string>())) .Returns(false); uncachedToCachedFiles.Setup(d => d.Add(It.IsAny<string>(), It.IsAny<string>())) .Throws(new Exception( "Tried add a cached asset to the lookup dictionary when the bundle was not fully cached")); GetFromDisk(fileHelper.Object, directory.Object, uncachedToCachedFiles.Object, fileBundle); }
void ChangeFooterButtonColor(PlayerTurnData.UIColors playerColor) { clientFooterHelperButton.image.color = FileAsset.GetMaterialOfSoundParticleByColorName(System.Enum.GetName(typeof(PlayerTurnData.UIColors), playerColor)).color; }
public void SetUp() { _fileAsset = new FileAsset("file", Encoding.UTF8); }
public async Task UpdateAsync(FileAsset entity) { _context.Set <FileAsset>().Update(entity); await _context.SaveEntitiesAsync(); }
public UnityEngine.Material GetUIColorMaterial() { return(FileAsset.GetMaterialOfSoundParticleByColorName(System.Enum.GetName(typeof(UIColors), _uiColor))); }
public void GetAssetReferencesFromDisk_CheckProperRehydration() { fileHelper.Setup(fh => fh.ReadAllText(It.IsAny<string>())) .Returns("[{\"AssetReferenceType\":1,\"LineNumber\":1,\"Path\":\"~/file2\"}]") .Verifiable(); fileHelper.Setup(fh => fh.Exists(It.IsAny<string>())) .Returns(true); fileHelper.Setup(fh => fh.GetLastAccessTime(It.IsAny<string>())) .Returns(DateTime.Today); uncachedToCachedFiles.Setup(fh => fh.ContainsKey(It.IsAny<string>())) .Returns(true); var stubFileCreation = typeof(Asset_Tests).GetMethod("StubFile", BindingFlags.NonPublic | BindingFlags.Instance); var fileAssetChild = new FileAsset((IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", "~/file2" }), fileBundle); fileAsset.AddReference(fileAssetChild.SourceFile.FullPath, 1); fileBundle.Assets.Add(fileAssetChild); GetFromDisk(fileHelper.Object, directory.Object, uncachedToCachedFiles.Object, fileBundle); fileBundle.Assets.First().References.First().Path.Equals(fileAssetChild.SourceFile.FullPath); fileHelper.Verify(); }
public async Task AddAsync(FileAsset entity) { _context.Set <FileAsset>().Add(entity); await _context.SaveEntitiesAsync(); }
public void FixReferences_FileAndEmptyBundles() { fileHelper.Setup(fh => fh.Write(It.IsAny<string>(), It.IsAny<string>())); uncachedToCachedFiles.Setup(d => d.ContainsKey(It.IsAny<string>())) .Returns(true); diskBackedBundleCache.AddBundle(fileHelper.Object, uncachedToCachedFiles.Object, fileBundle.Path, fileBundle, unprocessedAssetPaths); unprocessedAssetPaths.Add("wasd"); uncachedToCachedFiles.Setup(d => d.ContainsKey(It.IsAny<string>())) .Returns(true); diskBackedBundleCache.AddBundle(fileHelper.Object, uncachedToCachedFiles.Object, emptyBundle.Path, emptyBundle, unprocessedAssetPaths); var stubFileCreation = typeof(Asset_Tests).GetMethod("StubFile", BindingFlags.NonPublic | BindingFlags.Instance); var fileAssetChild = new FileAsset((IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", "~/file2" }), fileBundle); fileAsset.AddReference(fileAssetChild.SourceFile.FullPath, 1); fileBundle.Assets.Add(fileAssetChild); var containsDict = new Dictionary<string, string>(); var originalPath = fileAsset.References.First().Path; containsDict.Add(fileAsset.References.First().Path, "good test result"); diskBackedBundleCache.FixReferences(containsDict, new List<Bundle> { fileBundle }); fileAsset.References.First().Path.ShouldEqual("good test result"); fileAssetChild.AddReference("http://www.google.com", -1); containsDict.Add("http://www.google.com", "bad test result"); diskBackedBundleCache.FixReferences(containsDict, new List<Bundle> { fileBundle }); fileAssetChild.References.First().Path.ShouldEqual("http://www.google.com"); //Just making sure it doesn't do anything with an empty bundle. diskBackedBundleCache.FixReferences(containsDict, new List<Bundle> { emptyBundle }); }
public static FileAssetUpdateRequestBuilder Update(long id, FileAsset fileAsset) { return(new FileAssetUpdateRequestBuilder(id, fileAsset)); }
public void testFileAsset() { FileAsset o= new FileAsset(); Assert.IsNotNull(o); }
IEnumerator Get_AllHardDiskAssets() { fileAssetsLoading = true; Debug.Log("Loading Player Assets..."); foreach (string url in FilePaths_Player){ fileOnLoad = Path.GetFileNameWithoutExtension(url); FileAsset newFileAsset = new FileAsset(); HDData = new WWW ("file://" + url); yield return HDData; if(string.IsNullOrEmpty(HDData.error)){ newFileAsset.fileName = fileOnLoad; newFileAsset.asset = HDData.assetBundle.mainAsset; FileDB_Player.Add(newFileAsset); } else{ Debug.Log("Error"); fileAssetsLoading = false; fileLoadError = true; StopCoroutine("Get_AllHardDiskAssets"); } } Debug.Log("Done..."); Debug.Log("Loading Weapon Assets..."); foreach (string url in FilePaths_Weapon){ fileOnLoad = Path.GetFileNameWithoutExtension(url); FileAsset newFileAsset = new FileAsset(); HDData = new WWW ("file://" + url); yield return HDData; if(string.IsNullOrEmpty(HDData.error)){ newFileAsset.fileName = fileOnLoad; newFileAsset.asset = HDData.assetBundle.mainAsset; FileDB_Weapon.Add(newFileAsset); } else{ Debug.Log("Error"); fileAssetsLoading = false; fileLoadError = true; StopCoroutine("Get_AllHardDiskAssets"); } } Debug.Log("Done..."); Debug.Log("Loading Zombie Assets..."); foreach (string url in FilePaths_Zombies){ fileOnLoad = Path.GetFileNameWithoutExtension(url); FileAsset newFileAsset = new FileAsset(); HDData = new WWW ("file://" + url); yield return HDData; if(string.IsNullOrEmpty(HDData.error)){ newFileAsset.fileName = fileOnLoad; newFileAsset.asset = HDData.assetBundle.mainAsset; FileDB_Zombies.Add(newFileAsset); } else{ Debug.Log("Error"); fileAssetsLoading = false; fileLoadError = true; StopCoroutine("Get_AllHardDiskAssets"); } } Debug.Log("Done..."); Debug.Log("Loading World..."); fileOnLoad = Path.GetFileNameWithoutExtension(FilePaths_Levels[0]); HDData = new WWW ("file://" + FilePaths_Levels[0]); yield return HDData; if(string.IsNullOrEmpty(HDData.error)){ streamedLevel = HDData.assetBundle; } else{ Debug.Log("Error"); fileAssetsLoading = false; fileLoadError = true; StopCoroutine("Get_AllHardDiskAssets"); } Debug.Log("Done..."); fileAssetsLoading = false; Debug.Log("Assets Loaded..."); if(!fileLoadError){ foreach (GameObject go in FindObjectsOfType(typeof (GameObject))) go.SendMessage("OnDataWasLoaded", SendMessageOptions.DontRequireReceiver); } }
public static FileAssetAddRequestBuilder Add(FileAsset fileAsset) { return(new FileAssetAddRequestBuilder(fileAsset)); }
public void SetPlayerColor(PlayerTurnData.UIColors playerColor) { _PlayerColorIcon.color = FileAsset.GetMaterialOfSoundParticleByColorName(System.Enum.GetName(typeof(PlayerTurnData.UIColors), playerColor)).color; }
public ActionResult ScheduleAssetJobs(string chosenAsset, string locTypeVal, string assetSelected, string fileSelected, string dateScheduled, string dateActivated) { List <string> errors = new List <string>(); string errormsg = ""; //**To send output to View List <FileAsset> assetList = new List <FileAsset>(); List <string> FilesAre = new List <string>(); //** Conversion of string type dates to datetime type DateTime scheduledDate; DateTime activatedDate; //** Get the array of assets and files from parameters string[] assets = assetSelected.Split(','); string[] files = fileSelected.Split(','); scheduledDate = Convert.ToDateTime(dateScheduled); activatedDate = Convert.ToDateTime(dateActivated); //** Check all the files in the fileSelected Array for ACtive Status for (var i = 0; i < files.Length; i++) { try { //** Get the File Active Status as well as file related info to store it in FDSummary table. //** Get the FileHash for the corresponding FileID so that it can be passed to FilExists controller method for active status checking and other file details long fileID = Convert.ToInt64(files[i]); //var getFileHash = (new FileUploadFactory(Session[Constants.Security.ConnectionStringSessionVariableName].ToString())).GetFileHash(fileID); //** Get the file active status and other file related details //var FDFilesValues = (new FileUploadFactory(Session[Constants.Security.ConnectionStringSessionVariableName].ToString())).FileExists(getFileHash.FileHash, CurrentCity.Id); var FDFilesValues = (new FileUploadFactory(Session[Constants.Security.ConnectionStringSessionVariableName].ToString())).FileExists1(fileID, CurrentCity.Id); if (FDFilesValues.Activestaus == "Active") { //** The current file is 'Active', then only allow to schedule that file. //** Get the user name who has scheduled the job. var UserId = WebSecurity.CurrentUserId; List <string> FileID = (new FileUploadFactory(Session[Duncan.PEMS.Utilities.Constants.Security.ConnectionStringSessionVariableName].ToString())).ScheduleJob(chosenAsset, locTypeVal, assets, FDFilesValues.FileID, scheduledDate, activatedDate, FDFilesValues.FileName, FDFilesValues.FileSizeBytes, FDFilesValues.FileHash, FDFilesValues.FileType, FDFilesValues.Activestaus, FDFilesValues.FileAdditionDate, UserId, CurrentCity.Id); //** After getting successful assset scheduled, store the asset ID in the List for (var j = 0; j < FileID.Count; j++) { FileAsset FA = new FileAsset(); FA.AssetIDIs = FileID[j]; FA.FileNameIs = FDFilesValues.FileName; assetList.Add(FA); } //** After getting successful File scheduled, store the File name in the List FilesAre.Add(FDFilesValues.FileName); } else { //** File is No Longer Active errormsg = FDFilesValues.FileName + " is No Longer Active and hence cannot be scheduled."; } } catch (Exception ex) { _logger.ErrorException("ERROR IN ScheduleAssetJobs Method (Asset Configuration - Schedule File Download)", ex); } } return(Json(assetList.Distinct(), JsonRequestBehavior.AllowGet)); }
public void CreateFileOnDiskFromAsset_CheckProperDehydration() { fileHelper.Setup(fh => fh.Write(It.IsAny<string>(), "asset content")) .Verifiable(); fileHelper.Setup(fh => fh.Write(It.IsAny<string>(), "[{\"AssetReferenceType\":1,\"LineNumber\":1,\"Path\":\"~/file2\"}]")) .Verifiable(); fileHelper.Setup(fh => fh.Write(It.IsAny<string>(), "[]")) .Verifiable(); fileHelper.Setup(fh => fh.Exists(It.IsAny<string>())) .Returns(true); fileHelper.Setup(fh => fh.GetLastAccessTime(It.IsAny<string>())) .Returns(DateTime.Today); uncachedToCachedFiles.Setup(d => d.ContainsKey(It.IsAny<string>())) .Returns(false); uncachedToCachedFiles.Setup(d => d.Add(It.IsAny<string>(), It.IsAny<string>())); unprocessedAssetPaths.Add("~/a"); var stubFileCreation = typeof(Asset_Tests).GetMethod("StubFile", BindingFlags.NonPublic | BindingFlags.Instance); var fileAssetChild = new FileAsset((IFile)stubFileCreation.Invoke(new Asset_Tests(), new object[] { "asset content", "~/file2" }), fileBundle); fileAsset.AddReference(fileAssetChild.SourceFile.FullPath, 1); fileBundle.Assets.Add(fileAssetChild); AddToDisk(fileHelper.Object, uncachedToCachedFiles.Object, fileBundle, unprocessedAssetPaths); fileBundle.Assets.First().References.First().Path.Equals(fileAssetChild.SourceFile.FullPath); fileHelper.Verify(); fileHelper.Verify(fh => fh.Write(It.IsAny<string>(), "[{\"AssetReferenceType\":1,\"LineNumber\":1,\"Path\":\"~/file2\"}]"), Times.Once()); fileHelper.Verify(fh => fh.Write(It.IsAny<string>(), "[]"), Times.Exactly(3)); fileHelper.Verify(fh => fh.Write(It.IsAny<string>(), "asset content"), Times.Exactly(2)); }