internal void CalculateSync() { if (SyncEntireLibrary) { sync_src.ConditionTree = null; } else if (SyncSource != null) { var src = SyncSource; QueryListNode playlists_node = new QueryListNode(Keyword.Or); if (src is PlaylistSource) { playlists_node.AddChild(UserQueryParser.Parse(String.Format("playlistid:{0}", (src as PlaylistSource).DbId), BansheeQuery.FieldSet)); } else if (src is SmartPlaylistSource) { playlists_node.AddChild(UserQueryParser.Parse(String.Format("smartplaylistid:{0}", (src as SmartPlaylistSource).DbId), BansheeQuery.FieldSet)); } sync_src.ConditionTree = playlists_node; } sync_src.RefreshAndReload(); to_add.RefreshAndReload(); to_remove.RefreshAndReload(); }
private void BuildSyncLists() { // This smart playlist is the list of items we want on the device - nothing more, nothing less sync_src = new SmartPlaylistSource("sync_list", library); sync_src.IsTemporary = true; sync_src.Save(); sync_src.AddCondition(library.AttributesCondition); sync_src.AddCondition(library.SyncCondition); // This is the same as the previous list with the items that are already on the device removed to_add = new SmartPlaylistSource("to_add", library); to_add.IsTemporary = true; to_add.Save(); to_add.ConditionTree = UserQueryParser.Parse(String.Format("smartplaylistid:{0}", sync_src.DbId), Banshee.Query.BansheeQuery.FieldSet); to_add.DatabaseTrackModel.AddCondition(String.Format( "MetadataHash NOT IN (SELECT MetadataHash FROM CoreTracks WHERE PrimarySourceId = {0})", sync.Dap.DbId )); // Any items on the device that aren't in the sync lists need to be removed to_remove = new SmartPlaylistSource("to_remove", sync.Dap); to_remove.IsTemporary = true; to_remove.Save(); to_remove.AddCondition(library.AttributesCondition); to_remove.AddCondition(String.Format( @"MetadataHash NOT IN (SELECT MetadataHash FROM CoreTracks, CoreSmartPlaylistEntries WHERE CoreSmartPlaylistEntries.SmartPlaylistID = {0} AND CoreTracks.TrackID = CoreSmartPlaylistEntries.TrackID)", sync_src.DbId )); }
void OnParseUserQuery(object o, EventArgs args) { var parser = new UserQueryParser { InputReader = StringToStream(input.Buffer.Text) }; var node = parser.BuildTree(query_field_set); sql.Buffer.Text = node.ToSql(query_field_set) ?? string.Empty; var doc = new XmlDocument(); doc.LoadXml(node.ToXml(query_field_set)); var s = new MemoryStream(); var w = new XmlTextWriter(s, System.Text.Encoding.UTF8) { Formatting = Formatting.Indented }; doc.WriteContentTo(w); w.Flush(); s.Flush(); s.Position = 0; xml.Buffer.Text = new StreamReader(s).ReadToEnd(); }
private void GenerateUserQueryFragment() { if (!have_new_user_query) { return; } if (String.IsNullOrEmpty(UserQuery)) { query_fragment = null; query_tree = null; } else { query_tree = UserQueryParser.Parse(UserQuery, BansheeQuery.FieldSet); query_fragment = (query_tree == null) ? null : query_tree.ToSql(BansheeQuery.FieldSet); if (query_fragment != null && query_fragment.Length == 0) { query_fragment = null; query_tree = null; } } have_new_user_query = false; }
// Test behavior issues described in // http://bugzilla.gnome.org/show_bug.cgi?id=547078 public void ParenthesesInQuotes() { string query = "artist==\"foo (disc 2)\""; QueryNode query_tree = UserQueryParser.Parse(query, FieldSet); Assert.IsNotNull(query_tree, "Query should parse"); Assert.AreEqual("by==\"foo (disc 2)\"", query_tree.ToUserQuery()); }
public SmartPlaylistSource ToSmartPlaylistSource(PrimarySource primary_source) { return(new SmartPlaylistSource( Name, UserQueryParser.Parse(Condition, BansheeQuery.FieldSet), Order, Limit, LimitNumber, primary_source )); }
private static void UserQueryParsesAndGenerates(string query) { QueryNode node = UserQueryParser.Parse(query, FieldSet); if (query == null || query.Trim() == String.Empty) { Assert.AreEqual(node, null); return; } Assert.AreEqual(query, node.ToUserQuery()); }
public SearchResultInfo SearchFiles(string query) { string sql; IDbCommand command; DataSet ds; int x; SearchResultInfo result; var directories = new List <string>(); var files = new List <SharedFileListing>(); result = new SearchResultInfo(); var queryNode = UserQueryParser.Parse(query, FieldSet); var queryFragment = queryNode.ToSql(FieldSet); var sb = new StringBuilder(); sb.Append("SELECT * FROM directoryitems WHERE "); sb.Append(queryFragment); sb.AppendFormat(" LIMIT {0}", MAX_RESULTS); UseConnection(delegate(IDbConnection connection) { command = connection.CreateCommand(); command.CommandText = sb.ToString(); ds = ExecuteDataSet(command); for (x = 0; x < ds.Tables[0].Rows.Count; x++) { if (ds.Tables[0].Rows[x]["type"].ToString() == "F") { files.Add(new SharedFileListing(LocalFile.FromDataRow(core.FileSystem, ds.Tables[0].Rows[x]), false)); } else { var dir = LocalDirectory.FromDataRow(this, ds.Tables[0].Rows[x]); // FIXME: Ugly: Remove '/local' from begining of path var path = "/" + string.Join("/", dir.FullPath.Split('/').Slice(2)); directories.Add(path); } } }); result.Files = files.ToArray(); result.Directories = directories.ToArray(); return(result); }
private void SetCustomSearchCriteria(ref SearchBuilder sb) { sb.Table = "[v_Asset]"; if (AuditAssetHistoryFinder != null) { AuditAssetHistoryFinder.OnlyDistinctAssetIds = true; sb.Criteria.Add(sb.TableAlias + ".AssetId IN (" + AuditAssetHistoryFinder.FindQuery + ")"); } if (Orientation != Orientation.All) { string sql = string.Empty; switch (Orientation) { case (Orientation.Portrait): sql = string.Format("[Height] > [Width]"); break; case (Orientation.Landscape): sql = string.Format("[Height] < [Width]"); break; case (Orientation.Square): sql = string.Format("[Height] = [Width]"); break; } if (sql != string.Empty) { sb.Criteria.Add(string.Format("({0})", sql)); } } if (GeneralKeyword != string.Empty) { if (FullTextSearchedEnabled) { UserQueryParser uq = new UserQueryParser(); bool isValid = uq.ParseTokens(GeneralKeyword); if (isValid) { string query = uq.GetSqlQuery(); SetFullTextSearchCriteria(sb, query); } else { string error = string.Format("Error parsing user query: \"{0}\" - {1}", GeneralKeyword, uq.Error); Debug.WriteLine(error); } } else { JoinableList jList = GetStandardSectorSearchSql(); sb.Criteria.Add(string.Format("({0})", jList)); } } if (IsBeforePublicationDate) { sb.Criteria.Add(string.Format("({0} > getdate())", Asset.Columns.PublishDate)); } if (IsExpired.HasValue) { sb.Criteria.Add("dbo.IsExpired(" + sb.TableAlias + ".ExpiryDate) = @isExpired"); sb.AddDataParameter("@isExpired", SqlUtils.BitValue(IsExpired.GetValueOrDefault())); } if (!ExpiryDateRange.IsNull) { const string dateFormat = "dd MMMM yyyy HH:mm:ss"; if (ExpiryDateRange.StartDate.HasValue && ExpiryDateRange.EndDate.HasValue) { sb.Criteria.Add(string.Format("({0} BETWEEN '{1}' AND '{2}')", Asset.Columns.ExpiryDate, ExpiryDateRange.StartDate.Value.ToString(dateFormat), ExpiryDateRange.EndDate.Value.ToString(dateFormat))); } else { if (ExpiryDateRange.StartDate.HasValue) { sb.Criteria.Add(string.Format("({0} >= '{1}')", Asset.Columns.ExpiryDate, ExpiryDateRange.StartDate.Value.ToString(dateFormat))); } if (ExpiryDateRange.EndDate.HasValue) { sb.Criteria.Add(string.Format("({0} <= '{1}')", Asset.Columns.ExpiryDate, ExpiryDateRange.EndDate.Value.ToString(dateFormat))); } } } foreach (ComplexCriteria cc in m_ComplexCriteria) { string operand; switch (cc.CompareType) { case (CompareType.LessThan): operand = "<"; break; case (CompareType.MoreThan): operand = ">"; break; default: operand = "="; break; } sb.Criteria.Add(string.Format("({0} {1} {2})", cc.Field, operand, cc.Value)); } if (IsCompletelyPublished) { // Entire clause JoinableList jList1 = new JoinableList(" OR "); // Currently published JoinableList jList2 = new JoinableList(" AND "); jList2.Add(string.Format("{0} = {1}", Asset.Columns.AssetPublishStatusId, Convert.ToInt32(AssetPublishStatus.Published))); jList2.Add(string.Format("{0} < getdate()", Asset.Columns.PublishDate)); jList2.Add(string.Format("{0} > getdate()", Asset.Columns.ExpiryDate)); // Add to entire clause jList1.Add(jList2); // If unpublished and expired assets need to be displayed too, we need to expand this criteria as follows: // 1. All admin users should see their own assets // 2. Brand admins should see assets in their primary brand // 3. Super admins should see all assets if (IncludeUnpublishedExpiredAssets) { JoinableList jList3 = new JoinableList(" OR "); if (IncludeUnpublishedExpiredAssets_UserId > 0) { jList3.Add(string.Format("({0}={1})", Asset.Columns.UploadedByUserId, IncludeUnpublishedExpiredAssets_UserId)); } if (IncludeUnpublishedExpiredAssets_BrandId > 0) { jList3.Add(string.Format("({0}={1})", Asset.Columns.BrandId, IncludeUnpublishedExpiredAssets_BrandId)); } if (jList3.Count > 0) { jList1.Add(jList3); } } string criteria = jList1.ToString(); if (!StringUtils.IsBlank(criteria)) { sb.Criteria.Add(string.Format("({0})", criteria)); } } if (IsPublished.HasValue) { string op = (IsPublished.Value) ? " = " : " <> "; sb.Criteria.Add(string.Concat(Asset.Columns.AssetPublishStatusId, op, Convert.ToInt32(AssetPublishStatus.Published))); } if (BrandIdList.Count > 0) { JoinableList jList = new JoinableList(BrandIdList); sb.Criteria.Add(string.Format("BrandId IN ({0})", jList)); } // Production date filter SetProductionMonthDayCriteria(sb); // Metadata filters AddMetadataCriteria(sb); // Category filters AddManyToManyCriteria(sb, "AssetCategory", "CategoryId", CategoryIdList); // Setup results ordering AddOrderByClause(); Debug.WriteLine(string.Format("AssetFinder: {0}", sb.GetFullQuery())); }