Skip to content

Instantly share code, notes, and snippets.

View jpolvora's full-sized avatar

Jone jpolvora

View GitHub Profile
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for FilePicker.xaml
/// </summary>
public partial class FilePicker : UserControl
{
@jpolvora
jpolvora / BusyResultWrapper.cs
Created November 16, 2012 18:29
BusyResultWrapper
//Original Idea: http://blog.smoothfriction.nl/archive/2012/05/07/silverlight-busyindicator-in-caliburn-micro-pt-2-again.aspx
//A simpler solution:
public interface IBusy
{
bool IsBusy { get; set; }
}
@jpolvora
jpolvora / ActionResult.cs
Last active December 10, 2015 08:38
By using ActionResult, you can yield an inline IResult by constructing it with a delegate (Action) via Lambda Expression. You will receive an action as parameter, which you must invoke in order to do the completion of the IResult.
//Usage:
public IEnumerable<IResult> Logout()
{
yield return new ActionResult(completed =>
{
var operation = WebContext.Current.Authentication.Logout(false);
operation.Completed += (sender, args) => completed();
});
}
/* Exemplo:
O método SaveChanges foi sobrescrito para verificar se irá persistir instâncias de entidades que implementam
a interface IAuditableEntity.
Para facilitar, utilizo uma class base chamada EntityBase que implementa essa interface,
e implementa também IValidatableObject.
*/
public interface IAuditableEntity
{
/*
Exemplo de um C# Extension Method que verifica se qualquer IEnumerable<T> é nulo ou vazio (sem itens)
e retorna um IEnumerable<T> contendo no mínimo um item com o valor default
*/
public static class CSharpExtensions
{
public static IEnumerable<T> NotEmpty<T>(this IEnumerable<T> source, T defaultValue = default(T))
{
T[] array = null;
public ActionResult Pesquisar()
{
// simulando consulta
var resultado = new List<string>() { "texto1", "texto2" };
// troque por este para simular retorno de dados
// var resultado = new List<string>();
return PartialView("ResultadosDaPesquisa", resultado.NotEmpty(defaultValue: string.Empty));
}
public ActionResult JsonQuery<T>(IEnumerable<T> resultado, Func<IEnumerable<T>, PartialViewResult> partialView)
{
if (resultado.Any()) return partialView(resultado); //instancia a PartialViewResult
return Json(string.Empty, JsonRequestBehavior.AllowGet);
}
//uso:
return JsonQuery(resultado, x => PartialView("ResultadosDaPesquisa", x));
using System;
using System.Linq;
using System.Windows.Forms;
using PaxSF.Dados.Models;
using PaxSF.Util;
namespace PaxSF.Formularios
{
public partial class frmClientes : PaxSF.Formularios.frmCadastroPadrao
{
<UserControl x:Class="SCO.Ria.UI.Views.LoginView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:local="clr-namespace:Caliburn.Micro.Focus;assembly=Caliburn.Micro.Focus"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" mc:Ignorable="d"
d:DesignHeight="154" d:DesignWidth="468">
/* REFERENCIAR o assembly System.ServiceModel.dll */
using System.ServiceModel;
using System.ServiceModel.DomainServices.Client;
partial class MyDomainContext {
partial void OnCreated() {
var timeSpan = TimeSpan.FromSeconds(30); /* 30 segundos de timeout */
DomainContextExtensions.ChangeWcfSendTimeout(this, timeSpan);