Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    _logger.LogInformation("Starting to update RegistryCache");

                    var previousRegistryCache = _currentRegistryCache.Instance;
                    Debug.Assert(previousRegistryCache != null);
                    var newRegistryCache = new RegistryCache(previousRegistryCache.RootUnityPackageFolder, previousRegistryCache.RootHttpUrl, previousRegistryCache.Logger);
                    await newRegistryCache.Build();

                    if (newRegistryCache.HasErrors)
                    {
                        _logger.LogInformation("RegistryCache not updated due to errors. See previous logs");
                    }
                    else
                    {
                        // Update the registry cache in the services
                        _currentRegistryCache.Instance = newRegistryCache;

                        _logger.LogInformation("RegistryCache successfully updated");
                    }

                    await Task.Delay((int)DefaultIntervalUpdate.TotalMilliseconds, stoppingToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while building a new registry cache. Reason: {ex}");
            }
        }
Пример #2
0
        public async Task TestBuild()
        {
            var unityPackages = Path.Combine(Path.GetDirectoryName(typeof(RegistryCacheTests).Assembly.Location), "unity_packages");
            var registryCache = new RegistryCache(unityPackages, "http://localhost");

            await registryCache.Build();

            Assert.False(registryCache.HasErrors, "The registry failed to build, check the logs");

            var allResult = registryCache.All();

            Assert.True(allResult.Packages.Count >= 3);
            var allResultJson = allResult.ToJson();

            StringAssert.Contains("org.nuget.scriban", allResultJson);
            StringAssert.Contains("org.nuget.system.runtime.compilerservices.unsafe", allResultJson);

            var scribanPackage = registryCache.GetPackage("org.nuget.scriban");

            Assert.NotNull(scribanPackage);
            var scribanPackageJson = scribanPackage.ToJson();

            StringAssert.Contains("org.nuget.scriban", scribanPackageJson);
            StringAssert.Contains("2.1.0", scribanPackageJson);
        }
Пример #3
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            var loggerRedirect = new NuGetRedirectLogger(loggerFactory.CreateLogger("NuGet"));

            string url = "https://unitynuget-registry.azurewebsites.net/";

            bool isDevelopment = hostEnvironment.IsDevelopment();

            if (isDevelopment)
            {
                var urls = configuration[WebHostDefaults.ServerUrlsKey];

                // Select HTTPS in production, HTTP in development
                url = urls.Split(';').FirstOrDefault(x => !x.StartsWith("https"));
                if (url == null)
                {
                    throw new InvalidOperationException($"Unable to find a proper server URL from `{urls}`. Expecting a `http://...` URL in development");
                }
            }

            // Get the current directory /home/site/unity_packages or binary folder in dev
            var currentDirectory   = isDevelopment ? Path.GetDirectoryName(typeof(Startup).Assembly.Location) : Directory.GetCurrentDirectory();
            var unityPackageFolder = Path.Combine(currentDirectory, "unity_packages");

            loggerRedirect.LogInformation($"Using Unity Package folder `{unityPackageFolder}`");

            // Build the cache synchronously because ConfigureServices doesn't support async Task
            var initialCache = new RegistryCache(unityPackageFolder, url, loggerRedirect);
            await initialCache.Build();

            // Add the cache accessible from the services
            registryCacheSingleton.Instance = initialCache;
        }
