/// <summary> /// Faz a desserialização do objeto. /// </summary> /// <param name="reader"></param> protected override void Deserialize(Colosoft.Serialization.IO.CompactReader reader) { if (reader.ReadBoolean()) { _term = GetConditionalTerm(reader); } }
/// <summary> /// Recupera os dados da instancia do leitor informado. /// </summary> /// <param name="reader"></param> protected override void ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement(); if (!reader.IsEmptyElement || reader.HasAttributes) { _left = GetConditionalTerm(reader); } else { reader.Skip(); } if (!reader.IsEmptyElement) { _operator = (Operator)GetConditionalTerm(reader); } else { reader.Skip(); } if (!reader.IsEmptyElement || reader.HasAttributes) { _right = GetConditionalTerm(reader); } else { reader.Skip(); } reader.ReadEndElement(); }
/// <summary> /// Preenche os dados da instancia com a expressões informadas. /// </summary> /// <param name="expressions"></param> private void Fill(List <Text.InterpreterExpression.Expression> expressions) { int ownerIndex; int aliasIndex; GetParameters(expressions, out ownerIndex, out aliasIndex); IEnumerator <Text.InterpreterExpression.Expression> enumerator = null; if (aliasIndex >= 0) { enumerator = (IEnumerator <Text.InterpreterExpression.Expression>)expressions.Take(aliasIndex).GetEnumerator(); } else { enumerator = (IEnumerator <Text.InterpreterExpression.Expression>)expressions.GetEnumerator(); } if (enumerator.MoveNext()) { _term = ConditionalParser.GetContainer(ref enumerator, new Text.InterpreterExpression.ContainerChars('(', ')')); } if (aliasIndex >= 0 && _alias == null) { _alias = expressions[aliasIndex + 1].Text; } }
/// <summary> /// Desserializa o objeto. /// </summary> /// <param name="reader"></param> public void Deserialize(Colosoft.Serialization.IO.CompactReader reader) { if (reader.ReadBoolean()) { _term = ConditionalTerm.GetConditionalTerm(reader); } }
/// <summary> /// Adiciona a condição inicial. Essa operação limpa todas a outras condições já existentes. /// </summary> /// <param name="conditional"></param> /// <returns></returns> public virtual ConditionalContainer Start(ConditionalTerm conditional) { conditional.Require("conditional").NotNull(); _conditionals.Clear(); _logicalOperators.Clear(); _conditionals.Add(conditional); return(this); }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> private GroupByEntry(SerializationInfo info, StreamingContext context) { var termType = info.GetString("TermType"); if (!string.IsNullOrEmpty(termType)) { _term = (ConditionalTerm)info.GetValue("Term", Type.GetType(termType, true)); } }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected Conditional(SerializationInfo info, StreamingContext context) : base(info, context) { var leftType = Type.GetType(info.GetString("LeftType")); var rightType = Type.GetType(info.GetString("RightType")); _left = (ConditionalTerm)info.GetValue("Left", typeof(ConditionalTerm)); _operator = (Operator)info.GetValue("Operator", typeof(Operator)); _right = (ConditionalTerm)info.GetValue("Right", typeof(ConditionalTerm)); }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected MinusTerm(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context) { var termType = info.GetString("TermType"); if (!string.IsNullOrEmpty(termType)) { _term = (ConditionalTerm)info.GetValue("Term", Type.GetType(termType, true)); } }
/// <summary> /// Preenche os dados da instancia com a expressões informadas. /// </summary> /// <param name="expressions"></param> private void Fill(List <Colosoft.Text.InterpreterExpression.Expression> expressions) { var enumerator = (IEnumerator <Text.InterpreterExpression.Expression>)expressions.GetEnumerator(); if (enumerator.MoveNext()) { _term = ConditionalParser.GetContainer(ref enumerator, new Text.InterpreterExpression.ContainerChars('(', ')')); } }
/// <summary> /// Adiciona uma condição do tipo OR. /// </summary> /// <param name="conditional"></param> /// <returns></returns> public virtual ConditionalContainer Or(ConditionalTerm conditional) { conditional.Require("conditional").NotNull(); _conditionals.Add(conditional); if (_conditionals.Count > 1) { _logicalOperators.Add(LogicalOperator.Or); } return(this); }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> private SortEntry(SerializationInfo info, StreamingContext context) { _reverse = info.GetBoolean("Reverse"); var termType = info.GetString("TermType"); if (!string.IsNullOrEmpty(termType)) { _term = (ConditionalTerm)info.GetValue("Term", Type.GetType(termType, true)); } }
/// <summary> /// Faz a desserialização do objeto. /// </summary> /// <param name="reader"></param> void Colosoft.Serialization.ICompactSerializable.Deserialize(Colosoft.Serialization.IO.CompactReader reader) { if (reader.ReadBoolean()) { _expression = ConditionalTerm.GetConditionalTerm(reader); } if (reader.ReadBoolean()) { _resultExpression = ConditionalTerm.GetConditionalTerm(reader); } }
/// <summary> /// Construtor para serialização. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected FunctionCall(SerializationInfo info, StreamingContext context) : base(info, context) { _call = (ConditionalTerm)info.GetValue("M", Type.GetType(info.GetString("T"), true)); var size = info.GetInt32("S"); _parameters = new ConditionalTerm[size]; for (var i = 0; i < size; ++i) { _parameters[i] = GetTerm(info, i); } _options = (FunctionCallOptions)info.GetInt32("Options"); }
/// <summary> /// Clona um array de valores. /// </summary> /// <returns></returns> public override object Clone() { var values = new ConditionalTerm[Values.Length]; for (int i = 0; i < Values.Length; i++) { values[i] = (ConditionalTerm)Values[i].Clone(); } return(new ValuesArray { Values = values }); }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected CaseWhenExpression(SerializationInfo info, StreamingContext context) { var expressionType = info.GetString("ExpressionType"); var resultExpressionType = info.GetString("ResultExpressionType"); if (!string.IsNullOrEmpty(expressionType)) { _expression = (ConditionalTerm)info.GetValue("Expression", Type.GetType(expressionType, true)); } if (!string.IsNullOrEmpty(resultExpressionType)) { _resultExpression = (ConditionalTerm)info.GetValue("ResultExpression", Type.GetType(resultExpressionType, true)); } }
void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement(); if (!reader.IsEmptyElement || reader.HasAttributes) { reader.ReadStartElement(); _term = ConditionalTerm.GetConditionalTerm(reader); reader.ReadEndElement(); } else { reader.Skip(); } reader.ReadEndElement(); }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="conditional">Condicionais do container.</param> public ConditionalContainer(ConditionalTerm conditional) { if (conditional != null) { _conditionals.Add(conditional); if (conditional is ConditionalContainer) { var cc = (ConditionalContainer)conditional; if (cc.ParameterContainer != this.ParameterContainer) { cc.ParameterContainer = this.ParameterContainer; } } } }
/// <summary> /// Lê os dados serializados para a instancia. /// </summary> /// <param name="reader"></param> protected override void ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement(); if (!reader.IsEmptyElement || reader.HasAttributes) { reader.ReadStartElement(); _term = GetConditionalTerm(reader); reader.ReadEndElement(); } else { reader.Skip(); } reader.ReadEndElement(); }
/// <summary> /// Serializa um termo na posição <paramref name="index"/>. /// </summary> /// <param name="info"></param> /// <param name="index"></param> /// <param name="term"></param> private static void SetTerm(SerializationInfo info, int index, ConditionalTerm term) { var tName = String.Format("t{0}", index); var pName = String.Format("p{0}", index); if (term == null) { info.AddValue(tName, "NULL"); } else { info.AddValue(tName, term.GetType().FullName); info.AddValue(pName, term); } }
/// <summary> /// Desserializa a instância previamente serializada em formato binário. /// </summary> /// <param name="reader"></param> protected override void Deserialize(CompactReader reader) { _call = GetConditionalTerm(reader); _options = (FunctionCallOptions)(int)reader.ReadInt32(); var size = reader.ReadInt32(); _parameters = new ConditionalTerm[size]; for (var i = 0; i < size; ++i) { if (reader.ReadBoolean()) { _parameters[i] = GetConditionalTerm(reader); } } }
/// <summary> /// Serializa o termo em formato xml. /// </summary> /// <param name="writer"></param> /// <param name="term"></param> private static void WriteTerm(XmlWriter writer, ConditionalTerm term) { var qName = term.QualifiedName; writer.WriteStartElement(qName.Name, qName.Namespace); if (!"ConditionalTerm".Equals(qName.Name)) { var prefix = writer.LookupPrefix(qName.Namespace); if (string.IsNullOrEmpty(prefix)) { writer.WriteAttributeString("xmlns", qName.Namespace); } } ((IXmlSerializable)term).WriteXml(writer); writer.WriteEndElement(); }
/// <summary> /// Faz a desserialização do objeto. /// </summary> /// <param name="reader"></param> protected override void Deserialize(Colosoft.Serialization.IO.CompactReader reader) { if (reader.ReadBoolean()) { _inputExpression = GetConditionalTerm(reader); } while (reader.ReadBoolean()) { var caseWhenExpression = new CaseWhenExpression(); ((Colosoft.Serialization.ICompactSerializable)caseWhenExpression).Deserialize(reader); _whenExpressions.Add(caseWhenExpression); } if (reader.ReadBoolean()) { _elseResultExpression = GetConditionalTerm(reader); } }
/// <summary> /// Serializa os dados no escritor informado. /// </summary> /// <param name="writer"></param> void System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter writer) { writer.WriteStartElement("Expression", Namespaces.Query); if (_expression != null) { ConditionalTerm.InsertConditionalTermType(writer, _expression); ((System.Xml.Serialization.IXmlSerializable)_expression).WriteXml(writer); } writer.WriteEndElement(); writer.WriteStartElement("ResultExpression", Namespaces.Query); if (_resultExpression != null) { ConditionalTerm.InsertConditionalTermType(writer, _resultExpression); ((System.Xml.Serialization.IXmlSerializable)_resultExpression).WriteXml(writer); } writer.WriteEndElement(); }
/// <summary> /// Determina se não existe chamada de função na avaliação do termo. /// </summary> /// <param name="term"></param> /// <returns></returns> public static bool HasNoFunctionCall(ConditionalTerm term) { if (term == null) { return(true); } if (term is FunctionCall) { return(false); } var cond = term as Conditional; if (cond == null) { return(true); } return(HasNoFunctionCall(cond.Left) && HasNoFunctionCall(cond.Right)); }
/// <summary> /// Faz a desserialização do objeto. /// </summary> /// <param name="reader"></param> protected override void Deserialize(Colosoft.Serialization.IO.CompactReader reader) { string position = reader.ReadString(); if (position == "Left") { _left = GetConditionalTerm(reader); } position = reader.ReadString(); if (position == "Operator") { _operator = (Operator)GetConditionalTerm(reader); } position = reader.ReadString(); if (position == "Right") { _right = GetConditionalTerm(reader); } }
/// <summary> /// Preenche os dados da instancia com a expressões informadas. /// </summary> /// <param name="expressions"></param> private void Fill(List <Colosoft.Text.InterpreterExpression.Expression> expressions) { var last = expressions.Last(); if (last.Token == (int)Parser.SqlTokenID.kDesc) { _reverse = true; } if (last.Token == (int)Parser.SqlTokenID.kAsc || last.Token == (int)Parser.SqlTokenID.kDesc) { expressions.RemoveAt(expressions.Count - 1); } var enumerator = (IEnumerator <Text.InterpreterExpression.Expression>)expressions.GetEnumerator(); if (enumerator.MoveNext()) { _term = ConditionalParser.GetContainer(ref enumerator, new Text.InterpreterExpression.ContainerChars('(', ')')); } }
/// <summary> /// Construtor usado na deserialização dos dados. /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected CaseConditional(SerializationInfo info, StreamingContext context) : base(info, context) { var inputExpressionType = info.GetString("InputExpressionType"); var elseResultExpressionType = info.GetString("ElseResultExpressionType"); if (!string.IsNullOrEmpty(inputExpressionType)) { _inputExpression = (ConditionalTerm)info.GetValue("InputExpression", Type.GetType(inputExpressionType, true)); } if (!string.IsNullOrEmpty(elseResultExpressionType)) { _elseResultExpression = (ConditionalTerm)info.GetValue("ElseResultExpression", Type.GetType(elseResultExpressionType, true)); } var count = info.GetInt32("WhenExpressionsCount"); for (var i = 0; i < count; i++) { _whenExpressions.Add((CaseWhenExpression)info.GetValue(string.Format("WhenExpression{0}", i), typeof(CaseWhenExpression))); } }
void System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader reader) { if (reader.MoveToAttribute("Reverse")) { _reverse = reader.ReadContentAsBoolean(); } reader.MoveToElement(); reader.ReadStartElement(); if (!reader.IsEmptyElement || reader.HasAttributes) { reader.ReadStartElement(); _term = ConditionalTerm.GetConditionalTerm(reader); reader.ReadEndElement(); } else { reader.Skip(); } reader.ReadEndElement(); }
/// <summary> /// Recupera os parametros. /// </summary> /// <param name="term"></param> /// <returns></returns> private static IEnumerable <QueryParameter> GetParameters(ConditionalTerm term) { if (term is Conditional) { var conditional = (Conditional)term; if (conditional.Left != null) { foreach (var i in GetParameters(conditional.Left)) { yield return(i); } } if (conditional.Right != null) { foreach (var i in GetParameters(conditional.Right)) { yield return(i); } } } else if (term is FunctionCall) { var functionCall = (FunctionCall)term; foreach (var parameter in functionCall.Parameters) { foreach (var i in GetParameters(parameter)) { yield return(i); } } } else if (term is ConditionalContainer) { foreach (var i in GetParameters((ConditionalContainer)term)) { yield return(i); } } }
/// <summary> /// Lê os dados serializados em XML. /// </summary> /// <param name="reader"></param> protected override void ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement(); if (!reader.IsEmptyElement || reader.HasAttributes) { _inputExpression = GetConditionalTerm(reader); } else { reader.Skip(); } if (!reader.IsEmptyElement && reader.LocalName == "WhenExpressions") { reader.ReadStartElement("WhenExpressions", Namespaces.Query); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { var caseWhenExpression = new CaseWhenExpression(); ((System.Xml.Serialization.IXmlSerializable)caseWhenExpression).ReadXml(reader); _whenExpressions.Add(caseWhenExpression); } reader.ReadEndElement(); } else { reader.Skip(); } if (!reader.IsEmptyElement || reader.HasAttributes) { _elseResultExpression = GetConditionalTerm(reader); } else { reader.Skip(); } reader.ReadEndElement(); }