コード例 #1
0
        private T CompileTagRelation(TagOperator @operator, string tag)
        {
            var tagEngine     = this.TagEngine;
            var tagInfo       = tagEngine[tag];
            var searchTags    = tagInfo.RelatedTags(HierarchyRelation.SelfOrDescendant);
            var exclusionTags = tagInfo.RelatedTags(HierarchyRelation.SelfOrAncestor);
            var rules         = tagEngine[@operator].Where(rule => rule.Right.Any(r => searchTags.Contains(r)));
            var exclusions    = tagEngine[TagOperator.Exclusion].Where(rule => rule.Right.Any(r => exclusionTags.Contains(r)));

            return(this.ParentCompiler.CompileConjunction(new[]
            {
                this.ParentCompiler.CompileNegation(this.CompileField(new FieldTerm("tag", FieldTerm.LessThanOrEqualOperator, tag))),
                this.ParentCompiler.CompileNegation(this.CompileField(new FieldTerm("rejected", FieldTerm.GreaterThanOrEqualOperator, tag))),
                this.ParentCompiler.CompileDisjunction(rules.Select(rule =>
                {
                    var requirements = Enumerable.Concat(
                        rule.Left.Select(required => this.CompileField(new FieldTerm("tag", FieldTerm.LessThanOrEqualOperator, required))),
                        rule.Right.Where(r => !searchTags.Contains(r)).Select(sufficient => this.ParentCompiler.CompileNegation(this.CompileField(new FieldTerm("tag", FieldTerm.LessThanOrEqualOperator, sufficient)))));
                    return this.ParentCompiler.CompileConjunction(requirements);
                })),
                this.ParentCompiler.CompileConjunction(exclusions.Select(rule =>
                {
                    var requirements = Enumerable.Concat(
                        rule.Left.Select(required => this.ParentCompiler.CompileNegation(this.CompileField(new FieldTerm("tag", FieldTerm.LessThanOrEqualOperator, required)))),
                        rule.Right.Where(r => !exclusionTags.Contains(r)).Select(excluded => this.ParentCompiler.CompileNegation(this.CompileField(new FieldTerm("tag", FieldTerm.LessThanOrEqualOperator, excluded)))));
                    return this.ParentCompiler.CompileDisjunction(requirements);
                })),
            }));
        }
コード例 #2
0
        /// <summary>
        /// Validate and make the request
        /// </summary>
        public async Task <TaggingOperationResult> SendAsync()
        {
            try
            {
                Validate();
                TagOperator            tagService = new TagOperator(base.Provider);
                TaggingOperationResult result     = await tagService.AddUserToTagsAsync(this.UserId, this.Tags);

                return(result);
            }
            catch (AWSMobilePushNotificationServiceException ex)
            {
                return(new TagCRUDFailedResult(ex));
            }
            catch (Exception ex)
            {
                if (Provider.CatchAllExceptions)
                {
                    return(new TagCRUDFailedResult(ex.Message));
                }
                else
                {
                    throw ex;
                }
            }
        }
コード例 #3
0
 public SwitchOperator(IAWSMobilePushNotificationConfigProvider provider) : base(provider)
 {
     subscribersTableOperator = new DynamoSubscribersTableOperator(provider);
     tagOperator        = new TagOperator(provider);
     unRegisterOperator = new UnRegisterOperator(provider);
     registerOperator   = new RegisterOperator(provider);
 }
コード例 #4
0
        public void Parse_WithASimpleRule_ReturnsTheExpectedOperator(string rule, TagOperator @operator)
        {
            var rules  = new TagRulesGrammar().Parse(rule);
            var actual = rules.Single();

            Assert.Equal(@operator, actual.Operator);
        }
