コード例 #1
0
ファイル: Program.cs プロジェクト: nabrezzelt/drawing-hammer
        private static void HandleOnRegistrationPackage(RegistrationPackage package, TcpClient senderTcpClient)
        {
            var client = _server.GetClientFromClientList(senderTcpClient);

            client.Uid = package.SenderUid;

            try
            {
                UserManager.CreateUser(package.Username, package.Password, _settingsManager.GetMinUsernameLength(), _settingsManager.GetMaxUsernameLength());
                Log.Info("User successfull created with username: "******"Registration failed. User with username '" + package.Username + "' already exitsts");
                client.EnqueueDataForWrite(new RegistrationResultPackage(RegistrationResult.UsernameAlreadyExists, Router.ServerWildcard, package.SenderUid));
            }
            catch (UsernameTooLongException)
            {
                Log.Info("Registration failed. Username '" + package.Username + "' is too long.");
                client.EnqueueDataForWrite(new RegistrationResultPackage(RegistrationResult.UsernameTooLong, Router.ServerWildcard, package.SenderUid));
            }
            catch (UsernameTooShortException)
            {
                Log.Info("Registration failed. Username '" + package.Username + "' is too short.");
                client.EnqueueDataForWrite(new RegistrationResultPackage(RegistrationResult.UsernameTooShort, Router.ServerWildcard, package.SenderUid));
            }
        }
コード例 #2
0
        private void VerifyRegistrationPackage(
            MemoryStorage registrationStorage,
            RegistrationPackage package,
            CatalogIndependentPackageDetails packageDetails,
            string commitId,
            string commitTimeStamp)
        {
            var packageId         = packageDetails.Id.ToLowerInvariant();
            var packageVersion    = packageDetails.Version.ToLowerInvariant();
            var packageVersionUri = GetRegistrationPackageVersionUri(packageId, packageVersion);
            var packageContentUri = GetPackageContentUri(_contentBaseAddress, packageId, packageVersion);

            Assert.Equal(packageVersionUri.AbsoluteUri, package.IdKeyword);
            Assert.Equal(CatalogConstants.Package, package.TypeKeyword);
            Assert.Equal(commitId, package.CommitId);
            Assert.Equal(commitTimeStamp, package.CommitTimeStamp);
            Assert.Equal(packageDetails.IdKeyword, package.CatalogEntry.IdKeyword);
            Assert.Equal(CatalogConstants.PackageDetails, package.CatalogEntry.TypeKeyword);
            Assert.Equal(packageDetails.Authors, package.CatalogEntry.Authors);
            Assert.Equal(packageDetails.Description, package.CatalogEntry.Description);
            Assert.Empty(package.CatalogEntry.IconUrl);
            Assert.Equal(packageDetails.Id, package.CatalogEntry.Id);
            Assert.Empty(package.CatalogEntry.Language);
            Assert.Empty(package.CatalogEntry.LicenseUrl);
            Assert.Equal(packageDetails.Listed, package.CatalogEntry.Listed);
            Assert.Empty(package.CatalogEntry.MinClientVersion);
            Assert.Equal(packageContentUri.AbsoluteUri, package.CatalogEntry.PackageContent);
            Assert.Empty(package.CatalogEntry.ProjectUrl);
            Assert.Equal(GetRegistrationDateTime(packageDetails.Published), package.CatalogEntry.Published);
            Assert.Equal(packageDetails.RequireLicenseAcceptance, package.CatalogEntry.RequireLicenseAcceptance);
            Assert.Empty(package.CatalogEntry.Summary);
            Assert.Equal(new[] { string.Empty }, package.CatalogEntry.Tags);
            Assert.Empty(package.CatalogEntry.Title);
            Assert.Equal(packageDetails.Version, package.CatalogEntry.Version);

            var independentPackageUri = GetRegistrationPackageVersionUri(packageId, packageVersion);
            var independentPackage    = GetStorageContent <RegistrationIndependentPackage>(
                registrationStorage,
                independentPackageUri);

            VerifyRegistrationIndependentPackage(
                registrationStorage,
                independentPackage,
                independentPackageUri,
                packageDetails,
                packageId,
                packageVersion);
        }