Пример #4
0
        private async void DoWork(object state)
        {
            try
            {
                _logger.LogInformation("Starting to update RegistryCache");

                var previousRegistryCache = _currentRegistryCache.Instance;
                Debug.Assert(previousRegistryCache != null);
                var newRegistryCache = new RegistryCache(previousRegistryCache.RootUnityPackageFolder, previousRegistryCache.RootHttpUrl, previousRegistryCache.Logger);
                await newRegistryCache.Build();

                if (newRegistryCache.HasErrors)
                {
                    _logger.LogInformation("RegistryCache not updated due to errors. See previous logs");
                }
                else
                {
                    // Update the registry cache in the services
                    _currentRegistryCache.Instance = newRegistryCache;

                    _logger.LogInformation("RegistryCache successfully updated");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while building a new registry cache. Reason: {ex}");
            }
        }
Пример #5
0
        private bool TryGetInstance(out RegistryCache cacheInstance, out NpmError npmError)
        {
            var instance = _cacheSingleton.Instance;

            cacheInstance = instance;
            var currentIndex = _cacheSingleton.ProgressPackageIndex;
            var totalCount   = _cacheSingleton.ProgressTotalPackageCount;
            var percent      = totalCount != 0 ? (double)currentIndex * 100 / totalCount : 0;

            npmError = instance == null ? new NpmError("not_initialized", $"The server is initializing ({percent:F1}% completed). Please retry later...") : null;

            return(instance != null);
        }
Пример #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var loggerRedirect = new NuGetRedirectLogger(LoggerFactory.CreateLogger("NuGet"));

            string url = "https://unitynuget-registry.azurewebsites.net/";

            bool isDevelopment = HostingEnvironment.IsDevelopment();

            if (isDevelopment)
            {
                var urls = Configuration[WebHostDefaults.ServerUrlsKey];

                // Select HTTPS in production, HTTP in development
                url = urls.Split(';').FirstOrDefault(x => !x.StartsWith("https"));
                if (url == null)
                {
                    throw new InvalidOperationException($"Unable to find a proper server URL from `{urls}`. Expecting a `http://...` URL in development");
                }
            }

            // Get the current directory /home/site/unity_packages or binary folder in dev
            var currentDirectory   = isDevelopment ? Path.GetDirectoryName(typeof(Startup).Assembly.Location) : Directory.GetCurrentDirectory();
            var unityPackageFolder = Path.Combine(currentDirectory, "unity_packages");

            loggerRedirect.LogInformation($"Using Unity Package folder `{unityPackageFolder}`");

            // Build the cache synchronously because ConfigureServices doesn't support async Task
            var initialCache = new RegistryCache(unityPackageFolder, url, loggerRedirect);

            initialCache.Build().GetAwaiter().GetResult();

            // Add the cache accessible from the services
            var singletonCache = new RegistryCacheSingleton(initialCache);

            services.AddSingleton(singletonCache);

            // Add the registry cache updater
            services.AddHostedService <RegistryCacheUpdater>();

            // Also enable NewtonsoftJson serialization
            services.AddControllers().AddNewtonsoftJson();
        }
        protected void Run(ClientPipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            ListString str = new ListString(args.Parameters["username"]);

            if (args.IsPostBack)
            {
                if (args.Result == "yes")
                {
                    foreach (string str2 in str)
                    {
                        Contact contactFromName = Util.GetContactFromName(str2);
                        if (contactFromName.Profile.UndeliveredCount != 0)
                        {
                            contactFromName.Profile.UndeliveredCount = 0;
                            contactFromName.Profile.Save();
                        }
                        RegistryCache registryCache = CacheManager.GetRegistryCache(Context.Site);
                        if (registryCache != null)
                        {
                            registryCache.Clear();
                        }
                        Log.Audit(this, "Reset Profile Undelivered Count: {0}", new string[] { str2 });
                    }
                    AjaxScriptManager.Current.Dispatch("usermanager:refresh");
                }
            }
            else
            {
                if (str.Count == 1)
                {
                    User user2 = User.FromName(str[0], true);
                    Assert.IsNotNull(user2, typeof(User));
                    SheerResponse.Confirm(Translate.Text("Are you sure you want to reset the Undelivered Count of {0} from {1} to 0 ?", new object[] { user2.GetLocalName(), GetUndeliveredCount(str[0]) }));
                }
                else
                {
                    SheerResponse.Confirm(Translate.Text("Are you sure you want to reset the Undelivered Count of these {0} users to 0 ?", new object[] { str.Count }));
                }
                args.WaitForPostBack();
            }
        }
