예제 #1
0
        public void SearchArgumentSerializeTest()
        {
            var query1 = new Library.Query();

            query1.Uri.Add("local:track");
            query1.TrackName.Add("Feel The Breeze");
            query1.Album.Add("Strangers In Love");
            query1.Artist.Add("Air Supply");
            query1.AlbumArtist.Add("Air Supply");
            query1.Composer.Add("Air Supply");
            query1.Performer.Add("Air Supply");
            query1.TrackNo.Add(1);
            query1.Genre.Add("AOR");
            query1.Date.Add("1976");
            query1.Comment.Add("Air Supply");
            query1.Any.Add("Air Supply");

            string json = null;

            try
            {
                json = JsonConvert.SerializeObject(query1);
            }
            catch (Exception)
            {
                Assert.True(false, "Query Serialize Error");
            }
        }
예제 #2
0
        /// <summary>
        /// Evaluates a single SIF_Condition
        /// </summary>
        /// <param name="query"></param>
        /// <param name="cond"></param>
        /// <param name="str"></param>
        /// <param name="table"></param>
        /// <exception cref="QueryFormatterException">Thrown if no mapping was found for a requested element</exception>
        /// <param name="isExplicit"></param>
        protected virtual void EvaluateCondition(Library.Query query,
                                                 Condition cond,
                                                 StringBuilder str,
                                                 IDictionary table,
                                                 bool isExplicit)
        {
            String path = cond.GetXPath();
            Object o    = table[path];

            if (o == null)
            {
                IElementDef field = cond.Field;
                if (field != null)
                {
                    o = table[field];
                }
            }

            if (o == null)
            {
                if (isExplicit)
                {
                    throw new QueryFormatterException
                          (
                              "QueryFormatter was not provided with an application-defined field value for " +
                              query.ObjectTag + "/" + cond.GetXPath() +
                              "; cannot format the SIF_Query");
                }
                else
                {
                    // Render a default operation that will always return true
                    // as a placeholder
                    str.Append("1=1");
                    return;
                }
            }

            if (o is IQueryField)
            {
                str.Append(((IQueryField)o).Render(this, query, cond));
            }
            else
            {
                str.Append(RenderField(cond.Field, o));
                str.Append(GetOperator(cond.Operators));
                str.Append(RenderValue(cond.Value, o));
            }
        }
예제 #3
0
        public virtual string Format(Library.Query query,
                                     IDictionary table, bool isExplicit)
        {
            StringBuilder str = new StringBuilder();

            ConditionGroup[] grp = query.Conditions;
            for (int c = 0; c < grp.Length; c++)
            {
                str.Append(OpenBrace);
                EvaluateConditionGroup(query, grp[c], str, table, isExplicit);
                str.Append(CloseBrace);

                if (c != grp.Length - 1)
                {
                    str.Append(GetOperator(query.RootConditionGroup.Operator));
                }
            }

            return(str.ToString());
        }
예제 #4
0
        protected internal virtual void EvaluateConditionGroup(Library.Query query,
                                                               ConditionGroup grp,
                                                               StringBuilder str,
                                                               IDictionary table,
                                                               bool isExplicit)
        {
            Condition[] conds = grp.Conditions;

            if (conds.Length != 0)
            {
                for (int i = 0; i < conds.Length; i++)
                {
                    EvaluateCondition(query, conds[i], str, table, isExplicit);

                    if (i != conds.Length - 1)
                    {
                        str.Append(GetOperator(grp.Operator));
                    }
                }
            }
            else
            {
                ConditionGroup[] groups = grp.Groups;

                for (int i = 0; i < groups.Length; i++)
                {
                    str.Append(OpenBrace);
                    EvaluateConditionGroup(query, groups[i], str, table, isExplicit);
                    str.Append(CloseBrace);

                    if (i != groups.Length - 1)
                    {
                        str.Append(GetOperator(grp.Operator));
                    }
                }
            }
        }
예제 #5
0
        public async Task SearchByClassTest()
        {
            var query = new Library.Query();

            query.Uri.Add("local:track");
            query.TrackName.Add("Feel The Breeze");
            query.Album.Add("Strangers In Love");
            query.Artist.Add("Air Supply");
            query.AlbumArtist.Add("Air Supply");
            query.Composer.Add("Air Supply");
            query.Performer.Add("Air Supply");
            query.TrackNo.Add(1);
            query.Genre.Add("AOR");
            query.Date.Add("1976");
            query.Comment.Add("Air Supply");
            query.Any.Add("Air Supply");

            var res1 = await Library.Search(
                query : query,
                uris : new string[] { "local:track" },
                exact : true
                );

            Assert.True(res1.Succeeded);

            query.Clear();
            query.TrackName.Add("Feel The Breeze");
            query.Album.Add("Strangers In Love");
            query.Artist.Add("Air Supply");
            query.AlbumArtist.Add("Air Supply");
            query.TrackNo.Add(1);
            query.Genre.Add("AOR");
            query.Date.Add("1976");

            var res2 = await Library.Search(
                query : query
                );

            Assert.True(res2.Succeeded);

            query.Clear();
            query.Uri.Add("local:track");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.TrackName.Add("Feel The Breeze");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Album.Add("Strangers In Love");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Artist.Add("Air Supplym");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.AlbumArtist.Add("Air Supply");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Composer.Add("Air Supply");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Performer.Add("Air Supply");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.TrackNo.Add(1);
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Genre.Add("AOR");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Date.Add("1976");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Comment.Add("Air Supply");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.Any.Add("Air Supply");
            Assert.True((await Library.Search(query)).Succeeded);

            query.Clear();
            query.TrackNo.Add(1);
            var res3 = await Library.Search(query);

            Assert.True(res3.Succeeded);
        }
예제 #6
0
 /// <summary>  Builds a query string given a dictionary of mappings and a Query
 /// instance. This method evaluates the conditions of that Query to produce
 /// a textual query string in format determined by the implementation.</summary>
 /// <para>
 /// The Map should contain application-defined field values that map
 /// to <c>ElementDef</c> key elements. Whenever a SIF element or attribute
 /// is found in the Query, the corresponding application-defined field is
 /// used in its place.
 /// </para>
 /// <para>
 /// A special convention allows agents to also map field values: If a field
 /// in the Map is expressed in the form "field-name{value1=cons1;value2=cons2;..}",
 /// the list of value replacements within the curly braces is applied to the
 /// value of the SIF_Value element in the SIF_Query. For example, the
 /// acceptable values for LibraryPatronStatus/@SifRefIdType attribute are
 /// "StudentPersonal" and "StaffPersonal". If in your application you
 /// represent these values as numeric types - say, 1 and 2, respectively -
 /// you could create the following field mapping to instruct the QueryFormatter
 /// to substitute "StudentPersonal" with "1" and "StaffPersonal" with "2":
 ///
 /// "MyCircStatus.Type{StudentPersonal=1;StaffPersonal=2}"
 /// </para>
 /// <param name="query">An ADK Query object, usually obtained during the processing
 /// of a SIF_Request by a <i>Publisher</i> message handler
 /// </param>
 /// <param name="table">A dictionary that maps SIFDTD ElementDef constants to
 /// application-defined field values
 /// </param>
 /// <exception cref="QueryFormatterException">Thrown if the query contains conditions that are not mapped in the table</exception>
 public virtual string Format(Library.Query query,
                              IDictionary table)
 {
     return(Format(query, table, true));
 }