public class CloudBlobDeletionEnListment : CloudBlobBaseEnListment,IEnListmentNotification,Idisposable{ public CloudBlobDeletionEnListment(GuID ownerID,string blobID,CloudBlobContainer container,Logger logger,IUserUploadActivity currentUploadActivity) { ctx = new Context { OwnerID = ownerID,BlobID = blobID,Container = container,Logger = logger,CurrentUploadActivity = currentUploadActivity }; } public ~CloudBlobDeletionEnListment() { dispose(false); } public class Context { public GuID OwnerID; public string BlobID; public string Contentfilename; public string MimeType; public bool IsCompressed; public CloudBlobContainer Container; public Logger Logger; public IUserUploadActivity CurrentUploadActivity; } private Readonly Context ctx; private CloudBlob blob; public voID Prepare(PreparingEnListment preparingEnListment) { blob = ctx.Container.GetBlobReference(ctx.BlobID); // save backup information ctx.Contentfilename = Path.GetTempfilename(); blob.DownloadTofile(ctx.Contentfilename); blob.FetchAttributes(); ctx.MimeType = blob.Metadata[Constants.BlobMetaAttributeContentType]; ctx.IsCompressed = bool.Parse(blob.Metadata[Constants.BlobMetaAttributeCompressed]); // delete it blob.DeleteIfExists(); // done preparingEnListment.Prepared(); } public voID Commit(EnListment enListment) { Cleanup(); // done enListment.Done(); } public voID Rollback(EnListment enListment) { if (blob != null) { try { blob.Uploadfile(ctx.Contentfilename); blob.Metadata[Constants.BlobMetaAttributeContentType] = ctx.MimeType; blob.Metadata[Constants.BlobMetaAttributeCompressed] = ctx.IsCompressed.ToString(); blob.SetMetadata(); } finally { Cleanup(); } } else Cleanup(); // done enListment.Done(); } public voID InDoubt(EnListment enListment) { Cleanup(); enListment.Done(); } voID Cleanup() { // delete the temporary file holding the blob content if (!string.IsNullOrEmpty(ctx.Contentfilename) && file.Exists(ctx.Contentfilename)) { file.Delete(ctx.Contentfilename); ctx.Contentfilename = null; } } public voID dispose() { dispose(true); GC.SuppressFinalize(this); } protected virtual voID dispose(bool disposing) { if (disposing) { // free managed resources } // free native resources if there are any. Cleanup(); } #endregion}解决方法 这对我来说似乎不是一个安全的回滚机制 – 上传可能会失败,如果发生这种情况,那么您的数据一致性就会被破坏.
如果你通过将他们的名字放入数据库中的Tobedeleted表来删除你的blob怎么样 – 然后你设置一些常规作业不时删除这些blob?
总结以上是内存溢出为你收集整理的c# – Transactional CloudBlobs全部内容,希望文章能够帮你解决c# – Transactional CloudBlobs所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)