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

b1f6c1c4 / ProfessionalAccounting / 322

28 Nov 2024 10:42PM UTC coverage: 54.819% (-1.5%) from 56.293%
322

push

appveyor

b1f6c1c4
improv document

6319 of 11527 relevant lines covered (54.82%)

123.52 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-2024 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.Pivot;
32
using AccountingServer.Shell.Plugins.SpreadSheet;
33
using AccountingServer.Shell.Plugins.Statement;
34
using AccountingServer.Shell.Plugins.Utilities;
35
using AccountingServer.Shell.Plugins.YieldRate;
36
using AccountingServer.Shell.Util;
37
using static AccountingServer.BLL.Parsing.Facade;
38

39
namespace AccountingServer.Shell;
40

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

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

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

78
        var plgName = Parsing.Quoted(ref expr, '$');
×
79

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

88
        return GetPlugin(plgName).Execute(expr, session);
×
89
    }
×
90

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

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

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

110
    /// <summary>
111
    ///     列出所有插件
112
    /// </summary>
113
    /// <returns>插件</returns>
114
    private IEnumerable<string> ListPlugins()
115
    {
×
116
        foreach (var (key, value) in m_Plugins)
×
117
            yield return $"{key,-8}{value.GetType().FullName}\n";
×
118
    }
×
119
}
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

© 2025 Coveralls, Inc