Ejemplo n.º 1
0
 public LocalRunner(string schemaPath, int port, ProjectRunArgs args, ImageCredentials image)
 {
     Port           = port;
     ProjectRunArgs = args;
     SchemaPath     = schemaPath;
     this.image     = image;
     watcher        = new FileSystemWatcher();
 }
Ejemplo n.º 2
0
        public async Task DeployLocally(FileInfo csdl, string portString, bool seedData)
        {
            if (csdl != null)
            {
                app.Out.WriteLine($"Schema Path: {csdl.FullName}");
            }

            Random r    = new Random();
            int    port = r.Next(4000, 9000);

            if (!string.IsNullOrEmpty(portString))
            {
                port = int.Parse(portString);
            }

            string Schema = File.ReadAllText(csdl.FullName);

            var args = new ProjectRunArgs()
            {
                SeedData = seedData
            };

            var image = await imageProvider.GetCredentials();

            app.Out.WriteLine("Updating core service...");
            var updater = new ServiceUpdater(image);

            updater.UpdateService();

            using (var serverRunner = new LocalRunner(csdl.FullName, port, args, image))
            {
                Console.CancelKeyPress += (sender, args) =>
                {
                    // dispose server if terminated with Ctrl+C
                    serverRunner.Stop();
                    Environment.Exit(0);
                };

                serverRunner.OnError        = e => app.Error.WriteLine(e.Message);
                serverRunner.OnSchemaChange = () => app.Out.WriteLine($"Changes detected to {csdl.FullName}...");
                serverRunner.BeforeRestart  = (path, port) => app.Out.WriteLine("Restarting server...");
                serverRunner.AfterRestart   = (path, port) => app.Out.WriteLine($"Server running on http://localhost:{port}/odata");
                serverRunner.OnTerminate    = () => app.Out.WriteLine("Terminating server...");
                serverRunner.Start();

                app.Out.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
Ejemplo n.º 3
0
        public async Task DeployRemotely(FileInfo csdl, string appId, string tenantId, string subscriptionId, bool seedData)
        {
            var config = configManager.GetRootConfig();

            if (appId == null)
            {
                throw new Exception("Please specify unique app name for remote deployment");
            }

            if (csdl == null)
            {
                throw new Exception("Please specify the schema file for your project");
            }

            tenantId ??= config.Tenant;
            subscriptionId ??= config.Subscription;

            if (string.IsNullOrEmpty(tenantId))
            {
                throw new Exception("Please provide value for tenant");
            }

            app.Out.WriteLine($"Schema Path: {csdl.FullName}");
            app.Out.WriteLine($"App name: {appId}");
            app.Out.WriteLine($"Tenant Id: {tenantId}");
            app.Out.WriteLine($"Subscription Id: {subscriptionId}");

            var args = new ProjectRunArgs()
            {
                SeedData = seedData
            };

            var image = await imageProvider.GetCredentials();

            var remoteManager = new RemoteServiceManager(tenantId, subscriptionId, image)
            {
                OnAuthenticating = () => app.Out.WriteLine("Signing into your Azure subscription...")
            };

            var deployment = await remoteManager.Create(appId, csdl.FullName, args);

            var project = deployment.Project;

            configManager.SaveProjectData(project);
            app.Out.WriteLine($"App created successfully. Your app URL is: {project.AppUrl}");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a remote service based on the specified schema and deploys it on Azure
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="schema"></param>
        /// <returns></returns>
        public async Task <RemoteDeployment> Create(string appId, string schemaPath, ProjectRunArgs projectRunArgs)
        {
            await InitClient();

            SchemaValidator.ValidateSchema(schemaPath);

            var project = new RemoteProject();

            project.AppId           = appId;
            project.SubScriptionId  = azure.SubscriptionId;
            project.TenantId        = tenantId;
            project.SeedData        = projectRunArgs.SeedData;
            project.LocalSchemaPath = schemaPath;

            var deployment = new RemoteDeployment();

            deployment.Project        = project;
            deployment.StartedAt      = DateTimeOffset.Now;
            deployment.DeploymentName = $"dep{appId}";

            var rgName             = $"rg{appId}";
            var storageAccountName = $"st{appId}";
            var shareName          = $"share{appId}";

            project.ResourceGroup      = rgName;
            project.StorageAccountName = storageAccountName;
            project.AzureFileShare     = shareName;


            var region = Region.USCentral;

            project.Region = region.Name;

            await azure.ResourceGroups.Define(rgName).WithRegion(region).CreateAsync();

            // create storage account
            var storage = await azure.StorageAccounts.Define(storageAccountName).WithRegion(region)
                          .WithExistingResourceGroup(rgName)
                          .WithAccessFromAllNetworks()
                          .CreateAsync();

            var stKey = storage.GetKeys().First().Value;

            project.StorageAccountKey = stKey;

            var storageConnString = $"DefaultEndpointsProtocol=https;AccountName={storage.Name};AccountKey={stKey}";
            var shareClient       = new ShareClient(storageConnString, shareName);
            await shareClient.CreateAsync();

            // upload CSDL
            await UploadSchema(shareClient, schemaPath, RemoteCsdlFileDir, RemoteCsdlFileName);

            var template     = TemplateHelper.CreateDeploymentTemplate(project, image);
            var templateJson = JsonSerializer.Serialize(template);
            await azure.Deployments.Define(deployment.DeploymentName)
            .WithExistingResourceGroup(rgName)
            .WithTemplate(templateJson)
            .WithParameters("{}")
            .WithMode(Microsoft.Azure.Management.ResourceManager.Fluent.Models.DeploymentMode.Incremental)
            .CreateAsync();

            deployment.FinishedAt = DateTimeOffset.Now;

            return(deployment);
        }