Beispiel #1
0
        public static void AddInfoCommand(this CommandLineApplication app, ConfigFile config)
        {
            app.Command("info", cmd =>
            {
                cmd.Description = "Show Afas connector information.";
                cmd.OnValidate((ctx) =>
                {
                    if ((config == null) || (!config.HasToken))
                    {
                        return(new ValidationResult("A valid configuration (with token) could not be found. Use [config].  "));
                    }
                    return(ValidationResult.Success);
                });
                cmd.OnExecute(() =>
                {
                    IAfasClient client = new AfasClient(config.MemberNumber, config.Token, (Environments)config.Environment);

                    //try
                    //{
                    //    var version = client.GetVersion();
                    //    Console.WriteLine($"Afas version     : ", version);
                    //}
                    //catch (Exception)
                    //{
                    //    Console.WriteLine($"Afas version     : ", "AppVersion connector not installed");
                    //}

                    var info = client.GetSessionInfo();
                    Console.WriteLine($"Application Name: {info.Info.ApplicationName} ");
                    Console.WriteLine($"Environment Id: {info.Info.EnvironmentID} ");
                    Console.WriteLine($"Group: {info.Info.Group} ");


                    if (info.GetConnectors != null)
                    {
                        Console.WriteLine();
                        Console.WriteLine("GetConnectors");
                        Console.WriteLine("=============");
                        foreach (var item in info.GetConnectors)
                        {
                            Console.WriteLine($"{item.Id} - {item.Description}");
                        }
                    }

                    if (info.UpdateConnectors != null)
                    {
                        Console.WriteLine();
                        Console.WriteLine("UpdateConnectors");
                        Console.WriteLine("================");
                        foreach (var item in info.UpdateConnectors ?? new ConnectorInfo[] { })
                        {
                            Console.WriteLine($"{item.Id} - {item.Description}");
                        }
                    }
                });
            });
        }
Beispiel #2
0
        public static void AddGenerateCommand(this CommandLineApplication app, ConfigFile config)
        {
            app.Command("generate", generateCmd =>
            {
                generateCmd.Description = "Generate the C# Get- and UpdateConnector files for AfasClient";

                //generate will only work with a valid Afas Token.
                generateCmd.OnValidate((ctx) =>
                {
                    if ((config == null) || (!config.HasToken))
                    {
                        return(new ValidationResult("A valid configuration (with token) could not be found. Use [config].  "));
                    }
                    return(ValidationResult.Success);
                });


                generateCmd.OnExecuteAsync(async(cancellationToken) =>
                {
                    IAfasClient client = new AfasClient(config.MemberNumber, config.Token, (Environments)config.Environment);

                    //Make sure the folder exists.
                    System.IO.Directory.CreateDirectory(DestinationFolder);

                    var si = await client.GetSessionInfoAsync();

                    if (si.GetConnectors != null)
                    {
                        foreach (var connector in si.GetConnectors)
                        {
                            var meta = await client.GetMetaDataGetConAsync(connector.Id);
                            Console.WriteLine($"Processing : {meta.Name}");
                            SaveGetConnector(meta);
                        }
                    }

                    //UpdateConnector requires the use of the generator.
                    var updGenerator = new UpdateGenerator(client);
                    var updMetas     = updGenerator.GenerateList();
                    foreach (var meta in updMetas)
                    {
                        Console.WriteLine($"Processing : {meta.Name}");
                        SaveUpdateConnector(meta);
                    }
                });
            });
        }
Beispiel #3
0
        static async Task <int> Main(string[] args)
        {
            //If you don't have a token , you can generate one
            var otpclient = new AfasOtpClient(12345, "api-key", "environment-key");

            //Request the otp valdiation code, which is send by mail by Afas.
            await otpclient.GetOtpTokenRequest("*****@*****.**");

            //Assume you received validation code 123456 by mail, you can request a token.
            var token = await otpclient.GetOtpTokenValidation("*****@*****.**", "123456");


            //With a token, you can start working with the AfasClient
            var client = new AfasClient(00000, "token", Environments.Test);


            var session = client.GetSessionInfo();

            Console.WriteLine($"ConnectorName: {session.Info.ApplicationName}");
            Console.WriteLine($"EnvironmentID: {session.Info.EnvironmentID}");
            Console.WriteLine($"Group        : {session.Info.Group}");


            //overview of GetConnectors.
            foreach (var conn in session.GetConnectors)
            {
                Console.WriteLine($"{conn.Id} - {conn.Description}");
            }

            //Request a file
            var fileInfo = await client.GetFileAsync("test", "invoice001.pdf");

            if (fileInfo != null)
            {
                var bytes = Convert.FromBase64String(fileInfo.FileDataBase64);
            }
            ;



            return(0);
        }