Пример #1
0
        public static OperationContext CreateSystemContext(this EntityApp app)
        {
            Util.Check(app != null, "App may not be null.");
            var sysContext = new OperationContext(app, UserInfo.System);

            return(sysContext);
        }
Пример #2
0
        public static IEntitySession OpenSystemSession(this EntityApp app)
        {
            Util.Check(app != null, "App may not be null.");
            var sysContext = new OperationContext(app, UserInfo.System);

            return(new EntitySession(sysContext));
        }
Пример #3
0
 public OperationContext(EntityApp app, UserInfo user         = null, WebCallContext webContext = null, ILog log = null,
                         DbConnectionReuseMode connectionMode = DbConnectionReuseMode.NoReuse,
                         ProcessType?processType = null, Guid?processId = null)
 {
     App              = app;
     User             = user ?? UserInfo.Anonymous;
     WebContext       = webContext;
     Log              = log ?? new DefaultOperationLog(this);
     DbConnectionMode = connectionMode;
     ProcessId        = processId;
     if (WebContext != null)
     {
         ProcessType = ProcessType.WebRequest;
     }
     else
     {
         if (processType == null)
         {
             ProcessType = (processId == null) ? ProcessType.User : ProcessType.BackgroundProcess;
         }
         else
         {
             ProcessType = processType.Value;
         }
     }
 }
Пример #4
0
        public static IEntitySession OpenSystemSession(this EntityApp app)
        {
            Util.CheckParam(app, nameof(app));
            var ctx = app.CreateSystemContext();

            return(ctx.OpenSession());
        }
Пример #5
0
        public static int GetPropertySize <TEntity>(this EntityApp app, Expression <Func <TEntity, object> > selector)
        {
            var propName = ExpressionHelper.GetSelectedProperty(selector);
            var ent      = app.Model.GetEntityInfo(typeof(TEntity), throwIfNotFound: true);
            var member   = ent.GetMember(propName, throwIfNotFound: true);

            return(member.Size);
        }
Пример #6
0
        /// <summary>Opens entity session.</summary>
        /// <param name="app">Entity app.</param>
        /// <param name="user">User info, optional.</param>
        /// <returns>Entity session instance.</returns>
        public static IEntitySession OpenSession(this EntityApp app, UserInfo user = null)
        {
            Util.Check(app != null, "App may not be null.");
            user = user ?? UserInfo.Anonymous;
            var anonContext = new OperationContext(app, user);

            return(new EntitySession(anonContext));
        }
Пример #7
0
        //.NET framework's GetHashCode() is not guaranteed to be stable between .NET versions.
        // If we want to keep hashes in database, we need a stable hash implementation
        public static int ComputeStableHash(this EntityApp app, string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                return(0);
            }
            var hasher = app.GetService <IHashingService>();

            return(hasher.ComputeHash(value));
        }
Пример #8
0
 /// <summary>Constructs a new instance of the <c>EntityModule</c> class. </summary>
 /// <param name="area">Primary entity area to register module entities.</param>
 /// <param name="name">Module name.</param>
 /// <param name="description">Optional. Module description.</param>
 /// <param name="version">Module version.</param>
 public EntityModule(EntityArea area, string name, string description = null, Version version = null)
 {
     Area = area;
     App  = Area.App;
     Util.Check(App.Status == EntityAppStatus.Created, "Module may not be added to an entity app after it is initialized.");
     Name        = name;
     Description = description;
     Version     = version ?? new Version("1.0.0.0");
     App.AddModule(this);
 }
Пример #9
0
 public OperationContext(EntityApp app, UserInfo user         = null, WebCallContext webContext = null,
                         DbConnectionReuseMode connectionMode = DbConnectionReuseMode.NoReuse)
 {
     App              = app;
     User             = user ?? UserInfo.Anonymous;
     WebContext       = webContext;
     DbConnectionMode = connectionMode;
     LocalLog         = new MemoryLog(this);
     Disposables      = new ConcurrentDisposableSet();
 }