コード例 #3
0
        private async Task <RegistrationPackage> PollAsync(
            string baseUrl,
            string id,
            string version,
            Func <CatalogEntry, bool> isComplete,
            string successMessageFormat,
            string failureMessageFormat,
            ITestOutputHelper logger)
        {
            await Task.Yield();

            var url = $"{baseUrl}/{id.ToLowerInvariant()}/index.json";

            var nugetVersion = NuGetVersion.Parse(version);
            var duration     = Stopwatch.StartNew();
            var complete     = false;

            RegistrationPackage package = null;

            do
            {
                var root = await _httpClient.GetJsonAsync <RegistrationRoot>(
                    url,
                    allowNotFound : true,
                    logResponseBody : false,
                    logger : logger);

                if (root != null)
                {
                    var page = root.Items
                               .SingleOrDefault(item => item.Lower <= nugetVersion && nugetVersion <= item.Upper);

                    if (page != null)
                    {
                        if (!page.Items.Any())
                        {
                            page = await _httpClient.GetJsonAsync <RegistrationPage>(
                                page.Id.AbsoluteUri,
                                allowNotFound : true,
                                logResponseBody : false,
                                logger : logger);
                        }

                        if (page != null)
                        {
                            package = page.Items
                                      .SingleOrDefault(item => item.CatalogEntry.Id == id && item.CatalogEntry.Version == version);

                            if (package != null)
                            {
                                complete = isComplete(package.CatalogEntry);
                            }
                        }
                    }
                }

                if (!complete && duration.Elapsed + TestData.V3SleepDuration < TestData.RegistrationWaitDuration)
                {
                    await Task.Delay(TestData.V3SleepDuration);
                }
            }while (!complete && duration.Elapsed < TestData.RegistrationWaitDuration);

            Assert.True(complete, string.Format(failureMessageFormat, url, duration.Elapsed));
            logger.WriteLine(string.Format(successMessageFormat, url, duration.Elapsed));

            return(package);
        }
コード例 #4
0
        private void VerifyRegistrationPackage(
            MemoryStorage registrationStorage,
            RegistrationPackage package,
            CatalogIndependentPackageDetails packageDetails,
            string commitId,
            string commitTimeStamp,
            bool filterOutDeprecation)
        {
            var packageId         = packageDetails.Id.ToLowerInvariant();
            var packageVersion    = packageDetails.Version.ToLowerInvariant();
            var packageVersionUri = GetRegistrationPackageVersionUri(packageId, packageVersion);
            var packageContentUri = GetPackageContentUri(_contentBaseAddress, packageId, packageVersion);

            Assert.Equal(packageVersionUri.AbsoluteUri, package.IdKeyword);
            Assert.Equal(CatalogConstants.Package, package.TypeKeyword);
            Assert.Equal(commitId, package.CommitId);
            Assert.Equal(commitTimeStamp, package.CommitTimeStamp);
            Assert.Equal(packageDetails.IdKeyword, package.CatalogEntry.IdKeyword);
            Assert.Equal(CatalogConstants.PackageDetails, package.CatalogEntry.TypeKeyword);
            Assert.Equal(packageDetails.Authors, package.CatalogEntry.Authors);
            Assert.Equal(packageDetails.Description, package.CatalogEntry.Description);
            Assert.Empty(package.CatalogEntry.IconUrl);
            Assert.Equal(packageDetails.Id, package.CatalogEntry.Id);
            Assert.Empty(package.CatalogEntry.Language);
            Assert.Empty(package.CatalogEntry.LicenseUrl);
            Assert.Equal(packageDetails.Listed, package.CatalogEntry.Listed);
            Assert.Empty(package.CatalogEntry.MinClientVersion);
            Assert.Equal(packageContentUri.AbsoluteUri, package.CatalogEntry.PackageContent);
            Assert.Empty(package.CatalogEntry.ProjectUrl);
            Assert.Equal(GetRegistrationDateTime(packageDetails.Published), package.CatalogEntry.Published);
            Assert.Equal(packageDetails.RequireLicenseAcceptance, package.CatalogEntry.RequireLicenseAcceptance);
            Assert.Empty(package.CatalogEntry.Summary);
            Assert.Equal(new[] { string.Empty }, package.CatalogEntry.Tags);
            Assert.Empty(package.CatalogEntry.Title);
            Assert.Equal(packageDetails.Version, package.CatalogEntry.Version);

            var actualDeprecation   = package.CatalogEntry.Deprecation;
            var expectedDeprecation = packageDetails.Deprecation;

            if (filterOutDeprecation || expectedDeprecation == null)
            {
                Assert.Null(actualDeprecation);
            }
            else
            {
                Assert.NotNull(actualDeprecation);

                Assert.Equal(expectedDeprecation.Reasons.OrderBy(r => r), actualDeprecation.Reasons.OrderBy(r => r));
                Assert.Equal(expectedDeprecation.Message, actualDeprecation.Message);

                var actualDeprecationAltPackage   = actualDeprecation.AlternatePackage;
                var expectedDeprecationAltPackage = expectedDeprecation.AlternatePackage;
                if (expectedDeprecationAltPackage == null)
                {
                    Assert.Null(actualDeprecationAltPackage);
                }
                else
                {
                    Assert.NotNull(actualDeprecationAltPackage);

                    Assert.Equal(expectedDeprecationAltPackage.Id, actualDeprecationAltPackage.Id);
                    Assert.Equal(expectedDeprecationAltPackage.Range, actualDeprecationAltPackage.Range);
                }
            }

            var independentPackageUri = GetRegistrationPackageVersionUri(packageId, packageVersion);
            var independentPackage    = GetStorageContent <RegistrationIndependentPackage>(
                registrationStorage,
                independentPackageUri);

            VerifyRegistrationIndependentPackage(
                registrationStorage,
                independentPackage,
                independentPackageUri,
                packageDetails,
                packageId,
                packageVersion);
        }