private async Task uploadReleaseAssets(AppKey appKey, AppVersionKey versionKey, XtiGitHubRepository gitHubRepo, GitHubRelease release)
        {
            Console.WriteLine("Uploading app.zip");
            var publishDir = getPublishDir(appKey, versionKey);
            var appZipPath = Path.Combine(publishDir, "app.zip");

            if (File.Exists(appZipPath))
            {
                File.Delete(appZipPath);
            }
            ZipFile.CreateFromDirectory(Path.Combine(publishDir, "App"), appZipPath);
            using (var appStream = new MemoryStream(File.ReadAllBytes(appZipPath)))
            {
                appStream.Seek(0, SeekOrigin.Begin);
                await gitHubRepo.UploadReleaseAsset(release, new FileUpload(appStream, "app.zip", "application/zip"));
            }
            var publishSetupDir = Path.Combine(publishDir, "Setup");

            if (Directory.Exists(publishSetupDir))
            {
                Console.WriteLine("Uploading setup.zip");
                var setupZipPath = Path.Combine(publishDir, "setup.zip");
                if (File.Exists(setupZipPath))
                {
                    File.Delete(setupZipPath);
                }
                ZipFile.CreateFromDirectory(publishSetupDir, setupZipPath);
                using (var setupStream = new MemoryStream(File.ReadAllBytes(setupZipPath)))
                {
                    setupStream.Seek(0, SeekOrigin.Begin);
                    await gitHubRepo.UploadReleaseAsset(release, new FileUpload(setupStream, "setup.zip", "application/zip"));
                }
            }
        }
Exemple #2
0
        internal async Task <AppVersion> StartNewVersion(AppVersionKey key, App app, DateTimeOffset timeAdded, AppVersionType type)
        {
            AppVersionRecord record = null;
            await factory.DB.Transaction(async() =>
            {
                record = new AppVersionRecord
                {
                    VersionKey  = new GeneratedKey().Value(),
                    AppID       = app.ID.Value,
                    Major       = 0,
                    Minor       = 0,
                    Patch       = 0,
                    TimeAdded   = timeAdded,
                    Description = "",
                    Status      = AppVersionStatus.Values.New.Value,
                    Type        = type.Value
                };
                await factory.DB.Versions.Create(record);
                if (key.Equals(AppVersionKey.None))
                {
                    await factory.DB.Versions.Update(record, r => r.VersionKey = new AppVersionKey(r.ID).Value);
                }
            });

            return(factory.Version(record));
        }
 public ApiAppClass(string ns, Func <string, Stream> createStream, AppApiTemplate template, AppVersionKey versionKey)
 {
     this.ns           = ns;
     this.createStream = createStream;
     this.template     = template;
     this.versionKey   = versionKey;
 }
        public async Task ShouldSetStatusToPublishing()
        {
            var tester = await setup();

            var hubApi  = tester.Services.GetService <HubAppApi>();
            var version = await hubApi.AppRegistration.NewVersion.Invoke(new NewVersionRequest
            {
                AppKey      = HubInfo.AppKey,
                VersionType = AppVersionType.Values.Patch
            });

            var adminUser = await tester.AdminUser();

            var versionKey = AppVersionKey.Parse(version.VersionKey);
            var request    = new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = versionKey
            };
            await tester.Execute(request, adminUser);

            version = await hubApi.AppRegistration.GetVersion.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = versionKey
            });

            Assert.That(version.Status, Is.EqualTo(AppVersionStatus.Values.Publishing));
        }
Exemple #5
0
 public HubClientVersion(HubAppClient hubClient, HubClientAppContext appContext, AppVersionModel model)
 {
     this.hubClient  = hubClient;
     this.appContext = appContext;
     ID         = new EntityID(model.ID);
     versionKey = AppVersionKey.Parse(model.VersionKey);
 }
Exemple #6
0
        public async Task Execute(VersionToolOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AppName))
            {
                throw new ArgumentException("App Name is required");
            }
            if (string.IsNullOrWhiteSpace(options.AppType))
            {
                throw new ArgumentException("App Type is required");
            }
            var gitRepo = await gitFactory.CreateGitRepo();

            var branchName    = gitRepo.CurrentBranchName();
            var xtiBranchName = XtiBranchName.Parse(branchName);

            if (xtiBranchName is not XtiVersionBranchName versionBranchName)
            {
                throw new ArgumentException($"Branch '{branchName}' is not a version branch");
            }
            var version = await hubApi.AppRegistration.BeginPublish.Invoke(new GetVersionRequest
            {
                AppKey     = options.AppKey(),
                VersionKey = AppVersionKey.Parse(versionBranchName.Version.Key)
            });

            var output = new VersionOutput();

            output.Output(version, options.OutputPath);
        }
