Esempio n. 1
0
        [HttpPut("{server}/{database}/script/{uuid}")] public async Task <ActionResult> UpdateScript([FromRoute] Guid server, [FromRoute] Guid database, [FromRoute] Guid uuid, [FromBody] MetaScript script)
        {
            if (script.Identity != uuid)
            {
                return(BadRequest());
            }
            DatabaseServer srv = Metadata.Servers.Where(s => s.Identity == server).FirstOrDefault();

            if (srv == null)
            {
                return(NotFound());
            }
            DatabaseInfo db = srv.Databases.Where(db => db.Identity == database).FirstOrDefault();

            if (db == null)
            {
                return(NotFound());
            }
            MetaScript existing = db.Scripts.Where(scr => scr.Identity == uuid).FirstOrDefault();

            if (existing == null)
            {
                return(NotFound());
            }

            string    catalogName = GetDatabaseCatalog(srv, db);
            string    scriptPath  = $"{catalogName}/{uuid.ToString().ToLower()}{SCRIPT_FILE_EXTENSION}";
            IFileInfo fileInfo    = FileProvider.GetFileInfo(scriptPath);

            using (var stream = System.IO.File.Create(fileInfo.PhysicalPath))
            {
                await stream.WriteAsync(Convert.FromBase64String(script.SourceCode));
            }

            script.CopyTo(existing);
            existing.SourceCode = string.Empty;
            SaveMetadataSettings();

            return(Ok());
        }