Esempio n. 1
0
        public async Task Seed()
        {
            var versionNumber = await _versionNumberFactory.FindOrCreateVersionNumber("1.0.0");

            var disunityVersion = new DisunityVersion {
                Url =
                    $"https://github.com/disunity-hq/core/releases/download/{versionNumber}/disunity-{versionNumber}.zip",
                VersionNumber          = versionNumber,
                CompatibleUnityVersion = new DisunityVersionCompatibility()
            };

            _context.DisunityVersions.Add(disunityVersion);

            await _context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <ModVersion> FromArchiveAsync(ZipArchive archive)
        {
            var manifest = archive.Manifest;

            var existingVersion = await _context.ModVersions
                                  .Where(v => v.Mod.Owner.Slug == manifest.OrgID &&
                                         v.Mod.Slug == manifest.ModID)
                                  .FindExactVersion(manifest.Version)
                                  .SingleOrDefaultAsync();

            if (existingVersion != null)
            {
                if (existingVersion.IsActive == true)
                {
                    throw new InvalidOperationException(
                              $"Cannot create mod version {manifest.OrgID}/{manifest.ModID}@{manifest.Version} as it already exists");
                }
                else
                {
                    _context.ModVersions.Remove(existingVersion);
                }
            }

            var mod = await _context.Mods.FirstOrDefaultAsync(m => m.Slug == manifest.ModID);

            var owner = await _context.Orgs.FirstOrDefaultAsync(o => o.Slug == manifest.OrgID);

            if (mod == null)
            {
                mod = new Mod()
                {
                    Owner = owner,
                    Slug  = manifest.ModID,
                };

                _context.Attach(mod);
            }

            var modVersion = new ModVersion()
            {
                Mod           = mod,
                Description   = manifest.Description,
                Readme        = archive.Readme,
                DisplayName   = manifest.DisplayName,
                FileId        = "",
                IconUrl       = "",
                WebsiteUrl    = manifest.URL,
                VersionNumber = await _versionNumberFactory.FindOrCreateVersionNumber(manifest.Version),
            };

            var requiredDeps = manifest.Dependencies
                               .Select(DependencyDictToModDependency(
                                           modVersion, ModDependencyType.Dependency));

            var optionalDeps = manifest.OptionalDependencies.Select(
                DependencyDictToModDependency(
                    modVersion, ModDependencyType.OptionalDependency));

            var incompatible = manifest.Incompatibilities.Select(
                DependencyDictToModDependency(
                    modVersion, ModDependencyType.Incompatible));

            modVersion.ModDependencies = requiredDeps.Concat(optionalDeps).Concat(incompatible).ToList();

            _context.Attach(modVersion);

            return(modVersion);
        }
Esempio n. 3
0
        public async Task Seed()
        {
            var random  = new Random();
            var orgs    = _context.Orgs.ToList();
            var targets = await _context.Targets.ToListAsync();

            var names           = new HashSet <string>();
            var disunityVersion = await _context.DisunityVersions.FirstOrDefaultAsync();

            for (var i = 0; i < 45; i++)
            {
                var org             = orgs.PickRandom();
                var target          = targets.PickRandom();
                var version         = new VersionNumber(random.Next(3), random.Next(3), random.Next(3));
                var attachedVersion = await _versionNumberFactory.FindOrCreateVersionNumber(version);

                var displayName = _unparser.Generate("#display_name.title#");

                while (names.Contains(displayName))
                {
                    displayName = _unparser.Generate("#display_name.title#");
                }

                names.Add(displayName);

                var slug        = _slugifier.Slugify(displayName);
                var description = _unparser.Generate("#description.capitalize#");
                var iconUrl     = _iconRandomizer.GetIconUrl();
                var website     = _unparser.Generate("http://#adjective##noun.s#.#tld#");
                var readme      = displayName + "\n=====\n\n" + _unparser.Generate("#readme#");

                var modVersion = new ModVersion()
                {
                    Description           = description,
                    Readme                = readme,
                    DisplayName           = displayName,
                    FileId                = "",
                    IconUrl               = iconUrl,
                    VersionNumber         = attachedVersion,
                    WebsiteUrl            = website,
                    IsActive              = true,
                    TargetCompatibilities = new List <ModTargetCompatibility>
                    {
                        new ModTargetCompatibility()
                        {
                            Target = target
                        }
                    },
                    DisunityCompatibilities = new List <ModDisunityCompatibility> {
                        new ModDisunityCompatibility()
                        {
                            MinCompatibleVersion = disunityVersion
                        }
                    }
                };

                var mod = new Mod()
                {
                    Owner    = org,
                    Slug     = slug,
                    Versions = new List <ModVersion>()
                    {
                        modVersion
                    },
                };

                _context.Mods.Add(mod);
            }

            await _context.SaveChangesAsync();
        }