コード例 #1
0
        public void Test()
        {
            var text         = @"[Google](http://www.google.com)";
            var markdownLink = MarkdownLink.Parse(text);

            Assert.That(markdownLink != null);
            Assert.That(markdownLink.Href, Is.EqualTo("http://www.google.com"));
            Assert.That(markdownLink.Title, Is.EqualTo("Google"));
        }
コード例 #2
0
        public void Test2()
        {
            var text         = @"[Chp Program Board](https://teams.microsoft.com/l/entity/com.microsoft.teamspace.tab.planner/_djb2_msteams_prefix_209840166?context=%7B%22subEntityId%22%3Anull%2C%22channelId%22%3A%2219%3A29f088ae953743d08b9197c30c09bab7%40thread.skype%22%7D&groupId=f0ed42fe-c7b4-4d43-8015-078f7e7f24f3&tenantId=5dbf1add-202a-4b8d-815b-bf0fb024e033)";
            var markdownLink = MarkdownLink.Parse(text);

            Assert.That(markdownLink != null);
            Assert.That(markdownLink.Href, Is.EqualTo("https://teams.microsoft.com/l/entity/com.microsoft.teamspace.tab.planner/_djb2_msteams_prefix_209840166?context=%7B%22subEntityId%22%3Anull%2C%22channelId%22%3A%2219%3A29f088ae953743d08b9197c30c09bab7%40thread.skype%22%7D&groupId=f0ed42fe-c7b4-4d43-8015-078f7e7f24f3&tenantId=5dbf1add-202a-4b8d-815b-bf0fb024e033"));
            Assert.That(markdownLink.Title, Is.EqualTo("Chp Program Board"));
        }
コード例 #3
0
        protected override IEnumerable <IResult> GetResults(IQuery query)
        {
            var terms = query.GetTerms();
            var tags  = query.Tags;

            if (!tags.Any() && !terms.Any(_ => _.Length >= 1))
            {
                return(Enumerable.Empty <IResult>());
            }

            var cmd = actions.Connection.CreateCommand();

            var termsQuery = And(terms.Select((t, i) =>
            {
                var paramName   = String.Format("@term{0}", i);
                var parameter   = cmd.Parameters.Add(paramName, System.Data.DbType.String);
                parameter.Value = String.Format("%{0}%", t);
                return(String.Format("Name like {0}", paramName));
            }));

            var tagsQuery = And(tags.Select((t, i) =>
            {
                var paramName   = String.Format("@tag{0}", i);
                var parameter   = cmd.Parameters.Add(paramName, System.Data.DbType.String);
                parameter.Value = String.Format("%{0}%", t);
                return(String.Format("Name like {0}", paramName));
            }));

            cmd.CommandText = String.Format($"select oid from {actions.Table} where {And(tagsQuery, termsQuery)} order by LastUseTime desc limit 50");
            log.Info(cmd.CommandText);

            IList <Action> r;

            try
            {
                r = actions.Query(cmd);
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                log.Info(e);
                return(Enumerable.Empty <IResult>());
            }

            var results = r.SelectMany(action => ToIActions(action))
                          .Select(a => a.ToResult(query))
                          .ToList();

            if (results.Count == 0)
            {
                var markdownLink = MarkdownLink.Parse(query.RawText);
                if (markdownLink != null)
                {
                    results.Add(new SimpleAction("add", $"Add {markdownLink.Title}", () =>
                    {
                        var factory = new FileActionFactory();
                        var title   = Prompt.GetText("Title");
                        var action  = factory.FromUrl(markdownLink.Href, markdownLink.Title);
                        actions.Add(action);
                    }).ToResult());
                }

                var namedUrl = NamedUrl.Parse(query.RawText);
                if (namedUrl != null)
                {
                    results.Add(new SimpleAction("add", $"Add {namedUrl.Title}", () =>
                    {
                        var factory = new FileActionFactory();
                        var title   = Prompt.GetText("Title");
                        var action  = factory.FromUrl(namedUrl.Url, namedUrl.Title);
                        actions.Add(action);
                    }).ToResult());
                }
            }
            return(results);
        }