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);
        }
Example #2
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);
        }
        public override bool Open()
        {
            if (_queryCustomShared != 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
                // Remove old shared folders query if present
                if ((root.Operands.Count == 3 || root.Operands.Count == 5) && root.Operands.ElementAt(2) is SearchQuery.Or)
                {
                    while (root.Operands.Count > 2)
                    {
                        root.Operands.RemoveAt(2);
                    }
                }

                if (root.Operands.Count == 3)
                {
                    _queryCustomShared = (SearchQuery.Not)root.Operands.ElementAt(2);
                }
                else
                {
                    SetReminders(false); // Default to false
                    root.Operands.Add(_queryCustomShared);
                }

                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);
        }
        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);
        }
 public void Encode(SearchQuery.And part)
 {
     Current->header.rt    = RestrictionType.AND;
     Current->data.sub.cb  = (uint)part.Operands.Count;
     Current->data.sub.ptr = EncodePointer(part.Operands);
 }