public static BlobFile DownloadFile(Guid id) { var fileInfo = db.Files.FirstOrDefault(f => f.File_Id == id); if (fileInfo == null) { // means that no file return(null); } var uniqueBlobName = String.Format("files/{0}", id); CloudBlockBlob blob = container.GetBlockBlobReference(uniqueBlobName); // catch here errors var data = blob.DownloadByteArray(); var res = new BlobFile { ID = fileInfo.File_Id, Name = fileInfo.Name, CreationTime = fileInfo.CreationTime, Description = fileInfo.Description, LongDescription = fileInfo.LongComment, Data = data }; return(res); }
public async Task<List<BlobFile>> ListBlobsAsync(string container) { var containerClient = _blobServiceClient.GetBlobContainerClient(container.ToLower()); var items = new List<BlobFile>(); await foreach (var blobItem in containerClient.GetBlobsAsync()) { var blobClient = containerClient.GetBlobClient(blobItem.Name); BlobProperties properties = blobClient.GetProperties(); var blobFile = new BlobFile { Container = container, Directory = (Path.GetDirectoryName(blobItem.Name) + "/").StartsWith("/") ? "" : (Path.GetDirectoryName(blobItem.Name) + "/").Replace("\\", "/"), Name = Path.GetFileNameWithoutExtension(blobItem.Name), Extension = Path.GetExtension(blobItem.Name), Size = (int)properties.ContentLength, Uri = blobClient.Uri.ToString(), DateCreated = properties.CreatedOn.LocalDateTime, LastModified = properties.LastModified.LocalDateTime, UserID = 1, ProjectID = 1 }; items.Add(blobFile); } return items; }
public BlobFile Update(BlobFile blobFile) { BlobHelper blobHelper; string oldID; try { blobHelper = new BlobHelper(_loggerFactory, _config); if (string.IsNullOrEmpty(blobFile.ID)) { throw new Exception("ID vazio, avalie a utilização do POST"); } else { if (!string.IsNullOrEmpty(blobFile?.Name) && blobFile?.Data != null) { oldID = blobFile.ID; blobHelper.InsertOrUpdate(blobFile, oldID); } else { throw new Exception("Informações insuficientes"); } } } catch (Exception ex) { throw ex; } return(blobFile); }
public override void Deserialize(Stream input, ParseSchema.Column column, XmlWriter output) { var flags = ColumnFlags.None; flags |= column.Flags & ColumnFlags.FIXED_ARRAY; flags |= column.Flags & ColumnFlags.EARRAY; flags |= column.Flags & ColumnFlags.INDIRECT; if (flags == ColumnFlags.INDIRECT) { var hasValue = input.ReadValueU32(); if (hasValue == 0) { return; } } var index = input.ReadValueS32(); var target = column.Subtable.Columns[index]; output.WriteStartElement("polymorph"); output.WriteAttributeString("name", target.Name); BlobFile.DeserializeColumn(target, input, output); output.WriteEndElement(); }
public List <BlobFile> FileList(string Container, string Directory) { BlobContinuationToken blobContinuousToken = null; var returnList = new List <BlobFile>(); var cloudBlobContainer = _CBC.GetContainerReference(Container); var directory = cloudBlobContainer.GetDirectoryReference(Directory); var sasToken = GenerateSharedAccessSignature(cloudBlobContainer); do { var results = directory.ListBlobsSegmented(blobContinuousToken); blobContinuousToken = results.ContinuationToken; foreach (var blob in results.Results.Where(w => w as CloudBlobDirectory == null).ToList()) { var newBlob = new BlobFile(); newBlob.Container = Container; newBlob.Directory = Directory; newBlob.DownloadURL = blob.Uri.ToString(); newBlob.sasToken = sasToken; returnList.Add(newBlob); } }while (blobContinuousToken != null); return(returnList); }
public async Task <string> SaveImagesAsync() { var files = Request.Form.Files.ToList(); await BlobFile.SaveImagesAsync(files); return("ok"); }
/// <summary> /// The operation of loading a document from file. /// </summary> private void LoadDocumentOperation() { DialogResult result; result = openBlobDialog.ShowDialog(this); if (result == DialogResult.OK) { try { _document = new BlobFile(openBlobDialog.FileName); DocumentOpened(); UpdateBlobUI(); documentStatusLabel.Text = "\"" + openBlobDialog.FileName + "\"" + " loaded"; } catch (Exception e) { #if DEBUG Trace.WriteLine("Exception thrown when trying to LoadDocument(): " + e, "Error"); #endif MessageBox.Show(this, "Unable to load file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public BlobFile Insert(BlobFile blobFile) { BlobHelper blobHelper; try { blobHelper = new BlobHelper(_loggerFactory, _config); if (string.IsNullOrEmpty(blobFile.ID)) { if (!string.IsNullOrEmpty(blobFile?.Name) && blobFile?.Data != null) { blobFile.ID = Guid.NewGuid().ToString(); blobFile.ID += Path.GetExtension(blobFile.Name); blobFile = blobHelper.InsertOrUpdate(blobFile); } else { throw new Exception("Informações insuficientes"); } } else { throw new Exception("ID diferente de vazio, avalie a utilização do PUT"); } } catch (Exception ex) { throw ex; } return(blobFile); }
public void Setup() { #if UNITY_EDITOR PlaymodeTestsEditorSetup.CreateStreamingAssetsDirectory(); { var motionClip = CreateLinearDenseClip ( new[] { new LinearBinding <float3> { Path = "Motion", ValueStart = m_StartTranslation, ValueEnd = m_StopTranslation }, }, new[] { new LinearBinding <quaternion> { Path = "Motion", ValueStart = math.normalize(m_StartRotation), ValueEnd = math.normalize(m_StopRotation) }, }, new[] { new LinearBinding <float3> { Path = "Motion", ValueStart = new float3(1, 1, 1), ValueEnd = new float3(1, 1, 1) } } ); var blobPath = "MotionClip.blob"; BlobFile.WriteBlobAsset(ref motionClip, blobPath); } #endif }
private static object FromFile(BlobFile file) { return(new { name = file.Name, path = file.Path }); }
protected override void OneTimeSetUp() { base.OneTimeSetUp(); var path = "Ninja.blob"; m_RigDefinition = BlobFile.ReadBlobAsset <RigDefinition>(path); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); BlobFile.Initialize(ConfigurationManager.AppSettings["BlobFileShareProjects"], ConfigurationManager.AppSettings["BlobStorageConnectionString"], this); }
public async Task <IActionResult> ReadMe(string repoName) { BlobFile readMeFile = await GitRepo.GetReadMeFile(repoName); byte[] readMeBytes = Convert.FromBase64String(readMeFile.content); string readMeContents = System.Text.Encoding.Default.GetString(readMeBytes); return(View((object)readMeContents)); }
private Project GetProject(string projectName) { string fileName = projectName.Trim() + ".json"; Project project = null; string data = BlobFile.GetFileAsString(fileName); project = (Project)JsonSerializer.ToObject(data); return(project); }
/// <summary> /// Returns null if the file is null, the file is not an image, or there is no thumbnail resource getter. /// </summary> internal static IReadOnlyCollection <PhrasingComponent> GetThumbnailControl(BlobFile file, Func <int, ResourceInfo> thumbnailResourceGetter) { // NOTE: We'd like to check here whether the file is a renderable image or not. But we can't because we don't have the file contents. // So, we'll have to make sure that all ThumbnailPageInfoCreators provide a page that knows how to handle NEF files (ideally we'd want // it to behave as if there was no thumbnail at all if there is an unrenderable image file). // The only alternative to this that I can think of is creating a new file table field called "IsRenderable" that we store when // we first save the image. if (file == null || !ContentTypes.IsImageType(file.ContentType) || thumbnailResourceGetter == null) { return(Enumerable.Empty <PhrasingComponent>().Materialize()); } return(new EwfImage(new ImageSetup(null, sizesToAvailableWidth: true), thumbnailResourceGetter(file.FileId)).ToCollection()); }
public async Task<BlobDownloadInfo> GetBlobAsync(BlobFile file) { // Get Storage Container var containerClient = _blobServiceClient.GetBlobContainerClient(file.Container.ToLower()); // Get File Reference var blobClient = containerClient.GetBlobClient(file.Directory + file.Name + file.Extension); // Download File BlobDownloadInfo blobDownloadInfo = await blobClient.DownloadAsync(); // Return Downloaded File Info return blobDownloadInfo; }
public async Task<BlobClient> DeleteBlobAsync(BlobFile blobFile) { // Get Storage Container var containerClient = _blobServiceClient.GetBlobContainerClient(blobFile.Container.ToLower()); // Get File Reference var blobClient = containerClient.GetBlobClient(blobFile.Directory + blobFile.Name + blobFile.Extension); // Delete File If Exist await blobClient.DeleteIfExistsAsync(); // Return Blob Client return blobClient; }
public string UploadToBlob(BlobFile blobFile, byte[] fileBytes) { var azureAccount = CloudStorageAccount.Parse(_blobAccount); var blobClient = new CloudBlobClient(azureAccount.BlobStorageUri.PrimaryUri, new StorageCredentials("classics", "aAh4x4MJpEDybKGMCyEnN/FmPyxrkER6nuUg/D4lqorKdEtCdih2XWRi1YrUNv8L4gpy8TWyXBLPCD+dT+n6BQ==")); var containerReference = blobClient.GetContainerReference(blobFile.Container); var blockBlob = containerReference.GetBlockBlobReference(blobFile.Name); blockBlob.Properties.ContentType = blobFile.MIME; blockBlob.UploadFromByteArray(fileBytes, 0, fileBytes.Length); return(blockBlob.Uri.AbsoluteUri); }
public BlobFile InsertOrUpdate(BlobFile blobFile, string oldID = null) { CloudStorageAccount storageAccount; CloudBlobClient blobClient; CloudBlobContainer container; CloudBlockBlob blockBlob; string baseName; string currentExtension; string newName; byte[] currentData; try { //Getting new ID with fixed extension baseName = Path.GetFileNameWithoutExtension(blobFile.ID); currentExtension = Path.GetExtension(blobFile.Name); newName = baseName + currentExtension; storageAccount = CloudStorageAccount.Parse(blobConnection); blobClient = storageAccount.CreateCloudBlobClient(); container = blobClient.GetContainerReference(blobFolder); if (oldID != null) { blockBlob = container.GetBlockBlobReference(oldID); blockBlob.DeleteIfExistsAsync().Wait(); } blockBlob = container.GetBlockBlobReference(blobFile.ID); blockBlob.DeleteIfExistsAsync().Wait(); //Preventing wrong file format blobFile.ID = newName; blockBlob = container.GetBlockBlobReference(blobFile.ID); blockBlob.DeleteIfExistsAsync().Wait(); currentData = Convert.FromBase64String(blobFile.Data); blockBlob.UploadFromByteArrayAsync(currentData, 0, currentData.Length); } catch (Exception ex) { throw (ex); } return(blobFile); }
private static async Task <BlobFile> GetBlobFileFromRepo(string fileSha, string repoName) { BlobFile blobFile = new BlobFile(); ///repos/:owner/:repo/git/blobs/:file_sha HttpResponseMessage response = await client.GetAsync($"repos/{repoOwner}/{repoName}/git/blobs/{fileSha}"); response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { blobFile = await response.Content.ReadAsAsync <BlobFile>(); } // return URI of the created resource. return(blobFile); }
public static void BuildClipBlobAsset(string path) { var animationClip = AssetDatabase.LoadMainAssetAtPath(path) as AnimationClip; if (animationClip == null) { throw new NullReferenceException($"Asset '{path}' not found"); } var blobPath = GetBlobAssetPath(path); var clip = ClipBuilder.AnimationClipToDenseClip(animationClip); BlobFile.WriteBlobAsset(ref clip, blobPath); }
/// <summary> /// The operation of creating a new blank document. /// </summary> private void NewDocumentOperation() { DialogResult result; result = newFileDialog.ShowDialog(this); if (result == DialogResult.OK) { _document = new BlobFile(newFileDialog.FileName); _open = true; DocumentOpened(); UpdateBlobUI(); } }
public static List <BlobImage> GetBlobsFrom(FileInfo[] files) { List <BlobImage> result = new List <BlobImage>(files.Length); foreach (FileInfo file in files) { BlobFile blob = new BlobFile(); using (Stream s = file.Open(FileMode.Open, FileAccess.Read)) { blob.Deserialize(s); foreach (var entry in blob.Entries) { BlobImage image = new BlobImage(); image.BlobReference = new BlobReference(); image.BlobReference.Id = entry.Name; image.BlobReference.FileName = file.Name; s.Seek(entry.Offset, SeekOrigin.Begin); byte[] data = new byte[entry.Size]; s.Read(data, 0, data.Length); Bitmap b = null; try { b = GenerateBitmapFromCfs(new MemoryStream(data), file.Name); } catch (Exception) { b = null; } if (b == null) { continue; } image.Image = b; result.Add(image); } } } return(result); }
public bool Save(string path, BlobFile file) { try { using (FileStream fs = new FileStream($"{path}/{file.Name}", FileMode.Create)) { fs.Write(file.Contents, 0, file.Contents.Length); } return(true); } catch (Exception ex) { _logger.LogError(ex, $"Failed to save file : '{file.Name}' on '{path}'."); throw; } }
protected override void OneTimeSetUp() { base.OneTimeSetUp(); // Create rig m_Rig = new Rig { Value = CreateTestRigDefinition() }; var path = "MotionClip.blob"; m_Clip = BlobFile.ReadBlobAsset <Clip>(path); ClipManager.Instance.GetClipFor(m_Rig, m_Clip); }
public static void BuildRigDefinitionBlobAsset(string path) { var gameObject = AssetDatabase.LoadMainAssetAtPath(path) as GameObject; if (gameObject == null) { throw new NullReferenceException($"Asset '{path}' not found"); } var blobPath = GetBlobAssetPath(path); var skeletonNode = RigGenerator.ExtractSkeletonNodesFromGameObject(gameObject); var rigDefinition = RigBuilder.CreateRigDefinition(skeletonNode); BlobFile.WriteBlobAsset(ref rigDefinition, blobPath); }
private List <Project> GetProjects() { List <string> projectitems = BlobFile.ListFiles(); List <Project> projects = new List <Project>(); foreach (string item in projectitems) { string data = BlobFile.GetFileAsString(item); Project project = (Project)JsonSerializer.ToObject(data); if (project != null) { projects.Add(project); } } return(projects); }
public override void Deserialize(Stream input, ParseSchema.Column column, XmlWriter output) { var flags = ColumnFlags.None; flags |= column.Flags & ColumnFlags.FIXED_ARRAY; flags |= column.Flags & ColumnFlags.EARRAY; flags |= column.Flags & ColumnFlags.INDIRECT; if (flags == ColumnFlags.INDIRECT) { var hasValue = input.ReadValueU32(); if (hasValue == 0) { return; } } BlobFile.DeserializeTable(column.Subtable, input, output); }
public async Task<BlobClient> MoveBlobAsync(BlobFile blobFile, string filePath) { // Get Storage Container var containerClient = _blobServiceClient.GetBlobContainerClient(blobFile.Container.ToLower()); // Get Source File Reference var blobClientSource = containerClient.GetBlobClient(blobFile.Directory + blobFile.Name + blobFile.Extension); // Get Target File Reference var blobClientTarget = containerClient.GetBlobClient(filePath); // Copy Source To Target Reference await blobClientTarget.StartCopyFromUriAsync(new Uri(blobFile.Uri)); // Delete Source Reference await blobClientSource.DeleteIfExistsAsync(); // Return Target Blob Client return blobClientTarget; }
public void SaveProject(Project project) { if (project == null) { return; } try { string projectInfo = JsonSerializer.ToString(project); string localFile = Path.Combine(Path.GetTempPath(), project.FileName); System.IO.File.WriteAllText(localFile, projectInfo); BlobFile.UploadFile(localFile); } catch (Exception ex) { } }
public static void SaveImagesBlob(string userId, HttpPostedFileBase upImage) { #region Create Blob Original Image BlobFileModel blobOriginal = new BlobFileModel(upImage); BlobFile blobFile = new BlobFile { Container = (int)BlobFileType.ImagesOriginal, CreatedBy = userId, Filename = blobOriginal.FileName, BlobKey = Common.GetGuid(), dtCreated = DateTime.Now }; #endregion CloudStorageManagerHelper.InsertFileWithStaticName(BlobFileType.ImagesOriginal, blobFile.BlobKey, blobOriginal, userId); BlobFileModel blobWaterMark = CloudStorageManagerHelper.GetFileInfo(BlobFileType.ImagesOriginal, "Watermark.png"); Bitmap imageWithWaterMark= AddWaterMark(blobOriginal.Data); byte[] data = imageWithWaterMark.ImageToByteArray(); BlobFileModel blobImageWithWaterMark = new BlobFileModel(imageWithWaterMark.ToStream(ImageFormat.Png), string.Format("{0}_WaterMark", blobOriginal.FileName), "Image"); BlobFile blobFileWithWaterMark = new BlobFile { Container = (int)BlobFileType.ImagesWaterMark, CreatedBy = userId, Filename = blobImageWithWaterMark.FileName, BlobKey = Common.GetGuid(), dtCreated = DateTime.Now }; CloudStorageManagerHelper.InsertFileWithStaticName((BlobFileType)blobFileWithWaterMark.Container, blobFileWithWaterMark.BlobKey, blobImageWithWaterMark, userId); var blobHelper = new BlobFilesHelper(); blobHelper.Add(blobFileWithWaterMark); }