Skip to content

Instantly share code, notes, and snippets.

@davidsavagejr
davidsavagejr / New.cs
Last active August 5, 2016 15:31
Implementation of a validator using a simple strategy pattern
using System;
using System.Collections.Generic;
namespace Sample
{
public class SubLedger
{
public string Subledger { get; set; }
public string SubledgerType { get; set; }
public string SubledgerJobType { get; set; }
@davidsavagejr
davidsavagejr / gist:6314753
Created August 23, 2013 01:50
A basic object with an enum property.
public class BlogPost
{
public string Subject { get; set; }
public string Content { get; set; }
public DayOfWeek PostDat { get; set; }
}
public enum DayOfWeek
{
ManualResetEvent resetEvent = new ManualResetEvent(false);
while(Run)
{
// ...
resetEvent.WaitOne(10000);
}
while(Run)
{
// ...
Thread.Sleep(10000);
}
OnStop()
{
Run = false;
}
while(true)
{
// do something
Thread.Sleep(10000);
}
private string GetErrorFromBlob(string blobId)
{
var container = CloudStorageAccount.Parse(this.connectionString).CreateCloudBlobClient().GetContainerReference("elmaherrors");
var blob = container.GetBlobReference(blobId);
return blob.DownloadText();
}
public override ErrorLogEntry GetError(string id)
{
private string SerializeErrorToBlob(ErrorEntity error)
{
string id = Guid.NewGuid().ToString();
string xml = ErrorXml.EncodeString(error.GetOriginalError());
var container = CloudStorageAccount.Parse(this.connectionString).CreateCloudBlobClient().GetContainerReference("elmaherrors");
var blob = container.GetBlobReference(id);
blob.UploadText(xml);
return id;
}
public override string Log(Error error)
{
var entity = new ErrorEntity(error);
var context = CloudStorageAccount.Parse(connectionString).CreateCloudTableClient().GetDataServiceContext();
entity.BlobId = SerializeErrorToBlob(entity);
context.AddObject("elmaherrors", entity);
context.SaveChangesWithRetries();
return entity.RowKey;
}
public class ErrorEntity : TableServiceEntity
{
public string BlobId { get; set; }
private Error OriginalError { get; set; }
public ErrorEntity() { }
public ErrorEntity(Error error) : base(...)
{
this.OriginalError = error;
}