Exemplo n.º 1
0
        private static void addArgs(ArgsBase args, IServiceCollection coll)
        {
            coll.AddSingleton(args);
            if (args is FileArgsBase fArgs)
            {
                coll.AddSingleton(fArgs);
            }
            if (args is LibraryTargetArgs lArgs)
            {
                coll.AddSingleton(lArgs);
            }
            if (args is ProjectTargetArgs ptArgs)
            {
                coll.AddSingleton(ptArgs);
                coll.AddSingleton <IProjectArgsBase>(new ProjectArgsBase {
                    ProjectName = ptArgs.ProjectName
                });
            }
            if (args is ProjectArgsBase pbArgs)
            {
                coll.AddSingleton(pbArgs);
            }
            if (args is TenantTargetArgs tArgs)
            {
                coll.AddSingleton(tArgs);
            }
            switch (args)
            {
            case ClearVariableSetArgs cArgs:
                coll.AddSingleton(cArgs);
                break;

            case ValidateArgs libArgs:
                coll.AddSingleton(libArgs);
                break;

            case ClearProjectArgs cpArgs:
                coll.AddSingleton(cpArgs);
                break;

            case ClearTenantArgs ctArgs:
                coll.AddSingleton(ctArgs);
                break;

            case ValidateTenantArgs vtArgs:
                coll.AddSingleton(vtArgs);
                break;

            case UploadProjectArgs upArgs:
                coll.AddSingleton(upArgs);
                break;

            case UploadTenantArgs utArgs:
                coll.AddSingleton(utArgs);
                break;

            default:
                throw new ArgumentException($"Unknown argument type '{args.GetType()}'", nameof(args));
            }
        }
        internal static bool ShowCannotEditError(Form owner, ArgsBase def)
        {
            if (def != null && !def.CheckIsAvailable())
            {
                FrmMsgBox.ShowWarning(owner, "Missing algorithm",
                                      "This algorithm uses an algorithm not installed on this machine and its parameters cannot be modified.");

                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public void PreLoad(object o)
        {
            ArgsBase e = o as ArgsBase;

            try
            {
                _engine.PreLoad();
            }
            catch (Exception ex)
            {
                OnError(null, ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// CONSTRUCTOR
        /// Remembers the data specified by <paramref name="source"/>.
        /// </summary>
        public SourceTracker(ArgsBase source)
        {
            var prov = source.SourceProvider?.Provide;

            this._sourceMatrix = prov != null ? new WeakReference(prov) : null;

            AlgoParameterCollection para = source.GetAlgorithmOrThrow().Parameters;

            this._parameters = new WeakReference[para.Count][];

            for (int n = 0; n < para.Count; ++n)
            {
                this._parameters[n] = para[n].Type.TrackChanges(source.Parameters[n]);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Process a script to be parsed (from the input resource).
        /// </summary>
        private static void Process(IndentingTextWriter wrt, string text, ArgsBase defaults)
        {
            var env = new TlcEnvironment(seed: 42);

            using (wrt.Nest())
            {
                var args1 = defaults.Clone();
                using (wrt.Nest())
                {
                    if (!CmdParser.ParseArguments(env, text, args1, s => wrt.WriteLine("*** {0}", s)))
                    {
                        wrt.WriteLine("*** Failed!");
                    }
                }
                string str1 = args1.ToString();
                wrt.WriteLine("ToString: {0}", str1);
                string settings1 = CmdParser.GetSettings(env, args1, defaults, SettingsFlags.None);
                wrt.WriteLine("Settings: {0}", settings1);

                var args2 = defaults.Clone();
                using (wrt.Nest())
                {
                    if (!CmdParser.ParseArguments(env, settings1, args2, s => wrt.WriteLine("*** BUG: {0}", s)))
                    {
                        wrt.WriteLine("*** BUG: parsing result of GetSettings failed!");
                    }
                }
                string str2 = args2.ToString();
                if (str1 != str2)
                {
                    wrt.WriteLine("*** BUG: ToString Mismatch: {0}", str2);
                }
                string settings2 = CmdParser.GetSettings(env, args2, defaults, SettingsFlags.None);
                if (settings1 != settings2)
                {
                    wrt.WriteLine("*** BUG: Settings Mismatch: {0}", settings2);
                }
            }
        }
Exemplo n.º 6
0
        public void CmdParsingSingle()
        {
            ArgsBase[] defaults = new ArgsBase[]
            {
                new ArgsSingle <sbyte>(), new ArgsSingle <sbyte>()
                {
                    value = 3
                },
                new ArgsSingle <short>(), new ArgsSingle <short>()
                {
                    value = 3
                },
                new ArgsSingle <int>(), new ArgsSingle <int>()
                {
                    value = 3
                },
                new ArgsSingle <long>(), new ArgsSingle <long>()
                {
                    value = 3
                },

                new ArgsSingle <byte>(), new ArgsSingle <byte>()
                {
                    value = 3
                },
                new ArgsSingle <ushort>(), new ArgsSingle <ushort>()
                {
                    value = 3
                },
                new ArgsSingle <uint>(), new ArgsSingle <uint>()
                {
                    value = 3
                },
                new ArgsSingle <ulong>(), new ArgsSingle <ulong>()
                {
                    value = 3
                },

                new ArgsSingle <float>(), new ArgsSingle <float>()
                {
                    value = 3
                },
                new ArgsSingle <double>(), new ArgsSingle <double>()
                {
                    value = 3
                },
                new ArgsSingle <decimal>(), new ArgsSingle <decimal>()
                {
                    value = 3
                },
                new ArgsSingle <char>(), new ArgsSingle <char>()
                {
                    value = '3'
                },

                new ArgsSingle <sbyte?>(), new ArgsSingle <sbyte?>()
                {
                    value = 3
                },
                new ArgsSingle <short?>(), new ArgsSingle <short?>()
                {
                    value = 3
                },
                new ArgsSingle <int?>(), new ArgsSingle <int?>()
                {
                    value = 3
                },
                new ArgsSingle <long?>(), new ArgsSingle <long?>()
                {
                    value = 3
                },

                new ArgsSingle <byte?>(), new ArgsSingle <byte?>()
                {
                    value = 3
                },
                new ArgsSingle <ushort?>(), new ArgsSingle <ushort?>()
                {
                    value = 3
                },
                new ArgsSingle <uint?>(), new ArgsSingle <uint?>()
                {
                    value = 3
                },
                new ArgsSingle <ulong?>(), new ArgsSingle <ulong?>()
                {
                    value = 3
                },

                new ArgsSingle <float?>(), new ArgsSingle <float?>()
                {
                    value = 3
                },
                new ArgsSingle <double?>(), new ArgsSingle <double?>()
                {
                    value = 3
                },
                new ArgsSingle <decimal?>(), new ArgsSingle <decimal?>()
                {
                    value = 3
                },
                new ArgsSingle <char?>(), new ArgsSingle <char?>()
                {
                    value = '3'
                },

                new ArgsSingle <string>(), new ArgsSingle <string>()
                {
                    value = "3"
                },
            };

            Action <IndentingTextWriter>         init   = null;
            Action <IndentingTextWriter, string> action = null;

            foreach (var def in defaults)
            {
                init   += def.CallInit;
                action += def.CallProcess;
            }

            Run("CmdLine", "SingleParsing", init, action);
        }
Exemplo n.º 7
0
        public static async Task Setup(ArgsBase args, ICakeContext context = null, IServiceCollection _coll = null, bool connectToOctopus = true)
        {
            var coll = _coll ?? new ServiceCollection();

            if (String.IsNullOrEmpty(args.OctoUri))
            {
                throw new ArgumentException("Null or empty Octopus Deploy API URI", nameof(args.OctoUri));
            }
            if (String.IsNullOrEmpty(args.ApiKey))
            {
                throw new ArgumentException("Null or empty Octopus Deploy API key", nameof(args.ApiKey));
            }

            addArgs(args, coll);

            if (context != null)
            {
                coll.AddSingleton <ILogger>(new CakeLoggerAbstraction(context.Log, null));
            }
            else
            {
                var serilogLogger = new LoggerConfiguration()
                                    .WriteTo.Console();
                if (args.Verbose)
                {
                    serilogLogger.MinimumLevel.Verbose();
                }
                else
                {
                    serilogLogger.MinimumLevel.Information();
                }
                coll.AddSingleton <ILogger>(new CakeLoggerAbstraction(null, serilogLogger.CreateLogger()));
            }

            if (connectToOctopus)
            {
                var server  = new OctopusServerEndpoint(args.OctoUri, args.ApiKey);
                var factory = new OctopusClientFactory();
                coll.AddSingleton <IOctopusAsyncRepository>(new OctopusAsyncRepository(await factory.CreateAsyncClient(server).ConfigureAwait(false)));
            }

            coll.AddSingleton <IFileSystem, FileSystem>();

            coll.AddSingleton <IVaultClientFactory, VaultClientFactory>();
            coll.AddSingleton <ISecretProviderFactory, SecretProviderFactory>();
            coll.AddSingleton <ISecretsMananger, SecretsMananger>();
            coll.AddSingleton <VaultKVV2Provider>();
            coll.AddSingleton <VaultProvider>();

            coll.AddSingleton <ILibraryManager, LibraryManager>();
            coll.AddSingleton <IProjectManager, ProjectManager>();
            coll.AddSingleton <IProjectClearer, ProjectClearer>();
            coll.AddSingleton <ITenantClearer, TenantClearer>();
            coll.AddSingleton <ITenantManager, TenantManager>();
            coll.AddSingleton <VariableConverter>();

            coll.AddSingleton <ValidateLibraryCommand>();
            coll.AddSingleton <UploadLibraryCommand>();
            coll.AddSingleton <UploadTenantCommand>();
            coll.AddSingleton <ClearVariableSetCommand>();
            coll.AddSingleton <ClearTenantCommand>();
            coll.AddSingleton <ClearProjectCommand>();
            coll.AddSingleton <ValidateTenantCommand>();
            coll.AddSingleton <UploadProjectCommand>();
            Container = coll.BuildServiceProvider();
        }
 public async Task NullOrEmptyApiKeyThrows(string apiKey, Mock <IServiceCollection> mockColl, ArgsBase args)
 {
     args.ApiKey = apiKey;
     Func <Task> sut = () => DependencyConfig.Setup(args, null, mockColl.Object, false);
     await sut.Should().ThrowAsync <ArgumentException>().ConfigureAwait(false);
 }