コード例 #5
0
        /// <summary>
        /// Creates a single journal entry comprised of all entries found which match the specified criteria.
        /// </summary>
        /// <param name="range">The date range to search for entries. Dates are inclusive. Null values assume all entries are desired.</param>
        /// <param name="tags">Filters entries by tag. Null values assumes all tags are desired.</param>
        /// <param name="tagOperator">Indicates whether all tags must be matched, or if any tag can be matched.</param>
        /// <param name="overwrite">True to overwrite an existing compiled entry with the same name. Otherwise, an exception is thrown.</param>
        public void CreateCompiledEntry(DateRange range, string[] tags, TagOperator tagOperator, bool overwrite)
        {
            List <JournalEntryFile> entries;
            var hasTags = tags != null && tags.Length > 0;

            if (hasTags)
            {
                if (tagOperator == TagOperator.All)
                {
                    entries = CreateIndex <JournalEntryFile>(range, tags)
                              .SelectMany(x => x.Entries)
                              .OrderBy(x => x)
                              .Distinct()
                              .ToList();
                }
                else
                {
                    entries = CreateIndex <JournalEntryFile>(range)
                              .Where(x => tags.Contains(x.Tag))
                              .SelectMany(x => x.Entries)
                              .OrderBy(x => x)
                              .Distinct()
                              .ToList();
                }
            }
            else
            {
                entries = CreateIndex <JournalEntryFile>(range)
                          .SelectMany(x => x.Entries)
                          .OrderBy(x => x)
                          .Distinct()
                          .ToList();
            }

            if (entries.Count == 0)
            {
                throw new InvalidOperationException("No journal entries found matching the specified criteria. Please change your criteria and try again.");
            }

            range ??= new DateRange(entries.First().EntryDate, entries.Last().EntryDate);

            var journalWriter = _readerWriterFactory.CreateWriter();
            var entryFilePath = journalWriter.GetCompiledJournalEntryFilePath(range);

            if (journalWriter.EntryExists(entryFilePath) && !overwrite)
            {
                throw new JournalEntryAlreadyExistsException(entryFilePath);
            }

            var aggregatedTags = entries.SelectMany(x => x.Tags).Distinct();
            var content        = string.Join(Environment.NewLine, entries.Select(x => x.Body));

            var frontMatter = new JournalFrontMatter(aggregatedTags, ReadmeExpression.Empty());

            journalWriter.CreateCompiled(frontMatter, entryFilePath, content);
            _systemProcess.Start(entryFilePath);
        }
コード例 #6
0
        public MetaJournalEntry GetRandomEntry(ICollection <string> tags, TagOperator tagOperator, DateRange dateRange)
        {
            var entries = GetEntries <MetaJournalEntry>(tags, tagOperator, SortOrder.Ascending, dateRange, null).ToList();

            if (entries.Count == 0)
            {
                throw new InvalidOperationException("I couldn't find any journal entries. Did you pass in the right root directory?");
            }
            var index = new Random().Next(0, entries.Count - 1);

            return(entries[index]);
        }
コード例 #7
0
        // TODO: Some of these parameters make no sense when you just want all entries. Should they all be optional??
        public IEnumerable <T> GetEntries <T>(ICollection <string> tags, TagOperator tagOperator, SortOrder direction, DateRange dateRange, int?limit)
            where T : class, IJournalEntry
        {
            var entries = _markdownFiles.FindAll()
                          .Select(x => _readerWriterFactory.CreateReader(x).ToJournalEntry <T>());

            if (tags != null && tags.Any())
            {
                switch (tagOperator)
                {
                default:
                    throw new NotSupportedException();

                case TagOperator.All:
                    entries = entries.Where(x => x.Tags != null && x.Tags.ContainsAll(tags));
                    break;

                case TagOperator.Any:
                    entries = entries.Where(x => x.Tags != null && x.Tags.ContainsAny(tags));
                    break;
                }
            }

            if (dateRange != null)
            {
                entries = entries.Where(x => dateRange.Includes(x.EntryDate));
            }

            switch (direction)
            {
            case SortOrder.Ascending:
                entries = entries.OrderBy(x => x.EntryDate);
                break;

            case SortOrder.Descending:
                entries = entries.OrderByDescending(x => x.EntryDate);
                break;

            default:
                throw new NotSupportedException();
            }

            if (limit.HasValue)
            {
                entries = entries.Take(limit.Value);
            }

            return(entries);
        }
コード例 #8
0
 public UnRegisterOperator(IAWSMobilePushNotificationConfigProvider provider) : base(provider)
 {
     tagOperator = new TagOperator(provider);
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagRule"/> class.
 /// </summary>
 /// <param name="left">The tags used as the left operand.</param>
 /// <param name="operator">The tag operator applied between the operands.</param>
 /// <param name="right">The tags used as the right operand.</param>
 public TagRule(ImmutableHashSet <string> left, TagOperator @operator, ImmutableHashSet <string> right)
 {
     this.Left     = left;
     this.Operator = @operator;
     this.Right    = right;
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagRule"/> class.
 /// </summary>
 /// <param name="left">The tags used as the left operand.</param>
 /// <param name="operator">The tag operator applied between the operands.</param>
 /// <param name="right">The single tag used as the right operand.</param>
 public TagRule(ImmutableHashSet <string> left, TagOperator @operator, string right)
     : this(left, @operator, ImmutableHashSet.Create(right))
 {
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagRule"/> class.
 /// </summary>
 /// <param name="left">The single tag used as the left operand.</param>
 /// <param name="operator">The tag operator applied between the operands.</param>
 /// <param name="right">The tags used as the right operand.</param>
 public TagRule(string left, TagOperator @operator, ImmutableHashSet <string> right)
     : this(ImmutableHashSet.Create(left), @operator, right)
 {
 }
コード例 #12
0
 /// <summary>
 /// Gets rules with the specified operator.
 /// </summary>
 /// <param name="operator">The <see cref="TagOperator"/> for which rules will be retrieved.</param>
 /// <returns>An enumerable collection of the specified rules.</returns>
 public IEnumerable <TagRule> this[TagOperator @operator] => this.tagRules[@operator];