Beispiel #1
0
        public void VisitDecorated(Decorated d)
        {
            var decorators = d.Decorations.ToList();

            if (this.properties.TryGetValue(d, out var propdef))
            {
                if (propdef.IsTranslated)
                {
                    return;
                }
                decorators.Remove(propdef.GetterDecoration);
                decorators.Remove(propdef.SetterDecoration);
                this.customAttrs = decorators.Select(dd => VisitDecorator(dd));
                var prop = gen.PropertyDef(
                    propdef.Name,
                    () => GeneratePropertyGetter(propdef.Getter),
                    () => GeneratePropertySetter(propdef.Setter));
                LocalVariableGenerator.Generate(null, prop.GetStatements, globals);
                LocalVariableGenerator.Generate(
                    new List <CodeParameterDeclarationExpression> {
                    new CodeParameterDeclarationExpression(prop.PropertyType, "value"),
                },
                    prop.SetStatements,
                    globals);
                propdef.IsTranslated = true;
            }
            else
            {
                this.customAttrs = d.Decorations.Select(dd => VisitDecorator(dd));
                d.Statement.Accept(this);
            }
        }
Beispiel #2
0
        protected virtual void GetByIdOnThread <TId>(TId id, ModelReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.GetById <TId>(id));
            Decorated.Session = currentSession;
        }
Beispiel #3
0
        protected virtual void GetByQueryOnThread <TReturnType>(string queryString, object[] parameters, ListReturnCallback <TReturnType> callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.GetByQuery <TReturnType>(queryString, parameters));
            Decorated.Session = currentSession;
        }
Beispiel #4
0
        protected virtual void GetByNamedQueryOnThread(string queryName, object[] parameters, ListReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.GetByNamedQuery(queryName, parameters));
            Decorated.Session = currentSession;
        }
Beispiel #5
0
        protected virtual void LoadByIdOnThread(object id, ModelReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.LoadById(id));
            Decorated.Session = currentSession;
        }
Beispiel #6
0
        protected virtual void UpdateOnThread(TModel entity, ModelReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.Update(entity));
            Decorated.Session = currentSession;
        }
Beispiel #7
0
        protected virtual void UpdateOnThread(IEnumerable <TModel> entityList, ModelsReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            callback(Decorated.Update(entityList));
            Decorated.Session = currentSession;
        }
        public override ILogic Perform(object context = null)
        {
            this.SmellCheck();

            var rv = Decorated.Perform(context);

            return(rv);
        }
Beispiel #9
0
        public override T GetValue()
        {
            if (this.IsExpired())
            {
                throw new InvalidOperationException("expired");
            }

            return(Decorated.GetValue());
        }
Beispiel #10
0
        public override ILogic Perform(object context = null)
        {
            if (this.IsExpired())
            {
                throw new InvalidOperationException("expired");
            }

            return(Decorated.Perform(context));
        }
Beispiel #11
0
        protected virtual void DeleteOnThread(TModel entity, VoidReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            Decorated.Delete(entity);
            callback();
            Decorated.Session = currentSession;
        }
        public Task <Result> ExecuteAsync(TCommand command)
        {
            if (!CheckPermissions(command))
            {
                return(Task.FromResult(Result.Fail(403, "Доступ запрещен")));
            }

            return(Decorated.ExecuteAsync(command));
        }
Beispiel #13
0
        protected virtual void DeleteOnThread(IEnumerable <TModel> entityList, VoidReturnCallback callback)
        {
            ISession currentSession = Decorated.Session;

            Decorated.Session = Session;
            Decorated.Delete(entityList);
            callback();
            Decorated.Session = currentSession;
        }
Beispiel #14
0
        private void GeneratePropertyGetter(Decorated getter)
        {
            var def      = (FunctionDef)getter.Statement;
            var mgen     = new MethodGenerator(def, null, def.parameters, false, gen);
            var comments = ConvertFirstStringToComments(def.body.stmts);

            gen.CurrentMemberComments.AddRange(comments);
            mgen.Xlat(def.body);
        }
        public override TResult Handle(TQuery query)
        {
            if (!CheckPermissions(query))
            {
                throw new SecurityException();
            }

            return(Decorated.Handle(query));
        }
Beispiel #16
0
 public void MouseLeaveHint()
 {
     if (!Decorated.IsSelected)
     {
         Decorated.ChangeBackgroundColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeMouseDownBackColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeMouseOverBackColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeTextColor(FORE_COLOR);
     }
 }
        public override ILogic Perform(object context = null)
        {
            ILogic rv = null;

            this.Throttle.Perform(() =>
            {
                rv = Decorated.Perform(context);
            });
            return(rv);
        }
