This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id" : ObjectId("54256f999d663727782e9569"), | |
"timestamp" : ISODate("2014-09-26T13:52:25.155Z"), | |
"level" : "INFO", | |
"thread" : "7", | |
"logger" : "Sam.MongoLogging.Logging.Logger", | |
"message" : "Home" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool AwardElectorateBadge(User user) | |
{ | |
const int MinimumRequiredQuestionVotes = 600; | |
return user.Votes.Questions >= MinimumRequiredQuestionVotes && | |
user.Votes.Total <= user.Votes.Questions * 4; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// size in bytes | |
db.runCommand({"convertToCapped": "logs", size: 100000}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (entity.EntityKey != null) | |
{ | |
ObjectStateEntry stateEntry; | |
bool isPresent = this.Entities.ObjectStateManager.TryGetObjectStateEntry( | |
entity.EntityKey, | |
out stateEntry); | |
if (isPresent) | |
{ | |
this.Entities.ApplyCurrentValues("Entity", entity); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public T CopyEntity<T>(T entity, bool copyKeys = false) where T : EntityObject | |
{ | |
var clone = this.Context.CreateObject<T>(); | |
var pis = entity.GetType().GetProperties(); | |
foreach (var pi in pis) | |
{ | |
var attrs = (EdmScalarPropertyAttribute[])pi.GetCustomAttributes(typeof(EdmScalarPropertyAttribute), false); | |
foreach (EdmScalarPropertyAttribute attr in attrs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ExecuteSql(string sql) | |
{ | |
var entityConnection = (System.Data.EntityClient.EntityConnection)Context.Connection; | |
DbConnection conn = entityConnection.StoreConnection; | |
ConnectionState initialState = conn.State; | |
try | |
{ | |
if (initialState != ConnectionState.Open) | |
conn.Open(); | |
using (DbCommand cmd = conn.CreateCommand()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ObjectExtensions | |
{ | |
public static object ThrowIfNull(this object argument, string argumentName) | |
{ | |
if (argument == null) | |
{ | |
throw new ArgumentNullException(argumentName); | |
} | |
return argument; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MyClass( | |
IDependency1 dependency1, | |
IDependency2 dependency2, | |
IDependency3 dependency3, | |
IDependency4 dependency4) | |
{ | |
if (dependency1 == null) | |
{ | |
throw new ArgumentNullException("dependency1"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MyClass( | |
IDependency1 dependency1, | |
IDependency2 dependency2, | |
IDependency3 dependency3, | |
IDependency4 dependency4) | |
{ | |
dependency1.ThrowIfNull("dependency1"); | |
dependency2.ThrowIfNull("dependency2"); | |
dependency3.ThrowIfNull("dependency3"); | |
dependency4.ThrowIfNull("dependency4"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Guard | |
{ | |
public static void AgainstNulls(object parameter, string name) | |
{ | |
if (parameter == null) | |
{ | |
throw new ArgumentNullException(name); | |
} | |
} | |
} |