Exemple #1
0
        private void LinksFromInternetExplorerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var links = ActionExtensions.GetAllIeLinks().ToList();

            try
            {
                var tagsPrefix = GetTagsPrefix();

                var selected = Prompt.ChooseMany(links.ListFormat().DefaultColumns(), "Add Links")
                               .Select(_ => new Action {
                    Command = _.Command, Name = new[] { tagsPrefix, _.Name }.Join(" ")
                })
                               .ToList();

                context.AddJob(new Job(
                                   String.Format("Add {0} links from Internet Explorer", selected.Count),
                                   () =>
                {
                    foreach (var a in selected)
                    {
                        actions.Add(a);
                    }
                }));
            }
            catch
            {
            }
        }
Exemple #2
0
        public void AddPayments(IEnumerable <Payment> payments)
        {
            int totalCount = 0;
            int newCount   = 0;

            foreach (Payment p in payments)
            {
                ++totalCount;
                p.OwnName = OwnName(p);
                if (!Payments.Contains(p))
                {
                    Payments.Add(p);

                    ++newCount;
                    StringWriter w = new StringWriter();
                    w.WriteLine("new:");
                    p.Print(w);
                    log.Debug(w.ToString());
                }
                else
                {
                    StringWriter w = new StringWriter();
                    w.WriteLine("known:");
                    p.Print(w);
                    log.Debug(w.ToString());
                }
            }
            log.InfoFormat("Total: {0}, New: {1}", totalCount, newCount);
        }
Exemple #3
0
        public void TestCollectorSample()
        {
            ICollector c = new Sidi.Sammy.CollectorSample.CollectorSample();
            string path = FileUtil.BinFile(@"test-data\test.sqlite");
            if (File.Exists(path)) File.Delete(path);
            Sidi.Persistence.Collection<Payment> pc = new Sidi.Persistence.Collection<Payment>(path);
            IList<Payment> p = c.GetPayments();
            foreach (Payment i in p)
            {
                pc.Add(i);
            }

            foreach (Payment i in p)
            {
                Assert.AreEqual(true, pc.Contains(i));
            }
        }
Exemple #4
0
        public void TestCollectorSample()
        {
            ICollector c    = new Sidi.Sammy.CollectorSample.CollectorSample();
            string     path = FileUtil.BinFile(@"test-data\test.sqlite");

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            Sidi.Persistence.Collection <Payment> pc = new Sidi.Persistence.Collection <Payment>(path);
            IList <Payment> p = c.GetPayments();

            foreach (Payment i in p)
            {
                pc.Add(i);
            }

            foreach (Payment i in p)
            {
                Assert.AreEqual(true, pc.Contains(i));
            }
        }
Exemple #5
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);
        }