[ServiceContract(SessionMode = SessionMode.Required)] public interface IBaseServer { //Is used when you need to navigate to an entity, or when you need to retrieve a Lazy. [OperationContract, NetDataContract] IdentifiableEntity Retrieve(Type type, int id); //Used by [EntityWindows|NormalWindow] to save an entity. [OperationContract, NetDataContract] IdentifiableEntity Save(IdentifiableEntity entidad); //Retrives all the entities of a given type. Expensive operation, used by AdminWindows for administrating simple types with few instances on the database. [OperationContract, NetDataContract] List<IdentifiableEntity> RetrieveAll(Type type); //Saves all the entities in a list. Used by AdminWindows when clicking save. [OperationContract, NetDataContract] List<IdentifiableEntity> SaveList(List<IdentifiableEntity> list); //Retrieves the lazy version of all the entities of a given type, used by EntityCombo. When the EntityCombo has Implementations, types is filled. [OperationContract, NetDataContract] List<Lite> RetrieveAllLite(Type liteType, Type[] types); //Retrieves the lazy version of the top ''count'' entities of a given type which ToStr looks like the subString provided, used by EntityLine when auto-complete is enabled. //When the EntityList has Implementations, types parameter is set. [OperationContract, NetDataContract] List<Lazy> FindLiteLike(Type liteType, Type[] types, string subString, int count); //Given the type of an IdentitiableEntity, and path of MemberInfo (presumably PropertyInfo) returns the Type[] //with the different implementations of the ImplementedBy reference the path points to, otherwise null. [OperationContract, NetDataContract] Type[] FindImplementations(Type type, MemberInfo[] implementations); //Return the list of all the server types (entity controls use it to avoid calling FindImplementations). New in SF 2.0 [OperationContract, NetDataContract] Dictionary<Type, TypeDN> ServerTypes(); //Returns DateTime.Now in the server. Handy for custom client logic. New in SF 2.0 [OperationContract, NetDataContract] DateTime ServerNow(); //Returns the registered types in the server that are assignable to 'type'. Handy for custom client logic. New in SF 2.0 [OperationContract, NetDataContract] List<Lite<TypeDN>> TypesAssignableFrom(Type type); }
ServiceBasic
IBaseServer, IQueryServer, INotesServer
IAlertsServer
[ServiceContract(SessionMode = SessionMode.Required)] public interface IMyCustomServer: IBaseServer { } public class ServerBugs : IMyCustomServer { #region Internal Methods protected T Return<T>(MethodBase mi, Func<T> function) { return Return(mi, mi.Name, function); } protected virtual T Return<T>(MethodBase mi, string description, Func<T> function) { try { return function(); } catch (Exception e) { throw new FaultException(e.Message); } } protected void Execute(MethodBase mi, Action action) { Return(mi, mi.Name, () => { action(); return true; }); } protected void Execute(MethodBase mi, string description, Action action) { Return(mi, description, () => { action(); return true; }); } #endregion public IdentifiableEntity Retrieve(Type type, int id) { return Return(MethodInfo.GetCurrentMethod(), "Retrieve {0}".Formato(type.Name), () => Database.Retrieve(type, id)); } public IdentifiableEntity Save(IdentifiableEntity entidad) { return Return(MethodInfo.GetCurrentMethod(), "Save {0}".Formato(entidad.GetType()), () => { Database.Save(entidad); return entidad; }); } public List<Lite> RetrieveAllLite(Type liteType, Type[] types) { return Return(MethodInfo.GetCurrentMethod(), "RetrieveAllLite {0}".Formato(liteType), () => AutoCompleteUtils.RetriveAllLite(liteType, types)); } (...) }
[ServiceContract] public interface IQueryServer { //returns the QueryDescription (columns and filter names and types). [OperationContract, NetDataContract] QueryDescription GetQueryDescription(object queryName); //returns the QueryResult (actual data) given a queryName, some filters, and an optional limit to reduce the number of results. [OperationContract, NetDataContract] QueryResult GetQueryResult(object queryName, List<Filter> filters, int? limit); //Used by CountSearchControl [OperationContract, NetDataContract] int GetQueryCount(object queryName, List<Filter> filters); //Handy to retrieve an associated entity using a view. Used bu FindUnique [OperationContract, NetDataContract] Lite GetUniqueEntity(object queryName, List<Filter> filters, UniqueType uniqueType); //Return the names of all the available queries in the server. [OperationContract, NetDataContract] List<object> GetQueryNames(); }
public static class Starter { //Call this method when start application in Global.asax, after Connection.Default is set-up public static void Start() { SchemaBuilder sb = (...) DynamicQueryManager dqm = new DynamicQueryManager(); dqm[typeof(ProjectDN)] = from p in Database.Query<ProjectDN>() select new { Entity = p.ToLazy(), p.Name, p.IsInternal }; //Add as many queries as you want ConnectionScope.Default = new Connection(connectionString, sb.Schema, dqm); } }
public QueryDescription GetQueryDescription(object queryName) { return Return(MethodInfo.GetCurrentMethod(), () => DynamicQueryManager.Current.QueryDescription(queryName)); } public QueryResult GetQueryResult(object queryName, List<Filter> filters, int? limit) { return Return(MethodInfo.GetCurrentMethod(), () => DynamicQueryManager.Current.DynamicQueryManager.ExecuteQuery(queryName, filters, limit)); } public List<object> GetQueryNames() { return Return(MethodInfo.GetCurrentMethod(), () => DynamicQueryManager.Current.DynamicQueryManager.GetQueryNames()); } (...)