Beispiel #18
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                Decorated.Dispose();
                ClosingAction();
            }

            base.Dispose(disposing);
        }
Beispiel #19
0
        /// <summary>
        /// Gets a single instance of T matching the given Id from the cache, or via the decorated method if not already cached.
        /// If not already cached, the entity retrieved is cached.
        /// </summary>
        /// <param name="guid">The globally unique identifier for the entity.</param>
        /// <returns>An asynchronous <see cref="Task{T}"/> containing the entity if found, otherwise null.</returns>
        public async Task <T> GetById(Guid guid)
        {
            var entity = await MemoryCache.GetOrCreateAsync(guid, async entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5); // TODO - put magic number into config
                return(await Decorated.GetById(guid).ConfigureAwait(false));
            }).ConfigureAwait(false);

            return(Mapper.Map <T, T>(entity));
        }
Beispiel #20
0
 public override T GetValue()
 {
     try
     {
         return(Decorated.GetValue());
     }
     catch
     {
     }
     return(default(T));
 }
        public override T GetValue()
        {
            var waitRV = this.Waiter.WaitAround();

            if (!waitRV)
            {
                throw new InvalidOperationException("wait stopped");
            }

            return(Decorated.GetValue());
        }
Beispiel #22
0
 public override bool?Evaluate()
 {
     try
     {
         return(Decorated.Evaluate());
     }
     catch
     {
     }
     return(false);
 }
        public override T GetValue()
        {
            T rv = default(T);

            this.Throttle.Perform(() =>
            {
                rv = Decorated.GetValue();
            });

            return(rv);
        }
Beispiel #24
0
 public override void TurnOff()
 {
     if (Decorated.IsSelected)
     {
         Decorated.TurnOff();
         Decorated.ChangeBackgroundColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeMouseDownBackColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeMouseOverBackColor(BG_COLOR_UNSELECTED);
         Decorated.ChangeTextColor(FORE_COLOR);
     }
 }
        public override ILogic Perform(object context = null)
        {
            var waitRV = this.Waiter.WaitAround();

            if (!waitRV)
            {
                throw new InvalidOperationException("wait stopped");
            }

            return(Decorated.Perform(context));
        }
        public override T GetValue()
        {
            var condVal = this.IsValidCondition.Evaluate();

            if (!condVal.GetValueOrDefault())
            {
                throw new InvalidOperationException("Condition not ready");
            }

            return(Decorated.GetValue());
        }
Beispiel #27
0
        /// <summary>
        /// Searches for a newer version of an entity in the database if it exists and returns it if found.
        /// If found, the newer version is saved to the cache.
        /// </summary>
        /// <param name="guid">The globally unique identifier for the entity.</param>
        /// <param name="version">The presumed most recent version of the entity document.</param>
        /// <returns>The newer version of the entity if it exists. Otherwise, default(T).</returns>
        public async Task <T> GetNewerVersionIfExists(Guid guid, int version)
        {
            var entity = await Decorated.GetNewerVersionIfExists(guid, version).ConfigureAwait(false);

            if (entity != null)
            {
                CacheCopyOfEntity(entity);
            }

            return(Mapper.Map <T, T>(entity));
        }
 public async Task <Response> Handle(TCommand request, CancellationToken cancellationToken)
 {
     try
     {
         return(await Decorated.Handle(request, cancellationToken));
     }
     catch (Exception e)
     {
         Log.LogError(e, "Error executing {@Command} at {CommandHandler}", request, Decorated.GetType().FullName);
         return(Response.Failed(e, $"Error executing {request.GetType().Name} at {GetType().Name}"));
     }
 }
Beispiel #29
0
        public override Money CalculateRebate(Product product, int quantity, Money regularCost)
        {
            Money baseValue = (Decorated == null)
                                  ? regularCost
                                  : Decorated.CalculateRebate(product, quantity, regularCost);

            if (baseValue > _minimalThreshold)
            {
                return(baseValue - _rebateValue);
            }
            return(baseValue);
        }
 /// <summary>
 /// Decorated Handle
 /// </summary>
 public override async Task Handle(TEvent @event)
 {
     try
     {
         await Decorated.Handle(@event);
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         throw;
     }
 }
