public void AddCustomizer(ICustomizer customizer)
 {
     _dependencies.Add(customizer);
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Customize([FromBody] RelayBuildRequest request, [FromServices] ICustomizer customizer)
        {
            RelayBuild newBuild = null;

            System.Action cleanupBuild = () =>
            {
                if (newBuild != null)
                {
                    try
                    {
                        context.RelayBuilds.Remove(newBuild);
                        context.SaveChanges();
                    }
                    catch (Exception)
                    {
                    }
                }
            };
            try
            {
                newBuild = Convert(request);
                byte[] output;
                {
                    context.RelayBuilds.Add(newBuild);
                    context.SaveChanges();
                }
                output = await customizer.CustomizeNodeRelay(newBuild);

                var buildName = String.IsNullOrEmpty(newBuild.Name) ? "" : $"_{newBuild.Name}";
                return(File(output, "application/octet-stream", $"Relay_{newBuild.Arch.ToString().ToLower()}_{newBuild.BuildId:x}{buildName}.{newBuild.Type.ToString().ToLower()}"));
            }
            catch (TimeoutException e)
            {
                cleanupBuild();
                return(StatusCode(StatusCodes.Status408RequestTimeout, e.Message));
            }
            catch (CommandQueues.InvalidGateway e)
            {
                cleanupBuild();
                return(StatusCode(StatusCodes.Status410Gone, $"Failed to add build, because {e.Message}. Try restarting gateway."));
            }
            catch (Exception e)
                when(e is CustomizerError || e is GatewayResponseError)
                {
                    cleanupBuild();
                    return(BadRequest(e.Message));
                }
            catch (Exception e)
            {
                cleanupBuild();
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Unknown error. {e.Message}"));
            }
        }
 public FormParameterModifier(ICustomizer after)
 {
     _after = after;
 }
Exemplo n.º 4
0
        public IActionResult GetGatewayExeArchitecture(Build.Architecture architecture, string name, [FromServices] ICustomizer customizer, [FromServices] GatewaysSyncService gss)
        {
            using (var ms = new MemoryStream())
            {
                var rand          = new Random();
                var agentId       = new HexId(rand.NextU64()).ToString();
                var nameOrAgentId = name ?? agentId;
                using (var zipArchive = new ZipArchive(ms, ZipArchiveMode.Create))
                {
                    var gatewayEntry = zipArchive.CreateEntry($"Gateway{architecture}_{nameOrAgentId}.exe");
                    using (var bw = new BinaryWriter(gatewayEntry.Open()))
                    {
                        bw.Write(customizer.GetGateway(architecture));
                    }

                    var configEntry = zipArchive.CreateEntry("GatewayConfiguration.json");
                    var config      = new JObject()
                    {
                        ["BuildId"]         = new HexId(rand.NextU16()).ToString(),
                        ["AgentId"]         = agentId,
                        ["Name"]            = nameOrAgentId,
                        ["API Bridge IP"]   = gss.conf.apiBridge.ipAddress.ToString(),
                        ["API Bridge port"] = gss.conf.apiBridge.port,
                    };
                    using (var w = new StreamWriter(configEntry.Open()))
                    {
                        w.Write(config.ToString());
                    }
                }
                return(File(ms.ToArray(), "application/zip", $"Gateway_{nameOrAgentId}.zip"));
            }
        }