From 722bb2201a74669b8629d8f8888f9ba9f990501f Mon Sep 17 00:00:00 2001 From: MAGDY SALEM <63874487+msalemcode@users.noreply.github.com> Date: Tue, 8 Aug 2023 10:53:00 -0700 Subject: [PATCH 1/3] Adding scheduler notification --- .../20230804174355_Baseline_v8.Designer.cs | 1162 +++++++++++++++++ .../Migrations/20230804174355_Baseline_v8.cs | 20 + .../Migrations/Custom/BaselineV8_Seed.cs | 40 + src/MeteredTriggerJob/MeteredTriggerHelper.cs | 238 +++- src/MeteredTriggerJob/Program.cs | 9 +- src/Services/Helpers/EmailHelper.cs | 60 + .../ApplicationConfigurationService.cs | 5 + .../MeteredPlanSchedulerManagementService.cs | 93 +- 8 files changed, 1558 insertions(+), 69 deletions(-) create mode 100644 src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs create mode 100644 src/DataAccess/Migrations/20230804174355_Baseline_v8.cs create mode 100644 src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs diff --git a/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs b/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs new file mode 100644 index 00000000..76892fbc --- /dev/null +++ b/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs @@ -0,0 +1,1162 @@ +// +using System; +using Marketplace.SaaS.Accelerator.DataAccess.Context; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations +{ + [DbContext(typeof(SaasKitContext))] + [Migration("20230804174355_Baseline_v8")] + partial class Baseline_v8 + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ApplicationConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Name") + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ApplicationConfiguration"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ApplicationLog", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ActionTime") + .HasColumnType("datetime"); + + b.Property("LogDetail") + .HasMaxLength(4000) + .IsUnicode(false) + .HasColumnType("varchar(4000)"); + + b.HasKey("Id"); + + b.ToTable("ApplicationLog"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.DatabaseVersionHistory", b => + { + b.Property("ChangeLog") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CreateBy") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("VersionNumber") + .HasColumnType("decimal(6,2)"); + + b.ToTable("DatabaseVersionHistory"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.EmailTemplate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Bcc") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)") + .HasColumnName("BCC"); + + b.Property("Cc") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)") + .HasColumnName("CC"); + + b.Property("Description") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)"); + + b.Property("InsertDate") + .HasColumnType("datetime"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("Status") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)"); + + b.Property("Subject") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)"); + + b.Property("TemplateBody") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("ToRecipients") + .HasMaxLength(1000) + .IsUnicode(false) + .HasColumnType("varchar(1000)"); + + b.HasKey("Id"); + + b.ToTable("EmailTemplate"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Events", b => + { + b.Property("EventsId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("EventsId"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("EventsName") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.HasKey("EventsId"); + + b.ToTable("Events"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.KnownUsers", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("RoleId") + .HasColumnType("int"); + + b.Property("UserEmail") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("KnownUsers"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredAuditLogs", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedBy") + .HasColumnType("int"); + + b.Property("CreatedDate") + .HasColumnType("datetime"); + + b.Property("RequestJson") + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("varchar(500)"); + + b.Property("ResponseJson") + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("varchar(500)"); + + b.Property("RunBy") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("StatusCode") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)"); + + b.Property("SubscriptionId") + .HasColumnType("int"); + + b.Property("SubscriptionUsageDate") + .HasColumnType("datetime"); + + b.HasKey("Id"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("MeteredAuditLogs"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreatedDate") + .HasColumnType("datetime"); + + b.Property("Description") + .HasMaxLength(250) + .IsUnicode(false) + .HasColumnType("varchar(250)"); + + b.Property("Dimension") + .HasMaxLength(150) + .IsUnicode(false) + .HasColumnType("varchar(150)"); + + b.Property("PlanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanId"); + + b.ToTable("MeteredDimensions"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredPlanSchedulerManagement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("DimensionId") + .IsRequired() + .HasColumnType("int"); + + b.Property("FrequencyId") + .IsRequired() + .HasColumnType("int"); + + b.Property("NextRunTime") + .HasColumnType("datetime2"); + + b.Property("PlanId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Quantity") + .IsRequired() + .HasColumnType("float"); + + b.Property("SchedulerName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("StartDate") + .IsRequired() + .HasColumnType("datetime2"); + + b.Property("SubscriptionId") + .IsRequired() + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DimensionId"); + + b.HasIndex("FrequencyId"); + + b.HasIndex("PlanId"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("MeteredPlanSchedulerManagement"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.OfferAttributes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("Description") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("DisplayName") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("DisplaySequence") + .HasColumnType("int"); + + b.Property("FromList") + .HasColumnType("bit"); + + b.Property("IsDelete") + .HasColumnType("bit"); + + b.Property("IsRequired") + .HasColumnType("bit"); + + b.Property("Isactive") + .HasColumnType("bit"); + + b.Property("Max") + .HasColumnType("int"); + + b.Property("Min") + .HasColumnType("int"); + + b.Property("OfferId") + .HasColumnType("uniqueidentifier"); + + b.Property("ParameterId") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("Type") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("ValueTypeId") + .HasColumnType("int"); + + b.Property("ValuesList") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OfferAttributes"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Offers", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("OfferGuid") + .HasColumnType("uniqueidentifier") + .HasColumnName("OfferGUId"); + + b.Property("OfferId") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("OfferName") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Offers"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanAttributeMapping", b => + { + b.Property("PlanAttributeId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PlanAttributeId"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("IsEnabled") + .HasColumnType("bit"); + + b.Property("OfferAttributeId") + .HasColumnType("int") + .HasColumnName("OfferAttributeID"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("PlanAttributeId") + .HasName("PK__PlanAttr__8B476A98C058FAF2"); + + b.ToTable("PlanAttributeMapping"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanAttributeOutput", b => + { + b.Property("RowNumber") + .HasColumnType("int"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("IsEnabled") + .HasColumnType("bit"); + + b.Property("OfferAttributeId") + .HasColumnType("int"); + + b.Property("PlanAttributeId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.HasKey("RowNumber") + .HasName("PK__PlanAttr__AAAC09D888FE3E40"); + + b.ToTable("PlanAttributeOutput"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanEventsMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CopyToCustomer") + .HasColumnType("bit"); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("EventId") + .HasColumnType("int"); + + b.Property("FailureStateEmails") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("Isactive") + .HasColumnType("bit"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier"); + + b.Property("SuccessStateEmails") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("PlanEventsMapping"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanEventsOutPut", b => + { + b.Property("RowNumber") + .HasColumnType("int"); + + b.Property("CopyToCustomer") + .HasColumnType("bit"); + + b.Property("EventId") + .HasColumnType("int"); + + b.Property("EventsName") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("FailureStateEmails") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("Id") + .HasColumnType("int") + .HasColumnName("ID"); + + b.Property("Isactive") + .HasColumnType("bit"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier"); + + b.Property("SuccessStateEmails") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.HasKey("RowNumber") + .HasName("PK__PlanEven__AAAC09D8C9229532"); + + b.ToTable("PlanEventsOutPut"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Description") + .HasMaxLength(500) + .IsUnicode(false) + .HasColumnType("varchar(500)"); + + b.Property("DisplayName") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)"); + + b.Property("IsPerUser") + .HasColumnType("bit"); + + b.Property("IsmeteringSupported") + .HasColumnType("bit"); + + b.Property("OfferId") + .HasColumnType("uniqueidentifier") + .HasColumnName("OfferID"); + + b.Property("PlanGuid") + .HasColumnType("uniqueidentifier") + .HasColumnName("PlanGUID"); + + b.Property("PlanId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Plans"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Frequency") + .IsRequired() + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("varchar(50)"); + + b.HasKey("Id"); + + b.ToTable("SchedulerFrequency"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerManagerView", b => + { + b.Property("AMPSubscriptionId") + .HasColumnType("uniqueidentifier"); + + b.Property("Dimension") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("Frequency") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("Id") + .HasColumnType("int"); + + b.Property("NextRunTime") + .HasColumnType("datetime2"); + + b.Property("PlanId") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("PurchaserEmail") + .HasColumnType("nvarchar(max)"); + + b.Property("Quantity") + .HasColumnType("float"); + + b.Property("SchedulerName") + .HasColumnType("nvarchar(max)"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.Property("SubscriptionName") + .HasColumnType("nvarchar(max)"); + + b.ToView("SchedulerManagerView"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAttributeValues", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("OfferId") + .HasColumnType("uniqueidentifier") + .HasColumnName("OfferID"); + + b.Property("PlanAttributeId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier") + .HasColumnName("PlanID"); + + b.Property("SubscriptionId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Value") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.HasKey("Id"); + + b.ToTable("SubscriptionAttributeValues"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAuditLogs", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Attribute") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("varchar(20)"); + + b.Property("CreateBy") + .HasColumnType("int"); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("NewValue") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("OldValue") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("varchar(50)"); + + b.Property("SubscriptionId") + .HasColumnType("int") + .HasColumnName("SubscriptionID"); + + b.HasKey("Id"); + + b.HasIndex("SubscriptionId"); + + b.ToTable("SubscriptionAuditLogs"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionEmailOutput", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Name") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("Value") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.ToTable("SubscriptionEmailOutput"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionParametersOutput", b => + { + b.Property("RowNumber") + .HasColumnType("int"); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("DisplaySequence") + .HasColumnType("int"); + + b.Property("FromList") + .HasColumnType("bit"); + + b.Property("Htmltype") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)") + .HasColumnName("HTMLType"); + + b.Property("Id") + .HasColumnType("int"); + + b.Property("IsEnabled") + .HasColumnType("bit"); + + b.Property("IsRequired") + .HasColumnType("bit"); + + b.Property("Max") + .HasColumnType("int"); + + b.Property("Min") + .HasColumnType("int"); + + b.Property("OfferAttributeId") + .HasColumnType("int") + .HasColumnName("OfferAttributeID"); + + b.Property("OfferId") + .HasColumnType("uniqueidentifier"); + + b.Property("PlanAttributeId") + .HasColumnType("int"); + + b.Property("PlanId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubscriptionId") + .HasColumnType("uniqueidentifier"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("Value") + .IsRequired() + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("ValueType") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("ValuesList") + .IsRequired() + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.HasKey("RowNumber") + .HasName("PK__Subscrip__AAAC09D8BA727059"); + + b.ToTable("SubscriptionParametersOutput"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("AmpplanId") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)") + .HasColumnName("AMPPlanId"); + + b.Property("Ampquantity") + .HasColumnType("int") + .HasColumnName("AMPQuantity"); + + b.Property("AmpsubscriptionId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier") + .HasColumnName("AMPSubscriptionId") + .HasDefaultValueSql("(newid())"); + + b.Property("CreateBy") + .HasColumnType("int"); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("IsActive") + .HasColumnType("bit"); + + b.Property("ModifyDate") + .HasColumnType("datetime"); + + b.Property("Name") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)"); + + b.Property("PurchaserEmail") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.Property("PurchaserTenantId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubscriptionStatus") + .HasMaxLength(50) + .IsUnicode(false) + .HasColumnType("varchar(50)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Subscriptions"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId"), 1L, 1); + + b.Property("CreatedDate") + .HasColumnType("datetime"); + + b.Property("EmailAddress") + .HasMaxLength(100) + .IsUnicode(false) + .HasColumnType("varchar(100)"); + + b.Property("FullName") + .HasMaxLength(200) + .IsUnicode(false) + .HasColumnType("varchar(200)"); + + b.HasKey("UserId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ValueTypes", b => + { + b.Property("ValueTypeId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ValueTypeId"), 1L, 1); + + b.Property("CreateDate") + .HasColumnType("datetime"); + + b.Property("Htmltype") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)") + .HasColumnName("HTMLType"); + + b.Property("ValueType") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.HasKey("ValueTypeId") + .HasName("PK__ValueTyp__A51E9C5AEA096123"); + + b.ToTable("ValueTypes"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.WebJobSubscriptionStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ID"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Description") + .IsUnicode(false) + .HasColumnType("varchar(max)"); + + b.Property("InsertDate") + .HasColumnType("datetime"); + + b.Property("SubscriptionId") + .HasColumnType("uniqueidentifier"); + + b.Property("SubscriptionStatus") + .HasMaxLength(225) + .IsUnicode(false) + .HasColumnType("varchar(225)"); + + b.HasKey("Id"); + + b.ToTable("WebJobSubscriptionStatus"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.KnownUsers", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", "Role") + .WithMany("KnownUsers") + .HasForeignKey("RoleId") + .IsRequired() + .HasConstraintName("FK__KnownUser__RoleI__619B8048"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredAuditLogs", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscription") + .WithMany("MeteredAuditLogs") + .HasForeignKey("SubscriptionId") + .HasConstraintName("FK__MeteredAu__Subsc__628FA481"); + + b.Navigation("Subscription"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", "Plan") + .WithMany("MeteredDimensions") + .HasForeignKey("PlanId") + .HasConstraintName("FK__MeteredDi__PlanI__6383C8BA"); + + b.Navigation("Plan"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredPlanSchedulerManagement", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", "MeteredDimensions") + .WithMany("MeteredPlanSchedulerManagements") + .HasForeignKey("DimensionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", "SchedulerFrequency") + .WithMany("MeteredPlanSchedulerManagements") + .HasForeignKey("FrequencyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", "Plan") + .WithMany("MeteredPlanSchedulerManagements") + .HasForeignKey("PlanId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscriptions") + .WithMany("MeteredPlanSchedulerManagements") + .HasForeignKey("SubscriptionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("MeteredDimensions"); + + b.Navigation("Plan"); + + b.Navigation("SchedulerFrequency"); + + b.Navigation("Subscriptions"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAuditLogs", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscription") + .WithMany("SubscriptionAuditLogs") + .HasForeignKey("SubscriptionId") + .HasConstraintName("FK__Subscript__Subsc__6477ECF3"); + + b.Navigation("Subscription"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => + { + b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", "User") + .WithMany("Subscriptions") + .HasForeignKey("UserId") + .HasConstraintName("FK__Subscript__UserI__656C112C"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => + { + b.Navigation("MeteredPlanSchedulerManagements"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", b => + { + b.Navigation("MeteredDimensions"); + + b.Navigation("MeteredPlanSchedulerManagements"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", b => + { + b.Navigation("KnownUsers"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", b => + { + b.Navigation("MeteredPlanSchedulerManagements"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => + { + b.Navigation("MeteredAuditLogs"); + + b.Navigation("MeteredPlanSchedulerManagements"); + + b.Navigation("SubscriptionAuditLogs"); + }); + + modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", b => + { + b.Navigation("Subscriptions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs b/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs new file mode 100644 index 00000000..91472eb5 --- /dev/null +++ b/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs @@ -0,0 +1,20 @@ +using Marketplace.SaaS.Accelerator.DataAccess.Migrations.Custom; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations +{ + public partial class Baseline_v8 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.BaselineV8_SeedData(); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.BaselineV8_DeSeedData(); + } + } +} diff --git a/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs b/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs new file mode 100644 index 00000000..bc6c2593 --- /dev/null +++ b/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Query.Internal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations.Custom +{ + internal static class BaselineV8_Seed + { + public static void BaselineV8_SeedData(this MigrationBuilder migrationBuilder) + { + var seedDate = DateTime.Now; + migrationBuilder.Sql(@$" + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesSuccessfulSchedulerEmail', N'False', N'This will enable sending email for successful metered usage.') + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesFailureSchedulerEmail', N'False', N'This will enable sending email for failure metered usage.') + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesMissingSchedulerEmail', N'False', N'This will enable sending email for missing metered usage.') + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'SchedulerEmailTo', N'', N'Scheduler email receiver(s) ') + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Accepted',N'Accepted',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired Successfully

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Submitted Successfully!',N'True') + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Failure',N'Failure',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired but Failed to Submit Data


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Failure!',N'True') + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Missing',N'Missing',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was skipped by scheduler engine!


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Task was Skipped!',N'True') + GO"); + } + + public static void BaselineV8_DeSeedData(this MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql(@$" + Delete from [dbo].[ApplicationConfiguration] where [Name]= 'EnablesSuccessfulSchedulerEmail' + Delete from [dbo].[ApplicationConfiguration] where [Name]= 'EnablesFailureSchedulerEmail' + Delete From [dbo].[ApplicationConfiguration] where [Name]= 'EnablesMissingSchedulerEmail' + Delete From [dbo].[ApplicationConfiguration] where [Name]= 'SchedulerEmailTo' + Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Usage Submitted Successfully!' + Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Usage Failure!' + Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Task was Skipped!' + GO"); + } + } +} \ No newline at end of file diff --git a/src/MeteredTriggerJob/MeteredTriggerHelper.cs b/src/MeteredTriggerJob/MeteredTriggerHelper.cs index 694215d3..acda2c03 100644 --- a/src/MeteredTriggerJob/MeteredTriggerHelper.cs +++ b/src/MeteredTriggerJob/MeteredTriggerHelper.cs @@ -8,64 +8,123 @@ using Marketplace.SaaS.Accelerator.Services.Exceptions; using Marketplace.SaaS.Accelerator.Services.Models; using Marketplace.SaaS.Accelerator.Services.Services; +using Microsoft.AspNetCore.Mvc; namespace Marketplace.SaaS.Accelerator.MeteredTriggerJob; public class Executor { - - private MeteredPlanSchedulerManagementService schedulerService; - private ISchedulerFrequencyRepository frequencyRepository; + /// + /// Frequency Repository Interface + /// + private readonly ISchedulerFrequencyRepository frequencyRepository; + /// + /// Scheduler Repository Interface + /// private IMeteredPlanSchedulerManagementRepository schedulerRepository; - private ISchedulerManagerViewRepository schedulerViewRepository; + /// + /// Scheduler View Repository Interface + /// + private readonly ISchedulerManagerViewRepository schedulerViewRepository; + /// + /// Subscription Usage Logs Repository Interface + /// private ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository; + /// + /// Metered Billing Api Service Interface + /// private readonly IMeteredBillingApiService billingApiService; + /// + /// Application Config Repository Interface + /// private readonly IApplicationConfigRepository applicationConfigRepository; + /// + /// Email Template Repository Interface + /// + private readonly IEmailTemplateRepository emailTemplateRepository; + /// + /// Email Service Interface + /// + private IEmailService emailService; + /// + /// Metered Plan Scheduler Management Service + /// + private MeteredPlanSchedulerManagementService schedulerService; + /// + /// Application Log Service + /// + private ApplicationLogService applicationLogService = null; + private ApplicationConfigService applicationConfigService = null; + /// + /// Initiate dependency components + /// + /// + /// + /// + /// + /// + /// + /// + /// public Executor(ISchedulerFrequencyRepository frequencyRepository, IMeteredPlanSchedulerManagementRepository schedulerRepository, ISchedulerManagerViewRepository schedulerViewRepository, - ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository, + ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository, IMeteredBillingApiService billingApiService, - IApplicationConfigRepository applicationConfigRepository) + IApplicationConfigRepository applicationConfigRepository, + IEmailService emailService, + IEmailTemplateRepository emailTemplateRepository, IApplicationLogRepository applicationLogRepository) { this.frequencyRepository = frequencyRepository; this.schedulerRepository = schedulerRepository; this.schedulerViewRepository = schedulerViewRepository; this.subscriptionUsageLogsRepository = subscriptionUsageLogsRepository; - this.schedulerService = new MeteredPlanSchedulerManagementService(this.frequencyRepository, this.schedulerRepository, this.schedulerViewRepository, this.subscriptionUsageLogsRepository, this.applicationConfigRepository); this.billingApiService = billingApiService; this.applicationConfigRepository = applicationConfigRepository; + this.emailTemplateRepository = emailTemplateRepository; + this.emailService = emailService; + schedulerService = new MeteredPlanSchedulerManagementService(this.frequencyRepository, + this.schedulerRepository, + this.schedulerViewRepository, + this.subscriptionUsageLogsRepository, + this.applicationConfigRepository, + this.emailTemplateRepository, + this.emailService); + this.billingApiService = billingApiService; + + this.applicationLogService = new ApplicationLogService(applicationLogRepository); + this.applicationConfigService = new ApplicationConfigService(applicationConfigRepository); } + /// + /// Execute the scheduler engine + /// public void Execute() - { - schedulerService = new MeteredPlanSchedulerManagementService(frequencyRepository, - schedulerRepository, - schedulerViewRepository, - subscriptionUsageLogsRepository,applicationConfigRepository); - - + { //Get all Scheduled Data List getAllSchedulerManagerViewData = schedulerService.GetAllSchedulerManagerList(); + //GetCurrentUTC time DateTime _currentUTCTime = DateTime.UtcNow; TimeSpan ts = new TimeSpan(DateTime.UtcNow.Hour, 0, 0); _currentUTCTime = _currentUTCTime.Date + ts; + // Send Email in case of missing Scheduler + bool.TryParse(this.applicationConfigService.GetValueByName("EnablesMissingSchedulerEmail"), out bool enablesMissingSchedulerEmail); //Process each scheduler frequency foreach (SchedulerFrequencyEnum frequency in Enum.GetValues(typeof(SchedulerFrequencyEnum))) { - var ableToParse = bool.TryParse(this.applicationConfigRepository.GetValueByName($"Enable{frequency}MeterSchedules"), out bool runSchedulerForThisFrequency); + + var ableToParse = bool.TryParse(this.applicationConfigService.GetValueByName($"Enable{frequency}MeterSchedules"), out bool runSchedulerForThisFrequency); if (ableToParse && runSchedulerForThisFrequency) { - Console.WriteLine(); - Console.WriteLine($"==== Checking all {frequency} scheduled items at {_currentUTCTime} UTC. ===="); + LogLine($"==== Checking all {frequency} scheduled items at {_currentUTCTime} UTC. ===="); var scheduledItems = getAllSchedulerManagerViewData .Where(a => a.Frequency == frequency.ToString()) @@ -86,44 +145,54 @@ public void Execute() //Past scheduler items if (timeDifferentInHours > 0) { - Console.WriteLine($"Item Id: {scheduledItem.Id} will not run as {_nextRunTime} has passed. Please check audit logs if its has run previously."); + var msg = $"Scheduled Item Id: {scheduledItem.Id} will not run as {_nextRunTime} has passed. Please check audit logs if its has run previously."; + LogLine(msg,true); + + + if (enablesMissingSchedulerEmail) + { + var newMeteredAuditLog = new MeteredAuditLogs() + { + StatusCode = "Missing", + ResponseJson = msg + }; + SendMissingEmail(scheduledItem,newMeteredAuditLog); + } + continue; } else if (timeDifferentInHours < 0) { - Console.WriteLine($"Item Id: {scheduledItem.Id} future run will be at {_nextRunTime} UTC."); + LogLine($"Scheduled Item Id: {scheduledItem.Id} future run will be at {_nextRunTime} UTC."); + continue; } else if (timeDifferentInHours == 0) { - TriggerSchedulerItem(scheduledItem, - frequency, - billingApiService, - schedulerService, - subscriptionUsageLogsRepository); + TriggerSchedulerItem(scheduledItem); } else { - Console.WriteLine($"Item Id: {scheduledItem.Id} will not run as it doesn't match any time difference logic. {_nextRunTime} UTC."); + LogLine($"Scheduled Item Id: {scheduledItem.Id} will not run as it doesn't match any time difference logic. {_nextRunTime} UTC."); } + } } else { - Console.WriteLine($"{frequency} scheduled items will not be run as it's disabled in the application config."); + LogLine($"{frequency} scheduled items will not be run as it's disabled in the application config."); } } } - - public static void TriggerSchedulerItem(SchedulerManagerViewModel item, - SchedulerFrequencyEnum frequency, - IMeteredBillingApiService billingApiService, - MeteredPlanSchedulerManagementService schedulerService, - ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository) + /// + /// Trigger scheduler task + /// + /// scheduler task + private void TriggerSchedulerItem(SchedulerManagerViewModel item) { try { - Console.WriteLine($"---- Item Id: {item.Id} Start Triggering meter event ----"); + LogLine($"---- Scheduled Item Id: {item.Id} Start Triggering meter event ----",true); var subscriptionUsageRequest = new MeteringUsageRequest() { @@ -138,41 +207,38 @@ public static void TriggerSchedulerItem(SchedulerManagerViewModel item, var responseJson = string.Empty; try { - Console.WriteLine($"Item Id: {item.Id} Request {requestJson}"); + LogLine($"Scheduled Item Id: {item.Id} Request {requestJson}", true); meteringUsageResult = billingApiService.EmitUsageEventAsync(subscriptionUsageRequest).ConfigureAwait(false).GetAwaiter().GetResult(); responseJson = JsonSerializer.Serialize(meteringUsageResult); - Console.WriteLine($"Item Id: {item.Id} Response {responseJson}"); + LogLine($"Scheduled Item Id: {item.Id} Response {responseJson}", true); } catch (MarketplaceException marketplaceException) { responseJson = JsonSerializer.Serialize(marketplaceException.Message); meteringUsageResult.Status = marketplaceException.ErrorCode; - Console.WriteLine($" Item Id: {item.Id} Error during EmitUsageEventAsync {responseJson}"); + LogLine($"Scheduled Item Id: {item.Id} Error during EmitUsageEventAsync {responseJson}", true); } - UpdateSchedulerItem(item, - requestJson, - responseJson, - meteringUsageResult.Status, - schedulerService, - subscriptionUsageLogsRepository); + UpdateSchedulerItem(item,requestJson, responseJson,meteringUsageResult.Status); } catch (Exception ex) { - Console.WriteLine(ex.Message); + LogLine(ex.Message, true); } } - public static void UpdateSchedulerItem(SchedulerManagerViewModel item, - string requestJson, - string responseJson, - string status, - MeteredPlanSchedulerManagementService schedulerService, - ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository) + /// + /// Update Scheduler Item + /// + /// scheduler task + /// usage post payload + /// API respond + /// status code + private void UpdateSchedulerItem(SchedulerManagerViewModel item,string requestJson,string responseJson,string status) { try { - Console.WriteLine($"Item Id: {item.Id} Saving Audit information"); + LogLine($"Scheduled Item Id: {item.Id} Saving Audit information", true); var scheduler = schedulerService.GetSchedulerDetailById(item.Id); var newMeteredAuditLog = new MeteredAuditLogs() { @@ -187,9 +253,9 @@ public static void UpdateSchedulerItem(SchedulerManagerViewModel item, }; subscriptionUsageLogsRepository.Save(newMeteredAuditLog); - if ((status == "Accepted")) + if ((status == "Accepted")) { - Console.WriteLine($"Item Id: {item.Id} Meter event Accepted"); + LogLine($"Scheduled Item Id: {item.Id} Meter event Accepted", true); //Ignore updating NextRuntime value for OneTime frequency as they always depend on StartTime value Enum.TryParse(item.Frequency, out SchedulerFrequencyEnum itemFrequency); @@ -197,37 +263,58 @@ public static void UpdateSchedulerItem(SchedulerManagerViewModel item, { scheduler.NextRunTime = GetNextRunTime(item.NextRunTime ?? item.StartDate, itemFrequency); - Console.WriteLine($"Item Id: {item.Id} Updating Scheduler NextRunTime from {item.NextRunTime} to {scheduler.NextRunTime}"); + LogLine($"Scheduled Item Id: {item.Id} Updating Scheduler NextRunTime from {item.NextRunTime} to {scheduler.NextRunTime}", true); schedulerService.UpdateSchedulerNextRunTime(scheduler); } } else { - Console.WriteLine($"Item Id: {item.Id} failed with status {status}. NextRunTime will not be updated."); + LogLine($"Scheduled Item Id: {item.Id} failed with status {status}. NextRunTime will not be updated.", true); + } + LogLine($"Scheduled Item Id: {item.Id} Complete Triggering Meter event.", true); + + // Check if Sending Email is Enabled + _= bool.TryParse(applicationConfigService.GetValueByName("EnablesSuccessfulSchedulerEmail"), out bool enablesSuccessfulSchedulerEmail); + _ = bool.TryParse(applicationConfigService.GetValueByName("EnablesFailureSchedulerEmail"), out bool enablesFailureSchedulerEmail); + if(enablesFailureSchedulerEmail || enablesSuccessfulSchedulerEmail) + { + LogLine("Send scheduled Email"); + schedulerService.SendSchedulerEmail(item, newMeteredAuditLog); } - Console.WriteLine($"Item Id: {item.Id} Complete Triggering Meter event."); } catch (Exception ex) { - Console.WriteLine(ex.Message); + LogLine(ex.Message); } } - public static void PrintScheduler(SchedulerManagerViewModel item, + /// + /// Print Scheduler item + /// + /// scheduler item + /// next run time + /// difference time + private void PrintScheduler(SchedulerManagerViewModel item, DateTime? nextRun, int timeDifferenceInHours) { - Console.WriteLine($"Item Id: {item.Id} " + - $"Expected NextRun : {nextRun} " + - $"SubId : {item.AMPSubscriptionId} " + - $"Plan : {item.PlanId} " + - $"Dim : {item.Dimension} " + - $"Start Date : {item.StartDate} " + - $"NextRun : {item.NextRunTime}" + - $"TimeDifferenceInHours : {timeDifferenceInHours}"); + LogLine($"Scheduled Item Id: {item.Id} " + Environment.NewLine+ + $"Expected NextRun : {nextRun} "+Environment.NewLine+ + $"SubId : {item.AMPSubscriptionId} "+Environment.NewLine+ + $"Plan : {item.PlanId} " + Environment.NewLine + + $"Dim : {item.Dimension} " + Environment.NewLine + + $"Start Date : {item.StartDate} " + Environment.NewLine + + $"NextRun : {item.NextRunTime}" + Environment.NewLine + + $"TimeDifferenceInHours : {timeDifferenceInHours}" + Environment.NewLine ); } - public static DateTime? GetNextRunTime(DateTime? startDate, SchedulerFrequencyEnum frequency) + /// + /// Get Next Run Time + /// + /// Start task Date + /// Task frequency + /// + private DateTime? GetNextRunTime(DateTime? startDate, SchedulerFrequencyEnum frequency) { switch (frequency) { @@ -241,4 +328,23 @@ public static void PrintScheduler(SchedulerManagerViewModel item, { return null; } } } + + private void LogLine(string message, bool appplicationLog=false) { + Console.WriteLine(message); + if(appplicationLog) + this.applicationLogService.AddApplicationLog(message).ConfigureAwait(false); + + } + + private void SendMissingEmail(SchedulerManagerViewModel schedulerTask, MeteredAuditLogs meteredAuditItem) + { + // check if the task was run before + if(!this.schedulerService.CheckIfSchedulerRun(schedulerTask.Id,schedulerTask.SchedulerName)) + { + // send email if it never ran + schedulerService.SendSchedulerEmail(schedulerTask, meteredAuditItem); + } + + + } } \ No newline at end of file diff --git a/src/MeteredTriggerJob/Program.cs b/src/MeteredTriggerJob/Program.cs index aa104fef..47f4aff8 100644 --- a/src/MeteredTriggerJob/Program.cs +++ b/src/MeteredTriggerJob/Program.cs @@ -16,6 +16,10 @@ namespace Marketplace.SaaS.Accelerator.MeteredTriggerJob; class Program { + /// + /// Entery point to the scheduler engine + /// + /// static void Main (string[] args) { @@ -39,11 +43,14 @@ static void Main (string[] args) var creds = new ClientSecretCredential(config.TenantId.ToString(), config.ClientId.ToString(), config.ClientSecret); var services = new ServiceCollection() - .AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))) + .AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Transient) .AddScoped() .AddScoped() .AddScoped() .AddScoped() + .AddScoped() + .AddScoped() + .AddScoped() .AddScoped() .AddSingleton(new MeteredBillingApiService(new MarketplaceMeteringClient(creds), config, new SaaSClientLogger())) .AddSingleton() diff --git a/src/Services/Helpers/EmailHelper.cs b/src/Services/Helpers/EmailHelper.cs index 7c0596a6..358c2633 100644 --- a/src/Services/Helpers/EmailHelper.cs +++ b/src/Services/Helpers/EmailHelper.cs @@ -121,4 +121,64 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, return emailContent; } + + /// + /// Prepares the content of the scheduler email. + /// + /// The subscription Name. + /// scheduler Task Name. + /// response Json. + /// The subscription status. + /// + /// Email Content Model. + /// + /// Error while sending an email, please check the configuration. + /// or + /// Error while sending an email, please check the configuration. + public EmailContentModel PrepareMeteredEmailContent(string schedulerTaskName, String subscriptionName, string subscriptionStatus, string responseJson) + { + bool copyToCustomer = false; + bool isActive = false; + string ccReceipents = string.Empty; + string bccReceipents = string.Empty; + + EmailContentModel emailContent = new EmailContentModel(); + var emailTemplateData = this.emailTemplateRepository.GetTemplateForStatus(subscriptionStatus); + var subject = emailTemplateData.Subject; + string body = emailTemplateData.TemplateBody; + + string fromMail = this.applicationConfigRepository.GetValueByName("SMTPFromEmail"); + string password = this.applicationConfigRepository.GetValueByName("SMTPPassword"); + string username = this.applicationConfigRepository.GetValueByName("SMTPUserName"); + bool smtpSsl = bool.Parse(this.applicationConfigRepository.GetValueByName("SMTPSslEnabled")); + int port = int.Parse(this.applicationConfigRepository.GetValueByName("SMTPPort")); + string smtpHost = this.applicationConfigRepository.GetValueByName("SMTPHost"); + string toReceipents = this.applicationConfigRepository.GetValueByName("SchedulerEmailTo"); + + if (string.IsNullOrEmpty(toReceipents)) + { + throw new Exception(" Error while sending an email, please check the configuration. "); + } + + body=body.Replace("****SubscriptionName****", subscriptionName).Replace("****SchedulerTaskName****", schedulerTaskName).Replace("****ResponseJson****", responseJson); + + emailContent.BCCEmails = bccReceipents; + emailContent.CCEmails = ccReceipents; + emailContent.ToEmails = toReceipents; + emailContent.Body = body; + emailContent.Subject = subject; + emailContent.CopyToCustomer = copyToCustomer; + emailContent.IsActive = isActive; + emailContent.FromEmail = fromMail; + emailContent.Password = password; + emailContent.SSL = smtpSsl; + emailContent.UserName = username; + emailContent.Port = port; + emailContent.SMTPHost = smtpHost; + + return emailContent; + } + + + } \ No newline at end of file diff --git a/src/Services/Services/ApplicationConfigurationService.cs b/src/Services/Services/ApplicationConfigurationService.cs index 24f9f57e..d1e6ab30 100644 --- a/src/Services/Services/ApplicationConfigurationService.cs +++ b/src/Services/Services/ApplicationConfigurationService.cs @@ -101,4 +101,9 @@ public bool UploadFileToDatabase(IFormFile file, string fileExtension) return false; } } + + public string GetValueByName(string configName) + { + return this.appConfigRepository.GetValueByName(configName); + } } \ No newline at end of file diff --git a/src/Services/Services/MeteredPlanSchedulerManagementService.cs b/src/Services/Services/MeteredPlanSchedulerManagementService.cs index 9a487f8e..6ecc5040 100644 --- a/src/Services/Services/MeteredPlanSchedulerManagementService.cs +++ b/src/Services/Services/MeteredPlanSchedulerManagementService.cs @@ -4,8 +4,9 @@ using System.Text.Json; using Marketplace.SaaS.Accelerator.DataAccess.Contracts; using Marketplace.SaaS.Accelerator.DataAccess.Entities; +using Marketplace.SaaS.Accelerator.Services.Contracts; +using Marketplace.SaaS.Accelerator.Services.Helpers; using Marketplace.SaaS.Accelerator.Services.Models; - namespace Marketplace.SaaS.Accelerator.Services.Services; /// @@ -13,12 +14,37 @@ namespace Marketplace.SaaS.Accelerator.Services.Services; /// public class MeteredPlanSchedulerManagementService { + /// + /// Scheduler Frequency Repository Interface + /// private ISchedulerFrequencyRepository frequencyRepository; + /// + /// Metered Plan Scheduler Management Repository Interface + /// private IMeteredPlanSchedulerManagementRepository schedulerRepository; + /// + /// Scheduler Manager View Repository Interface + /// private ISchedulerManagerViewRepository schedulerViewRepository; + /// + /// Subscription UsageLogs Repository Interface + /// private ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository; + /// + /// Email Service Interface + /// + private IEmailService emailService; + /// + /// Email Helper utility + /// + private EmailHelper emailHelper; + + /// + /// Application Config Repository + /// private IApplicationConfigRepository applicationConfigRepository; + /// /// Initializes a new instance of the class. /// @@ -26,12 +52,34 @@ public class MeteredPlanSchedulerManagementService /// The Frequency attributes repository. /// The Scheduler Manager View attributes repository. - public MeteredPlanSchedulerManagementService(ISchedulerFrequencyRepository schedulerFrequencyRepository, IMeteredPlanSchedulerManagementRepository meteredPlanSchedulerManagementRepository, ISchedulerManagerViewRepository schedulerManagerViewRepository, ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository,IApplicationConfigRepository applicationConfigRepository) + public MeteredPlanSchedulerManagementService(ISchedulerFrequencyRepository schedulerFrequencyRepository, + IMeteredPlanSchedulerManagementRepository meteredPlanSchedulerManagementRepository, + ISchedulerManagerViewRepository schedulerManagerViewRepository, + ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository, + IApplicationConfigRepository applicationConfigRepository, + IEmailTemplateRepository emailTemplateRepository, + IEmailService emailService) { this.frequencyRepository = schedulerFrequencyRepository; this.schedulerRepository = meteredPlanSchedulerManagementRepository; this.schedulerViewRepository = schedulerManagerViewRepository; this.subscriptionUsageLogsRepository = subscriptionUsageLogsRepository; + this.emailService = emailService; + this.emailHelper = new EmailHelper(applicationConfigRepository, null, emailTemplateRepository, null, null); + + } + + public MeteredPlanSchedulerManagementService(ISchedulerFrequencyRepository schedulerFrequencyRepository, + IMeteredPlanSchedulerManagementRepository meteredPlanSchedulerManagementRepository, + ISchedulerManagerViewRepository schedulerManagerViewRepository, + ISubscriptionUsageLogsRepository subscriptionUsageLogsRepository, + IApplicationConfigRepository applicationConfigRepository) + { + this.frequencyRepository = schedulerFrequencyRepository; + this.schedulerRepository = meteredPlanSchedulerManagementRepository; + this.schedulerViewRepository = schedulerManagerViewRepository; + this.subscriptionUsageLogsRepository = subscriptionUsageLogsRepository; + this.applicationConfigRepository = applicationConfigRepository; this.applicationConfigRepository = applicationConfigRepository; } @@ -207,6 +255,25 @@ public List GetSchedulerItemRunHistory(int id) } + public bool CheckIfSchedulerRun(int id, string schedulerName) + { + var scheduledItem = this.schedulerRepository.Get(id); + var meteredAudits = this.subscriptionUsageLogsRepository.GetMeteredAuditLogsBySubscriptionId(Convert.ToInt32(scheduledItem.SubscriptionId)); + var scheduledItemView = this.schedulerViewRepository.GetById(id); + foreach (var auditLog in meteredAudits) + { + var MeteringUsageRequest = JsonSerializer.Deserialize(auditLog.RequestJson); + + if ((MeteringUsageRequest.Dimension == scheduledItemView.Dimension) && (auditLog.RunBy == $"Scheduler - {schedulerName}")) + { + return true; + } + + } + return false; + + } + /// /// Saves the Metered Plan Scheduler Management Model attributes. /// @@ -257,4 +324,26 @@ public void DeleteSchedulerDetailById(int id) this.schedulerRepository.Remove(meteredPlanScheduler); } + public void SendSchedulerEmail(SchedulerManagerViewModel schedulerTask,MeteredAuditLogs meteredAuditItem) + { + var emailContent = new EmailContentModel(); + + if ((meteredAuditItem.StatusCode== "Accepted")|| (meteredAuditItem.StatusCode == "Missing")) + { + //Success + emailContent = this.emailHelper.PrepareMeteredEmailContent(schedulerTask.SchedulerName, schedulerTask.SubscriptionName, meteredAuditItem.StatusCode, meteredAuditItem.ResponseJson); + } + else + { + //Faliure + emailContent = this.emailHelper.PrepareMeteredEmailContent(schedulerTask.SchedulerName, schedulerTask.SubscriptionName, "Failure", meteredAuditItem.ResponseJson); + } + + if (!string.IsNullOrWhiteSpace(emailContent.ToEmails)) + { + this.emailService.SendEmail(emailContent); + } + + } + } \ No newline at end of file From 606e809bfc36a83c22a5daeb06396450c0b6479b Mon Sep 17 00:00:00 2001 From: MAGDY SALEM <63874487+msalemcode@users.noreply.github.com> Date: Tue, 8 Aug 2023 15:37:09 -0700 Subject: [PATCH 2/3] clean up EmailHelper --- src/Services/Helpers/EmailHelper.cs | 76 +++++++---------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/src/Services/Helpers/EmailHelper.cs b/src/Services/Helpers/EmailHelper.cs index 358c2633..125601d4 100644 --- a/src/Services/Helpers/EmailHelper.cs +++ b/src/Services/Helpers/EmailHelper.cs @@ -63,20 +63,11 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, } string subject = string.Empty; - bool copyToCustomer = false; - bool isActive = false; string toReceipents = string.Empty; string ccReceipents = string.Empty; string bccReceipents = string.Empty; - string fromMail = this.applicationConfigRepository.GetValueByName("SMTPFromEmail"); - string password = this.applicationConfigRepository.GetValueByName("SMTPPassword"); - string username = this.applicationConfigRepository.GetValueByName("SMTPUserName"); - bool smtpSsl = bool.Parse(this.applicationConfigRepository.GetValueByName("SMTPSslEnabled")); - int port = int.Parse(this.applicationConfigRepository.GetValueByName("SMTPPort")); - string smtpHost = this.applicationConfigRepository.GetValueByName("SMTPHost"); - var eventData = this.planEventsMappingRepository.GetPlanEvent(planGuId, subscriptionEvent.EventsId); if (eventData != null) @@ -105,23 +96,9 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, subject = emailTemplateData.Subject; } - emailContent.BCCEmails = bccReceipents; - emailContent.CCEmails = ccReceipents; - emailContent.ToEmails = toReceipents; - emailContent.Body = body; - emailContent.Subject = subject; - emailContent.CopyToCustomer = copyToCustomer; - emailContent.IsActive = isActive; - emailContent.FromEmail = fromMail; - emailContent.Password = password; - emailContent.SSL = smtpSsl; - emailContent.UserName = username; - emailContent.Port = port; - emailContent.SMTPHost = smtpHost; - - return emailContent; + return FinalizeContentEmail(subject, body, ccReceipents, bccReceipents, toReceipents, copyToCustomer); + } - /// /// Prepares the content of the scheduler email. /// @@ -137,48 +114,31 @@ public EmailContentModel PrepareEmailContent(Guid subscriptionID, Guid planGuId, /// Error while sending an email, please check the configuration. public EmailContentModel PrepareMeteredEmailContent(string schedulerTaskName, String subscriptionName, string subscriptionStatus, string responseJson) { - bool copyToCustomer = false; - bool isActive = false; - string ccReceipents = string.Empty; - string bccReceipents = string.Empty; - - EmailContentModel emailContent = new EmailContentModel(); var emailTemplateData = this.emailTemplateRepository.GetTemplateForStatus(subscriptionStatus); - var subject = emailTemplateData.Subject; - string body = emailTemplateData.TemplateBody; - - string fromMail = this.applicationConfigRepository.GetValueByName("SMTPFromEmail"); - string password = this.applicationConfigRepository.GetValueByName("SMTPPassword"); - string username = this.applicationConfigRepository.GetValueByName("SMTPUserName"); - bool smtpSsl = bool.Parse(this.applicationConfigRepository.GetValueByName("SMTPSslEnabled")); - int port = int.Parse(this.applicationConfigRepository.GetValueByName("SMTPPort")); - string smtpHost = this.applicationConfigRepository.GetValueByName("SMTPHost"); string toReceipents = this.applicationConfigRepository.GetValueByName("SchedulerEmailTo"); - if (string.IsNullOrEmpty(toReceipents)) { throw new Exception(" Error while sending an email, please check the configuration. "); } - - body=body.Replace("****SubscriptionName****", subscriptionName).Replace("****SchedulerTaskName****", schedulerTaskName).Replace("****ResponseJson****", responseJson); - - emailContent.BCCEmails = bccReceipents; - emailContent.CCEmails = ccReceipents; - emailContent.ToEmails = toReceipents; - emailContent.Body = body; - emailContent.Subject = subject; + var body = emailTemplateData.TemplateBody.Replace("****SubscriptionName****", subscriptionName).Replace("****SchedulerTaskName****", schedulerTaskName).Replace("****ResponseJson****", responseJson); ; + return FinalizeContentEmail(emailTemplateData.Subject,body, string.Empty, string.Empty, toReceipents, false); + } + private EmailContentModel FinalizeContentEmail(string subject, string body, string ccEmails,string bcEmails, string toEmails, bool copyToCustomer) + { + EmailContentModel emailContent = new EmailContentModel(); + emailContent.BCCEmails = bcEmails; + emailContent.CCEmails = ccEmails; + emailContent.ToEmails = toEmails; + emailContent.IsActive = false; emailContent.CopyToCustomer = copyToCustomer; - emailContent.IsActive = isActive; - emailContent.FromEmail = fromMail; - emailContent.Password = password; - emailContent.SSL = smtpSsl; - emailContent.UserName = username; - emailContent.Port = port; - emailContent.SMTPHost = smtpHost; - + emailContent.FromEmail = this.applicationConfigRepository.GetValueByName("SMTPFromEmail"); + emailContent.Password = this.applicationConfigRepository.GetValueByName("SMTPPassword"); + emailContent.SSL = bool.Parse(this.applicationConfigRepository.GetValueByName("SMTPSslEnabled")); + emailContent.UserName = this.applicationConfigRepository.GetValueByName("SMTPUserName"); + emailContent.Port = int.Parse(this.applicationConfigRepository.GetValueByName("SMTPPort")); + emailContent.SMTPHost = this.applicationConfigRepository.GetValueByName("SMTPHost"); return emailContent; } - } \ No newline at end of file From 6821220c4a6ed9659458054fc47255ae56119f3c Mon Sep 17 00:00:00 2001 From: MAGDY SALEM <63874487+msalemcode@users.noreply.github.com> Date: Tue, 8 Aug 2023 16:28:08 -0700 Subject: [PATCH 3/3] merge migration v8 to v7 --- .../20230804174355_Baseline_v8.Designer.cs | 1162 ----------------- .../Migrations/20230804174355_Baseline_v8.cs | 20 - .../Migrations/Custom/BaselineV7_Seed.cs | 80 +- .../Migrations/Custom/BaselineV8_Seed.cs | 40 - 4 files changed, 76 insertions(+), 1226 deletions(-) delete mode 100644 src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs delete mode 100644 src/DataAccess/Migrations/20230804174355_Baseline_v8.cs delete mode 100644 src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs diff --git a/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs b/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs deleted file mode 100644 index 76892fbc..00000000 --- a/src/DataAccess/Migrations/20230804174355_Baseline_v8.Designer.cs +++ /dev/null @@ -1,1162 +0,0 @@ -// -using System; -using Marketplace.SaaS.Accelerator.DataAccess.Context; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations -{ - [DbContext(typeof(SaasKitContext))] - [Migration("20230804174355_Baseline_v8")] - partial class Baseline_v8 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.1") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ApplicationConfiguration", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Description") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); - - b.Property("Name") - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("ApplicationConfiguration"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ApplicationLog", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("ActionTime") - .HasColumnType("datetime"); - - b.Property("LogDetail") - .HasMaxLength(4000) - .IsUnicode(false) - .HasColumnType("varchar(4000)"); - - b.HasKey("Id"); - - b.ToTable("ApplicationLog"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.DatabaseVersionHistory", b => - { - b.Property("ChangeLog") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("CreateBy") - .HasMaxLength(100) - .HasColumnType("nvarchar(100)"); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("VersionNumber") - .HasColumnType("decimal(6,2)"); - - b.ToTable("DatabaseVersionHistory"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.EmailTemplate", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Bcc") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)") - .HasColumnName("BCC"); - - b.Property("Cc") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)") - .HasColumnName("CC"); - - b.Property("Description") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)"); - - b.Property("InsertDate") - .HasColumnType("datetime"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("Status") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)"); - - b.Property("Subject") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)"); - - b.Property("TemplateBody") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("ToRecipients") - .HasMaxLength(1000) - .IsUnicode(false) - .HasColumnType("varchar(1000)"); - - b.HasKey("Id"); - - b.ToTable("EmailTemplate"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Events", b => - { - b.Property("EventsId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("EventsId"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("EventsName") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.HasKey("EventsId"); - - b.ToTable("Events"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.KnownUsers", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("RoleId") - .HasColumnType("int"); - - b.Property("UserEmail") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("KnownUsers"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredAuditLogs", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CreatedBy") - .HasColumnType("int"); - - b.Property("CreatedDate") - .HasColumnType("datetime"); - - b.Property("RequestJson") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("varchar(500)"); - - b.Property("ResponseJson") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("varchar(500)"); - - b.Property("RunBy") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("varchar(255)"); - - b.Property("StatusCode") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)"); - - b.Property("SubscriptionId") - .HasColumnType("int"); - - b.Property("SubscriptionUsageDate") - .HasColumnType("datetime"); - - b.HasKey("Id"); - - b.HasIndex("SubscriptionId"); - - b.ToTable("MeteredAuditLogs"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CreatedDate") - .HasColumnType("datetime"); - - b.Property("Description") - .HasMaxLength(250) - .IsUnicode(false) - .HasColumnType("varchar(250)"); - - b.Property("Dimension") - .HasMaxLength(150) - .IsUnicode(false) - .HasColumnType("varchar(150)"); - - b.Property("PlanId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PlanId"); - - b.ToTable("MeteredDimensions"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredPlanSchedulerManagement", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("DimensionId") - .IsRequired() - .HasColumnType("int"); - - b.Property("FrequencyId") - .IsRequired() - .HasColumnType("int"); - - b.Property("NextRunTime") - .HasColumnType("datetime2"); - - b.Property("PlanId") - .IsRequired() - .HasColumnType("int"); - - b.Property("Quantity") - .IsRequired() - .HasColumnType("float"); - - b.Property("SchedulerName") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("StartDate") - .IsRequired() - .HasColumnType("datetime2"); - - b.Property("SubscriptionId") - .IsRequired() - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("DimensionId"); - - b.HasIndex("FrequencyId"); - - b.HasIndex("PlanId"); - - b.HasIndex("SubscriptionId"); - - b.ToTable("MeteredPlanSchedulerManagement"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.OfferAttributes", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("Description") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("DisplayName") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("DisplaySequence") - .HasColumnType("int"); - - b.Property("FromList") - .HasColumnType("bit"); - - b.Property("IsDelete") - .HasColumnType("bit"); - - b.Property("IsRequired") - .HasColumnType("bit"); - - b.Property("Isactive") - .HasColumnType("bit"); - - b.Property("Max") - .HasColumnType("int"); - - b.Property("Min") - .HasColumnType("int"); - - b.Property("OfferId") - .HasColumnType("uniqueidentifier"); - - b.Property("ParameterId") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("Type") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("ValueTypeId") - .HasColumnType("int"); - - b.Property("ValuesList") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.HasKey("Id"); - - b.ToTable("OfferAttributes"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Offers", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("OfferGuid") - .HasColumnType("uniqueidentifier") - .HasColumnName("OfferGUId"); - - b.Property("OfferId") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("OfferName") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Offers"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanAttributeMapping", b => - { - b.Property("PlanAttributeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PlanAttributeId"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("IsEnabled") - .HasColumnType("bit"); - - b.Property("OfferAttributeId") - .HasColumnType("int") - .HasColumnName("OfferAttributeID"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("PlanAttributeId") - .HasName("PK__PlanAttr__8B476A98C058FAF2"); - - b.ToTable("PlanAttributeMapping"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanAttributeOutput", b => - { - b.Property("RowNumber") - .HasColumnType("int"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("IsEnabled") - .HasColumnType("bit"); - - b.Property("OfferAttributeId") - .HasColumnType("int"); - - b.Property("PlanAttributeId") - .HasColumnType("int"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier"); - - b.Property("Type") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.HasKey("RowNumber") - .HasName("PK__PlanAttr__AAAC09D888FE3E40"); - - b.ToTable("PlanAttributeOutput"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanEventsMapping", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CopyToCustomer") - .HasColumnType("bit"); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("EventId") - .HasColumnType("int"); - - b.Property("FailureStateEmails") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("Isactive") - .HasColumnType("bit"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier"); - - b.Property("SuccessStateEmails") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("PlanEventsMapping"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.PlanEventsOutPut", b => - { - b.Property("RowNumber") - .HasColumnType("int"); - - b.Property("CopyToCustomer") - .HasColumnType("bit"); - - b.Property("EventId") - .HasColumnType("int"); - - b.Property("EventsName") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("FailureStateEmails") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("Id") - .HasColumnType("int") - .HasColumnName("ID"); - - b.Property("Isactive") - .HasColumnType("bit"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier"); - - b.Property("SuccessStateEmails") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.HasKey("RowNumber") - .HasName("PK__PlanEven__AAAC09D8C9229532"); - - b.ToTable("PlanEventsOutPut"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Description") - .HasMaxLength(500) - .IsUnicode(false) - .HasColumnType("varchar(500)"); - - b.Property("DisplayName") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)"); - - b.Property("IsPerUser") - .HasColumnType("bit"); - - b.Property("IsmeteringSupported") - .HasColumnType("bit"); - - b.Property("OfferId") - .HasColumnType("uniqueidentifier") - .HasColumnName("OfferID"); - - b.Property("PlanGuid") - .HasColumnType("uniqueidentifier") - .HasColumnName("PlanGUID"); - - b.Property("PlanId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)"); - - b.HasKey("Id"); - - b.ToTable("Plans"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Name") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.HasKey("Id"); - - b.ToTable("Roles"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Frequency") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.HasKey("Id"); - - b.ToTable("SchedulerFrequency"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerManagerView", b => - { - b.Property("AMPSubscriptionId") - .HasColumnType("uniqueidentifier"); - - b.Property("Dimension") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("Frequency") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("Id") - .HasColumnType("int"); - - b.Property("NextRunTime") - .HasColumnType("datetime2"); - - b.Property("PlanId") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("PurchaserEmail") - .HasColumnType("nvarchar(max)"); - - b.Property("Quantity") - .HasColumnType("float"); - - b.Property("SchedulerName") - .HasColumnType("nvarchar(max)"); - - b.Property("StartDate") - .HasColumnType("datetime2"); - - b.Property("SubscriptionName") - .HasColumnType("nvarchar(max)"); - - b.ToView("SchedulerManagerView"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAttributeValues", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("OfferId") - .HasColumnType("uniqueidentifier") - .HasColumnName("OfferID"); - - b.Property("PlanAttributeId") - .HasColumnType("int"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier") - .HasColumnName("PlanID"); - - b.Property("SubscriptionId") - .HasColumnType("uniqueidentifier"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.HasKey("Id"); - - b.ToTable("SubscriptionAttributeValues"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAuditLogs", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Attribute") - .HasMaxLength(20) - .IsUnicode(false) - .HasColumnType("varchar(20)"); - - b.Property("CreateBy") - .HasColumnType("int"); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("NewValue") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("OldValue") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("SubscriptionId") - .HasColumnType("int") - .HasColumnName("SubscriptionID"); - - b.HasKey("Id"); - - b.HasIndex("SubscriptionId"); - - b.ToTable("SubscriptionAuditLogs"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionEmailOutput", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Name") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("Value") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.ToTable("SubscriptionEmailOutput"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionParametersOutput", b => - { - b.Property("RowNumber") - .HasColumnType("int"); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("DisplayName") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("DisplaySequence") - .HasColumnType("int"); - - b.Property("FromList") - .HasColumnType("bit"); - - b.Property("Htmltype") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)") - .HasColumnName("HTMLType"); - - b.Property("Id") - .HasColumnType("int"); - - b.Property("IsEnabled") - .HasColumnType("bit"); - - b.Property("IsRequired") - .HasColumnType("bit"); - - b.Property("Max") - .HasColumnType("int"); - - b.Property("Min") - .HasColumnType("int"); - - b.Property("OfferAttributeId") - .HasColumnType("int") - .HasColumnName("OfferAttributeID"); - - b.Property("OfferId") - .HasColumnType("uniqueidentifier"); - - b.Property("PlanAttributeId") - .HasColumnType("int"); - - b.Property("PlanId") - .HasColumnType("uniqueidentifier"); - - b.Property("SubscriptionId") - .HasColumnType("uniqueidentifier"); - - b.Property("Type") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.Property("Value") - .IsRequired() - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("ValueType") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("ValuesList") - .IsRequired() - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.HasKey("RowNumber") - .HasName("PK__Subscrip__AAAC09D8BA727059"); - - b.ToTable("SubscriptionParametersOutput"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("AmpplanId") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)") - .HasColumnName("AMPPlanId"); - - b.Property("Ampquantity") - .HasColumnType("int") - .HasColumnName("AMPQuantity"); - - b.Property("AmpsubscriptionId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("AMPSubscriptionId") - .HasDefaultValueSql("(newid())"); - - b.Property("CreateBy") - .HasColumnType("int"); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("IsActive") - .HasColumnType("bit"); - - b.Property("ModifyDate") - .HasColumnType("datetime"); - - b.Property("Name") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)"); - - b.Property("PurchaserEmail") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.Property("PurchaserTenantId") - .HasColumnType("uniqueidentifier"); - - b.Property("SubscriptionStatus") - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("Subscriptions"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", b => - { - b.Property("UserId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("UserId"), 1L, 1); - - b.Property("CreatedDate") - .HasColumnType("datetime"); - - b.Property("EmailAddress") - .HasMaxLength(100) - .IsUnicode(false) - .HasColumnType("varchar(100)"); - - b.Property("FullName") - .HasMaxLength(200) - .IsUnicode(false) - .HasColumnType("varchar(200)"); - - b.HasKey("UserId"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.ValueTypes", b => - { - b.Property("ValueTypeId") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ValueTypeId"), 1L, 1); - - b.Property("CreateDate") - .HasColumnType("datetime"); - - b.Property("Htmltype") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)") - .HasColumnName("HTMLType"); - - b.Property("ValueType") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.HasKey("ValueTypeId") - .HasName("PK__ValueTyp__A51E9C5AEA096123"); - - b.ToTable("ValueTypes"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.WebJobSubscriptionStatus", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ID"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - - b.Property("Description") - .IsUnicode(false) - .HasColumnType("varchar(max)"); - - b.Property("InsertDate") - .HasColumnType("datetime"); - - b.Property("SubscriptionId") - .HasColumnType("uniqueidentifier"); - - b.Property("SubscriptionStatus") - .HasMaxLength(225) - .IsUnicode(false) - .HasColumnType("varchar(225)"); - - b.HasKey("Id"); - - b.ToTable("WebJobSubscriptionStatus"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.KnownUsers", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", "Role") - .WithMany("KnownUsers") - .HasForeignKey("RoleId") - .IsRequired() - .HasConstraintName("FK__KnownUser__RoleI__619B8048"); - - b.Navigation("Role"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredAuditLogs", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscription") - .WithMany("MeteredAuditLogs") - .HasForeignKey("SubscriptionId") - .HasConstraintName("FK__MeteredAu__Subsc__628FA481"); - - b.Navigation("Subscription"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", "Plan") - .WithMany("MeteredDimensions") - .HasForeignKey("PlanId") - .HasConstraintName("FK__MeteredDi__PlanI__6383C8BA"); - - b.Navigation("Plan"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredPlanSchedulerManagement", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", "MeteredDimensions") - .WithMany("MeteredPlanSchedulerManagements") - .HasForeignKey("DimensionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", "SchedulerFrequency") - .WithMany("MeteredPlanSchedulerManagements") - .HasForeignKey("FrequencyId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", "Plan") - .WithMany("MeteredPlanSchedulerManagements") - .HasForeignKey("PlanId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscriptions") - .WithMany("MeteredPlanSchedulerManagements") - .HasForeignKey("SubscriptionId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("MeteredDimensions"); - - b.Navigation("Plan"); - - b.Navigation("SchedulerFrequency"); - - b.Navigation("Subscriptions"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SubscriptionAuditLogs", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", "Subscription") - .WithMany("SubscriptionAuditLogs") - .HasForeignKey("SubscriptionId") - .HasConstraintName("FK__Subscript__Subsc__6477ECF3"); - - b.Navigation("Subscription"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => - { - b.HasOne("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", "User") - .WithMany("Subscriptions") - .HasForeignKey("UserId") - .HasConstraintName("FK__Subscript__UserI__656C112C"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.MeteredDimensions", b => - { - b.Navigation("MeteredPlanSchedulerManagements"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Plans", b => - { - b.Navigation("MeteredDimensions"); - - b.Navigation("MeteredPlanSchedulerManagements"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Roles", b => - { - b.Navigation("KnownUsers"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.SchedulerFrequency", b => - { - b.Navigation("MeteredPlanSchedulerManagements"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Subscriptions", b => - { - b.Navigation("MeteredAuditLogs"); - - b.Navigation("MeteredPlanSchedulerManagements"); - - b.Navigation("SubscriptionAuditLogs"); - }); - - modelBuilder.Entity("Marketplace.SaaS.Accelerator.DataAccess.Entities.Users", b => - { - b.Navigation("Subscriptions"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs b/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs deleted file mode 100644 index 91472eb5..00000000 --- a/src/DataAccess/Migrations/20230804174355_Baseline_v8.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Marketplace.SaaS.Accelerator.DataAccess.Migrations.Custom; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations -{ - public partial class Baseline_v8 : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.BaselineV8_SeedData(); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.BaselineV8_DeSeedData(); - } - } -} diff --git a/src/DataAccess/Migrations/Custom/BaselineV7_Seed.cs b/src/DataAccess/Migrations/Custom/BaselineV7_Seed.cs index e39776ec..295a9262 100644 --- a/src/DataAccess/Migrations/Custom/BaselineV7_Seed.cs +++ b/src/DataAccess/Migrations/Custom/BaselineV7_Seed.cs @@ -14,10 +14,46 @@ public static void BaselineV7_SeedData(this MigrationBuilder migrationBuilder) { var seedDate = DateTime.Now; migrationBuilder.Sql(@$" - IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'WebNotificationUrl') - BEGIN - INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'WebNotificationUrl', N'', N'Setting this URL will enable pushing LandingPage/Webhook events to this external URL') - END + IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'WebNotificationUrl') + BEGIN + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'WebNotificationUrl', N'', N'Setting this URL will enable pushing LandingPage/Webhook events to this external URL') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesSuccessfulSchedulerEmail') + BEGIN + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesSuccessfulSchedulerEmail', N'False', N'This will enable sending email for successful metered usage.') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesFailureSchedulerEmail') + BEGIN + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesFailureSchedulerEmail', N'False', N'This will enable sending email for failure metered usage.') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesMissingSchedulerEmail') + BEGIN + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesMissingSchedulerEmail', N'False', N'This will enable sending email for missing metered usage.') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'SchedulerEmailTo') + BEGIN + INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'SchedulerEmailTo', N'', N'Scheduler email receiver(s) ') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Accepted') + BEGIN + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Accepted',N'Accepted',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired Successfully

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Submitted Successfully!',N'True') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Failure') + BEGIN + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Failure',N'Failure',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired but Failed to Submit Data


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Failure!',N'True') + END + + IF NOT EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Missing') + BEGIN + INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Missing',N'Missing',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was skipped by scheduler engine!


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Task was Skipped!',N'True') + END + GO"); } @@ -28,6 +64,42 @@ IF EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'WebNot BEGIN DELETE FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'WebNotificationUrl' END + + IF EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesSuccessfulSchedulerEmail') + BEGIN + DELETE FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesSuccessfulSchedulerEmail' + END + + IF EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesFailureSchedulerEmail') + BEGIN + DELETE FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesFailureSchedulerEmail' + END + + IF EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesMissingSchedulerEmail') + BEGIN + DELETE FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'EnablesMissingSchedulerEmail' + END + + IF EXISTS (SELECT * FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'SchedulerEmailTo') + BEGIN + DELETE FROM [dbo].[ApplicationConfiguration] WHERE [Name] = 'SchedulerEmailTo' + END + + IF EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Accepted') + BEGIN + DELETE FROM [dbo].[EmailTemplate] WHERE [Status] = 'Accepted' + END + + IF EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Failure') + BEGIN + DELETE FROM [dbo].[EmailTemplate] WHERE [Status] = 'Failure' + END + + IF EXISTS (SELECT * FROM [dbo].[EmailTemplate] WHERE [Status] = 'Missing') + BEGIN + DELETE FROM [dbo].[EmailTemplate] WHERE [Status] = 'Missing' + END + GO"); } } diff --git a/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs b/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs deleted file mode 100644 index bc6c2593..00000000 --- a/src/DataAccess/Migrations/Custom/BaselineV8_Seed.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Query.Internal; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Marketplace.SaaS.Accelerator.DataAccess.Migrations.Custom -{ - internal static class BaselineV8_Seed - { - public static void BaselineV8_SeedData(this MigrationBuilder migrationBuilder) - { - var seedDate = DateTime.Now; - migrationBuilder.Sql(@$" - INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesSuccessfulSchedulerEmail', N'False', N'This will enable sending email for successful metered usage.') - INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesFailureSchedulerEmail', N'False', N'This will enable sending email for failure metered usage.') - INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'EnablesMissingSchedulerEmail', N'False', N'This will enable sending email for missing metered usage.') - INSERT [dbo].[ApplicationConfiguration] ( [Name], [Value], [Description]) VALUES ( N'SchedulerEmailTo', N'', N'Scheduler email receiver(s) ') - INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Accepted',N'Accepted',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired Successfully

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Submitted Successfully!',N'True') - INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Failure',N'Failure',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was fired but Failed to Submit Data


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Usage Failure!',N'True') - INSERT [dbo].[EmailTemplate] ([Status],[Description],[InsertDate],[TemplateBody],[Subject],[isActive]) VALUES (N'Missing',N'Missing',GetDate(),N'

Subscription ****SubscriptionName****


The Scheduled Task ****SchedulerTaskName**** was skipped by scheduler engine!


Please try again or contact technical support to troubleshoot the issue.

The following section is the deatil results.


****ResponseJson****
',N'Scheduled SaaS Metered Task was Skipped!',N'True') - GO"); - } - - public static void BaselineV8_DeSeedData(this MigrationBuilder migrationBuilder) - { - migrationBuilder.Sql(@$" - Delete from [dbo].[ApplicationConfiguration] where [Name]= 'EnablesSuccessfulSchedulerEmail' - Delete from [dbo].[ApplicationConfiguration] where [Name]= 'EnablesFailureSchedulerEmail' - Delete From [dbo].[ApplicationConfiguration] where [Name]= 'EnablesMissingSchedulerEmail' - Delete From [dbo].[ApplicationConfiguration] where [Name]= 'SchedulerEmailTo' - Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Usage Submitted Successfully!' - Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Usage Failure!' - Delete From [dbo].[EmailTemplate] Where [Subject] = 'Scheduled SaaS Metered Task was Skipped!' - GO"); - } - } -} \ No newline at end of file