コード例 #1
0
ファイル: Banking.asmx.cs プロジェクト: Dynalon/genbanking
        public Banking()
        {
            var conf = (string)ConfigurationManager.AppSettings ["ConfigFile"];
            config = new ProviderConfig (conf);

            passkey = (string)ConfigurationManager.AppSettings ["Passkey"];

            // see if we have SHA1 or SHA256 hashes
            try {
                // conversion will NOT yield correct integer result, but
                Convert.ToInt32 (passkey, 16);
                log.Debug (passkey);
                switch (passkey.Length) {
                case 40:
                    passkeyType = PasskeyType.SHA1;
                    break;
                case 64:
                    passkeyType = PasskeyType.SHA256;
                    break;
                default:
                    passkeyType = PasskeyType.Plaintext;
                    break;
                }
            } catch {
                // its not a hex represenation
                log.Debug ("caught exception");
                passkeyType = PasskeyType.Plaintext;
            }
        }
コード例 #2
0
ファイル: BankingFactory.cs プロジェクト: Dynalon/genbanking
        public IBankingProvider GetProvider(ProviderConfig config)
        {
            var catalogs = new List<ComposablePartCatalog> ();
            // we always search the directory with the running assembly first
            // Note: GetExecutingAssembly() returns a string with 'file:/' prefix
            // which is not removed by GetDirectoryName(). The Path will thus not be valid
            // if file: prefix is not removed first
            var assemblyDir = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().CodeBase.Substring (5));
            catalogs.Add (new DirectoryCatalog (assemblyDir));

            // assemble the backends
            var catalog = new AggregateCatalog (catalogs);
            var container = new CompositionContainer (catalog);
            var providerlist = container.GetExports<IBankingProvider, IBankingProviderMetadata> ();

            // default provider is aqbanking
            var providerName = "aqbanking";

            if (config != null && config.Settings ["Provider"] != null)
                providerName = config.Settings ["Provider"].Value;

            IBankingProvider provider;
            try {
                provider = (from p in providerlist where p.Metadata.Name == providerName select p.Value).First ();
            } catch {
                //log.Fatal (e.Message);
                throw new Exception ("no backend by name '" + providerName + "' could be loaded. Check the backend .dll exists");
            }

            provider.Init (config);
            return provider;
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: Dynalon/genbanking
        public static void Main(string[] args)
        {
            // set default options and parameter arguments
            string configfile = "";
            string account = "";
            string task = "";
            string provider = "";
            string gui = "";
            bool help = false;
            bool list = false;
            bool debug = false;

            var p = new OptionSet () {
                { "c=",	"configuration file to use. Default is provider.config in assembly directory",
                    v => configfile = v },
                { "g=", "gui to use, default is CGui (only for aqbanking)", v=> gui = v },
                { "v", "increase verbosity, usefull for debugging", v=> debug = true },
                { "p=", "provider to use, default is aqbanking", v => provider = v },
                { "a=", "AccountIdentifier/Number to use", v => account = v },
                { "t=",	"task that should be performed. Can be getbalance or gettransactions", v => task = v },
                { "l", "list all available accounts", v => list = v != null },
                { "h|?|help", "shows this help",  v => help = v != null },
            };

            try {
                // readin cmdline options
                p.Parse (args);
                if (help) {
                    p.WriteOptionDescriptions (Console.Out);
                    return;
                }

                // read in configuration or use default
                ProviderConfig conf;
                if (!string.IsNullOrEmpty (configfile))
                    conf = new ProviderConfig (configfile);
                else
                    conf = new ProviderConfig ();

                // setup logging
                log4net.Appender.ConsoleAppender appender;
                appender = new log4net.Appender.ConsoleAppender ();
                appender.Layout = new log4net.Layout.PatternLayout ("%-4timestamp %-5level %logger %M %ndc - %message%newline");
                log4net.Config.BasicConfigurator.Configure (appender);
                if (debug)
                    appender.Threshold = log4net.Core.Level.Debug;
                else
                    appender.Threshold = log4net.Core.Level.Warn;

                if (!string.IsNullOrEmpty (gui)) {
                    conf.Settings.Remove ("Gui");
                    conf.Settings.Add (new KeyValueConfigurationElement ("Gui", gui));
                }
                if (!string.IsNullOrEmpty (provider)) {
                    conf.Settings.Remove ("Provider");
                    conf.Settings.Add (new KeyValueConfigurationElement ("Provider", provider));
                }

                // init
                using (var banking = new BankingFactory().GetProvider(conf)) {

                    // output account overview
                    if (list) {
                        foreach (var acc in banking.Accounts)
                            acc.Print ();
                        return;
                    }
                    // account requests (Balance, Transactions)

                    // parameter sanitation
                    IBankAccount b;
                    if (string.IsNullOrEmpty (account)) {
                        b = banking.Accounts.First ();
                    } else
                        b = banking.GetAccountByIdentifier (account);

                    if (string.IsNullOrEmpty (task))
                        throw new Exception ("Task needed, specify via -t <task>");

                    switch (task) {
                    case "gettransactions":
                        List<ITransaction > l = banking.GetTransactions (b);
                        foreach (ITransaction t in l)
                            t.Print ();
                        return;
                    case "getbalance":
                        var bal = banking.GetBalance (b);
                        Console.WriteLine (bal);
                        return;
                    }
                }
            } catch (Exception e) {
                Console.WriteLine ("ERROR: " + e.Message);
                p.WriteOptionDescriptions (Console.Out);
                //throw e;
            }
            return;
        }
