• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 302

22 Aug 2023 03:11AM UTC coverage: 58.453% (-0.4%) from 58.835%
302

push

appveyor

b1f6c1c4
spread sheet plugin

5971 of 10215 relevant lines covered (58.45%)

130.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.33
/AccountingServer.Shell/PluginShell.cs
1
/* Copyright (C) 2020-2023 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System;
20
using System.Collections.Generic;
21
using System.Linq;
22
using AccountingServer.Shell.Plugins;
23
using AccountingServer.Shell.Plugins.AssetHelper;
24
using AccountingServer.Shell.Plugins.BankBalance;
25
using AccountingServer.Shell.Plugins.CashFlow;
26
using AccountingServer.Shell.Plugins.Cheque;
27
using AccountingServer.Shell.Plugins.Composite;
28
using AccountingServer.Shell.Plugins.Coupling;
29
using AccountingServer.Shell.Plugins.CreditCardConvert;
30
using AccountingServer.Shell.Plugins.Interest;
31
using AccountingServer.Shell.Plugins.SpreadSheet;
32
using AccountingServer.Shell.Plugins.Statement;
33
using AccountingServer.Shell.Plugins.Utilities;
34
using AccountingServer.Shell.Plugins.YieldRate;
35
using AccountingServer.Shell.Util;
36
using static AccountingServer.BLL.Parsing.Facade;
37

38
namespace AccountingServer.Shell;
39

40
/// <summary>
41
///     插件表达式解释器
42
/// </summary>
43
internal class PluginShell : IShellComponent
44
{
45
    private readonly Dictionary<string, PluginBase> m_Plugins;
46

47
    public PluginShell() => m_Plugins =
10✔
48
        new()
49
            {
50
                ["adb"] = new AverageDailyBalance(),
51
                ["af"] = new AssetFactory(),
52
                ["ad"] = new AssetDisposition(),
53
                ["ir"] = new InterestRevenue(),
54
                ["ie"] = new InterestExpense(),
55
                ["cf"] = new CashFlow(),
56
                ["c"] = new Composite(),
57
                ["ccc"] = new CreditCardConvert(),
58
                ["chq"] = new Cheque(),
59
                ["cp"] = new Coupling(),
60
                ["ss"] = new SpreadSheet(),
61
                ["stmt"] = new Statement(),
62
                ["u"] = new Utilities(),
63
                ["yr"] = new YieldRate(),
64
            };
65

66
    /// <inheritdoc />
67
    public IAsyncEnumerable<string> Execute(string expr, Session session)
68
    {
×
69
        var help = false;
×
70
        if (expr.StartsWith("?", StringComparison.Ordinal))
×
71
        {
×
72
            expr = expr[1..];
×
73
            help = true;
×
74
        }
×
75

76
        var plgName = Parsing.Quoted(ref expr, '$');
×
77

78
        if (help)
×
79
        {
×
80
            Parsing.Eof(expr);
×
81
            if (plgName == "")
×
82
                return ListPlugins().ToAsyncEnumerable();
×
83
            return GetHelp(plgName);
×
84
        }
85

86
        return GetPlugin(plgName).Execute(expr, session);
×
87
    }
×
88

89
    /// <inheritdoc />
90
    public bool IsExecutable(string expr)
91
        => expr.StartsWith("$", StringComparison.Ordinal)
6✔
92
            || expr.StartsWith("?$", StringComparison.Ordinal);
93

94
    /// <summary>
95
    ///     根据名称检索插件
96
    /// </summary>
97
    /// <param name="name">名称</param>
98
    /// <returns>插件</returns>
99
    private PluginBase GetPlugin(string name) => m_Plugins[name];
×
100

101
    /// <summary>
102
    ///     显示插件帮助
103
    /// </summary>
104
    /// <param name="name">名称</param>
105
    /// <returns>帮助内容</returns>
106
    private IAsyncEnumerable<string> GetHelp(string name) => GetPlugin(name).ListHelp();
×
107

108
    /// <summary>
109
    ///     列出所有插件
110
    /// </summary>
111
    /// <returns>插件</returns>
112
    private IEnumerable<string> ListPlugins()
113
    {
×
114
        foreach (var (key, value) in m_Plugins)
×
115
            yield return $"{key,-8}{value.GetType().FullName}\n";
×
116
    }
×
117
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc