Last active
September 20, 2016 05:57
-
-
Save markdchurchill/925e6e076a959e8bb48df035bca3e181 to your computer and use it in GitHub Desktop.
Condense simple sample #1
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
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); | |
} | |
} |
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
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); | |
} | |
} |
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
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