Пример #1
0
    public void Validate(Type type, HashSet <string>?paramSkip = null)
    {
        if (ShouldSkip.ShouldSkip(type))
        {
            return;
        }
        var constr = type.GetConstructors();

        if (constr.Length > 1)
        {
            throw new AutofacValidationException(
                      $"'{type.FullName}' has more than one constructor");
        }

        if (constr.Length == 0)
        {
            return;
        }

        foreach (var param in constr[0].GetParameters())
        {
            if (param.IsOptional)
            {
                continue;
            }
            if (param.Name != null && (paramSkip?.Contains(param.Name) ?? false))
            {
                continue;
            }
            ValidateType.Validate(param.ParameterType);
        }
    }
Пример #2
0
        public override void StartWatching()
        {
            var actualPath = Path.GetDirectoryName(Path.GetFullPath(Watch.Path));
            var binPath    = CsprojHelper.GetBinaryPath(actualPath);
            var outputDir  = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()) + "\\";

            // Run Process Delegate
            WaitCallback runProcess = (o) =>
            {
                var process = new ProcessStartInfo()
                {
                    CreateNoWindow         = false,
                    WorkingDirectory       = actualPath,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardInput  = true,
                    RedirectStandardError  = true
                };

                if (Path.GetExtension(binPath) == ".exe")
                {
                    process.FileName = Path.Combine(outputDir, Path.GetFileName(binPath));
                }
                else
                {
                    process.FileName  = "dotnet";
                    process.Arguments = Path.Combine(outputDir, Path.GetFileName(binPath));
                }

                foreach (var env in Watch.Environment)
                {
                    process.Environment[env.Key] = env.Value;
                }

                if (!string.IsNullOrWhiteSpace(Watch.Args))
                {
                    process.Arguments = string.Join(" ", process.Arguments, Watch.Args);
                }

                var proc = Process.Start(process);
                proc.EnableRaisingEvents = true;
                RunningProcesses.GetOrAdd(Watch, proc);
                DisplayUpdate?.Invoke();
                proc.WaitForExit();
                RunningProcesses.TryRemove(Watch, out proc);

                if (Directory.Exists(outputDir))
                {
                    Directory.Delete(outputDir, true);
                }

                DisplayUpdate?.Invoke();
            };

            Watcher = new FileSystemWatcher(Path.GetDirectoryName(binPath), Path.GetFileName(binPath))
            {
                NotifyFilter = NotifyFilters.LastWrite
            };

            Watcher.Changed += (sender, e) =>
            {
                if (ShouldSkip?.Invoke() ?? false)
                {
                    return;
                }

                InvokeCallback?.Invoke();

                if (RunningProcesses.ContainsKey(Watch))
                {
                    RunningProcesses[Watch].Kill();
                }

                Thread.Sleep(500);
                Extensions.CloneDirectory(Path.GetDirectoryName(binPath), outputDir);
                ThreadPool.QueueUserWorkItem(runProcess);
            };

            Watcher.EnableRaisingEvents = true;

            if (!RunningProcesses.ContainsKey(Watch))
            {
                // Initial Run - we want to run at startup
                Extensions.CloneDirectory(Path.GetDirectoryName(binPath), outputDir);
                ThreadPool.QueueUserWorkItem(runProcess);
            }
        }
Пример #3
0
 public void ValidateEverything()
 {
     InternalValidate(Registrations.Items.Keys
                      .Where(type => !ShouldSkip.ShouldSkip(type)));
 }