Skip to content

Instantly share code, notes, and snippets.

View davybrion's full-sized avatar

Davy Brion davybrion

  • That Extra Mile
  • Belgium
View GitHub Profile
@davybrion
davybrion / s1.cs
Created September 8, 2012 14:04
Code snippets for "How To Write Testable ASP.NET WebForms" post, part II
public void Load()
{
if (!View.IsPostBack)
{
var batcher = new ServiceCallBatcher(service);
batcher.Add(new GetProductCategoriesRequest());
batcher.Add(new GetSuppliersRequest());
View.ProductCategories = batcher.Get<GetProductCategoriesResponse>().ProductCategories;
View.Suppliers = batcher.Get<GetSuppliersResponse>().Suppliers;
View.DataBind();
@davybrion
davybrion / s1.cs
Created September 8, 2012 14:41
Code snippets for "Mocking expensive template methods" post
public abstract class Command
{
private readonly List<string> errorMessages = new List<string>();
public void Execute()
{
try
{
CheckAuthorization();
CheckErrorMessages();
@davybrion
davybrion / s1.cs
Created September 8, 2012 15:58
code snippets for "Batching SqlCommand Queries" post
public class SelectCommandCombiner
{
private readonly List<SqlCommand> commands = new List<SqlCommand>();
public SelectCommandCombiner() : this(new SqlCommand[0]) { }
public SelectCommandCombiner(IEnumerable<SqlCommand> commandsToCombine)
{
commands = new List<SqlCommand>();
if (commandsToCombine != null)
@davybrion
davybrion / s1.txt
Created September 8, 2012 16:01
snippets for "Easing the pain of WCF debugging" post
[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +73
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing) +110
[CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:29:59.8590000'.]
System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing) +183
System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) +54
System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) +32
System.ServiceModel.Channels.ConnectionStream.
@davybrion
davybrion / s1.cs
Created September 8, 2012 16:08
code snippets for ".NET Memory Management" post
public class MyDisposableClass : IDisposable
{
private bool disposed = false;
public void Dispose()
{
Dispose(true);
// prevent this object from being placed in the finalization queue if some
// derived class provides a finalizer
GC.SuppressFinalize(this);
@davybrion
davybrion / s1.cs
Created September 8, 2012 16:15
Code snippets for "Why you should always unsubscribe event handlers" post
public class Publisher
{
public event EventHandler MyEvent;
public void FireEvent()
{
if (MyEvent != null)
{
MyEvent(this, EventArgs.Empty);
}
@davybrion
davybrion / s1.cs
Created September 8, 2012 16:24
Code snippets for the "The Select Command Batcher" post
public IEnumerable<Product> TransformTableToListOfProducts(DataTable table)
{
var products = new List<Product>();
foreach (DataRow row in table.Rows)
{
products.Add(TransformRowToProduct(row));
}
return products;
@davybrion
davybrion / s1.xml
Created September 9, 2012 12:04
code snippets for "WCF and large amounts of data" post
<bindings>
<netTcpBinding>
<binding name="MyTcpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="00:30" sendTimeout="00:30">
<readerQuotas maxStringContentLength="8192" maxArrayLength="20971520" />
</binding>
</netTcpBinding>
</bindings>
@davybrion
davybrion / s1.xml
Created September 9, 2012 12:08
code snippets for "Batching NHibernate's DML statements" post
<class name="CrudTest" table="CrudTest">
<id name="Id" column="Id" type="guid" >
<generator class="assigned" />
</id>
<property name="Description" column="Description" type="string" length="200" not-null="true" />
</class>
@davybrion
davybrion / s1.cs
Created September 9, 2012 12:14
code snippets for "Bulk Data Operations With NHibernate's Stateless Sessions" post
var testObjects = CreateTestObjects(500000);
var stopwatch = new Stopwatch();
stopwatch.Start();
using (ITransaction transaction = Session.BeginTransaction())
{
foreach (var testObject in testObjects)
{
Session.Save(testObject);