Exemple #7
0
        public async Task <IAppVersion> Version(AppVersionKey versionKey)
        {
            var modifier = await appContext.GetModifierKey();

            var version = await hubClient.Version.GetVersion(modifier, versionKey.Value);

            return(new HubClientVersion(hubClient, appContext, version));
        }
Exemple #8
0
        public async Task <AppVersionModel> Execute(string versionKey)
        {
            var app = await appFromPath.Value();

            var version = await app.Version(AppVersionKey.Parse(versionKey));

            return(version.ToModel());
        }
 public HubClientResourceGroup(HubAppClient hubClient, HubClientAppContext appContext, AppVersionKey versionKey, ResourceGroupModel model)
 {
     this.hubClient  = hubClient;
     this.appContext = appContext;
     this.versionKey = versionKey;
     ID   = new EntityID(model.ID);
     name = new ResourceGroupName(model.Name);
 }
Exemple #10
0
        public async Task ShouldOnlyAllowOneCurrentVersion()
        {
            var tester = await setup();

            var hubApi   = tester.Services.GetService <HubAppApi>();
            var version1 = await hubApi.AppRegistration.NewVersion.Invoke(new NewVersionRequest
            {
                AppKey      = HubInfo.AppKey,
                VersionType = AppVersionType.Values.Patch
            });

            await hubApi.AppRegistration.BeginPublish.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version1.VersionKey)
            });

            await hubApi.AppRegistration.EndPublish.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version1.VersionKey)
            });

            var version2 = await hubApi.AppRegistration.NewVersion.Invoke(new NewVersionRequest
            {
                AppKey      = HubInfo.AppKey,
                VersionType = AppVersionType.Values.Patch
            });

            await hubApi.AppRegistration.BeginPublish.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version2.VersionKey)
            });

            await hubApi.AppRegistration.EndPublish.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version2.VersionKey)
            });

            version1 = await hubApi.AppRegistration.GetVersion.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version1.VersionKey)
            });

            version2 = await hubApi.AppRegistration.GetVersion.Invoke(new GetVersionRequest
            {
                AppKey     = HubInfo.AppKey,
                VersionKey = AppVersionKey.Parse(version2.VersionKey)
            });

            Assert.That(version1.Status, Is.EqualTo(AppVersionStatus.Values.Old), "Should archive previous version");
            Assert.That(version2.Status, Is.EqualTo(AppVersionStatus.Values.Current), "Should make latest published version current");
        }
Exemple #11
0
        public async Task ShouldCompleteVersion()
        {
            var services   = setup("Production");
            var appFactory = services.GetService <AppFactory>();
            var app        = await appFactory.Apps().App(HubInfo.AppKey);

            var version = await app.Version(AppVersionKey.Parse("V1169"));

            await version.Published();
        }
Exemple #12
0
 public CsClient
 (
     AppVersionKey versionKey,
     string outputFolder,
     Func <string, Stream> createStream
 )
 {
     this.versionKey = versionKey;
     ns = new NamespaceFromFolder(outputFolder).Value();
     this.createStream = createStream;
 }
        public async Task <ResourceModel> Execute(GetResourceRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var resource = await version.Resource(model.ResourceID);

            return(resource.ToModel());
        }
Exemple #14
0
        public async Task <ResourceGroupModel> Execute(GetResourceGroupRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var group = await version.ResourceGroup(model.GroupID);

            return(group.ToModel());
        }
        public async Task <ModifierCategoryModel> Execute(GetResourceGroupModCategoryRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var group = await version.ResourceGroup(model.GroupID);

            var modCategory = await group.ModCategory();

            return(modCategory.ToModel());
        }
Exemple #16
0
        public async Task Run(AppVersionKey versionKey)
        {
            var versions = await hubApi.AppRegistration.GetVersions.Invoke(HubInfo.AppKey);

            var template = apiFactory.CreateTemplate();
            var request  = new RegisterAppRequest
            {
                AppTemplate = template.ToModel(),
                VersionKey  = versionKey,
                Versions    = versions
            };
            await hubApi.AppRegistration.RegisterApp.Invoke(request);
        }
Exemple #17
0
        public async Task <AppEventModel[]> Execute(GetResourceLogRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var resource = await version.Resource(model.ResourceID);

            var events = await resource.MostRecentErrorEvents(model.HowMany);

            return(events.Select(evt => evt.ToModel()).ToArray());
        }
