Skip to content

Commit

Permalink
1st version
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarfg78 authored Aug 26, 2024
1 parent f3193d2 commit 6d0961c
Show file tree
Hide file tree
Showing 52 changed files with 1,308 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Maxi.Services.SouthSide.Data.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Maxi.Services.SouthSide.Data
{
public class ApplicationDbContext : DbContext
{
private DbSet<ServiceConfiguration> _servicesConfiguration;
private DbSet<ServiceAttribute> _attributes;
private DbSet<GlobalAttributes> _globalAttributes;

public DbSet<ServiceConfiguration> ServicesConfiguration
{
get
{
if (_servicesConfiguration == null)
_servicesConfiguration = Set<ServiceConfiguration>();
return _servicesConfiguration;
}
}

public DbSet<ServiceAttribute> Attributes
{
get
{
if (_attributes == null)
_attributes = Set<ServiceAttribute>();
return _attributes;
}

}

public DbSet<GlobalAttributes> GlobalAttributes
{
get
{
if (_globalAttributes == null)
_globalAttributes = Set<GlobalAttributes>();
return _globalAttributes;
}
}

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
if (modelBuilder != null)
{
// base.OnModelCreating(modelBuilder);
//modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();


foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
// equivalent of modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
entityType.GetForeignKeys()
.Where(fk => !fk.IsOwnership && fk.DeleteBehavior == DeleteBehavior.Cascade)
.ToList()
.ForEach(fk => fk.DeleteBehavior = DeleteBehavior.Restrict);
}

// TODO
//modelBuilder.Conventions.Remove<IncludeMetadataConvention>();


//modelBuilder.Configurations.Add(new ServiceConfiguationScheduleTypeConfiguration());
//modelBuilder.Configurations.Add(new ServiceConfigurationTickTypeConfiguration());
//modelBuilder.Configurations.Add(new ServiceConfigurationTypeConfiguration());
//modelBuilder.Configurations.Add(new ServiceAttributeTypeConfiguration());
//modelBuilder.Configurations.Add(new GlobalAttributesTypeConfiguration());
//modelBuilder.Configurations.Add(new ServiceScheduleTypeConfiguration());

modelBuilder.Entity<ServiceConfiguration>().ToTable("ServiceConfiguration", "Services");
modelBuilder.Entity<ServiceConfiguration>().HasKey(c => c.Code);
modelBuilder.Entity<ServiceAttribute>().ToTable("ServiceAttributes", "Services");
modelBuilder.Entity<ServiceAttribute>().HasKey(c => new { c.Code, c.Key});
modelBuilder.Entity<GlobalAttributes>().ToTable("GlobalAttributes");
modelBuilder.Entity<GlobalAttributes>().HasKey(c => c.Name);


}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder for "MaxiSolution\src\"com.maxi.checks.Repository"\Configurations\AppSettings.json"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder for "MaxiSolution\src\"com.maxi.checks.Repository"\Interfaces\I"com.maxi.checks.Repository"Service.cs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Text;

namespace com.maxi.checks.Repository.Messaging
{
public class RabbitMQMessaging
{
private readonly IConnection _connection;
private readonly IModel _channel;

public RabbitMQMessaging()
{
var factory = new ConnectionFactory() { HostName = "localhost" };
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();
}

public void SendMessage(string queueName, string message)
{
_channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);

var body = Encoding.UTF8.GetBytes(message);

_channel.BasicPublish(exchange: "",
routingKey: queueName,
basicProperties: null,
body: body);
Console.WriteLine(" [x] Sent {0}", message);
}

public void ReceiveMessage(string queueName)
{
_channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);

var consumer = new EventingBasicConsumer(_channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0}", message);
};
_channel.BasicConsume(queue: queueName,
autoAck: true,
consumer: consumer);
}

public void Close()
{
_channel.Close();
_connection.Close();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder for "MaxiSolution\src\"com.maxi.checks.Repository"\Models\"com.maxi.checks.Repository"Model.cs"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Placeholder for "MaxiSolution\src\"com.maxi.checks.Repository"\Program.cs"
Loading

0 comments on commit 6d0961c

Please sign in to comment.