Ejemplo n.º 1
0
 // if we use EntityFramework in our strategy we are better to provide a CheckAccess() method
 // in our BaseStrategyEF by which sub-classes are able to check current user permission regarding
 // a specific action, like posting comments, deleting records, ...
 //
 // public virtual bool CheckAccess(string code) { ... }
 //
 // if we use SPROCs in our strageies (like ServiceModel.Babbage strategies) we don't need to provide
 // such a method. we can do this in the SPROCs, especially that we can use ContextInfo in SQL Server
 // and send current user's name, role, IP or other relevent data to the SPROC over the database connection
 // and check user access there.
 void IBaseServiceStrategy.Run(IServiceStrategyContext context)
 {
     if (context != null && context.Ready)
     {
         Run(context as TContext);
     }
 }
Ejemplo n.º 2
0
        IServiceStrategyContext IBaseServiceStrategy.CreateContextBy <TWRequest>(IServiceStrategyContext context, TWRequest request)
        {
            var result = CreateContextBy(context);

            result.Request = request as WRequest;

            return(result);
        }
Ejemplo n.º 3
0
        public TContext Invoke(IServiceStrategyContext context, WRequest args = null)
        {
            var result = CreateContextBy(context, args);

            Run(result);

            return(result);
        }
Ejemplo n.º 4
0
        public async Task <TContext> InvokeAsync(IServiceStrategyContext context, WRequest args = null)
        {
            var result = CreateContextBy(context, args);

            await RunAsync(result);

            return(result);
        }
Ejemplo n.º 5
0
        public TContext CreateContextBy(IServiceStrategyContext context, WRequest request)
        {
            var result = CreateContextBy(context);

            result.Request = request;

            return(result);
        }
Ejemplo n.º 6
0
        public override async Task FetchSettingsAsync(IServiceStrategyContext context = null)
        {
            if (serviceSettingService != null)
            {
                var ctx = await serviceSettingService.GetAllByService.InvokeAsync(context, new ServiceSettingGetAllByServiceRequest { Service = this.Name });

                FinalizeFetchSettings(ctx);
            }
        }
Ejemplo n.º 7
0
        public override void FetchSettings(IServiceStrategyContext context = null)
        {
            if (serviceSettingService != null)
            {
                var ctx = serviceSettingService.GetAllByService.Invoke(context, new ServiceSettingGetAllByServiceRequest {
                    Service = this.Name
                });

                FinalizeFetchSettings(ctx);
            }
        }
Ejemplo n.º 8
0
 Task IBaseServiceStrategy.RunAsync(IServiceStrategyContext context)
 {
     if (context != null && context.Ready)
     {
         return(RunAsync(context as TContext));
     }
     else
     {
         return(Task.Run(() => { }));
     }
 }
Ejemplo n.º 9
0
        public TContext CreateContextBy <TContext>(IServiceStrategyContext fromContext) where TContext : class
        {
            var strategy = strategyStore.GetStrategy(typeof(TContext));

            if (strategy == null)
            {
                throw new ArgumentException(string.Format("requested context '{0}' does not belong to this service"), typeof(TContext).Name);
            }

            return(strategy.CreateContextBy(fromContext) as TContext);
        }
Ejemplo n.º 10
0
        public IServiceStrategyContext CreateContextBy(IServiceStrategyContext ctx, string strategyName, object request)
        {
            var strategy = Store.GetAllStrategies().FirstOrDefault(s => string.Compare(s.Name, strategyName, StringComparison.OrdinalIgnoreCase) == 0);

            if (strategy != null)
            {
                return(strategy.CreateContextBy(ctx, request));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 11
0
        protected virtual IDbCommand GetContextCommand(IServiceStrategyContext context)
        {
            var babbageContext = context as BabbageContext <TResponse, UData, VStatus, WRequest>;
            var _cmd           = "";

            if (babbageContext != null && !string.IsNullOrEmpty(babbageContext.CommandText))
            {
                _cmd = babbageContext.CommandText;
            }
            else
            {
                _cmd = "usp1_" + context.Strategy.Store.Service.Name + "_" + context.Strategy.Name;
            }

            return(Db.GetCommand(_cmd));
        }
Ejemplo n.º 12
0
        public TContext CreateContextBy(IServiceStrategyContext context, object request)
        {
            var result = CreateContextBy(context);

            try
            {
                result.Request.Init(request);
            }
            catch (Exception e)
            {
                result.Log.Danger(new MessageItem {
                    Category = result.ServiceName, Code = "req_init_err", Exception = e, Source = MessageSource.Framework, Operation = result.Strategy.Name
                });
            }

            return(result);
        }
Ejemplo n.º 13
0
        public TContext CreateContextBy(IServiceStrategyContext context)
        {
            var result = CreateContext();

            if (context != null)
            {
                result.Log = context.Log;

                if (result.Strategy != null && result.Strategy.Store != null && result.Strategy.Store.Service != null &&
                    context.Strategy != null && context.Strategy.Store != null &&
                    context.Strategy.Store.Service != null)
                {
                    result.Strategy.Store.Service.Db = context.Strategy.Store.Service.Db;
                }

                if (result.Log.Options.DebugMode)
                {
                    result.Parent = context;
                    context.Children.Add(result);
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
        public override async Task FetchSettingsAsync(IServiceStrategyContext context = null)
        {
            await base.FetchSettingsAsync(context);

            InitSettings();
        }
Ejemplo n.º 15
0
        public override void FetchSettings(IServiceStrategyContext context = null)
        {
            base.FetchSettings(context);

            InitSettings();
        }
Ejemplo n.º 16
0
 IServiceStrategyContext IBaseServiceStrategy.CreateContextBy(IServiceStrategyContext context, object request)
 {
     return(CreateContextBy(context, request));
 }
Ejemplo n.º 17
0
 public virtual void FetchSettings(IServiceStrategyContext context = null)
 {
     settings = new CaseInsensitiveDictionary <string>();
 }
Ejemplo n.º 18
0
        public virtual Task FetchSettingsAsync(IServiceStrategyContext context = null)
        {
            settings = new CaseInsensitiveDictionary <string>();

            return(Task.FromResult(0));
        }
Ejemplo n.º 19
0
 IServiceStrategyContext IBaseServiceStrategy.CreateContextBy(IServiceStrategyContext context)
 {
     return(CreateContextBy(context));
 }