Exemple #18
0
        public async Task <ResourceModel[]> Execute(GetResourcesRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var resourceGroup = await version.ResourceGroup(model.GroupID);

            var resources = await resourceGroup.Resources();

            return(resources.Select(r => r.ToModel()).ToArray());
        }
        public async Task <AppRequestExpandedModel[]> Execute(GetResourceGroupLogRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var group = await version.ResourceGroup(model.GroupID);

            var requests = await group.MostRecentRequests(model.HowMany);

            return(requests.ToArray());
        }
Exemple #20
0
        public async Task Run(AppVersionKey versionKey)
        {
            var versions = await versionReader.Versions();

            var template = apiFactory.CreateTemplate();
            var request  = new RegisterAppRequest
            {
                AppTemplate = ToClientTemplateModel(template.ToModel()),
                VersionKey  = versionKey,
                Versions    = versions
            };
            await hubClient.AppRegistration.RegisterApp("", request);
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            using var scope = services.CreateScope();
            var defaultSetup = scope.ServiceProvider.GetService <HubAppSetup>();
            var options      = scope.ServiceProvider.GetService <IOptions <SetupOptions> >().Value;
            var versionKey   = string.IsNullOrWhiteSpace(options.VersionKey)
                ? AppVersionKey.Current
                : AppVersionKey.Parse(options.VersionKey);
            await defaultSetup.Run(versionKey);

            var lifetime = scope.ServiceProvider.GetService <IHostApplicationLifetime>();

            lifetime.StopApplication();
        }
Exemple #22
0
    private async Task <IServiceProvider> setup(AppVersionKey versionKey, string domain = "www.xartogg.com")
    {
        var host = Host.CreateDefaultBuilder()
                   .ConfigureServices
                   (
            (hostContext, services) =>
        {
            services.AddMemoryCache();
            services.AddFakesForXtiWebApp(hostContext.Configuration);
            services.AddSingleton <FakeAppOptions>();
            services.AddSingleton(sp => FakeInfo.AppKey);
            services.AddScoped <FakeAppApiFactory>();
            services.AddScoped <AppApiFactory>(sp => sp.GetRequiredService <FakeAppApiFactory>());
            services.AddScoped <FakeAppSetup>();
            services.AddSingleton(_ => new FakeAppClientDomain(domain));
            services.AddSingleton(sp =>
            {
                var cache      = sp.GetRequiredService <IMemoryCache>();
                var appClients = new AppClients(cache);
                appClients.AddAppVersion("Fake", "Current");
                appClients.AddAppClientDomain(sp.GetRequiredService <FakeAppClientDomain>());
                return(appClients);
            });
        }
                   )
                   .Build();
        var scope        = host.Services.CreateScope();
        var sp           = scope.ServiceProvider;
        var pathAccessor = (FakeXtiPathAccessor)sp.GetRequiredService <IXtiPathAccessor>();

        pathAccessor.SetPath
        (
            new XtiPath
            (
                FakeInfo.AppKey.Name.DisplayText,
                versionKey.DisplayText,
                "",
                "",
                ModifierKey.Default
            )
        );
        var setup = sp.GetRequiredService <FakeAppSetup>();
        await setup.Run(AppVersionKey.Current);

        var userContext = sp.GetRequiredService <FakeUserContext>();

        userContext.AddUser(new AppUserName("someone"));
        return(sp);
    }
Exemple #23
0
        public async Task <AppRoleModel[]> Execute(GetResourceRoleAccessRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var resource = await version.Resource(model.ResourceID);

            var allowedRoles = await resource.AllowedRoles();

            var allowedRoleModels = allowedRoles.Select(ar => ar.ToModel()).ToArray();

            return(allowedRoleModels);
        }
        public async Task <ResourceModel> Execute(GetResourceGroupResourceRequest model)
        {
            var app = await appFromPath.Value();

            var versionKey = AppVersionKey.Parse(model.VersionKey);
            var version    = await app.Version(versionKey);

            var group = await version.ResourceGroup(model.GroupID);

            var resourceName = new ResourceName(model.ResourceName);
            var resource     = await group.Resource(resourceName);

            var resourceModel = resource.ToModel();

            return(resourceModel);
        }
Exemple #25
0
        internal async Task <AppVersion> AddVersion(AppVersionKey key, App app, DateTimeOffset timeAdded, AppVersionStatus status, AppVersionType type, Version version)
        {
            var record = new AppVersionRecord
            {
                VersionKey  = key.Value,
                AppID       = app.ID.Value,
                Major       = version.Major,
                Minor       = version.Minor,
                Patch       = version.Build,
                TimeAdded   = timeAdded,
                Description = "",
                Status      = status.Value,
                Type        = type.Value
            };
            await factory.DB.Versions.Create(record);

            return(factory.Version(record));
        }
