Ejemplo n.º 1
0
        public static XmlSchema IsSchemaValid(XmlReader reader, bool warningsAsError)
        {
            Assert.IsNotNull(reader);
            SchemaValidator validator = new SchemaValidator(warningsAsError);

            return(validator.ValidateSchema(reader));
        }
Ejemplo n.º 2
0
        public static XmlSchema IsSchemaValid(Stream stream, bool warningsAsError)
        {
            Assert.IsNotNull(stream);
            SchemaValidator validator = new SchemaValidator(warningsAsError);

            return(validator.ValidateSchema(stream));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the remote project's schema and restarts the service
        /// </summary>
        /// <param name="project"></param>
        /// <param name="schemaPath"></param>
        /// <returns></returns>
        public async Task UpdateSchema(RemoteProject project, string schemaPath)
        {
            await InitClient();

            SchemaValidator.ValidateSchema(schemaPath);
            var shareClient = new ShareClient(project.StorageConnectionString, project.AzureFileShare);

            await UploadSchema(shareClient, schemaPath, RemoteCsdlFileDir, RemoteCsdlFileName);

            await azure.ContainerGroups.GetByResourceGroup(project.ResourceGroup, project.AppId).RestartAsync();

            project.LocalSchemaPath = schemaPath;
        }
Ejemplo n.º 4
0
        private bool RestartContainer()
        {
            if (!firstStart)
            {
                BeforeRestart?.Invoke(SchemaPath, Port);
            }

            container?.Dispose();
            container = null;

            try
            {
                SchemaValidator.ValidateSchema(SchemaPath);
            }
            catch (Exception ex)
            {
                OnError?.Invoke(ex);
                return(false);
            }


            var builder = new Builder()
                          .UseContainer()
                          .UseImage(image.Name)
                          .WithCredential(image.Server, image.Username, image.Password)
                          .ExposePort(Port, 80)
                          .KeepRunning()
                          .CopyOnStart(SchemaPath, "/app/Project.csdl");

            if (ProjectRunArgs.SeedData)
            {
                builder.WithEnvironment("SEED_DATA=true");
            }

            container = builder
                        .Build();

            container.StopOnDispose   = true;
            container.RemoveOnDispose = true;
            container.Start();

            firstStart = false;

            AfterRestart?.Invoke(SchemaPath, Port);

            return(true);
        }
Ejemplo n.º 5
0
 public static XmlSchema IsSchemaValid(XmlReader reader, bool warningsAsError)
 {
     Assert.IsNotNull(reader);
     SchemaValidator validator = new SchemaValidator(warningsAsError);
     return validator.ValidateSchema(reader);
 }
Ejemplo n.º 6
0
 public static XmlSchema IsSchemaValid(Stream stream, bool warningsAsError)
 {
     Assert.IsNotNull(stream);
     SchemaValidator validator = new SchemaValidator(warningsAsError);
     return validator.ValidateSchema(stream);
 }
Ejemplo n.º 7
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);
        }