public static void Main(string[] args) { IBus myBus = null; try { myBus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectionStringRabbitMQ", "host=localhost")); var mongoCnn = EnvironmentVariable.GetValueOrDefault("ConnectionStringDocumentDB", "mongodb://localhost"); using (var worker = new ImageWorker(myBus, mongoCnn)) { worker.Init(); Console.WriteLine("ImageProcessor gestartet..."); while (Console.ReadLine() != "quit") { Thread.Sleep(int.MaxValue); } } } catch (Exception ex) { Console.WriteLine("Verbindung ist fehlgeschlagen"); Console.WriteLine(ex); } finally { myBus?.Dispose(); } Console.WriteLine("ImageProcessor beendet..."); }
public static void Main(string[] args) { IBus myBus = null; try { myBus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectionStringRabbitMQ", "host=localhost")); var cnnImageDb = EnvironmentVariable.GetValueOrDefault("ConnectionStringDocumentDB", "mongodb://localhost"); var externalAppUrl = EnvironmentVariable.GetValueOrDefault("ExternalAppUrl", "http://localhost:8000/api/postimage"); using (var transmittter = new Transmitter(myBus, cnnImageDb, externalAppUrl)) { transmittter.Init(); Console.WriteLine("Uploader gestartet..."); while (Console.ReadLine() != "quit") { Thread.Sleep(int.MaxValue); } } } catch (Exception ex) { Console.WriteLine("Uploader ist fehlgeschlagen"); Console.WriteLine(ex); } finally { myBus?.Dispose(); } Console.WriteLine("Uploader beendet..."); }
public static void Main(string[] args) { IBus myBus = null; try { myBus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectingStringRabbitMQ", "host=localhost")); myBus.Subscribe <LogItem>("ConsoleLogger", log => { System.Console.WriteLine("{0:HH:mm:ss.fff} [{1}] {2} -> {3} {4}", log.Timestamp, log.SessionId, log.RemoteHost, log.InstanceHost, log.State); }); System.Console.WriteLine("Logger gestartet..."); System.Console.ReadLine(); } catch (Exception ex) { System.Console.WriteLine("Verbindung ist fehlgeschlagen"); System.Console.WriteLine(ex); } finally { myBus?.Dispose(); } System.Console.WriteLine("Logger beendet..."); }
/// <summary> /// To use log with elasticsearch inputing configuration /// values, create into <i>appsettings.json</i> project /// the follow field: /// <code> /// "Elasticsearch": {<br/> /// "Url": "http://localhost:5151/elasticsearch",<br/> /// "Appname": "YourAppNameInElasticsearch"<br/> /// }, /// </code> /// or create the follow simple field within only elasticsearch url, /// then the app name will be the current execunting assembly name. /// <code> /// "Elasticsearch": "http://localhost:5151/elasticsearch" /// </code> /// </summary> /// <param name="services"></param> /// <returns></returns> public static IServiceCollection AddLogServiceWithElasticsearch(this IServiceCollection services, IConfiguration configuration = null) { if (configuration is null) { var provider = services.BuildServiceProvider(); configuration = provider.GetService <IConfiguration>(); } string elasticsearchUrl = ElasticsearchUrl.GetValueOrDefault(configuration?["Elasticsearch:Url"] ?? configuration?["Elasticsearch"]); string appName = configuration?["Elasticsearch:Appname"] ?? Assembly.GetEntryAssembly().GetName().Name; if (string.IsNullOrWhiteSpace(elasticsearchUrl)) { throw new InvalidOperationException("[Elastisearch:Url|Elasticsearch] URL not set!"); } Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .Enrich.FromLogContext() .WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(elasticsearchUrl)) { AutoRegisterTemplate = true, AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7, IndexFormat = $"{appName}-at-{DateTime.Now:yyyy-MM-dd}", NumberOfReplicas = 1 }).CreateLogger(); return(services.AddLogService()); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { var bus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectionStringRabbitMQ", "host=localhost")); container.Register <IBus>(bus); container.Register(new ImageRepository(EnvironmentVariable.GetValueOrDefault("ConnectionStringImageDB", "host=localhost;database=spartakiade;password=sportfrei;username=spartakiade"))); var authenticationRepository = new AuthenticationRepository(bus); container.Register <AuthenticationRepository>(authenticationRepository); container.Register <IFileHandler, MongoDbFileHandler>(new MongoDbFileHandler(EnvironmentVariable.GetValueOrDefault("ConnectionStringDocumentDB", "mongodb://localhost"))); base.ApplicationStartup(container, pipelines); }
public async Task <IActionResult> Index() { var model = new Dashboard(); var pingMeUrl = EnvironmentVariable.GetValueOrDefault("PingMeUrl", string.Empty); if (!string.IsNullOrEmpty(pingMeUrl)) { model.PingMeInfo = await GetObject <PingMeInfo>(pingMeUrl); } var timeUrl = EnvironmentVariable.GetValueOrDefault("TimeUrl", string.Empty); if (!string.IsNullOrEmpty(timeUrl)) { model.TimeInfo = await GetObject <TimeInfo>(timeUrl); } return(View(model)); }
public static void Main(string[] args) { IBus myBus = null; try { myBus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectionStringRabbitMQ", "host=localhost")); var userRepo = new UserRepository(EnvironmentVariable.GetValueOrDefault("ConnectionStringImageDB", "host=localhost;database=spartakiade;password=sportfrei;username=spartakiade")); myBus.SubscribeAsync <AuthenticationRequest>("Auth", async request => { var response = new AuthenticationResponse { Id = request.Id, }; var userInfo = await userRepo.CheckUser(request.UserName, request.PasswordHash); if (userInfo.IsValid) { response.UserId = userInfo.Id; response.User = userInfo.User; response.IsValid = true; } await myBus.PublishAsync(response); }); Console.WriteLine("Authorization gestartet..."); while (Console.ReadLine() != "quit") { Thread.Sleep(int.MaxValue); } } catch (Exception ex) { Console.WriteLine("Authorization - Verbindung ist fehlgeschlagen"); Console.WriteLine(ex); } finally { myBus?.Dispose(); } Console.WriteLine("Authorization beendet..."); }
public async Task <ActionResult> Execute([FromRoute] string appkey, [FromBody] DockerhubWebhock webhock, CancellationToken ct) { if (!string.IsNullOrEmpty(SecretHelper.GetSecret("appkey"))) { if (!string.Equals(appkey, SecretHelper.GetSecret("appkey"), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine($"HTTP 401: appkey invalid {appkey} "); return(Unauthorized()); } } else { if (!string.Equals(appkey, EnvironmentVariable.GetValueOrDefault("appkey", "topsecret"), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine($"HTTP 401: appkey invalid {appkey} "); return(Unauthorized()); } } if (!string.Equals(webhock.PushData.Tag, EnvironmentVariable.GetValue("tag")) || !string.Equals(webhock.Repository.Owner, EnvironmentVariable.GetValue("owner")) || !string.Equals(webhock.Repository.Name, EnvironmentVariable.GetValue("imagename"))) { return(BadRequest($"docker invalid: tag {webhock.PushData.Tag} / owner {webhock.Repository.Owner} / imagename {webhock.Repository.Name}")); } string containerName = EnvironmentVariable.GetValue("containername"); string portMap = EnvironmentVariable.GetValueOrDefault("portmap", ""); var helper = new ContainerHelper(EnvironmentVariable.GetValueOrDefault("endpointUrl", "unix:///var/run/docker.sock")); helper.PullImage(webhock.Repository.Owner, webhock.Repository.Name, webhock.PushData.Tag, ct); var containerId = await helper.GetContainerIdByName(containerName, ct); if (!string.IsNullOrEmpty(containerId)) { await helper.StopContainer(containerId, ct); await helper.DeleteContainer(containerId); } await helper.StartContainer(containerName, webhock.Repository.Owner, webhock.Repository.Name, webhock.PushData.Tag, portMap, ct); return(Ok()); }
public DockerHubModule() { Post("/dockerhub/{appkey}", async(ctx, ct) => { if (!string.Equals(ctx.appkey, EnvironmentVariable.GetValueOrDefault("appkey", "topsecret"), StringComparison.CurrentCultureIgnoreCase)) { Console.WriteLine($"HTTP 401: appkey invalid {ctx.appkey} "); return(HttpStatusCode.Unauthorized); } using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8)) { var contentAsText = await reader.ReadToEndAsync(); var webhock = JsonConvert.DeserializeObject <DockerhubWebhock>(contentAsText); if (!string.Equals(webhock.PushData.Tag, EnvironmentVariable.GetValue("tag")) || !string.Equals(webhock.Repository.Owner, EnvironmentVariable.GetValue("owner")) || !string.Equals(webhock.Repository.Name, EnvironmentVariable.GetValue("imagename"))) { Console.WriteLine($"HTTP 400: docker invalid: tag {webhock.PushData.Tag} / owner {webhock.Repository.Owner} / imagename {webhock.Repository.Name}"); return(HttpStatusCode.BadRequest); } string containerName = EnvironmentVariable.GetValue("containername"); string portMap = EnvironmentVariable.GetValueOrDefault("portmap", ""); var helper = new ContainerHelper(EnvironmentVariable.GetValueOrDefault("endpointUrl", "unix://var/run/docker.sock")); await helper.PullImage(webhock.Repository.Owner, webhock.Repository.Name, webhock.PushData.Tag); var containerId = await helper.GetContainerIdByName(containerName); if (!string.IsNullOrEmpty(containerId)) { await helper.StopContainer(containerId, ct); await helper.DeleteContainer(containerId); } await helper.StartContainer(containerName, webhock.Repository.Owner, webhock.Repository.Name, webhock.PushData.Tag, portMap); Console.WriteLine("HTTP 200"); return(HttpStatusCode.OK); } }); }
public static void Main(string[] args) { var dbCnn = EnvironmentVariable.GetValueOrDefault("ConnectionStringImageDB", "host=localhost;database=spartakiade;password=sportfrei;username=spartakiade"); var mongoCnn = EnvironmentVariable.GetValueOrDefault("ConnectionStringDocumentDB", "mongodb://localhost"); var rabbitCnn = EnvironmentVariable.GetValueOrDefault("ConnectionStringRabbitMQ", "host=localhost"); IBus myBus = null; try { myBus = RabbitHutch.CreateBus(rabbitCnn); myBus.SubscribeAsync <ImageSaveJob>("ImagePersistor", async job => { var dbWriter = new DbWriter(mongoCnn, dbCnn); await dbWriter.PersistImage(job.Id, job.UserId, job.SourceId, job.Message, job.Resolution); }); Console.WriteLine("ImagePersistor gestartet..."); while (Console.ReadLine() != "quit") { Thread.Sleep(int.MaxValue); } } catch (Exception ex) { Console.WriteLine("ImagePersistor - Verbindung ist fehlgeschlagen"); Console.WriteLine(ex); } finally { myBus?.Dispose(); } Console.WriteLine("ImagePersistor beendet..."); }
private IBus GetOrCreateBus() { return(bus ?? (bus = RabbitHutch.CreateBus(EnvironmentVariable.GetValueOrDefault("ConnectingStringRabbitMQ", "host=localhost")))); }