private void RemoveStaleReminders(ISet <string> prefixes, SearchQuery.Or query)
        {
            // Remove all operands for which we do not want the prefix
            for (int i = 0; i < query.Operands.Count;)
            {
                SearchQuery.PropertyContent element = query.Operands[i] as SearchQuery.PropertyContent;
                if (element != null)
                {
                    string prefix = (string)element.Content;
                    if (prefixes.Contains(prefix))
                    {
                        ++i;
                        continue;
                    }

                    Logger.Instance.Trace(this, "Unwanted prefix at {0}: {1}", i, prefix);
                    query.Operands.RemoveAt(i);
                    _queryCustomModified = true;
                }
                else
                {
                    ++i;
                }
            }
        }
        override public bool Open()
        {
            if (_queryCustomShared != null && _queryCustomConfigured != null)
            {
                return(true);
            }

            try
            {
                _queryRoot = FolderQuery;
                if (!(_queryRoot is SearchQuery.And))
                {
                    return(false);
                }
                Logger.Instance.Trace(this, "Current query:\n{0}", _queryRoot.ToString());

                SearchQuery.And root = (SearchQuery.And)_queryRoot;
                // TODO: more strict checking of query
                if (root.Operands.Count == 5)
                {
                    this._queryCustomShared     = root.Operands.ElementAt(2) as SearchQuery.Or;
                    this._queryCustomConfigured = root.Operands.ElementAt(3) as SearchQuery.Or;
                    if (this._queryCustomShared != null)
                    {
                        // TODO: check property test
                        return(true);
                    }
                }
                else if (root.Operands.Count == 3)
                {
                    // KOE-98 introduced also checking of G and C prefixes, which are not yet present
                    _queryCustomShared = root.Operands.ElementAt(2) as SearchQuery.Or;
                }

                // We have the root, but not the custom query. Create it.
                Logger.Instance.Trace(this, "Creating custom query");
                if (_queryCustomShared == null)
                {
                    _queryCustomShared = AddCustomQuery(root, "S");
                }
                _queryCustomConfigured = AddCustomQuery(root, "C");
                // Add the G (GAB) exclusion. Folders will never have a flag with this prefix, so it's simpler
                root.Operands.Add(new SearchQuery.Not(
                                      new SearchQuery.PropertyContent(
                                          PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, "G"
                                          )
                                      ));

                Logger.Instance.Trace(this, "Modified query:\n{0}", root.ToString());
                // Store it
                FolderQuery = root;
                Logger.Instance.Trace(this, "Modified query readback:\n{0}", FolderQuery);
            }
            catch (Exception e)
            {
                Logger.Instance.Error(this, "Exception in Open: {0}", e);
            }
            return(_queryCustomShared != null && _queryCustomConfigured != null);
        }
Beispiel #3
0
        public bool Open()
        {
            if (_queryCustom != null)
            {
                return(true);
            }
            try
            {
                _queryRoot = FolderQuery;
                if (!(_queryRoot is SearchQuery.And))
                {
                    return(false);
                }
                Logger.Instance.Debug(this, "Current query:\n{0}", _queryRoot.ToString());

                SearchQuery.And root = (SearchQuery.And)_queryRoot;
                // TODO: more strict checking of query
                if (root.Operands.Count == 3)
                {
                    this._queryCustom = root.Operands.ElementAt(2) as SearchQuery.Or;
                    if (this._queryCustom != null)
                    {
                        // TODO: check property test
                        return(true);
                    }
                }

                // We have the root, but not the custom query. Create it.
                Logger.Instance.Debug(this, "Creating custom query");
                _queryCustom = new SearchQuery.Or();

                // Add the prefix exclusion for shared folders
                _queryCustom.Add(
                    new SearchQuery.Not(
                        new SearchQuery.PropertyContent(
                            PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, "S"
                            )
                        )
                    );

                root.Operands.Add(_queryCustom);
                Logger.Instance.Debug(this, "Modified query:\n{0}", root.ToString());
                // Store it
                FolderQuery = root;
                Logger.Instance.Debug(this, "Modified query readback:\n{0}", FolderQuery);
            }
            catch (Exception e)
            {
                Logger.Instance.Error(this, "Exception in Open: {0}", e);
            }
            return(_queryCustom != null);
        }
        private SearchQuery.Or AddCustomQuery(SearchQuery.And root, string prefix)
        {
            SearchQuery.Or custom = new SearchQuery.Or();

            // Add the prefix exclusion
            custom.Add(
                new SearchQuery.Not(
                    new SearchQuery.PropertyContent(
                        PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, prefix
                        )
                    )
                );

            root.Operands.Add(custom);
            return(custom);
        }
        private void UpdateReminders(SearchQuery.Or query, SyncId folderId, bool wantReminders)
        {
            string prefix = MakeFolderPrefix(folderId);

            if (prefix == null)
            {
                return;
            }

            // Find existing
            for (int i = 0; i < query.Operands.Count;)
            {
                SearchQuery.PropertyContent element = query.Operands[i] as SearchQuery.PropertyContent;
                if (element != null && prefix == (string)element.Content)
                {
                    Logger.Instance.Trace(this, "Found at {0}: {1}", i, folderId);
                    // Found it. If we want reminders, we're done
                    if (wantReminders)
                    {
                        return;
                    }

                    // Otherwise remove it. Still continue looking for others, just in case of duplicates
                    query.Operands.RemoveAt(i);
                    _queryCustomModified = true;
                }
                else
                {
                    ++i;
                }
            }

            // Not found, add if wanted
            if (wantReminders)
            {
                Logger.Instance.Trace(this, "Adding reminders for {0}", folderId);
                query.Operands.Add(new SearchQuery.PropertyContent(
                                       PROP_FOLDER, SearchQuery.ContentMatchOperation.Prefix, SearchQuery.ContentMatchModifiers.None, prefix
                                       ));
                _queryCustomModified = true;
            }
        }
 public void Encode(SearchQuery.Or part)
 {
     Current->header.rt    = RestrictionType.OR;
     Current->data.sub.cb  = (uint)part.Operands.Count;
     Current->data.sub.ptr = EncodePointer(part.Operands);
 }