Пример #8
0
        public async Task TestBuild()
        {
            var unityPackages = Path.Combine(Path.GetDirectoryName(typeof(RegistryCacheTests).Assembly.Location), "unity_packages");
            var registryCache = new RegistryCache(
                unityPackages,
                new Uri("http://localhost/"),
                "org.nuget",
                "2019.1",
                " (NuGet)",
                new RegistryTargetFramework[] {
                new RegistryTargetFramework {
                    Name = "netstandard2.1", DefineConstraints = new string[] { "UNITY_2021_2_OR_NEWER" }
                },
                new RegistryTargetFramework {
                    Name = "netstandard2.0", DefineConstraints = new string[] { "!UNITY_2021_2_OR_NEWER" }
                },
            },
                new NuGetConsoleLogger());

            // Uncomment when testing locally
            // registryCache.Filter = "scriban|bcl\\.asyncinterfaces|compilerservices\\.unsafe";

            await registryCache.Build();

            Assert.False(registryCache.HasErrors, "The registry failed to build, check the logs");

            var allResult = registryCache.All();

            Assert.True(allResult.Packages.Count >= 3);
            var allResultJson = allResult.ToJson();

            StringAssert.Contains("org.nuget.scriban", allResultJson);
            StringAssert.Contains("org.nuget.system.runtime.compilerservices.unsafe", allResultJson);

            var scribanPackage = registryCache.GetPackage("org.nuget.scriban");

            Assert.NotNull(scribanPackage);
            var scribanPackageJson = scribanPackage.ToJson();

            StringAssert.Contains("org.nuget.scriban", scribanPackageJson);
            StringAssert.Contains("2.1.0", scribanPackageJson);
        }
Пример #9
0
        public async Task TestBuild()
        {
            var unityPackages = Path.Combine(Path.GetDirectoryName(typeof(RegistryCacheTests).Assembly.Location), "unity_packages");

            Directory.Delete(unityPackages, true);

            var registryCache = new RegistryCache(
                unityPackages,
                new Uri("http://localhost/"),
                "org.nuget",
                "2019.1",
                " (NuGet)",
                new RegistryTargetFramework[] {
                new RegistryTargetFramework {
                    Name = "netstandard2.1", DefineConstraints = new string[] { "UNITY_2021_2_OR_NEWER" }
                },
                new RegistryTargetFramework {
                    Name = "netstandard2.0", DefineConstraints = new string[] { "!UNITY_2021_2_OR_NEWER" }
                },
            },
                new NuGetConsoleLogger())
            {
                Filter = "rhino3dm"
            };

            await registryCache.Build();

            Assert.False(registryCache.HasErrors, "The registry failed to build, check the logs");
            var allResult     = registryCache.All();
            var allResultJson = allResult.ToJson();

            StringAssert.Contains("org.nuget.rhino3dm", allResultJson);

            var rhinoPackage = registryCache.GetPackage("org.nuget.rhino3dm");

            Assert.NotNull(rhinoPackage);
            var rhinopackageJson = rhinoPackage.ToJson();

            StringAssert.Contains("org.nuget.rhino3dm", rhinopackageJson);
            StringAssert.Contains("7.11.0", rhinopackageJson);
        }
Пример #10
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    _logger.LogInformation("Starting to update RegistryCache");

                    var newRegistryCache = new RegistryCache(_currentRegistryCache.UnityPackageFolder, _currentRegistryCache.ServerUri, _registryOptions.UnityScope, _registryOptions.MinimumUnityVersion, _registryOptions.PackageNameNuGetPostFix, _registryOptions.TargetFrameworks, _currentRegistryCache.NuGetRedirectLogger)
                    {
                        // Update progress
                        OnProgress = (current, total) =>
                        {
                            _currentRegistryCache.ProgressTotalPackageCount = total;
                            _currentRegistryCache.ProgressPackageIndex      = current;
                        }
                    };

                    await newRegistryCache.Build();

                    if (newRegistryCache.HasErrors)
                    {
                        _logger.LogInformation("RegistryCache not updated due to errors. See previous logs");
                    }
                    else
                    {
                        // Update the registry cache in the services
                        _currentRegistryCache.Instance = newRegistryCache;

                        _logger.LogInformation("RegistryCache successfully updated");
                    }

                    await Task.Delay((int)_registryOptions.UpdateInterval.TotalMilliseconds, stoppingToken);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error while building a new registry cache. Reason: {ex}");
            }
        }
Пример #11
0
 public RegistryCacheSingleton(RegistryCache instance)
 {
     Instance = instance;
 }