コード例 #4
0
        public void Init(ProviderConfig config)
        {
            this.Accounts = new List<IBankAccount> ();
            var acc = new LRAccount ();

            this.Config = config;

            // retrieve list of accounts is not supported in LR, we only know of
            // one if its specified in config
            if (config.Settings ["Account"] == null)
                throw new Exception ("Account MUST be specified for LR");
            acc.AccountIdentifier = config.Settings ["Account"].Value as string;

            if (config.Settings ["ApiName"] == null)
                throw new Exception ("ApiName is required");
            acc.ApiName = config.Settings ["ApiName"].Value as string;

            if (config.Settings ["Secret"] == null)
                throw new Exception ("An API Secret must be set");
            acc.Secret = config.Settings ["Secret"].Value;

            if (config.Settings ["Currency"] != null)
                acc.Currency = config.Settings ["Currency"].Value;

            // end configuration

            Accounts.Add (acc);
        }
コード例 #5
0
        public void Init(ProviderConfig config)
        {
            if (initDone)
                return;

            this.Config = config;

            // configure aqbanking configuration path, default to $HOME/.aqbanking/
            string configPath = Path.Combine (System.Environment.GetEnvironmentVariable ("HOME"), ".aqbanking");
            if (config.Settings ["ConfigPath"] != null)
                configPath = config.Settings ["ConfigPath"].Value;

            if (!Directory.Exists (configPath))
                throw new Exception ("configPath  " + configPath +
                    "does not exist!");

            abHandle = AB.AB_Banking_new ("appstring", configPath, 0);

            // determine which gui to use
            string guiToUse = "";
            if (config.Settings ["Gui"] != null)
                guiToUse = config.Settings ["Gui"].Value;

            switch (guiToUse) {
            case "ManagedConsole":
                // our own simple console, implemented in managed code
                AqGuiHandler.SetGui (abHandle, new ConsoleGui ());
                break;

            case "AutoGui":
                // a non-interactive gui which requires pre-saved pin in the config
                var nigui = new AutoGui ();

                if (config.Settings ["Pin"] == null)
                    throw new Exception ("AutoGui requires a pre-saved pin");

                nigui.Pin = config.Settings ["Pin"].Value;
                AqGuiHandler.SetGui (abHandle, nigui);
                break;

            case "CGui": goto default;
            default:
                // default GUI is AqBankings/Gwen internal CGui
                var gui = AB.GWEN_Gui_CGui_new ();
                AB.GWEN_Gui_SetGui (gui);
                AB.AB_Gui_Extend (gui, abHandle);
                break;
            }

            // initialise aqbanking
            int errcode = AB.AB_Banking_Init (abHandle);
            if (errcode != 0)
                throw new Exception ("AB_Banking_Init nicht erfoglreich, fehlercode: " + errcode);
            if (!abHandle.Equals (IntPtr.Zero))
                AB.AB_Banking_OnlineInit (abHandle);
            else
                throw new Exception ("Failed to initialize aqBanking");
            initDone = true;

            return;
        }