Ejemplo n.º 1
0
        /// <summary>
        /// Formata o texto de um <see cref="ConditionalContainer"/>
        /// </summary>
        /// <param name="container">Container a ser formatado</param>
        /// <returns>Retorna o próprio objeto</returns>
        private DefaultSqlQueryParser Format(ConditionalContainer container)
        {
            int counter = 1;

            Append("(");
            var listLogicalOperators = container.LogicalOperators.ToList();

            foreach (var conditionalItem in container.Conditionals)
            {
                Format(conditionalItem);
                if (counter != container.ConditionalsCount)
                {
                    if (listLogicalOperators[counter - 1] == LogicalOperator.And)
                    {
                        Append(" AND ");
                    }
                    else
                    {
                        Append(" OR ");
                    }
                    counter++;
                }
            }
            Append(")");
            return(this);
        }
Ejemplo n.º 2
0
        private OracleQueryParser Format(ConditionalContainer a)
        {
            int b = 1;

            Append("(");
            var c = a.LogicalOperators.ToList();

            foreach (var conditionalItem in a.Conditionals)
            {
                Format(conditionalItem);
                if (b != a.ConditionalsCount)
                {
                    if (c [b - 1] == LogicalOperator.And)
                    {
                        Append(" AND ");
                    }
                    else
                    {
                        Append(" OR ");
                    }
                    b++;
                }
            }
            Append(")");
            return(this);
        }
Ejemplo n.º 3
0
        public bool EvaluateToken(string token)
        {
            // Start out as the true side
            if (_evaluator == null)
                _evaluator = new ConditionalFunctionEvaluatorState(_trueCore);

            // Evaluate current arguments
            _evaluator.EvaluateToken(token);

            // Get the result if it hit a conditional token
            if (_evaluator.ConditionalStatus != ConditionalFunctionEvaluatorState.ConditionalStatusType.None)
            {
                if (_evaluator.ConditionalStatus == ConditionalFunctionEvaluatorState.ConditionalStatusType.Else)
                {
                    if (_isFalseSide)
                        throw new MuftecCompilerException("Encountered else after else", Core.LineNumber);

                    // Switch to false side
                    _evaluator = new ConditionalFunctionEvaluatorState(_falseCore);
                    _isFalseSide = true;
                    return true;
                }
                if (_evaluator.ConditionalStatus == ConditionalFunctionEvaluatorState.ConditionalStatusType.Then)
                {
                    // Done here, wrap up
                    var container = new ConditionalContainer { TrueQueue = _trueCore.Queue, FalseQueue = _falseCore.Queue };

                    Core.Queue.Enqueue(new MuftecStackItem(container, Core.LineNumber));
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Localiza a coluna no container
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 private Column FindColumn(ConditionalContainer container)
 {
     foreach (var part in container.Conditionals)
     {
         if (part is Column)
         {
             return((Column)part);
         }
         else if (part is Conditional)
         {
             var conditional = (Conditional)part;
             if (conditional.Left is Column)
             {
                 return((Column)conditional.Left);
             }
             if (conditional.Right is Column)
             {
                 return((Column)conditional.Right);
             }
             {
                 Column column = null;
                 if (conditional.Left is ConditionalContainer)
                 {
                     column = FindColumn((ConditionalContainer)conditional.Left);
                 }
                 if (column != null)
                 {
                     return(column);
                 }
                 if (conditional.Right is ConditionalContainer)
                 {
                     column = FindColumn((ConditionalContainer)conditional.Right);
                 }
                 if (column != null)
                 {
                     return(column);
                 }
             }
         }
         else if (part is ConditionalContainer)
         {
             var column = FindColumn((ConditionalContainer)part);
             if (column != null)
             {
                 return(column);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Aplica os parametros da expressão para a consulta informada.
        /// </summary>
        /// <param name="queryable"></param>
        /// <param name="expression"></param>
        public void Apply(Query.Queryable queryable, Expression expression)
        {
            Visit(expression);
            if (_takeTranslator != null)
            {
                queryable.Take(_takeTranslator.Count.GetValueOrDefault());
            }
            if (_skipTranslator != null)
            {
                queryable.Skip(_skipTranslator.Skip.GetValueOrDefault());
            }
            if (_whereTranslator != null)
            {
                string where = _whereTranslator.WhereClause;
                if (!string.IsNullOrEmpty(where))
                {
                    queryable.WhereClause.And(ConditionalContainer.Parse(where));
                }
            }
            foreach (var i in _parameters)
            {
                queryable.Add(i);
            }
            if (_orderByTranslator != null && _orderByTranslator.Members.Any())
            {
                foreach (var i in _orderByTranslator.Members)
                {
                    queryable.Sort = new Sort();
                    queryable.Sort.Add(new SortEntry(new Column(i.DataMember.Name), i.Direction == OrderDirection.Descending));
                }
            }
            switch (_useMethod)
            {
            case QueryMethod.Count:
                queryable.Count();
                break;

            case QueryMethod.Sum:
            {
                if (_selectTranslator == null || !_selectTranslator.DataMembers.Any())
                {
                }
                break;
            }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Recupera usado para recupera a consulta associada com a ação.
        /// </summary>
        /// <param name="action"></param>
        /// <param name="typeMetadata"></param>
        /// <returns></returns>
        private Query.Queryable GetActionQuery(PersistenceAction action, Colosoft.Data.Schema.ITypeMetadata typeMetadata)
        {
            var                   query               = _sourceContext.CreateQuery();
            StringBuilder         wherePart           = new StringBuilder();
            List <QueryParameter> wherePartParameters = new List <QueryParameter>();
            bool                  isFirstWhere        = true;

            for (int i = 0; i < action.Parameters.Count; i++)
            {
                var propertyMetadata = typeMetadata[action.Parameters[i].Name];
                if (propertyMetadata != null && (propertyMetadata.ParameterType == Colosoft.Data.Schema.PersistenceParameterType.IdentityKey || propertyMetadata.ParameterType == Colosoft.Data.Schema.PersistenceParameterType.Key))
                {
                    if (action.Conditional != null)
                    {
                        continue;
                    }
                    wherePartParameters.Add(new QueryParameter("?" + action.Parameters[i].Name, action.Parameters[i].Value));
                    if (!isFirstWhere)
                    {
                        wherePart.Append(" && ");
                    }
                    else
                    {
                        isFirstWhere = false;
                    }
                    wherePart.Append(action.Parameters[i].Name).Append("=?").Append(action.Parameters[i].Name);
                }
            }
            if (action.Conditional == null && wherePart.Length > 0)
            {
                query.WhereClause = ConditionalContainer.Parse(wherePart.ToString(), wherePartParameters.ToArray());
            }
            else if (action.Conditional != null)
            {
                query.WhereClause = action.Conditional;
            }
            query.From(new EntityInfo()
            {
                Alias    = null,
                FullName = typeMetadata.FullName
            });
            return(query);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new <see cref="TradeList"/>.
        /// </summary>
        public TradeList()
        {
            this.tradeRows = new List <TradeRow>();

            // Create the initial layout
            tradeRowsFlexContainer = new VerticalFlexContainer();

            // Wrap the column in a scroll container
            VerticalScrollContainer scrolledColumn = new VerticalScrollContainer(tradeRowsFlexContainer);

            // Make sure we have active trades before attempting to draw them
            ConditionalContainer activeTradesConditional = new ConditionalContainer(
                childIfTrue: scrolledColumn,
                childIfFalse: new PlaceholderWidget("Phinix_trade_noActiveTradesPlaceholder".Translate()),
                condition: () => tradeRowsFlexContainer.Contents.Any()
                );

            // Make sure we are online above all else
            ConditionalContainer onlineConditional = new ConditionalContainer(
                childIfTrue: activeTradesConditional,
                childIfFalse: new PlaceholderWidget("Phinix_chat_pleaseLogInPlaceholder".Translate()),
                condition: () => Client.Instance.Online
                );

            // Save the layout ready for the draw thread
            constructedLayout = onlineConditional;

            // Subscribe to update events
            Client.Instance.OnTradesSynced           += (s, e) => repopulateTradeRows();
            Client.Instance.OnTradeCancelled         += onTradeCompletedOrCancelledHandler;
            Client.Instance.OnTradeCompleted         += onTradeCompletedOrCancelledHandler;
            Client.Instance.OnTradeCreationSuccess   += onTradeCreationSuccessHandler;
            Client.Instance.OnTradeUpdateFailure     += onTradeUpdateHandler;
            Client.Instance.OnTradeUpdateSuccess     += onTradeUpdateHandler;
            Client.Instance.OnUserDisplayNameChanged += onUserDisplayNameChangedHandler;

            // Pre-fill the trade rows
            repopulateTradeRows();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Formata o texto de um <see cref="ConditionalContainer"/>.
        /// </summary>
        /// <param name="container">Container a ser formatado.</param>
        /// <returns>Retorna o próprio objeto.</returns>
        private CacheQueryParser Format(ConditionalContainer container)
        {
            Append('(');
            int counter = 1;
            var listLogicalOperators = container.LogicalOperators.ToList();

            foreach (var conditionalItem in container.Conditionals)
            {
                if (conditionalItem is ConditionalContainer)
                {
                    var containerItem = (ConditionalContainer)conditionalItem;
                    Format(containerItem);
                }
                else
                {
                    var conditional = (Conditional)conditionalItem;
                    Format(conditional);
                }
                if (counter != container.ConditionalsCount)
                {
                    if (listLogicalOperators[counter - 1] == LogicalOperator.And)
                    {
                        Append(" AND ");
                    }
                    else
                    {
                        Append(" OR ");
                    }
                    counter++;
                }
                else
                {
                    Append(' ');
                }
            }
            Append(')');
            return(this);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Formata o texto de um <see cref="ConditionalContainer"/>
        /// </summary>
        /// <param name="container">Container a ser formatado</param>
        /// <param name="sqlCommand"></param>
        /// <returns>Retorna o próprio objeto</returns>
        private DefaultPersistenceSqlParser Format(ConditionalContainer container, StringBuilder sqlCommand)
        {
            int counter = 1;

            foreach (var parameter in container.ParameterContainer)
            {
                if (!this.Action.Parameters.Any(f => f.Name == parameter.Name))
                {
                    this.Action.Parameters.Add(new PersistenceParameter(parameter.Name, parameter.Value, parameter.Direction));
                }
            }
            Append("(", sqlCommand);
            var listLogicalOperators = container.LogicalOperators.ToList();

            foreach (var conditionalItem in container.Conditionals)
            {
                Format(conditionalItem, sqlCommand);
                if (counter != container.ConditionalsCount)
                {
                    if (listLogicalOperators[counter - 1] == LogicalOperator.And)
                    {
                        Append(" AND ", sqlCommand);
                    }
                    else
                    {
                        Append(" OR ", sqlCommand);
                    }
                    counter++;
                }
                else
                {
                    Append(' ', sqlCommand);
                }
            }
            Append(")", sqlCommand);
            return(this);
        }
        /// <summary>
        /// Formata o texto de um <see cref="ConditionalContainer"/>
        /// </summary>
        /// <param name="container">Container a ser formatado</param>
        /// <param name="sqlCommand">Objeto <see cref="StringBuilder"/> no qual será adicionado texto</param>
        /// <returns>Retorna o próprio objeto</returns>
        private OraclePersistenceSqlParser Format(ConditionalContainer container, StringBuilder sqlCommand)
        {
            int counter = 1;
            var listLogicalOperators = container.LogicalOperators.ToList();

            foreach (var conditionalItem in container.Conditionals)
            {
                if (conditionalItem is ConditionalContainer)
                {
                    var containerItem = (ConditionalContainer)conditionalItem;
                    Append('(', sqlCommand).Format(containerItem, sqlCommand).Append(')', sqlCommand);
                }
                else
                {
                    var conditional = (Conditional)conditionalItem;
                    Format(conditional, sqlCommand);
                }
                if (counter != container.ConditionalsCount)
                {
                    if (listLogicalOperators[counter - 1] == LogicalOperator.And)
                    {
                        Append(" AND ", sqlCommand);
                    }
                    else
                    {
                        Append(" OR ", sqlCommand);
                    }
                    counter++;
                }
                else
                {
                    Append(' ', sqlCommand);
                }
            }
            return(this);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Converte a expressão da consulta com uma consulta executável.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        private QueryInfo ConvertToExecutableQuery(Expression query)
        {
            Type source;

            if (!GetSourceEntity(query, out source))
            {
                throw new NotSupportedException("This query expression is not supported!");
            }
            var queryDetails = new QueryInfo()
            {
                Method = _useMethod
            };

            if (_takeTranslator != null)
            {
                queryDetails.TakeParameters = new TakeParameters(_takeTranslator.Count.GetValueOrDefault(), _skipTranslator != null ? _skipTranslator.Skip.GetValueOrDefault() : 0);
            }
            if (_selectTranslator == null || !_selectTranslator.DataMembers.Any())
            {
                _selectTranslator = new ProjectionTranslator(source.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Select(f => new Member(null, f)));
            }
            if (!_selectTranslator.DataMembers.Any())
            {
                throw new Exception("There are no items for projection in this query!");
            }
            var projection = new Projection();

            foreach (var i in _selectTranslator.DataMembers)
            {
                projection.Add(new ProjectionEntry(!string.IsNullOrEmpty(i.Owner) ? string.Format("{0}.{1}", i.Owner, i.Info.Name) : i.Info.Name, i.Info.Name));
            }
            queryDetails.Projection = projection;
            IEnumerable <Member> entities = _selectTranslator.DataMembers;

            if (_whereTranslator != null)
            {
                string where = _whereTranslator.WhereClause;
                if (!string.IsNullOrEmpty(where))
                {
                    queryDetails.WhereClause = ConditionalContainer.Parse(where);
                }
            }
            else
            {
                queryDetails.WhereClause = new ConditionalContainer().Add(_parameters);
            }
            var rr = entities.GroupBy(f => f.Owner, f => f).ToArray();

            if (_orderByTranslator != null && _orderByTranslator.Members.Any())
            {
                foreach (var i in _orderByTranslator.Members)
                {
                    if (queryDetails.Sort == null)
                    {
                        queryDetails.Sort = new Sort();
                    }
                    queryDetails.Sort.Add(new SortEntry(new Column(i.DataMember.Name), i.Direction == OrderDirection.Descending));
                }
            }
            return(queryDetails);
        }