Skip to content

Instantly share code, notes, and snippets.

@markdchurchill
Last active September 20, 2016 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markdchurchill/925e6e076a959e8bb48df035bca3e181 to your computer and use it in GitHub Desktop.
Save markdchurchill/925e6e076a959e8bb48df035bca3e181 to your computer and use it in GitHub Desktop.
Condense simple sample #1
using System.ServiceModel;
using Condense.Core;
namespace SimpleSample.Tiny1
{
[Entity]
public class GuestArrival
{
public string First { get; set; }
public string Last { get; set; }
}
[Entity]
public class Greeting
{
public string Text { get; set; }
}
public static class Code
{
[Lambda]
public static Greeting OnGuestArrived(GuestArrival n)
{
return new Greeting { Text = string.Format("Hello {0} {1}!", n.First, n.Last) };
}
}
[ServiceContract]
public interface IDataService
{
[OperationContract]
Greeting Arrival(GuestArrival i);
}
}
using Condense.Core;
using System.ServiceModel;
namespace SimpleSample.Tiny2
{
[Entity]
public class GuestArrival
{
public string First { get; set; }
public string Last { get; set; }
}
[Entity]
public class Greeting
{
public string Text { get; set; }
}
[Entity]
public class GreetingRequest
{
public string Name { get; set; }
}
[Entity]
public class DrinkOrder
{
public string Drink { get; set; }
}
public static class Code
{
[Lambda]
public static GreetingRequest OnGuestArrived(GuestArrival n)
{
return new GreetingRequest { Name = n.First + " " + n.Last };
}
[Lambda]
public static Greeting OnGreetingRequest(GreetingRequest gr)
{
return new Greeting() { Text = "Hello, " + gr.Name };
}
[Lambda]
public static DrinkOrder OnGreeting(Greeting g)
{
return new DrinkOrder() { Drink = "Coffee" };
}
}
[ServiceContract]
public interface IDataService
{
[OperationContract]
Greeting Arrival(GuestArrival i);
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using Condense.Core;
using System.ServiceModel;
namespace SimpleSample.Tiny3
{
[Entity(Mutable = true)]
public class Guest : IUid
{
public int Id { get; set; }
public string First { get; set; }
public string Last { get; set; }
string IUid.Uid => Id.ToString();
}
[Entity]
public class GuestArrival
{
public DateTime ArrivalTime { get; set; }
}
[Entity(RetentionDays = 1)]
public class Greeting
{
public string Text { get; set; }
}
[Entity]
public class PreferredSessions
{
public List<string> PreferredSessions { get; set; }
}
[Entity]
public class Restrictions
{
public bool IsVIP { get; set; }
public bool CanSeeGovernmentOnlySessions { get; set; }
}
[Entity]
public class Schedule
{
public Dictionary<DateTime, string> Sessions { get; set; }
}
[Entity]
public class Seating
{
public string Session { get; set; }
public Reference<Guest> Guest { get; set; }
}
public static class Code
{
[Lambda(ContextType = typeof(Guest))]
public static Greeting GreetGuests(GuestArrival arrival)
{
var uow = Context<IUnitOfWork>.Current;
var guest = uow.Get<Guest>();
return new Greeting() { Text = guest.First + " " + guest.Last };
}
[Lambda(ContextType = typeof (Guest))]
public static IEnumerable CreateScheduleForArrival(PreferredSessions prefs, Restrictions restrict)
{
// Perform some incredibly complicated scheduling
var schedule = new Schedule()
{
Sessions = new Dictionary<DateTime, string>()
{
{DateTime.Today.AddHours(11), "Intro to Condense"},
{DateTime.Today.AddHours(19), "After party"}
}
};
yield return schedule;
foreach (var session in schedule.Sessions.Values)
{
yield return new Seating()
{
Guest = Context<IUnitOfWork>.Current.Get<Guest>(),
Session = session
};
}
}
}
[ServiceContract]
public interface IConferenceService
{
[OperationContract]
Greeting Arrival([LambdaCausality(typeof(Guest))] string guestId, GuestArrival i);
[OperationContract]
void SetPreferredSessions([LambdaCausality(typeof (Guest))] string guestId, PreferredSessions sessions);
}
[ServiceContract]
public interface IAdminService
{
[OperationContract]
string AddGuest(Guest guest);
[OperationContract]
void SetRestrictions([LambdaCausality(typeof(Guest))] string guestId, Restrictions guestRestrictions);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment