Ejemplo n.º 1
0
        public void CreateQueryConditionWithAllParameters()
        {
            const string ColumnName = "some column 2";
            const LearningStoreConditionOperator Condition = LearningStoreConditionOperator.LessThan;
            var obj = TimeZone.CurrentTimeZone;

            var queryCondition = new QueryCondition(ColumnName, Condition, obj);

            Assert.AreEqual(ColumnName, queryCondition.ColumnName);
            Assert.AreEqual(Condition, queryCondition.ConditionOperator);
            Assert.AreSame(obj, queryCondition.Value);
        }
        /// <summary>
        /// Initializes a new instance of the <Typ>LearningStoreCondition</Typ> class.
        /// </summary>
        /// <param name="column"></param>
        /// <param name="conditionOperator"></param>
        /// <param name="conditionValue"></param>
        public LearningStoreCondition(LearningStoreViewColumn column, LearningStoreConditionOperator conditionOperator, object conditionValue)
        {
            // Check the parameters
            if (column == null)
            {
                throw new LearningComponentsInternalException("LSTR2200");
            }
            if ((conditionOperator != LearningStoreConditionOperator.Equal) &&
                (conditionOperator != LearningStoreConditionOperator.GreaterThan) &&
                (conditionOperator != LearningStoreConditionOperator.GreaterThanEqual) &&
                (conditionOperator != LearningStoreConditionOperator.LessThan) &&
                (conditionOperator != LearningStoreConditionOperator.LessThanEqual) &&
                (conditionOperator != LearningStoreConditionOperator.NotEqual))
            {
                throw new LearningComponentsInternalException("LSTR2210");
            }

            m_column            = column;
            m_conditionOperator = conditionOperator;
            m_conditionValue    = conditionValue;
        }
Ejemplo n.º 3
0
 public QueryCondition(string columnName, LearningStoreConditionOperator conditionOperator, object value)
 {
     this.ColumnName = columnName;
     this.ConditionOperator = conditionOperator;
     this.Value = value;
 }
        /// <summary>
        /// Add a condition that restricts the data returned in a query.
        /// </summary>
        /// <param name="columnName">Name of the column to be compared</param>
        /// <param name="conditionOperator">Condition operator</param>
        /// <param name="conditionValue">Value to be compared against.</param>
        /// <exception cref="ArgumentNullException"><paramref name="columnName"/> is a null reference.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="conditionOperator"/> is invalid.</exception>
        /// <exception cref="InvalidOperationException">
        ///     Invalid comparison, the column name wasn't found in the view, or an invalid
        ///     <paramref name="conditionValue"/> value.</exception>
        /// <remarks>
        /// See the <Typ>LearningStoreQuery</Typ> documentation for more
        /// information about creating and executing queries.
        /// <p/>
        /// <paramref name="conditionValue"/> must contain a value
        ///     that is valid based on the type of the column specified by
        ///     <paramref name="columnName"/>:
        /// <ul>
        /// <li><b>Boolean:</b> A System.Boolean, or an object that can be converted into
        ///     a System.Boolean using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>ByteArray</b> A System.Byte array.</li>
        /// <li><b>DateTime:</b> A System.DateTime, or an object that can be converted into
        ///     a System.DateTime using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>Double:</b> A System.Double, or an object that can be converted into
        ///     a System.Double using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>Enumeration:</b> An System.Int32, or an object that can be converted into
        ///     a System.Int32 using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>Guid</b> A System.Guid or a string representing a Guid.</li>
        /// <li><b>Item identifier:</b> A <Typ>LearningStoreItemIdentifier</Typ>
        ///     of the associated item type.</li>
        /// <li><b>Int32:</b> A System.Int32, or an object that can be converted into
        ///     a System.Int32 using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>Single:</b> A System.Single, or an object that can be converted into
        ///     a System.Single using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>String:</b> A System.String, or an object that can be converted into
        ///     a System.String using <Typ>/System.IConvertible</Typ>.</li>
        /// <li><b>Xml:</b> A <Typ>LearningStoreXml</Typ>.</li>
        /// </ul>
        /// <p/>
        /// <paramref name="conditionValue"/> must not contain a <Typ>LearningStoreItemIdentifier</Typ> returned
        ///     from <Mth>../LearningStoreJob.AddItem</Mth>.
        /// <p/>
        /// If <paramref name="columnName"/> refers to an XML column, then the following restrictions apply:
        /// <ul>
        /// <li><paramref name="conditionOperator"/> must be <Fld>../LearningStoreConditionOperator.Equal</Fld> or
        ///     <Fld>../LearningStoreConditionOperator.NotEqual</Fld></li>
        /// <li><paramref name="conditionValue"/> must be null.</li>
        /// </ul>
        /// <p/>
        /// If <paramref name="columnName"/> refers to an Guid column, then the following restrictions apply:
        /// <ul>
        /// <li><paramref name="conditionOperator"/> must be <Fld>../LearningStoreConditionOperator.Equal</Fld> or
        ///     <Fld>../LearningStoreConditionOperator.NotEqual</Fld></li>
        /// </ul>
        /// <p/>
        /// If <paramref name="conditionOperator"/> is <Fld>../LearningStoreConditionOperator.GreaterThan</Fld>,
        ///     <Fld>../LearningStoreConditionOperator.GreaterThanEqual</Fld>,
        ///     <Fld>../LearningStoreConditionOperator.LessThan</Fld>, or
        ///     <Fld>../LearningStoreConditionOperator.LessThanEqual</Fld>, then
        ///     <paramref name="conditionValue"/> must not contain null.
        /// <p/>
        /// Care must be taken when null is involved in a comparison.  In
        /// particular:<ul>
        /// <li>null == null: True</li>
        /// <li>null != null: False</li>
        /// <li>null == any other value: False</li>
        /// <li>null != any other value: True</li>
        /// <li>null &lt; any other value: False</li>
        /// <li>null &gt; any other value: False</li>
        /// </ul>
        /// </remarks>
        /// <example>
        /// The following code creates a new query that returns the id and name
        /// of the users with a name less than "Joe":
        /// <code language="C#">
        /// LearningStoreQuery query = store.CreateQuery("UserItem");
        /// query.AddColumn("Id");
        /// query.AddColumn("Name");
        /// query.AddCondition("Name", LearningStoreConditionOperator.LessThan, "Joe");
        /// </code>
        /// </example>
        public void AddCondition(string columnName, LearningStoreConditionOperator conditionOperator, object conditionValue)
        {
            // Check input parameters
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }
            else if ((conditionOperator != LearningStoreConditionOperator.Equal) &&
                     (conditionOperator != LearningStoreConditionOperator.GreaterThan) &&
                     (conditionOperator != LearningStoreConditionOperator.GreaterThanEqual) &&
                     (conditionOperator != LearningStoreConditionOperator.LessThan) &&
                     (conditionOperator != LearningStoreConditionOperator.LessThanEqual) &&
                     (conditionOperator != LearningStoreConditionOperator.NotEqual))
            {
                throw new ArgumentOutOfRangeException("conditionOperator");
            }

            // Find the column in the view
            LearningStoreViewColumn column = null;

            if (!m_view.TryGetColumnByName(columnName, out column))
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, LearningStoreStrings.ColumnNotFound, columnName));
            }

            // Cast the comparison value to the associated property type
            conditionValue = column.CastValue(conditionValue, m_locale,
                                              delegate(string reason, Exception innerException)
            {
                return(new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, LearningStoreStrings.InvalidConditionValueWithDescription, reason), innerException));
            }
                                              );

            // Fail if operator isn't compatible with null
            if ((conditionValue == null) &&
                (conditionOperator != LearningStoreConditionOperator.Equal) &&
                (conditionOperator != LearningStoreConditionOperator.NotEqual))
            {
                throw new InvalidOperationException(LearningStoreStrings.InvalidOperatorForNullConditionValue);
            }

            // Verify special rules for Xml properties
            if ((column.IsXml) && (conditionValue != null))
            {
                throw new InvalidOperationException(LearningStoreStrings.InvalidConditionValueForXmlColumn);
            }

            // Verify special rules for Guid properties
            if ((column.IsGuid) &&
                (conditionOperator != LearningStoreConditionOperator.Equal) &&
                (conditionOperator != LearningStoreConditionOperator.NotEqual))
            {
                throw new InvalidOperationException(LearningStoreStrings.InvalidConditionOperatorForGuidColumn);
            }

            // Verify special rules for LearningStoreItemIdentifier properties
            LearningStoreItemIdentifier idConditionValue = conditionValue as LearningStoreItemIdentifier;

            if ((idConditionValue != null) && (!idConditionValue.HasKey))
            {
                throw new InvalidOperationException(LearningStoreStrings.InvalidIdConditionValue);
            }

            // Add the condition
            LearningStoreCondition condition = new LearningStoreCondition(column, conditionOperator, conditionValue);

            m_conditions.Add(condition);
        }
Ejemplo n.º 5
0
 public QueryCondition(string columnName, LearningStoreConditionOperator conditionOperator, object value)
 {
     this.ColumnName        = columnName;
     this.ConditionOperator = conditionOperator;
     this.Value             = value;
 }
Ejemplo n.º 6
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Internal Methods
        //

        /// <summary>
        /// Initializes an instance of this class.
        /// </summary>
        ///
        /// <param name="viewColumnName">The value to use for the <c>ViewColumnName</c> property.
        ///     </param>
        ///
        /// <param name="oper">The value to use for the <c>Operator</c> property.  Note that
        ///     if this value is "IsNull" or "IsNotNull" then
        ///     <c>LearningStoreConditionOperator.Equal</c> or
        ///     <c>LearningStoreConditionOperator.NotEqual</c>, respectively, is used for the
        ///     <c>Operator</c> property; in this case <c>null</c> should be used for
        ///     <paramref name="value"/>.</param>
        ///
        /// <param name="value">The value to use for the <c>Value</c> property.</param>
        ///
        /// <param name="macroName">The value to use for the <c>MacroName</c> property.</param>
        ///
        /// <param name="noConditionOnNull">The value to use for the <c>NoConditionOnNull</c> property.
        ///     </param>
        ///
        /// <param name="lineNumber">The line number of the "&lt;Condition&gt;" element with the
        ///     XML file.</param>
        ///
        /// <remarks>
        /// Note that one of <paramref name="value"/> and <paramref name="macroName"/> must be
        /// non-null unless <paramref name="oper"/> equals "IsNull" or "IsNotNull".
        /// </remarks>
        ///
        internal ConditionDefinition(string viewColumnName, string oper, string value, string macroName, bool noConditionOnNull, int lineNumber)
        {
            // store state
            m_viewColumnName = viewColumnName;
            switch (oper)
            {
            case "Equal":
                m_operator = LearningStoreConditionOperator.Equal;
                break;

            case "GreaterThan":
                m_operator = LearningStoreConditionOperator.GreaterThan;
                break;

            case "GreaterThanEqual":
                m_operator = LearningStoreConditionOperator.GreaterThanEqual;
                break;

            case "LessThan":
                m_operator = LearningStoreConditionOperator.LessThan;
                break;

            case "LessThanEqual":
                m_operator = LearningStoreConditionOperator.LessThanEqual;
                break;

            case "NotEqual":
                m_operator = LearningStoreConditionOperator.NotEqual;
                break;

            case "IsNull":
                m_operator = LearningStoreConditionOperator.Equal;
                if ((value != null) || (macroName != null))
                {
                    throw new ArgumentException(SlkCulture.GetResources().SlkUtilitiesValueNullifIsNull, "operator");
                }
                break;

            case "IsNotNull":
                m_operator = LearningStoreConditionOperator.NotEqual;
                if ((value != null) || (macroName != null))
                {
                    throw new ArgumentException(SlkCulture.GetResources().SlkUtilitiesValueNullifIsNotNull, "operator");
                }
                break;
            }

            m_value = value;

            if (string.IsNullOrEmpty(macroName) == false)
            {
                MacroResolver.ValidateMacro(macroName);
            }

            m_macroName         = macroName;
            m_noConditionOnNull = noConditionOnNull;
            m_lineNumber        = lineNumber;

            // only one of <value> and <macroName> may be provided
            if ((value != null) && (macroName != null))
            {
                throw new ArgumentException(SlkCulture.GetResources().SlkUtilitiesOneValueNonNull, "value");
            }

            // if <noConditionOnNull> is true, <macroName> must be provided
            if (noConditionOnNull && (macroName == null))
            {
                throw new ArgumentException(SlkCulture.GetResources().SlkUtilitiesMacroNameNotProvided, "noConditionOnNull");
            }
        }