mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Feature repricing min max (#10)
amazon settlement import/export improvements
This commit is contained in:
98
src/bnhtrade.Core/Model/Data/DatabaseFileStream.cs
Normal file
98
src/bnhtrade.Core/Model/Data/DatabaseFileStream.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Model.Data
|
||||
{
|
||||
public class DatabaseFileStream : IDisposable, IValidatableObject
|
||||
{
|
||||
[Required()]
|
||||
public Guid FileGUID { get; set; }
|
||||
|
||||
[Required()]
|
||||
public MemoryStream FileData { get; set; }
|
||||
|
||||
public bool IsSetFileData
|
||||
{
|
||||
get { return FileData != null; }
|
||||
}
|
||||
|
||||
[Required(), StringLength(3, MinimumLength = 3)]
|
||||
public string FileExtention { get; set; }
|
||||
|
||||
[Required(), Range(1, 2147483647)]
|
||||
public int FileSize { get; set; }
|
||||
|
||||
[Required(), StringLength(24, MinimumLength = 24)]
|
||||
public string FileMD5base64 { get; set; }
|
||||
|
||||
public string CalculateContentMD5(MemoryStream stream)
|
||||
{
|
||||
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
|
||||
byte[] hash = provider.ComputeHash(stream);
|
||||
return Convert.ToBase64String(hash);
|
||||
}
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
var resultList = new List<ValidationResult>();
|
||||
|
||||
if (IsSetFileData && FileData.Length == 0)
|
||||
{
|
||||
var validate = new ValidationResult("Stream is empty");
|
||||
resultList.Add(validate);
|
||||
}
|
||||
if (IsSetFileData && FileMD5base64 != new Logic.Utilities.CalculateMD5().Base64(FileData))
|
||||
{
|
||||
var validate = new ValidationResult("Calculated file MD5 hash does not match.");
|
||||
resultList.Add(validate);
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
private bool disposedValue = false; // To detect redundant calls
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// TODO: dispose managed state (managed objects).
|
||||
if (FileData != null)
|
||||
FileData.Dispose();
|
||||
}
|
||||
|
||||
// TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
|
||||
// TODO: set large fields to null.
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
|
||||
//~AmazonFeedSubmission()
|
||||
//{
|
||||
// // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
// Dispose(false);
|
||||
//}
|
||||
|
||||
// This code added to correctly implement the disposable pattern.
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above.
|
||||
Dispose(true);
|
||||
// TODO: uncomment the following line if the finalizer is overridden above.
|
||||
// GC.SuppressFinalize(this);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user