Beispiel #31
0
 public void VisitDecorated(Decorated d)
 {
     foreach (var dec in d.Decorations)
     {
         w.Write("@");
         w.Write(dec.className.ToString());
         w.Write("(");
         var sep = "";
         foreach (var arg in dec.arguments)
         {
             w.Write(sep);
             sep = ", ";
             arg.Write(writer);
         }
         w.Write(")");
         w.WriteLine();
     }
     d.Statement.Accept(this);
 }
Beispiel #32
0
 public override void ExecuteCommand(CommandType commandType, object data)
 {
     deleteable = null;
     if (ActiveChild.GetType() == typeof(TextEquation))
     {
         EquationBase newEquation = null;
         switch (commandType)
         {
             case CommandType.Composite:
                 newEquation = CompositeFactory.CreateEquation(this, (Position)data);
                 break;
             case CommandType.CompositeBig:
                 newEquation = BigCompositeFactory.CreateEquation(this, (Position)data);
                 break;
             case CommandType.Division:
                 newEquation = DivisionFactory.CreateEquation(this, (DivisionType)data);
                 break;
             case CommandType.SquareRoot:
                 newEquation = new SquareRoot(this);
                 break;
             case CommandType.nRoot:
                 newEquation = new nRoot(this);
                 break;
             case CommandType.LeftBracket:
                 newEquation = new LeftBracket(this, (BracketSignType)data);
                 break;
             case CommandType.RightBracket:
                 newEquation = new RightBracket(this, (BracketSignType)data);
                 break;
             case CommandType.LeftRightBracket:
                 newEquation = new LeftRightBracket(this, ((BracketSignType[])data)[0], ((BracketSignType[])data)[1]);
                 break;
             case CommandType.Sub:
                 newEquation = new Sub(this, (Position)data);
                 break;
             case CommandType.Super:
                 newEquation = new Super(this, (Position)data);
                 break;
             case CommandType.SubAndSuper:
                 newEquation = new SubAndSuper(this, (Position)data);
                 break;
             case CommandType.TopBracket:
                 newEquation = new TopBracket(this, (HorizontalBracketSignType)data);
                 break;
             case CommandType.BottomBracket:
                 newEquation = new BottomBracket(this, (HorizontalBracketSignType)data);
                 break;
             case CommandType.DoubleArrowBarBracket:
                 newEquation = new DoubleArrowBarBracket(this);
                 break;
             case CommandType.SignComposite:
                 newEquation = SignCompositeFactory.CreateEquation(this, (Position)(((object[])data)[0]), (SignCompositeSymbol)(((object[])data)[1]), UseItalicIntergalOnNew);
                 break;
             case CommandType.Decorated:
                 newEquation = new Decorated(this, (DecorationType)(((object[])data)[0]), (Position)(((object[])data)[1]));
                 break;
             case CommandType.Arrow:
                 newEquation = new Arrow(this, (ArrowType)(((object[])data)[0]), (Position)(((object[])data)[1]));
                 break;
             case CommandType.Box:
                 newEquation = new Box(this, (BoxType)data);
                 break;
             case CommandType.Matrix:
                 newEquation = new MatrixEquation(this, ((int[])data)[0], ((int[])data)[1]);
                 break;
             case CommandType.DecoratedCharacter:
                 if (((TextEquation)ActiveChild).CaretIndex > 0)
                 {
                     //newEquation = new DecoratedCharacter(this,
                     //                                     (TextEquation)ActiveChild,
                     //                                     (CharacterDecorationType)((object[])data)[0],
                     //                                     (Position)((object[])data)[1],
                     //                                     (string)((object[])data)[2]);
                     ((TextEquation)ActiveChild).AddDecoration((CharacterDecorationType)((object[])data)[0],
                                                               (Position)((object[])data)[1],
                                                               (string)((object[])data)[2]);
                     CalculateSize();
                 }
                 break;
         }
         if (newEquation != null)
         {
             EquationBase newText = ActiveChild.Split(this);
             int caretIndex = ((TextEquation)ActiveChild).TextLength;
             AddChild(newEquation);
             AddChild(newText);
             newEquation.CalculateSize();
             ActiveChild = newEquation;
             CalculateSize();
             UndoManager.AddUndoAction(new RowAction(this, ActiveChild, (TextEquation)newText, childEquations.IndexOf(ActiveChild), caretIndex));
         }
     }
     else if (ActiveChild != null)
     {
         ((EquationContainer)ActiveChild).ExecuteCommand(commandType, data);
         CalculateSize();
     }
 }
Beispiel #33
0
 public void VisitDecorated(Decorated d)
 {
     this.customAttrs = d.Decorations.Select(dd => VisitDecorator(dd));
     d.Statement.Accept(this);
 }