Beispiel #1
0
    string GetOrRemove(bool remove, string channel, int assocPat, int iExclude)
    {
        if (iExclude < 0)
        {
            return(null);
        }

        string[] exPattern = null;
        lock (_storageLock)
        {
            ChannelPatterns chanPat = storage.Get(channel);

            List <string[]> exPatterns;
            if (TryGetExPatterns(chanPat, assocPat, out exPatterns) && iExclude < exPatterns.Count)
            {
                exPattern = exPatterns[iExclude];
                if (remove)
                {
                    exPatterns.RemoveAt(iExclude);
                    Write();
                }
            }
        }
        if (exPattern == null)
        {
            return(null);
        }
        else
        {
            return(string.Join(" ", exPattern));
        }
    }
Beispiel #2
0
    public int AddExclude(string channel, int assocPat, string exclude)
    {
        if (channel == null)
        {
            throw new ArgumentNullException("channel");
        }

        int index = -1;

        if (string.IsNullOrWhiteSpace(exclude))
        {
            return(index);
        }

        string[] split = exclude.Split();
        lock (_storageLock)
        {
            ChannelPatterns chanPat = storage.GetOrSet(channel, () => new ChannelPatterns(channel));
            List <string[]> exPatterns;
            if (TryGetExPatterns(chanPat, assocPat, out exPatterns))
            {
                exPatterns.Add(split);
                Write();

                index = exPatterns.Count - 1;
            }
        }
        return(index);
    }
Beispiel #3
0
    // -----------------------------------------------------------
    // Private methods for getting or removing (exclude) patterns.
    // -----------------------------------------------------------

    string GetOrRemove(bool remove, string channel, int index)
    {
        string[] pattern = null;
        lock (_storageLock)
        {
            ChannelPatterns chanPat = storage.Get(channel);
            if (IndexExists(chanPat, index))
            {
                pattern = chanPat.Patterns[index].IncludePattern;
                if (remove)
                {
                    chanPat.Patterns.RemoveAt(index);
                    Write();
                }
            }
        }
        if (pattern == null)
        {
            return(null);
        }
        else
        {
            return(string.Join(" ", pattern));
        }
    }
Beispiel #4
0
    // ----------------------------------
    // Helper functions for PatternMatch.
    // ----------------------------------

    static bool ContainsGlobalExcludePattern(ChannelPatterns chanPat, string title)
    {
        foreach (string[] pattern in chanPat.GlobalExcludePatterns)
        {
            if (IsMatch(pattern, title))
            {
                return(true);
            }
        }
        return(false);
    }
Beispiel #5
0
 static bool GlobalRequest(ChannelPatterns chanPat, int index)
 {
     if (chanPat != null && index < 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #6
0
 static bool IndexExists(ChannelPatterns chanPat, int index)
 {
     if (chanPat != null && index < chanPat.Patterns.Count && index >= 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #7
0
    // ------------------------------------------------------
    // Helper functions for the above Add/Get/Remove methods.
    // ------------------------------------------------------

    static bool TryGetExPatterns(ChannelPatterns chanPat, int assocPat, out List <string[]> exPatterns)
    {
        // Get all Exclude Patterns associated with a certain Include Pattern.
        if (IndexExists(chanPat, assocPat))
        {
            exPatterns = chanPat.Patterns[assocPat].ExcludePatterns;
            return(true);
        }
        // Get all Global Exclude Patterns.
        else if (GlobalRequest(chanPat, assocPat))
        {
            exPatterns = chanPat.GlobalExcludePatterns;
            return(true);
        }
        else
        {
            exPatterns = null;
            return(false);
        }
    }
Beispiel #8
0
    // If bool-exclude is false it will return the Include Patterns of passed `channel`.
    // Associated Pattern index is only used when bool-exclude is true, since only when returning those we need to know
    // with which pattern they are associated.
    // When bool-exclude is true and assocPat is negative it will return the Global Exclude Patterns.
    string[] InternalPatternsGet(string channel, bool exclude, int assocPat)
    {
        string[] patternsToRead = null;
        lock (_storageLock)
        {
            ChannelPatterns chanPat = storage.Get(channel);
            // Include Patterns.
            if (chanPat != null && !exclude)
            {
                patternsToRead = new string[chanPat.Patterns.Count];

                for (int i = 0; i < patternsToRead.Length; i++)
                {
                    patternsToRead[i] = string.Join(" ", chanPat.Patterns[i].IncludePattern);
                }
            }
            // (Global) Exclude Patterns.
            else
            {
                List <string[]> exPatterns;
                if (TryGetExPatterns(chanPat, assocPat, out exPatterns))
                {
                    patternsToRead = new string[exPatterns.Count];

                    for (int i = 0; i < patternsToRead.Length; i++)
                    {
                        patternsToRead[i] = string.Join(" ", exPatterns[i]);
                    }
                }
            }
        }

        if (patternsToRead == null)
        {
            return(new string[0]);
        }
        else
        {
            return(patternsToRead);
        }
    }
Beispiel #9
0
    // ----------------------
    // Add (exclude) pattern.
    // ----------------------

    public int Add(string channel, string pattern)
    {
        if (channel == null)
        {
            throw new ArgumentNullException("channel");
        }

        if (string.IsNullOrWhiteSpace(pattern))
        {
            return(-1);
        }

        string[] split = pattern.Split();
        lock (_storageLock)
        {
            ChannelPatterns chanPat = storage.GetOrSet(channel, () => new ChannelPatterns(channel));
            chanPat.Patterns.Add(new PatternEntry(split));
            Write();

            return(chanPat.Patterns.Count - 1);
        }
    }