Skip to content

Instantly share code, notes, and snippets.

View jpolvora's full-sized avatar

Jone jpolvora

View GitHub Profile
@jpolvora
jpolvora / Program.cs
Created November 10, 2011 14:04
Utilizando Entity Framework Code First 4.1 c/ ORACLE
//POST: http://silverlightrush.blogspot.com/2011/11/receita-de-bolo-para-ef-code-first-e.html
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using Oracle.DataAccess.Client;
CREATE TABLE "PESSOAS"
( "ID" NUMBER,
"NOME" VARCHAR2(50),
CONSTRAINT "PESSOAS_PK" PRIMARY KEY ("ID") ENABLE
)
/
CREATE TABLE "TELEFONES"
( "ID" NUMBER NOT NULL ENABLE,
"PESSOA_ID" NUMBER NOT NULL ENABLE,
"NUMERO" VARCHAR2(10) NOT NULL ENABLE,
@jpolvora
jpolvora / DynamicDecorator.cs
Created May 17, 2012 03:28
My custom implementation of DynamicDecorator from Gary H Guo
// Created by por Jone Polvora
// Twitter: @jpolvora
// WebSite: http://silverlightrush.blogspot.com
// Based on Dynamic Decorator / CBO Extender Project (http://www.codeproject.com/Articles/275292/Component-Based-Object-Extender)
// Depends on Impromptu-Interface (https://code.google.com/p/impromptu-interface/_
// Last Update: 21/05/2012 10:40AM GMT -04:00
// Brazil
/* USAGE EXAMPLE
@jpolvora
jpolvora / InterceptUsingActionsAndExpressionsToGetMethodNames.cs
Created May 18, 2012 04:22
InterceptUsingActionsAndExpressionsToGetMethodNames
static void InterceptUsingActionsAndExpressionsToGetMethodNames()
{
//pass an array of lambdas to get the names of the methods that will be intercepted
var proxyCtx = ObjectProxyFactory
.CreateUsingActions<IUnitOfWork>(new MyContext(),
pre => System.Console.WriteLine("Entering {0}", pre.CallCtx.MethodName),
pos => System.Console.WriteLine("Exiting {0}", pos.CallCtx.MethodName),
null, true,
//no magic strings
m1 => m1.SaveChanges(),
@jpolvora
jpolvora / InterceptUsingActionsAndStringArrayMethods.cs
Created May 18, 2012 04:27
InterceptUsingActionsAndStringArrayMethods
static void InterceptUsingActionsAndStringArrayMethods()
{
//helper method that returns the method name - no magic strings
var methods = ObjectProxyFactory.GetMethodNames<IUnitOfWork>(c => c.SaveChanges());
//helper method that returns the method names from the properties (getters and setters) - no magic strings
var methodsFromProperties = ObjectProxyFactory.GetMethodNamesFromProperties<IMyContext>(c => c.Customers);
//union two above arrays
var mixedArray = methods.Union(methodsFromProperties).ToArray();
@jpolvora
jpolvora / InterceptAllMethodsFromInterface.cs
Created May 18, 2012 04:29
InterceptAllMethodsFromInterface
using System;
namespace DynamicProxy.Console.Infra
{
public interface IUnitOfWork : IDisposable
{
int SaveChanges();
}
}
@jpolvora
jpolvora / InterceptWithAttributeEntity.cs
Created May 19, 2012 00:12
InterceptWithAttributeEntity
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Dynamic;
using System.Reflection;
using System.Linq.Expressions;
static void InterceptWithAttributeEntity()
{
var myContext = new MyContext();
@jpolvora
jpolvora / InterceptWithAttributeEntity2.cs
Created May 19, 2012 00:34
InterceptWithAttributeEntity2
public interface INotifyPropertyChangedExtended : INotifyPropertyChanged
{
void OnPropertyChanged(string propertyName);
}
public interface IOrder : INotifyPropertyChangedExtended
{
int Id { get; set; }
ICustomer Customer { get; set; }
}
@jpolvora
jpolvora / InterceptingWithDuckTyping.cs
Created May 19, 2012 12:07
InterceptingWithDuckTyping.cs
namespace DynamicProxy.Console
{
class Program
{
static void Main()
{
var myContext = new MyContext();
//create entries in DbContext
Customer entry = myContext.Customers.FirstOrDefault();
public static class CaliburnExtensions
{
public static IEnumerable<IResult> BeginExecute(this IEnumerable<Func<IResult>> routines)
{
return routines.Select(routine => routine());
}
public static void AsCoroutine(this IEnumerable<IResult> routine,
EventHandler<ResultCompletionEventArgs> callBack = null,
ActionExecutionContext ctx = null)