Exemple #1
0
 public CoreRunLibTests(BaseFixture baseFixture)
 {
     _baseFixture           = baseFixture;
     _snapFilesystem        = new SnapFilesystem();
     _snapCryptoProvider    = new SnapCryptoProvider();
     _snapEmbeddedResources = new SnapEmbeddedResources();
     _coreRunLibDirectory   = new DisposableDirectory(_baseFixture.WorkingDirectory, _snapFilesystem);
 }
Exemple #2
0
        static int MainImplAsync([NotNull] string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            using var cts = new CancellationTokenSource();

            ISnapOs snapOs;

            try
            {
                snapOs = SnapOs.AnyOs;
            }
            catch (PlatformNotSupportedException)
            {
                SnapLogger.Error($"Platform is not supported: {RuntimeInformation.OSDescription}");
                return(1);
            }
            catch (Exception e)
            {
                SnapLogger.ErrorException("Exception thrown while initializing snap os", e);
                return(1);
            }

            snapOs.InstallExitSignalHandler(async() =>
            {
                cts.Cancel();
                await OnExitAsync();
            });

            var workingDirectory = Environment.CurrentDirectory;

            if (!workingDirectory.EndsWith(snapOs.Filesystem.DirectorySeparator))
            {
                workingDirectory += snapOs.Filesystem.DirectorySeparator;
            }

            var toolWorkingDirectory = snapOs.Filesystem.PathGetDirectoryName(typeof(Program).Assembly.Location);

            var snapCryptoProvider    = new SnapCryptoProvider();
            var snapEmbeddedResources = new SnapEmbeddedResources();

            snapEmbeddedResources.ExtractCoreRunLibAsync(snapOs.Filesystem, snapCryptoProvider,
                                                         toolWorkingDirectory, snapOs.OsPlatform).GetAwaiter().GetResult();
            var snapXEmbeddedResources = new SnapxEmbeddedResources();

            var coreRunLib              = new CoreRunLib(snapOs.Filesystem, snapOs.OsPlatform, toolWorkingDirectory);
            var snapAppReader           = new SnapAppReader();
            var snapAppWriter           = new SnapAppWriter();
            var snapPack                = new SnapPack(snapOs.Filesystem, snapAppReader, snapAppWriter, snapCryptoProvider, snapEmbeddedResources);
            var snapExtractor           = new SnapExtractor(snapOs.Filesystem, snapPack, snapEmbeddedResources);
            var snapSpecsReader         = new SnapAppReader();
            var snapNetworkTimeProvider = new SnapNetworkTimeProvider("time.cloudflare.com", 123);
            var snapHttpClient          = new SnapHttpClient(new HttpClient());

            var nugetServiceCommandPack    = new NugetService(snapOs.Filesystem, new NugetLogger(SnapPackLogger));
            var nugetServiceCommandPromote = new NugetService(snapOs.Filesystem, new NugetLogger(SnapPromoteLogger));
            var nugetServiceCommandDemote  = new NugetService(snapOs.Filesystem, new NugetLogger(SnapDemoteLogger));
            var nugetServiceCommandRestore = new NugetService(snapOs.Filesystem, new NugetLogger(SnapRestoreLogger));
            var nugetServiceNoopLogger     = new NugetService(snapOs.Filesystem, new NugetLogger(new LogProvider.NoOpLogger()));

            var snapPackageRestorer = new SnapPackageManager(snapOs.Filesystem, snapOs.SpecialFolders,
                                                             nugetServiceCommandPack, snapHttpClient,
                                                             snapCryptoProvider, snapExtractor, snapAppReader, snapPack);

            var distributedMutexClient = new DistributedMutexClient(new JsonServiceClient("https://snapx.dev"));

            Console.CancelKeyPress += async(sender, eventArgs) =>
            {
                eventArgs.Cancel = !cts.IsCancellationRequested;
                cts.Cancel();

                await OnExitAsync();
            };

            return(MainAsync(args, coreRunLib, snapOs, snapExtractor, snapOs.Filesystem,
                             snapSpecsReader, snapCryptoProvider,
                             snapPack, snapAppWriter, snapXEmbeddedResources, snapPackageRestorer, snapNetworkTimeProvider,
                             nugetServiceCommandPack, nugetServiceCommandPromote, nugetServiceCommandDemote,
                             nugetServiceCommandRestore, nugetServiceNoopLogger, distributedMutexClient,
                             toolWorkingDirectory, workingDirectory, cts.Token));
        }