Exemple #26
0
        public async Task Execute(VersionToolOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.AppName))
            {
                throw new ArgumentException("App Name is required");
            }
            if (string.IsNullOrWhiteSpace(options.AppType))
            {
                throw new ArgumentException("App Type is required");
            }
            if (string.IsNullOrWhiteSpace(options.RepoOwner))
            {
                throw new ArgumentException("Repo Owner is required");
            }
            if (string.IsNullOrWhiteSpace(options.RepoName))
            {
                throw new ArgumentException("Repo Name is required");
            }
            var gitRepo = await gitFactory.CreateGitRepo();

            var currentBranchName = gitRepo.CurrentBranchName();
            var xtiBranchName     = XtiBranchName.Parse(currentBranchName);

            if (xtiBranchName is not XtiVersionBranchName versionBranchName)
            {
                throw new ArgumentException($"Branch '{currentBranchName}' is not a version branch");
            }
            var gitHubRepo = await gitFactory.CreateGitHubRepo(options.RepoOwner, options.RepoName);

            gitRepo.CommitChanges($"Version {versionBranchName.Version.Key}");
            await gitHubRepo.CompleteVersion(versionBranchName);

            var defaultBranchName = await gitHubRepo.DefaultBranchName();

            gitRepo.CheckoutBranch(defaultBranchName);
            await hubApi.AppRegistration.EndPublish.Invoke(new GetVersionRequest
            {
                AppKey     = options.AppKey(),
                VersionKey = AppVersionKey.Parse(versionBranchName.Version.Key)
            });

            gitRepo.DeleteBranch(versionBranchName.Value);
        }
        private async Task runDotNetPublish(AppKey appKey, AppVersionKey versionKey)
        {
            var publishDir    = getPublishDir(appKey, versionKey);
            var publishAppDir = Path.Combine(publishDir, "App");

            Console.WriteLine($"Publishing web app to '{publishAppDir}'");
            var publishProcess = new WinProcess("dotnet")
                                 .WriteOutputToConsole()
                                 .UseArgumentNameDelimiter("")
                                 .AddArgument("publish")
                                 .AddArgument(new Quoted(getProjectDir(appKey)))
                                 .UseArgumentNameDelimiter("-")
                                 .AddArgument("c", getConfiguration())
                                 .UseArgumentValueDelimiter("=")
                                 .AddArgument("p:PublishProfile", "Default")
                                 .AddArgument("p:PublishDir", publishAppDir);
            var result = await publishProcess.Run();

            result.EnsureExitCodeIsZero();
        }
Exemple #28
0
        internal async Task <AppVersion> VersionByApp(App app, AppVersionKey versionKey)
        {
            AppVersion version;

            if (versionKey.Equals(AppVersionKey.Current))
            {
                version = await CurrentVersion(app);
            }
            else
            {
                var record = await factory.DB
                             .Versions
                             .Retrieve()
                             .Where(v => v.AppID == app.ID.Value && v.VersionKey == versionKey.Value)
                             .FirstOrDefaultAsync();

                version = factory.Version(record);
            }
            return(version);
        }
        private string getPublishDir(AppKey appKey, AppVersionKey versionKey)
        {
            string versionDir;

            if (hostEnv.IsProduction())
            {
                versionDir = versionKey.DisplayText;
            }
            else
            {
                versionDir = AppVersionKey.Current.DisplayText;
            }
            return(Path.Combine
                   (
                       getXtiDir(),
                       "Published",
                       hostEnv.EnvironmentName,
                       $"{getAppType(appKey)}s",
                       getAppName(appKey),
                       versionDir
                   ));
        }
        public async Task Execute(VersionToolOptions options)
        {
            AppVersionModel version;
            var             gitRepo = await gitFactory.CreateGitRepo();

            var currentBranchName = gitRepo.CurrentBranchName();
            var xtiBranchName     = XtiBranchName.Parse(currentBranchName);

            if (xtiBranchName is XtiIssueBranchName issueBranchName && !string.IsNullOrWhiteSpace(options.RepoOwner))
            {
                var gitHubRepo = await gitFactory.CreateGitHubRepo(options.RepoOwner, options.RepoName);

                var issue = await gitHubRepo.Issue(issueBranchName.IssueNumber);

                var milestoneName = XtiMilestoneName.Parse(issue.Milestone.Title);
                var versionKey    = AppVersionKey.Parse(milestoneName.Version.Key);
                version = await hubApi.AppRegistration.GetVersion.Invoke(new GetVersionRequest
                {
                    AppKey     = options.AppKey(),
                    VersionKey = versionKey
                });
            }