Пример #10
0
 //Used for creating System-level context within user operation
 public OperationContext(OperationContext parentContext, UserInfo user)
 {
     App              = parentContext.App;
     User             = user;
     WebContext       = parentContext.WebContext;
     LocalLog         = parentContext.LocalLog;
     UserSession      = parentContext.UserSession;
     DataSourceName   = parentContext.DataSourceName;
     DbConnectionMode = parentContext.DbConnectionMode;
     Disposables      = parentContext.Disposables;
 }
Пример #11
0
        public static int GetPropertySize <TEntity>(this EntityApp app, Expression <Func <TEntity, object> > selector)
        {
            var ent = app.Model.GetEntityInfo(typeof(TEntity));

            Util.Check(ent != null, "Type {0} is not a registered entity, cannot retrieve property size.", typeof(TEntity));
            var propName = ReflectionHelper.GetSelectedProperty(selector);
            var member   = ent.GetMember(propName);

            Util.Check(member != null, "Property {0} not found on entity {1}.", propName, typeof(TEntity));
            return(member.Size);
        }
Пример #12
0
 /// <summary>Imports services from external service provider. </summary>
 /// <param name="fromApp">External service provider, usually another entity applications.</param>
 /// <param name="serviceTypes">Types of services to import.</param>
 public void ImportServices(EntityApp fromApp, params Type[] serviceTypes)
 {
     foreach (var type in serviceTypes)
     {
         var serv = fromApp.GetService(type);
         if (serv != null)
         {
             this._services[type] = serv;
         }
     }
 }
Пример #13
0
 public ServiceEventArgs(EntityApp app, Type serviceType, object serviceInstance)
 {
     App             = app;
     ServiceType     = serviceType;
     ServiceInstance = serviceInstance;
 }
Пример #14
0
 public AppInitEventArgs(EntityApp app, EntityAppInitStep step)
 {
     App  = app;
     Step = step;
 }
Пример #15
0
 internal void OnServiceAdded(EntityApp app, Type serviceType, object serviceInstance)
 {
     ServiceAdded?.Invoke(this, new ServiceEventArgs(app, serviceType, serviceInstance));
 }
Пример #16
0
 public EntityAppEvents(EntityApp app)
 {
     _app = app;
 }
Пример #17
0
 // The constructor is internal, use EntityModelSetup.AddArea method
 internal EntityArea(EntityApp app, string name)
 {
     App = app;
     Util.CheckNotEmpty(name, "SchemaName may not be empty.");
     Name = name.Trim().ToLowerInvariant();
 }
Пример #18
0
        /// <summary>Opens an entity session for an anonymous user. </summary>
        /// <param name="app">Entity app instance.</param>
        /// <returns>An entity session.</returns>
        public static IEntitySession OpenSession(this EntityApp app)
        {
            var context = new OperationContext(app, UserInfo.Anonymous);

            return(new EntitySession(context));
        }
Пример #19
0
 public static Vita.Data.Runtime.Database GetDefaultDatabase(this EntityApp app)
 {
     return(app.DataAccess.GetDataSources().FirstOrDefault()?.Database);
 }
Пример #20
0
 /// <summary>Checks if an entity is registered with entity model.
 /// For use in customizable models when several versions might exist for different environments,
 /// and some entities are excluded in some models.</summary>
 /// <param name="app">Entity app.</param>
 /// <param name="entityType">The type of entity to check.</param>
 /// <returns>True if the entity is part of the model; otherwise, false.</returns>
 public static bool IsRegisteredEntity(this EntityApp app, Type entityType)
 {
     return(app.Model.EntitiesByType.ContainsKey(entityType));
 }
Пример #21
0
        public static OperationContext CreateSystemContext(this EntityApp app)
        {
            var ctx = new OperationContext(app, UserInfo.System);

            return(ctx);
        }