A Pen by john Coxhead

Thumbnail
This awesome code was written by jcoxhead127, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright jcoxhead127 ©
  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>A Pen by  john Coxhead</title>
  
  
  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/jcoxhead127/a-pen-by-john-coxhead-ZearJJ */
{
  "dependencies": {
    "Autofac": "4.3.0",
    "Autofac.Extensions.DependencyInjection": "4.0.0",
    "ProductMaster.FredaSync.Commands": "1.0.0-*",
    "ProductMaster.FredaSync.Data": "1.0.0-*",
    "ProductMaster.FredaSync.Repository": "1.0.0-*"
  },
  "frameworks": {
    "net461": {}
  },
  "version": "1.0.0-*"
}


namespace ProductMaster.FredaSync
{
    using Autofac;
    using Tasks;
    using Commands.Handlers;
    using Repository.Interfaces;
    using Data.Domain;
    using System.Collections.Generic;
    using Repository.Queries.Requests;

    public class TaskModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(c => new NewSyncShareClass(
                c.Resolve<NewShareClassCommand>(),
                c.Resolve<IQuery<FredaShareClasses, NewShareClassQueryRequest>>(),
                c.Resolve<IRepository<FredaShareClasses>>())).As<ISyncTask>();

            builder.Register(c => new NewSyncShareClassRate(
                c.Resolve<NewShareClassRateCommand>(),
                c.Resolve<IQuery<ShareClassRate, NewShareClassRateQueryRequest>>(),
                c.Resolve<IRepository<FredaShareClassRates>>())).As<ISyncTask>();

            builder.Register(c => new EditSyncShareClass(
                c.Resolve<EditShareClassCommand>(),
                c.Resolve<IQuery<ShareClass, EditShareClassQueryRequest>>(),
                c.Resolve<IRepository<FredaShareClasses>>())).As<ISyncTask>();

            builder.Register(c => new EditSyncShareClassRate(
                c.Resolve<EditShareClassRateCommand>(),
                c.Resolve<IQuery<ShareClassRate, EditShareClassRateQueryRequest>>(),
                c.Resolve<IRepository<FredaShareClassRates>>())).As<ISyncTask>();

            builder.Register(c => new RemoveSyncShareClass(
                c.Resolve<RemoveShareClassCommand>(),
                c.Resolve<IQuery<ShareClass, RemoveShareClassQueryRequest>>(),
                c.Resolve<IRepository<FredaShareClasses>>())).As<ISyncTask>();

            builder.Register(c => new NewSyncPriipsShareClassIds(
                c.Resolve<NewPriipsShareClassIdsCommand>(),
                c.Resolve<IQuery<PriipsShareClassIds, NewPriipsShareClassIdsQueryRequest>>(),
                c.Resolve<IRepository<ShareClass>>())).As<ISyncTask>();

            builder.Register(c => new RemoveSyncPriipsShareClassIds(
                c.Resolve<RemovePriipsShareClassIdsCommand>(),
                c.Resolve<IQuery<PriipsShareClassIds, RemovePriipsShareClassIdsQueryRequest>>(),
                c.Resolve<IRepository<ShareClass>>())).As<ISyncTask>();

            builder.Register(c => new List<ISyncTask>(c.Resolve<IEnumerable<ISyncTask>>())).As<List<ISyncTask>>();
        }
    }

}


using System.Threading;

namespace ProductMaster.FredaSync.Tasks
{
    public interface ISyncTask
    {
        void Execute(CancellationToken cancelToken);
    }
}

namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries.Requests;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class RemoveSyncShareClass : ISyncTask
    {
        private ICommand<RemoveShareClassRequest, SyncResponse> command;
        private IQuery<ShareClass, RemoveShareClassQueryRequest> query;
        private IRepository<FredaShareClasses> repository;

        public RemoveSyncShareClass(ICommand<RemoveShareClassRequest, SyncResponse> command,
                                        IQuery<ShareClass, RemoveShareClassQueryRequest> query,
                                        IRepository<FredaShareClasses> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object> { };

            this.command.Execute(new RemoveShareClassRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new RemoveShareClassQueryRequest { Request = this.repository.List() })
            },
            context
            );
        }
    }
}


namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries;
    using Repository.Queries.Requests;
    using System.Linq;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class RemoveSyncPriipsShareClassIds : ISyncTask
    {
        private ICommand<RemovePriipsShareClassIdsRequest, SyncResponse> command;
        private IQuery<PriipsShareClassIds, RemovePriipsShareClassIdsQueryRequest> query;
        private IRepository<ShareClass> repository;

        public RemoveSyncPriipsShareClassIds(ICommand<RemovePriipsShareClassIdsRequest, SyncResponse> command,
                                        IQuery<PriipsShareClassIds, RemovePriipsShareClassIdsQueryRequest> query,
                                        IRepository<ShareClass> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object>();

            this.command.Execute(new RemovePriipsShareClassIdsRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new RemovePriipsShareClassIdsQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}

namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries.Requests;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewSyncShareClassRate : ISyncTask
    {
        private ICommand<NewShareClassRateRequest, SyncResponse> command;
        private IQuery<ShareClassRate, NewShareClassRateQueryRequest> query;
        private IRepository<FredaShareClassRates> repository;

        public NewSyncShareClassRate(ICommand<NewShareClassRateRequest, SyncResponse> command,
                                        IQuery<ShareClassRate, NewShareClassRateQueryRequest> query,
                                        IRepository<FredaShareClassRates> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object> { };

            this.command.Execute(new NewShareClassRateRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new NewShareClassRateQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}
namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries.Requests;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewSyncShareClass : ISyncTask
    {
        private ICommand<NewShareClassRequest, SyncResponse> command;
        private IQuery<FredaShareClasses, NewShareClassQueryRequest> query;
        private IRepository<FredaShareClasses> repository;

        public NewSyncShareClass(ICommand<NewShareClassRequest, SyncResponse> command,
                                        IQuery<FredaShareClasses, NewShareClassQueryRequest> query,
                                        IRepository<FredaShareClasses> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object> { };
            this.command.Execute(new NewShareClassRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new NewShareClassQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}

namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries;
    using Repository.Queries.Requests;
    using System.Linq;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewSyncPriipsShareClassIds : ISyncTask
    {
        private ICommand<NewPriipsShareClassIdsRequest, SyncResponse> command;
        private IQuery<PriipsShareClassIds, NewPriipsShareClassIdsQueryRequest> query;
        private IRepository<ShareClass> repository;

        public NewSyncPriipsShareClassIds(ICommand<NewPriipsShareClassIdsRequest, SyncResponse> command,
                                        IQuery<PriipsShareClassIds, NewPriipsShareClassIdsQueryRequest> query,
                                        IRepository<ShareClass> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object> { };
            this.command.Execute(new NewPriipsShareClassIdsRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new NewPriipsShareClassIdsQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}
namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries.Requests;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class EditSyncShareClassRate : ISyncTask
    {
        private ICommand<EditShareClassRateRequest, SyncResponse> command;
        private IQuery<ShareClassRate, EditShareClassRateQueryRequest> query;
        private IRepository<FredaShareClassRates> repository;

        public EditSyncShareClassRate(ICommand<EditShareClassRateRequest, SyncResponse> command,
                                        IQuery<ShareClassRate, EditShareClassRateQueryRequest> query,
                                        IRepository<FredaShareClassRates> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object> { };

            this.command.Execute(new EditShareClassRateRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new EditShareClassRateQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}


namespace ProductMaster.FredaSync.Tasks
{
    using Commands.Request;
    using Commands.Response;
    using Data.Domain;
    using Repository.Interfaces;
    using Repository.Queries.Requests;
    using System.Threading;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class EditSyncShareClass : ISyncTask
    {
        private ICommand<EditShareClassRequest, SyncResponse> command;
        private IQuery<ShareClass, EditShareClassQueryRequest> query;
        private IRepository<FredaShareClasses> repository;

        public EditSyncShareClass(ICommand<EditShareClassRequest, SyncResponse> command,
                                        IQuery<ShareClass, EditShareClassQueryRequest> query,
                                        IRepository<FredaShareClasses> repository)
        {
            this.command = command;
            this.query = query;
            this.repository = repository;
        }

        public void Execute(CancellationToken cancelToken)
        {
            var context = new Dictionary<string, object>();

            this.command.Execute(new EditShareClassRequest
            {
                CancelToken = cancelToken,
                Payload = this.query.Get(new EditShareClassQueryRequest { Request = this.repository.List() })
            },
            context);
        }
    }
}

{
  "buildOptions": {
    "emitEntryPoint": false
  },
  "dependencies": {
    "ProductMaster.FredaSync.Data": "1.0.0-*",
    "ProductMaster.FredaSync.Configuration": "1.0.0-*",
    "Autofac": "4.3.0"
  },
  "frameworks": {
    "net461": {
      "frameworkAssemblies": {
        "System.Transactions": "4.0.0.0"
      }
    }
  },
  "version": "1.0.0-*"
}
namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System.Linq;
    using System.Transactions;
    using System;
    using System.Linq.Expressions;

    public class ShareClassRepository : IRepository<ShareClass>
    {
        private FredaSyncContext context;
        private SyncDatabaseConfiguration configuration;

        public ShareClassRepository(FredaSyncContext context,
            SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
            this.context = context;
        }

        public IEnumerable<ShareClass> List()
        {
            IEnumerable<ShareClass> shareClasses;
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                shareClasses = this.context.ShareClass.ToList();
            }
            return shareClasses;
        }

        public void Delete(ShareClass entity)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
                {
                    context.ShareClass.Remove(context.ShareClass.First(x => x.ShareClassId == entity.ShareClassId));
                }
            }
        }

        public void Save(ShareClass entity)
        {
            try
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
                    {
                        var selectedEntity = context.ShareClass.FirstOrDefault(x => x.ShareClassCode == entity.ShareClassCode && x.SystemSource == entity.SystemSource);

                        if (selectedEntity != null)
                            context.Entry(selectedEntity).CurrentValues.SetValues(entity);
                        else
                            context.ShareClass.Add(entity);

                        context.SaveChanges();
                    }
                }
            }
            catch(Exception ex)
            {

            }
        }

        public ShareClass Find(Expression<Func<ShareClass, bool>> predicate)
        {
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                ShareClass result;
                result = this.context.ShareClass.FirstOrDefault(predicate);
                return result;
            }
        }
    }
}
namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System.Linq;
    using System.Transactions;
    using System;
    using System.Linq.Expressions;

    public class ShareClassRateRepository : IRepository<ShareClassRate>
    {
        private FredaSyncContext context;
        private SyncDatabaseConfiguration configuration;

        public ShareClassRateRepository(FredaSyncContext context, SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
            this.context = context;
        }

        public IEnumerable<ShareClassRate> List()
        {
            List<ShareClassRate> shareClassRates;
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                shareClassRates = this.context.ShareClassRate.ToList();
            }
            return shareClassRates;
        }

        public void Delete(ShareClassRate entity)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
                {
                    context.ShareClassRate.Remove(context.ShareClassRate.First(x => x.ShareClassId == entity.ShareClassId));
                }
            }
        }

        public void Save(ShareClassRate entity)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
                {
                    var selectedEntity = context.ShareClassRate.FirstOrDefault(x => x.ShareClassCode == entity.ShareClassCode && x.SystemSource == entity.SystemSource);

                    if (selectedEntity != null)
                        context.Entry(selectedEntity).CurrentValues.SetValues(entity);
                    else
                        context.ShareClassRate.Add(entity);

                    context.SaveChanges();
                }
            }
        }

        public ShareClassRate Find(Expression<Func<ShareClassRate, bool>> predicate)
        {
            ShareClassRate shareClassRate;
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                shareClassRate = this.context.ShareClassRate.FirstOrDefault(predicate);
            }

            return shareClassRate;
        }
    }
}
namespace ProductMaster.FredaSync.Repository
{
    using Autofac;
    using Data.Domain;
    using Interfaces;
    using Queries;
    using Queries.Requests;

    public class RepositoryModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<PriipsShareClassIdsRepository>().As<IRepository<PriipsShareClassIds>>();
            builder.RegisterType<ShareClassRateRepository>().As<IRepository<ShareClassRate>>();
            builder.RegisterType<ShareClassRepository>().As<IRepository<ShareClass>>();

            builder.RegisterType<FredaShareClassesRepository>().As<IRepository<FredaShareClasses>>();
            builder.RegisterType<FredaShareClassRatesRepository>().As<IRepository<FredaShareClassRates>>();

            builder.RegisterType<NewShareClassQuery>().As<IQuery<FredaShareClasses, NewShareClassQueryRequest>>();
            builder.RegisterType<NewShareClassRateQuery>().As<IQuery<ShareClassRate, NewShareClassRateQueryRequest>>();
            builder.RegisterType<EditShareClassQuery>().As<IQuery<ShareClass, EditShareClassQueryRequest>>();
            builder.RegisterType<EditShareClassRateQuery>().As<IQuery<ShareClassRate, EditShareClassRateQueryRequest>>();

            builder.RegisterType<RemoveShareClassQuery>().As<IQuery<ShareClass, RemoveShareClassQueryRequest>>();
            builder.RegisterType<NewPriipsShareClassIdsQuery>().As<IQuery<PriipsShareClassIds, NewPriipsShareClassIdsQueryRequest>>();
            builder.RegisterType<RemovePriipsShareClassIdsQuery>().As<IQuery<PriipsShareClassIds, RemovePriipsShareClassIdsQueryRequest>>();
        }
    }
}

namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System.Linq;
    using System;
    using System.Linq.Expressions;

    public class PriipsShareClassIdsRepository : IRepository<PriipsShareClassIds>
    {
        private SyncDatabaseConfiguration configuration;

        public PriipsShareClassIdsRepository(SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public IEnumerable<PriipsShareClassIds> List()
        {
            List<PriipsShareClassIds> priipsShareClassIds;
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                priipsShareClassIds = context.PriipsShareClassIds.ToList();
            }
            return priipsShareClassIds;
        }

        public void Delete(PriipsShareClassIds entity)
        {
            throw new NotSupportedException();
        }

        public void Save(PriipsShareClassIds entity)
        {
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                var selectedEntity = context.PriipsShareClassIds.FirstOrDefault(x => x.ShareClassId == entity.ShareClassId);

                if (selectedEntity != null)
                    context.Entry(selectedEntity).CurrentValues.SetValues(entity);
                else
                    context.PriipsShareClassIds.Add(entity);

                context.SaveChanges();
            }
        }

        public PriipsShareClassIds Find(Expression<Func<PriipsShareClassIds, bool>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}

namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using System;
    using System.Linq.Expressions;

    public class MockFredaShareClassRatesRepository : IRepository<FredaShareClassRates>
    {
        private List<FredaShareClassRates> fredaShareClassRates = new List<FredaShareClassRates>();
      
        public MockFredaShareClassRatesRepository()
        {
            for(int i = 1; i <= 200; i++)
            {
                fredaShareClassRates.Add(
                   new FredaShareClassRates
                   {
                       ShareClassCode = "0" + i,
                       SystemSource = "LUX",
                       CustodyFee = 1.2M,
                       DistributionFee = 2.3M,
                       EntryFee = 0.12M,
                       ExitFee = 0.13M,
                       FiduciaryFee = 0.12M,
                       FundAccountingFee = 2.12M,
                       LuxTax = 2,
                       ManagementFee = 0.13M,
                       OGCKiidFee = 0.14M,
                       ProspectusCustodyFee = 0.16M,
                       ProspectusManagementFee = 0.17M,
                       SafekeepingFee = 0.18M,
                       SecuritiesLendingFee = 0.34M,
                       StatutoryFee = 0.15M,
                       SwitchFee = 0.78M,
                       TAFee = 0.23M,
                       TransactionFee = 0.14M,
                       TrusteeFee = 0.78M
                   }
                );
            }
        }

        public IEnumerable<FredaShareClassRates> List()
        {
            return this.fredaShareClassRates;
        }

        public void Delete(FredaShareClassRates entity)
        {
            throw new NotSupportedException();
        }

        public void Save(FredaShareClassRates entity)
        {
            throw new NotSupportedException();
        }

        public FredaShareClassRates Find(Expression<Func<FredaShareClassRates, bool>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}

namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System;
    using System.Linq.Expressions;

    public class MockFredaShareClassesRepository : IRepository<FredaShareClasses>
    {
        private List<FredaShareClasses> fredaShareClasses = new List<FredaShareClasses>();

        public MockFredaShareClassesRepository()
        {
            for(int i = 1; i <= 200; i++ )
            {
                this.fredaShareClasses.Add(
                    new FredaShareClasses
                    {
                        ShareClassIncomeType = "A",
                        ShareClassIdentifierType = "0" + i,
                        LegalFundCode = "ABC",
                        LegalName = "Test Share Class " + i,
                        Priips = true,
                        ShareClassCode = "0" + i.ToString(),
                        ShareClassCurrency = "EUR",
                        SystemSource = "LUX"
                    }
                );
            }
        }
         
        public IEnumerable<FredaShareClasses> List()
        {
            return this.fredaShareClasses;
        }

        public void Delete(FredaShareClasses entity)
        {
            throw new NotSupportedException();
        }

        public void Save(FredaShareClasses entity)
        {
            throw new NotSupportedException();
        }

        public FredaShareClasses Find(Expression<Func<FredaShareClasses, bool>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}


namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System.Linq;
    using System;
    using System.Linq.Expressions;

    public class FredaShareClassRatesRepository : IRepository<FredaShareClassRates>
    {
        private SyncDatabaseConfiguration configuration;

        public FredaShareClassRatesRepository(SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public IEnumerable<FredaShareClassRates> List()
        {
            List<FredaShareClassRates> fredaShareClassRates;
            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                fredaShareClassRates = context.FredaShareClassRates.ToList();
            }

            return fredaShareClassRates;
        }

        public void Delete(FredaShareClassRates entity)
        {
            throw new NotSupportedException();
        }

        public void Save(FredaShareClassRates entity)
        {
            throw new NotSupportedException();
        }

        public FredaShareClassRates Find(Expression<Func<FredaShareClassRates, bool>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}

namespace ProductMaster.FredaSync.Repository
{
    using System.Collections.Generic;
    using Data.Domain;
    using Interfaces;
    using Data;
    using System.Linq;
    using System;
    using System.Linq.Expressions;
    public class FredaShareClassesRepository : IRepository<FredaShareClasses>
    {        
        private SyncDatabaseConfiguration configuration;

        public FredaShareClassesRepository(SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public IEnumerable<FredaShareClasses> List()
        {
            List<FredaShareClasses> fredaShareClasses;

            using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
            {
                fredaShareClasses = context.FredaShareClasses.ToList();
            }
            return fredaShareClasses;
        }

        public void Delete(FredaShareClasses entity)
        {
            throw new NotSupportedException();
        }

        public void Save(FredaShareClasses entity)
        {
            throw new NotSupportedException();
        }

        public FredaShareClasses Find(Expression<Func<FredaShareClasses, bool>> predicate)
        {
            throw new NotImplementedException();
        }
    }
}

namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class RemoveShareClassQueryRequest
    {
        public IEnumerable<FredaShareClasses> Request { get; set; }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class RemovePriipsShareClassIdsQueryRequest
    {
        public IEnumerable<ShareClass> Request { get; set; }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewShareClassRateQueryRequest
    {
        public IEnumerable<FredaShareClassRates> Request { get; set; }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewShareClassQueryRequest
    {
        public IEnumerable<FredaShareClasses> Request { get; set; }
    }
}



namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewPriipsShareClassIdsQueryRequest
    {
        public IEnumerable<ShareClass> Request { get; set; }
    }
}

namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class EditShareClassRateQueryRequest
    {
        public IEnumerable<FredaShareClassRates> Request { get; set; }
    }
}

namespace ProductMaster.FredaSync.Repository.Queries.Requests
{
    using Data.Domain;
    using System.Collections.Generic;

    public class EditShareClassQueryRequest
    {
        public IEnumerable<FredaShareClasses> Request { get; set; }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class RemoveShareClassQuery : IQuery<ShareClass, RemoveShareClassQueryRequest>
    {
        private IRepository<ShareClass> repository;

        public RemoveShareClassQuery(IRepository<ShareClass> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<ShareClass> Get(RemoveShareClassQueryRequest payload)
        {
            var allShareClassSet = payload.Request.ToList();
            var currentShareClassSet = this.repository.List().ToList();

            return (from sc in currentShareClassSet
                    where !allShareClassSet.Any(vw => sc.ShareClassCode == vw.ShareClassCode && sc.SystemSource == vw.SystemSource)
                    select new ShareClass
                    {
                        ShareClassId = sc.ShareClassId,
                        Priips = sc.Priips
                    }).ToList();
        }
    }

}namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class RemoveShareClassQuery : IQuery<ShareClass, RemoveShareClassQueryRequest>
    {
        private IRepository<ShareClass> repository;

        public RemoveShareClassQuery(IRepository<ShareClass> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<ShareClass> Get(RemoveShareClassQueryRequest payload)
        {
            var allShareClassSet = payload.Request.ToList();
            var currentShareClassSet = this.repository.List().ToList();

            return (from sc in currentShareClassSet
                    where !allShareClassSet.Any(vw => sc.ShareClassCode == vw.ShareClassCode && sc.SystemSource == vw.SystemSource)
                    select new ShareClass
                    {
                        ShareClassId = sc.ShareClassId,
                        Priips = sc.Priips
                    }).ToList();
        }
    }

}

namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class RemovePriipsShareClassIdsQuery : IQuery<PriipsShareClassIds, RemovePriipsShareClassIdsQueryRequest>
    {
        private IRepository<PriipsShareClassIds> repository;

        public RemovePriipsShareClassIdsQuery(IRepository<PriipsShareClassIds> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<PriipsShareClassIds> Get(RemovePriipsShareClassIdsQueryRequest payload)
        {
            var allShareClassSet = payload.Request.ToList();
            var currentShareClassSet = this.repository.List().ToList();

            return (from pr in currentShareClassSet
                    where !allShareClassSet.Any(sc => sc.ShareClassId == pr.ShareClassId)
                    select new PriipsShareClassIds
                    {
                        ShareClassId = pr.ShareClassId
                    }).ToList();

        }
    }

}
namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class NewShareClassRateQuery : IQuery<ShareClassRate, NewShareClassRateQueryRequest>
    {
        private IRepository<ShareClassRate> shareClassRateRepository;
        private IRepository<ShareClass> shareClassRepository;

        public NewShareClassRateQuery(IRepository<ShareClassRate> shareClassRateRepository,
                                        IRepository<ShareClass> shareClassRepository)
        {
            this.shareClassRateRepository = shareClassRateRepository;
            this.shareClassRepository = shareClassRepository;
        }

        public IEnumerable<ShareClassRate> Get(NewShareClassRateQueryRequest payload)
        {
            var fredaResultSet = payload.Request.ToList();
            var currentShareClassSet = this.shareClassRepository.List();
            var currentShareClassRateSet = this.shareClassRateRepository.List();

            var results = (from vw in fredaResultSet
                    join sc in currentShareClassSet on new { Code = vw.ShareClassCode, Source = vw.SystemSource } equals new { Code = sc.ShareClassCode, Source = sc.SystemSource }
                    where sc.ShareClassId != null && !currentShareClassRateSet.Any(sc => sc.ShareClassCode == vw.ShareClassCode && sc.SystemSource == vw.SystemSource)
                    select new ShareClassRate
                    {
                        ShareClassId = sc.ShareClassId,
                        ShareClassCode = vw.ShareClassCode,
                        SystemSource = vw.SystemSource,
                        EntryFee = vw.EntryFee,
                        ExitFee = vw.ExitFee,
                        SwitchFee = vw.SwitchFee,
                        OGCKiidFee = vw.OGCKiidFee,
                        ManagementFee = vw.ManagementFee,
                        DistributionFee = vw.DistributionFee,
                        SafekeepingFee = vw.SafekeepingFee,
                        TAFee = vw.TAFee,
                        StatutoryFee = vw.StatutoryFee,
                        TransactionFee = vw.TransactionFee,
                        FundAccountingFee = vw.FundAccountingFee,
                        TrusteeFee = vw.TrusteeFee,
                        ProspectusManagementFee = vw.ProspectusManagementFee,
                        ProspectusCustodyFee = vw.ProspectusCustodyFee,
                        LuxTax = vw.LuxTax,
                        FiduciaryFee = vw.FiduciaryFee,
                        SecuritiesLendingFee = vw.SecuritiesLendingFee,
                        CustodyFee = vw.CustodyFee
                    }).ToList();

            return results;

        }
    }

}

namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class NewShareClassQuery : IQuery<FredaShareClasses, NewShareClassQueryRequest>
    {
        private IRepository<ShareClass> repository;

        public NewShareClassQuery(IRepository<ShareClass> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<FredaShareClasses> Get(NewShareClassQueryRequest payload)
        {
            var allShareClassSet = payload.Request.ToList();
            var currentShareClassSet = this.repository.List();

            return (from vw in allShareClassSet
                    where !currentShareClassSet.Any(sc => sc.ShareClassCode == vw.ShareClassCode && sc.SystemSource == vw.SystemSource)
                    select vw).ToList();

        }
    }

}
namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class NewPriipsShareClassIdsQuery : IQuery<PriipsShareClassIds, NewPriipsShareClassIdsQueryRequest>
    {
        private IRepository<PriipsShareClassIds> repository;

        public NewPriipsShareClassIdsQuery(IRepository<PriipsShareClassIds> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<PriipsShareClassIds> Get(NewPriipsShareClassIdsQueryRequest payload)
        {
            var allShareClassSet = payload.Request.Where(x => x.ShareClassId != null && x.Priips == true).ToList();
            var currentShareClassSet = this.repository.List();

            return (from sc in allShareClassSet
                    where !currentShareClassSet.Any(pr => pr.ShareClassId == sc.ShareClassId)
                    select new PriipsShareClassIds
                    {
                        ShareClassId = sc.ShareClassId
                    }).ToList();

        }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class EditShareClassRateQuery : IQuery<ShareClassRate, EditShareClassRateQueryRequest>
    {
        private IRepository<ShareClassRate> repository;

        public EditShareClassRateQuery(IRepository<ShareClassRate> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<ShareClassRate> Get(EditShareClassRateQueryRequest payload)
        {
            var allShareClassRateSet = payload.Request.ToList();
            var currentShareClassRateSet = this.repository.List().Where(q => q.ShareClassRateId != null).ToList();
            if (currentShareClassRateSet.Count == 0)
                return new List<ShareClassRate>();

            return (from vw in allShareClassRateSet
                    join sc in currentShareClassRateSet.Where(x => x.ShareClassRateId != null) on new { Code = vw.ShareClassCode, Source = vw.SystemSource } equals new { Code = sc.ShareClassCode, Source = sc.SystemSource }
                    where vw.EntryFee != sc.EntryFee ||
                            vw.ExitFee != sc.ExitFee ||
                            vw.SwitchFee != sc.SwitchFee ||
                            vw.OGCKiidFee != sc.OGCKiidFee ||
                            vw.ManagementFee != sc.ManagementFee ||
                            vw.DistributionFee != sc.DistributionFee ||
                            vw.SafekeepingFee != sc.SafekeepingFee ||
                            vw.TAFee != sc.TAFee ||
                            vw.StatutoryFee != sc.StatutoryFee ||
                            vw.ManagementFee != sc.ManagementFee ||
                            vw.TransactionFee != sc.TransactionFee ||
                            vw.FundAccountingFee != sc.FundAccountingFee ||
                            vw.TrusteeFee != sc.TrusteeFee ||
                            vw.ProspectusManagementFee != sc.ProspectusManagementFee ||
                            vw.ProspectusCustodyFee != sc.ProspectusCustodyFee ||
                            vw.LuxTax != sc.LuxTax ||
                            vw.FiduciaryFee != sc.FiduciaryFee ||
                            vw.SecuritiesLendingFee != sc.SecuritiesLendingFee ||
                            vw.CustodyFee != sc.CustodyFee
                    select new ShareClassRate
                    {
                        ShareClassId = sc.ShareClassId,
                        ShareClassCode = vw.ShareClassCode,
                        SystemSource = vw.SystemSource,
                        EntryFee = vw.EntryFee,
                        ExitFee = vw.ExitFee,
                        SwitchFee = vw.SwitchFee,
                        OGCKiidFee = vw.OGCKiidFee,
                        ManagementFee = vw.ManagementFee,
                        DistributionFee = vw.DistributionFee,
                        SafekeepingFee = vw.SafekeepingFee,
                        TAFee = vw.TAFee,
                        StatutoryFee = vw.StatutoryFee,
                        TransactionFee = vw.TransactionFee,
                        FundAccountingFee = vw.FundAccountingFee,
                        TrusteeFee = vw.TrusteeFee,
                        ProspectusManagementFee = vw.ProspectusManagementFee,
                        ProspectusCustodyFee = vw.ProspectusCustodyFee,
                        LuxTax = vw.LuxTax,
                        FiduciaryFee = vw.FiduciaryFee,
                        SecuritiesLendingFee = vw.SecuritiesLendingFee,
                        CustodyFee = vw.CustodyFee
                    }).ToList();
        }
    }
}
namespace ProductMaster.FredaSync.Repository.Queries
{
    using System.Collections.Generic;
    using Data.Domain;
    using System.Linq;
    using Interfaces;
    using Requests;

    public class EditShareClassQuery : IQuery<ShareClass, EditShareClassQueryRequest>
    {
        private IRepository<ShareClass> repository;

        public EditShareClassQuery(IRepository<ShareClass> repository)
        {
            this.repository = repository;
        }

        public IEnumerable<ShareClass> Get(EditShareClassQueryRequest payload)
        {
            var allShareClassSet = payload.Request.ToList();
            var currentShareClassSet = this.repository.List();

            return (from vw in allShareClassSet
                    join sc in currentShareClassSet.Where(x => x.ShareClassId != null) on new { Code = vw.ShareClassCode, Source = vw.SystemSource } equals new { Code = sc.ShareClassCode, Source = sc.SystemSource }
                    where vw.LegalFundCode != sc.LegalFundCode ||
                            vw.ShareClassCurrency != sc.Currency ||
                            vw.ShareClassIdentifierType != sc.ShareClassIdentifierType ||
                            vw.LegalName != sc.LegalName ||
                            vw.ShareClassIncomeType != sc.ShareClassIncomeType ||
                            vw.Priips != sc.Priips ||
                            vw.Bloomberg != sc.Bloomberg ||
                            vw.CEDEL != sc.CEDEL || 
                            vw.ClosureDate != sc.ClosureDate ||
                            vw.LaunchDate != sc.LaunchDate ||
                            vw.SedolNumber != sc.SedolNumber ||
                            vw.Valoren != sc.Valoren ||
                            vw.Hedging != sc.Hedging ||
                            vw.IsinNumber != sc.IsinNumber ||
                            vw.LegalFundCode != sc.LegalFundCode                                                        
                    select new ShareClass
                    {
                        ShareClassId = sc.ShareClassId,
                        ShareClassCode = vw.ShareClassCode,
                        SystemSource = vw.SystemSource,
                        LegalFundCode = vw.LegalFundCode,
                        Currency = vw.ShareClassCurrency,
                        LegalName = vw.LegalName,
                        ShareClassIdentifierType = vw.ShareClassIdentifierType,
                        ShareClassIncomeType = vw.ShareClassIncomeType,
                        Bloomberg = vw.Bloomberg,
                        CEDEL = vw.CEDEL,
                        ClosureDate = vw.ClosureDate,
                        Hedging = vw.Hedging,
                        IsinNumber = vw.IsinNumber,
                        LaunchDate = vw.LaunchDate,
                        SedolNumber = vw.SedolNumber,
                        Valoren = vw.Valoren,
                        Priips = vw.Priips
                    }).ToList();

        }
    }

}

namespace ProductMaster.FredaSync.Repository.Interfaces
{
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;

    public interface IRepository<T>
    {
        T Find(Expression<Func<T, bool>> predicate);
        IEnumerable<T> List();
        void Save(T entity);
        void Delete(T entity);
    }

}

namespace ProductMaster.FredaSync.Repository.Interfaces
{
    using System.Collections.Generic;

    public interface IQuery<O, I>
    {
        IEnumerable<O> Get(I payload);
    }
}
{
  "buildOptions": {
    "emitEntryPoint": false
  },
  "dependencies": {
    "Autofac": "4.3.0",
    "Schroders.Bus.Core": "1.0.0-6",
    "Newtonsoft.Json": "9.0.1",
    "ProductMaster.FredaSync.Data": "1.0.0-*",
    "ProductMaster.FredaSync.Repository": "1.0.0-*",
    "ProductMaster.FundShareClass.DataContracts": "1.0.0-3",
    "ProductMaster.FundShareClassRates.DataContracts": "1.0.0-3",
    "Productmaster.FredaSync.Common": "1.0.0-*",
    "ProductMaster.FredaSync.Configuration": "1.0.0-*"
  },
  "frameworks": {
    "net461": {}
  },
  "version": "1.0.0-*"
}

namespace ProductMaster.FredaSync.Handlers
{
    using Data.Domain;
    using FundShareClassRates.DataContracts.DomainModel;

    public class ShareClassRateFactory
    {
        public static ShareClassRate Create(WriteShareClassRate payload)
        {
            return new ShareClassRate
            {
                ShareClassRateId = payload.ShareClassRateId,
                ShareClassId = payload.ShareClassId,
                ShareClassCode = payload.ShareClassCode,
                SystemSource = payload.SystemSource,
                EntryFee = payload.EntryCharge,
                ExitFee = payload.ExitCharge,
                SwitchFee = payload.SwitchCharge,
                OGCKiidFee = payload.OGCKiidFee,
                ManagementFee = payload.ManagementFee,
                DistributionFee = payload.DistributionFee,
                SafekeepingFee = payload.SafekeepingFee,
                TAFee = payload.TAFee,
                StatutoryFee = payload.StatutoryFee,
                TransactionFee = payload.TransactionFee,
                FundAccountingFee = payload.FundAccountingFee,
                TrusteeFee = payload.TrusteeFee,
                ProspectusManagementFee = payload.ProspectusManagementFee,
                ProspectusCustodyFee = payload.ProspectusCustodyFee,
                LuxTax = payload.LuxTax,
                FiduciaryFee = payload.FiduciaryFee,
                SecuritiesLendingFee = payload.SecuritiesLendingFee,
                CustodyFee = payload.CustodyFee
            };
        }
    }
}
namespace ProductMaster.FredaSync.Handlers
{
    using Data.Domain;
    using FundShareClassRates.DataContracts.DomainModel;    
    using Productmaster.FredaSync.Common.Constants;
    using Repository.Interfaces;
    using Schroders.Bus.Core;
    using Schroders.Bus.Core.Contracts;
    public class ShareClassRateCreatedMessageHandler : IBusHandler
    {
        private readonly IRepository<ShareClassRate> repository;

        public ShareClassRateCreatedMessageHandler(IRepository<ShareClassRate> repository)
        {
            this.repository = repository;
        }

        public bool CanHandleMessage(BusMessage message)
        {
            return message?.TopicName == ConfigTopicNames.ShareClassRateCreated;
        }

        public BusHandlerResponse HandleMessage(BusContext busContext, BusMessage busMessage)
        {
            var shareClassRate = busMessage.Payload as WriteShareClassRate;

            if (string.IsNullOrEmpty(shareClassRate?.ShareClassRateId))
                return new BusHandlerResponse();

            this.repository.Save(ShareClassRateFactory.Create(shareClassRate));

            return new BusHandlerResponse();
        }
    }
}
   namespace ProductMaster.FredaSync.Handlers
{
    using System.Data.Entity;
    using System.Linq;
    using Data;
    using FundShareClass.DataContracts.DomainModel;
    using Productmaster.FredaSync.Common.Constants;
    using Schroders.Bus.Core;
    using Schroders.Bus.Core.Contracts;
    using System.Transactions;
    using System;

    public class ShareClassCreatedMessageHandler : IBusHandler
    {
        private SyncDatabaseConfiguration configuration;
        public ShareClassCreatedMessageHandler(SyncDatabaseConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public bool CanHandleMessage(BusMessage message)
        {
            return message?.TopicName == ConfigTopicNames.ShareClassCreated;
        }

        public BusHandlerResponse HandleMessage(BusContext busContext, BusMessage busMessage)
        {
            var shareClass = busMessage.Payload as WriteShareClass;

            if (string.IsNullOrEmpty(shareClass?.ShareClassId))
                return new BusHandlerResponse();

            // Reason for transaction scope suppress
            // http://stackoverflow.com/questions/8088054/calling-entity-framework-from-a-nservicebus-method-causes-an-error
            // https://social.msdn.microsoft.com/Forums/en-US/7172223f-acbe-4472-8cdf-feec80fd2e64/the-partner-transaction-manager-has-disabled-its-support-for-remotenetwork-transactions?forum=adodotnetdataproviders
            // 1)
            //I think the IsTransactional property is only used by NSB to pass on to MSMQ. Using MSMQ you have to specify that a message is to be inserted into a transactional queue -and thus eventually (must)result in a commit or not.


            //2)
            //You should NOT avoid usage of DTC using NSB - in my opinion. When you pick up a message from your handler it is already running in a transaction from MSMQ.And when you acccess your database on another server that transaction is elevated to a distributed transaction. And this is good because when you get an error anywhere in that line (app server, database server, etc) the system rolls back all work and(eventually) puts your failed message in the error queue.Then you can correct whatever the problem was and re - submit the message.

            //All these are really good things.In my opinion you want that DTC.However as you said there might be a drawback of speed.The DTC is of course slower than running without.But I cant think of a situation where the DTC usage would be a practical problem in terms of speed!

            //3)
            //You can avoid the DTC by suppression just before you access the database stuff from your message handler, like this:

            //using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Suppress))
            //                YourDatabaseHandler.SaveMyStuff(whatever);

            using (var transactionScope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                // The scope has to be transient as DBContext does not handle thread safety and crashes
                // due to the fact there is one instance here used by several threads.
                // We have tried using service location using the autofac ILifeTimeScope
                // but this generates EntityFramework error - Failure on underlying connection            
                // so am falling back to new for now.
                using (var context = new FredaSyncContext(this.configuration.FredaSyncConnection))
                {
                    var fredaShareClass =
                        context.ShareClass.FirstOrDefault(
                            q =>
                                q.SystemSource == shareClass.PlatformSource &&
                                q.ShareClassCode == shareClass.PlatformCode);
                    if (fredaShareClass != null)
                    {
                        fredaShareClass.ShareClassId = shareClass.ShareClassId;
                        context.Entry(fredaShareClass).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                }
            }

            return new BusHandlerResponse();
        }
    }
}
       {
  "buildOptions": {
    "emitEntryPoint": false
  },
    "dependencies": {
      "Topshelf": "4.0.3",
      "EntityFramework": "6.1.3",
      "Autofac": "4.3.0",
      "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
      "System.Data.Common": "4.1.0"
    },
  "frameworks": {
    "net461": {}
  },
  "version": "1.0.0-*"
}
      
     namespace ProductMaster.FredaSync.Data
{
    using Configurators;
    using Domain;
    using System.Data.Entity;

    [DbConfigurationType(typeof(FredaSyncConfiguration))]
    public class FredaSyncContext : DbContext
    {
        public FredaSyncContext(string connString) : base(connString)
        {
            //Database.CreateIfNotExists();
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new ShareClassConfiguration());
            modelBuilder.Configurations.Add(new ShareClassRateConfiguration());
            modelBuilder.Configurations.Add(new PriipsShareClassIdsConfiguration());
            modelBuilder.Configurations.Add(new FredaShareClassesConfiguration());
            modelBuilder.Configurations.Add(new FredaShareClassRatesConfiguration());
        }

        public virtual DbSet<ShareClass> ShareClass { get; set; }
        public virtual DbSet<ShareClassRate> ShareClassRate { get; set; }
        public virtual DbSet<PriipsShareClassIds> PriipsShareClassIds { get; set; }

        public virtual DbSet<FredaShareClasses> FredaShareClasses { get; set; }

        public virtual DbSet<FredaShareClassRates> FredaShareClassRates { get; set; }
    }
}

      using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;

namespace ProductMaster.FredaSync.Data
{
    public class FredaSyncConfiguration : DbConfiguration
    {
        public FredaSyncConfiguration()
        {
            SetDatabaseInitializer<FredaSyncContext>(null);
        }
    }
}
namespace ProductMaster.FredaSync.Data
{
    using Autofac;
    using Microsoft.Extensions.Configuration;
    public class DataModule : Module
    {
        private IConfigurationRoot configuration;

        public DataModule(IConfigurationRoot configuration)
        {
            this.configuration = configuration;
        }
        protected override void Load(ContainerBuilder builder)
        {

            builder.Register(x => new FredaSyncContext(this.configuration.GetConnectionString("FredaSyncConnection")))
                 .As<FredaSyncContext>().InstancePerLifetimeScope();
        }
    }
}
  namespace ProductMaster.FredaSync.Data.Domain
{
    public class ShareClassRate
    {
        public string ShareClassRateId { get; set; }

        public string ShareClassId { get; set; }

        public string ShareClassCode { get; set; }

        public string SystemSource { get; set; }
        public decimal EntryFee { get; set; }
        public decimal ExitFee { get; set; }
        public decimal SwitchFee { get; set; }
        public decimal OGCKiidFee { get; set; }
        public decimal ManagementFee { get; set; }
        public decimal DistributionFee { get; set; }
        public decimal SafekeepingFee { get; set; }
        public decimal TAFee { get; set; }
        public decimal StatutoryFee { get; set; }
        public decimal TransactionFee { get; set; }
        public decimal FundAccountingFee { get; set; }
        public decimal TrusteeFee { get; set; }
        public decimal ProspectusManagementFee { get; set; }
        public decimal ProspectusCustodyFee { get; set; }
        public decimal LuxTax { get; set; }
        public decimal FiduciaryFee { get; set; }
        public decimal SecuritiesLendingFee { get; set; }
        public decimal CustodyFee { get; set; }

    }
}
          
         namespace ProductMaster.FredaSync.Data.Domain
{
    using System;
    using System.ComponentModel.DataAnnotations;
    public class ShareClass
    {
        public string ShareClassId { get; set; }
        public string ShareClassCode { get; set; }
        public string LegalFundCode { get; set; }
        public string SystemSource { get; set; }
        public string Currency { get; set; }
        public string LegalName { get; set; }        
        public string ShareClassIncomeType { get; set; }
        public DateTime? LaunchDate { get; set; }
        public DateTime? ClosureDate { get; set; }
        public string ShareClassIdentifierType { get; set; }
        public string Bloomberg { get; set; }
        public decimal? Valoren { get; set; }
        public string SedolNumber { get; set; }
        public decimal? CEDEL { get; set; }
        public string IsinNumber { get; set; }
        public string Hedging { get; set; }
        public bool Priips { get; set; }
    }
}
        namespace ProductMaster.FredaSync.Data.Domain
{
    using System.ComponentModel.DataAnnotations;
    public class PriipsShareClassIds
    {
        [Key]
        public string ShareClassId { get; set; }
    }
}
       namespace ProductMaster.FredaSync.Data.Domain
{
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    public class FredaShareClassRates
    {
        [Key, Column(Order = 0)]
        public string ShareClassCode { get; set; }

        [Key, Column(Order = 1)]
        public string SystemSource { get; set; }

        public decimal EntryFee { get; set; }
        public decimal ExitFee { get; set; }
        public decimal SwitchFee { get; set; }
        public decimal OGCKiidFee { get; set; }
        public decimal ManagementFee { get; set; }
        public decimal DistributionFee { get; set; }
        public decimal SafekeepingFee { get; set; }
        public decimal TAFee { get; set; }
        public decimal StatutoryFee { get; set; }
        public decimal TransactionFee { get; set; }
        public decimal FundAccountingFee { get; set; }
        public decimal TrusteeFee { get; set; }
        public decimal ProspectusManagementFee { get; set; }
        public decimal ProspectusCustodyFee { get; set; }
        public decimal LuxTax { get; set; }
        public decimal FiduciaryFee { get; set; }
        public decimal SecuritiesLendingFee { get; set; }
        public decimal CustodyFee { get; set; }

    }
}
        
   namespace ProductMaster.FredaSync.Data.Domain
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;

    public class FredaShareClasses
    {
        [Key, Column(Order = 0)]
        public string ShareClassCode { get; set; }

        public string LegalFundCode { get; set; }

        [Key, Column(Order = 1)]
        public string SystemSource { get; set; }

        public string ShareClassCurrency { get; set; }

        public string LegalName { get; set; }

        public DateTime? LaunchDate { get; set; }

        public DateTime? ClosureDate { get; set; }

        public string ShareClassIncomeType { get; set; }

        public string ShareClassIdentifierType { get; set; }

        public string Bloomberg { get; set; }

        public decimal? Valoren { get; set; }

        public string SedolNumber { get; set; }

        public decimal? CEDEL { get; set; }

        public string IsinNumber { get; set; }

        public string Hedging { get; set; }
        
        
        public bool Priips { get; set; }
    }
}
        
  namespace ProductMaster.FredaSync.Data.Configurators
{
    using Domain;
    using System.Data.Entity.ModelConfiguration;

    public class ShareClassRateConfiguration : EntityTypeConfiguration<ShareClassRate>
    {
        public ShareClassRateConfiguration()
        {
            ToTable("ShareClassRates");
            HasKey(x => new { x.ShareClassCode, x.SystemSource });
            Property(x => x.ShareClassRateId);
            Property(x => x.ShareClassId);
            Property(x => x.ShareClassCode);
            Property(x => x.SystemSource);
            Property(x => x.EntryFee).HasPrecision(9, 6);
            Property(x => x.CustodyFee).HasPrecision(9, 6);
            Property(x => x.DistributionFee).HasPrecision(9, 6);
            Property(x => x.ExitFee).HasPrecision(9, 6);
            Property(x => x.FiduciaryFee).HasPrecision(9, 6);
            Property(x => x.FundAccountingFee).HasPrecision(9, 6);
            Property(x => x.LuxTax).HasPrecision(9, 6);
            Property(x => x.ManagementFee).HasPrecision(9, 6);
            Property(x => x.OGCKiidFee).HasPrecision(9, 6);
            Property(x => x.ProspectusCustodyFee).HasPrecision(9, 6);
            Property(x => x.ProspectusManagementFee).HasPrecision(9, 6);
            Property(x => x.SafekeepingFee).HasPrecision(9, 6);
            Property(x => x.SecuritiesLendingFee).HasPrecision(9, 6);
            Property(x => x.StatutoryFee).HasPrecision(9, 6);
            Property(x => x.SwitchFee).HasPrecision(9, 6);
            Property(x => x.TAFee).HasPrecision(9, 6);
            Property(x => x.TransactionFee).HasPrecision(9, 6);
            Property(x => x.TrusteeFee).HasPrecision(9, 6);
        }
    }
}
  using ProductMaster.FredaSync.Data.Domain;
using System.Data.Entity.ModelConfiguration;

namespace ProductMaster.FredaSync.Data.Configurators
{
    public class ShareClassConfiguration : EntityTypeConfiguration<ShareClass>
    {
        public ShareClassConfiguration()
        {
            ToTable("ShareClasses");
            HasKey(x => new { x.ShareClassCode, x.SystemSource });
            Property(x => x.ShareClassId);
            Property(x => x.ShareClassCode);
            Property(x => x.SystemSource);
            Property(x => x.LegalFundCode);
            Property(x => x.SystemSource);
            Property(x => x.Currency);
            Property(x => x.LegalName);
            Property(x => x.ShareClassIncomeType);
            Property(x => x.ShareClassIdentifierType).HasMaxLength(2);
            Property(x => x.LaunchDate);
            Property(x => x.ClosureDate);
            Property(x => x.Bloomberg);
            Property(x => x.Valoren).HasPrecision(10, 0);
            Property(x => x.SedolNumber);
            Property(x => x.CEDEL).HasPrecision(10,0);
            Property(x => x.SedolNumber);
            Property(x => x.IsinNumber).HasMaxLength(12);
            Property(x => x.Priips);
        }
    }
}

 namespace ProductMaster.FredaSync.Data.Configurators
{
    using Domain;
    using System.Data.Entity.ModelConfiguration;

    public class PriipsShareClassIdsConfiguration : EntityTypeConfiguration<PriipsShareClassIds>
    {
        public PriipsShareClassIdsConfiguration()
        {
            ToTable("PriipsShareClassIds");
            HasKey(x => x.ShareClassId).Property(x => x.ShareClassId);
        }
    }
}

      namespace ProductMaster.FredaSync.Data.Configurators
{
    using Domain;
    using System.Data.Entity.ModelConfiguration;

    public class FredaShareClassRatesConfiguration : EntityTypeConfiguration<FredaShareClassRates>
    {
        public FredaShareClassRatesConfiguration()
        {
            ToTable("vwFredaShareClassRates");
            Property(x => x.ShareClassCode);
            Property(x => x.SystemSource);
            Property(x => x.EntryFee).HasPrecision(9, 6);
            Property(x => x.CustodyFee).HasPrecision(9, 6);
            Property(x => x.DistributionFee).HasPrecision(9, 6);
            Property(x => x.ExitFee).HasPrecision(9, 6);
            Property(x => x.FiduciaryFee).HasPrecision(9, 6);
            Property(x => x.FundAccountingFee).HasPrecision(9, 6);
            Property(x => x.LuxTax).HasPrecision(9, 6);
            Property(x => x.ManagementFee).HasPrecision(9, 6);
            Property(x => x.OGCKiidFee).HasPrecision(9, 6);
            Property(x => x.ProspectusCustodyFee).HasPrecision(9, 6);
            Property(x => x.ProspectusManagementFee).HasPrecision(9, 6);
            Property(x => x.SafekeepingFee).HasPrecision(9, 6);
            Property(x => x.SecuritiesLendingFee).HasPrecision(9, 6);
            Property(x => x.StatutoryFee).HasPrecision(9, 6);
            Property(x => x.SwitchFee).HasPrecision(9, 6);
            Property(x => x.TAFee).HasPrecision(9, 6);
            Property(x => x.TransactionFee).HasPrecision(9, 6);
            Property(x => x.TrusteeFee).HasPrecision(9, 6);

        }
    }
}
namespace ProductMaster.FredaSync.Data.Configurators
{
    using Domain;
    using System.Data.Entity.ModelConfiguration;

    public class FredaShareClassesConfiguration : EntityTypeConfiguration<FredaShareClasses>
    {
        public FredaShareClassesConfiguration()
        {
            ToTable("vwFredaShareClasses");
            Property(x => x.ShareClassCode);
            Property(x => x.SystemSource);
            Property(x => x.LegalFundCode);
            Property(x => x.LaunchDate);
            Property(x => x.ClosureDate);
            Property(x => x.ShareClassIdentifierType);
            Property(x => x.ShareClassIncomeType).HasMaxLength(1);
            Property(x => x.Bloomberg);
            Property(x => x.Valoren).HasPrecision(10, 0);
            Property(x => x.SedolNumber);
            Property(x => x.CEDEL).HasPrecision(10, 0);
            Property(x => x.IsinNumber);
            Property(x => x.Hedging);
            Property(x => x.SystemSource);
            Property(x => x.ShareClassCurrency);
            Property(x => x.LegalName);
            Property(x => x.ShareClassIdentifierType);            
            Property(x => x.Priips);
        }
    }
}
{
  "dependencies": {
  },
  "frameworks": {
    "net461": {}
  },
  "version": "1.0.0-*"
}


namespace ProductMaster.FredaSync
{
    public class SyncDatabaseConfiguration
    {
        public string FredaSyncConnection { get; set; }
    }
}
{
  "dependencies": {
    "Priips.Costs.Config.DataContracts": "1.0.0-1",
    "Productmaster.FredaSync.Common": "1.0.0-*",
    "ProductMaster.FredaSync.Data": "1.0.0-*",
    "ProductMaster.FredaSync.Repository": "1.0.0-*",
    "ProductMaster.FundShareClass.DataContracts": "1.0.0-3",
    "ProductMaster.FundShareClassRates.DataContracts": "1.0.0-3",
    "Schroders.ServiceBase.Commands": "1.0.0",
    "NServiceBus": "6.0.0",
    "Schroders.Bus.Core": "1.0.0-6"
  },
  "frameworks": {
    "net461": {}
  },
  "version": "1.0.0-*"
}

namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Productmaster.FredaSync.Common.Constants;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class RemoveShareClassCommand : ICommand<RemoveShareClassRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly IRepository<ShareClass> shareClassRepository;
        private readonly IRepository<ShareClassRate> shareClassRateRepository;
        private readonly IRepository<PriipsShareClassIds> priipsShareClassIdsRepository;
        private readonly ILogger<RemoveShareClassCommand> logger;

        public RemoveShareClassCommand(IMessageDispatcher dispatch,
                                        IRepository<ShareClass> shareClassRepository,
                                        IRepository<ShareClassRate> shareClassRateRepository,
                                        ILogger<RemoveShareClassCommand> logger)
        {
            this.dispatch = dispatch;
            this.shareClassRepository = shareClassRepository;
            this.shareClassRateRepository = shareClassRateRepository;
            this.logger = logger;

        }

        public SyncResponse Execute(RemoveShareClassRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.shareClassRepository.Delete(new ShareClass { ShareClassId = item.ShareClassId });
                    this.dispatch.Send(item.ShareClassId, ConfigTopicNames.RemoveShareClass);

                    this.shareClassRateRepository.Delete(new ShareClassRate { ShareClassId = item.ShareClassId });
                    this.dispatch.Send(item.ShareClassId, ConfigTopicNames.RemoveShareClassRate);
                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;
        }
    }
}
namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Productmaster.FredaSync.Common.Constants;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class RemovePriipsShareClassIdsCommand : ICommand<RemovePriipsShareClassIdsRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<RemovePriipsShareClassIdsCommand> logger;
        private readonly IRepository<PriipsShareClassIds> priipsShareClassIdsRepository;

        public RemovePriipsShareClassIdsCommand(IMessageDispatcher dispatch,
                                                IRepository<PriipsShareClassIds> priipsShareClassIdsRepository,
                                                ILogger<RemovePriipsShareClassIdsCommand> logger)
        {
            this.dispatch = dispatch;
            this.priipsShareClassIdsRepository = priipsShareClassIdsRepository;
            this.logger = logger;

        }

        public SyncResponse Execute(RemovePriipsShareClassIdsRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.priipsShareClassIdsRepository.Delete(item);
                    this.dispatch.Send(item.ShareClassId, ConfigTopicNames.PriipsDeleteTopic);
                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;

        }
    }
}

namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Factories;
    using Productmaster.FredaSync.Common.Constants;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewShareClassRateCommand : ICommand<NewShareClassRateRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<NewShareClassRateCommand> logger;
        private readonly IRepository<ShareClassRate> shareClassRateRepository;

        public NewShareClassRateCommand(IMessageDispatcher dispatch,
                                        IRepository<ShareClassRate> shareClassRateRepository,
                                        ILogger<NewShareClassRateCommand> logger)
        {
            this.dispatch = dispatch;
            this.shareClassRateRepository = shareClassRateRepository;
            this.logger = logger;
        }

        public SyncResponse Execute(NewShareClassRateRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.shareClassRateRepository.Save(item);
                    this.dispatch.Send(ShareClassRateFactory.Create(item), ConfigTopicNames.AddUpdateShareClassRate);

                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;
        }
    }
}
namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Productmaster.FredaSync.Common.Factories;
    using Productmaster.FredaSync.Common.Constants;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewShareClassCommand : ICommand<NewShareClassRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<NewShareClassCommand> logger;
        private readonly IRepository<ShareClass> shareClassRepository;

        public NewShareClassCommand(IMessageDispatcher dispatch,
                                    IRepository<ShareClass> shareClassRepository,
                                    ILogger<NewShareClassCommand> logger)
        {
            this.dispatch = dispatch;
            this.shareClassRepository = shareClassRepository;
            this.logger = logger;
        }

        public SyncResponse Execute(NewShareClassRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    var shareClass = ShareClassFactory.Create(item);
                    this.shareClassRepository.Save(shareClass);
                    this.dispatch.Send(ShareClassFactory.Create(shareClass), ConfigTopicNames.AddUpdateShareClass);
                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;

        }
    }
}

namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Productmaster.FredaSync.Common.Constants;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class NewPriipsShareClassIdsCommand : ICommand<NewPriipsShareClassIdsRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<NewPriipsShareClassIdsCommand> logger;
        private readonly IRepository<PriipsShareClassIds> priipsShareClassIdsRepository;

        public NewPriipsShareClassIdsCommand(IMessageDispatcher dispatch,
                                                IRepository<PriipsShareClassIds> priipsShareClassIdsRepository,
                                                ILogger<NewPriipsShareClassIdsCommand> logger)
        {
            this.dispatch = dispatch;
            this.priipsShareClassIdsRepository = priipsShareClassIdsRepository;
            this.logger = logger;
        }

        public SyncResponse Execute(NewPriipsShareClassIdsRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.priipsShareClassIdsRepository.Save(item);
                    this.dispatch.Send(item.ShareClassId, ConfigTopicNames.PriipsSaveTopic);

                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;
        }
    }
}

namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Data.Domain;
    using Dispatch;
    using Factories;
    using Repository.Interfaces;
    using Productmaster.FredaSync.Common.Constants;
    using Productmaster.FredaSync.Common.Factories;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class EditShareClassRateCommand : ICommand<EditShareClassRateRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<EditShareClassRateCommand> logger;
        private readonly IRepository<ShareClassRate> shareClassRateRepository;

        public EditShareClassRateCommand(IMessageDispatcher dispatch,
            IRepository<ShareClassRate> shareClassRateRepository,
            ILogger<EditShareClassRateCommand> logger)
        {
            this.dispatch = dispatch;
            this.shareClassRateRepository = shareClassRateRepository;
            this.logger = logger;
        }

        public SyncResponse Execute(EditShareClassRateRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.shareClassRateRepository.Save(item);
                    this.dispatch.Send(ShareClassRateFactory.Create(item), ConfigTopicNames.AddUpdateShareClassRate);
                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;
        }
    }
}
namespace ProductMaster.FredaSync.Commands.Handlers
{
    using Request;
    using Response;
    using System;
    using Data.Domain;
    using Dispatch;
    using Repository.Interfaces;
    using Productmaster.FredaSync.Common.Constants;
    using Productmaster.FredaSync.Common.Factories;
    using Microsoft.Extensions.Logging;
    using Schroders.ServiceBase.Commands;
    using System.Collections.Generic;

    public class EditShareClassCommand : ICommand<EditShareClassRequest, SyncResponse>
    {
        private readonly IMessageDispatcher dispatch;
        private readonly ILogger<EditShareClassCommand> logger;
        private readonly IRepository<ShareClass> shareClassRepository;

        public EditShareClassCommand(IMessageDispatcher dispatch, IRepository<ShareClass> shareClassRepository, ILogger<EditShareClassCommand> logger)
        {
            this.dispatch = dispatch;
            this.shareClassRepository = shareClassRepository;
            this.logger = logger;
        }

        public SyncResponse Execute(EditShareClassRequest request, IDictionary<string, object> context)
        {
            var response = new SyncResponse();

            try
            {
                foreach (var item in request.Payload)
                {
                    if (request.CancelToken.IsCancellationRequested)
                    {
                        logger.LogWarning("Cancel processing {@item}", item);
                        break;
                    }

                    this.shareClassRepository.Save(item);
                    this.dispatch.Send(ShareClassFactory.Create(item), ConfigTopicNames.AddUpdateShareClass);
                }

                response.Result = true;

            }
            catch (Exception ex)
            {
                response.Result = false;
                response.Error = ex.Message;
            }

            return response;
        }
    }
}
namespace ProductMaster.FredaSync.Commands
{
    using Autofac;
    using Handlers;
    using Repository.Interfaces;
    using Data.Domain;
    using Dispatch;
    using Microsoft.Extensions.Logging;

    public class CommandModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.Register(c => new NewShareClassCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<ShareClass>>(),
                c.Resolve<ILogger<NewShareClassCommand>>()
                ));

            builder.Register(c => new NewShareClassRateCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<ShareClassRate>>(),
                c.Resolve<ILogger<NewShareClassRateCommand>>()
                ));

            builder.Register(c => new EditShareClassCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<ShareClass>>(),
                c.Resolve<ILogger<EditShareClassCommand>>()
                ));

            builder.Register(c => new EditShareClassRateCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<ShareClassRate>>(),
                c.Resolve<ILogger<EditShareClassRateCommand>>()
                ));

            builder.Register(c => new RemoveShareClassCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<ShareClass>>(),
                c.Resolve<IRepository<ShareClassRate>>(),
                c.Resolve<ILogger<RemoveShareClassCommand>>()
                ));

            builder.Register(c => new NewPriipsShareClassIdsCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<PriipsShareClassIds>>(),
                c.Resolve<ILogger<NewPriipsShareClassIdsCommand>>()
                ));

            builder.Register(c => new RemovePriipsShareClassIdsCommand(
                c.Resolve<IMessageDispatcher>(),
                c.Resolve<IRepository<PriipsShareClassIds>>(),
                c.Resolve<ILogger<RemovePriipsShareClassIdsCommand>>()
                ));

            builder.RegisterType<MessageDispatcher>().As<IMessageDispatcher>().SingleInstance();
        }
    }
}

namespace ProductMaster.FredaSync.Commands.Response
{
    public class SyncResponse
    {
        public bool Result { get; set; }
        public string Error { get; set; }
    }
}
namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;
    public class RemoveShareClassRequest : CancellableRequest
    {
        public IEnumerable<ShareClass> Payload { get; set; }
    }
}

namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class RemovePriipsShareClassIdsRequest : CancellableRequest
    {
        public IEnumerable<PriipsShareClassIds> Payload { get; set; }
    }
}
namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewShareClassRequest : CancellableRequest
    {
        public IEnumerable<FredaShareClasses> Payload { get; set; }
    }
}

namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewShareClassRateRequest : CancellableRequest
    {
        public IEnumerable<ShareClassRate> Payload { get; set; }
    }
}
namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class NewPriipsShareClassIdsRequest : CancellableRequest
    {
        public IEnumerable<PriipsShareClassIds> Payload { get; set; }
    }
}

namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class EditShareClassRequest : CancellableRequest
    {
        public IEnumerable<ShareClass> Payload { get; set; }
    }
}
namespace ProductMaster.FredaSync.Commands.Request
{
    using Data.Domain;
    using System.Collections.Generic;

    public class EditShareClassRateRequest : CancellableRequest
    {
        public IEnumerable<ShareClassRate> Payload { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace ProductMaster.FredaSync.Commands.Request
{
    public class CancellableRequest
    {
        public CancellationToken CancelToken { get; set; }
    }
}

namespace ProductMaster.FredaSync.Commands.Factories
{
    using Data.Domain;
    using FundShareClassRates.DataContracts.DomainModel;

    public class ShareClassRateFactory
    {
        public static WriteShareClassRate Create(ShareClassRate payload)
        {
            return new WriteShareClassRate
            {
                ShareClassId = payload.ShareClassId,
                ShareClassCode = payload.ShareClassCode,
                SystemSource = payload.SystemSource,
                EntryCharge = payload.EntryFee,
                ExitCharge = payload.ExitFee,
                SwitchCharge = payload.SwitchFee,
                OGCKiidFee = payload.OGCKiidFee,
                ManagementFee = payload.ManagementFee,
                DistributionFee = payload.DistributionFee,
                SafekeepingFee = payload.SafekeepingFee,
                TAFee = payload.TAFee,
                StatutoryFee = payload.StatutoryFee,
                TransactionFee = payload.TransactionFee,
                FundAccountingFee = payload.FundAccountingFee,
                TrusteeFee = payload.TrusteeFee,
                ProspectusManagementFee = payload.ProspectusManagementFee,
                ProspectusCustodyFee = payload.ProspectusCustodyFee,
                LuxTax = payload.LuxTax,
                FiduciaryFee = payload.FiduciaryFee,
                SecuritiesLendingFee = payload.SecuritiesLendingFee,
                CustodyFee = payload.CustodyFee
            };
        }      
    }
}
namespace Productmaster.FredaSync.Common.Factories
{
    using ProductMaster.FredaSync.Data.Domain;
    using ProductMaster.FundShareClass.DataContracts.DomainModel;

    public class ShareClassFactory
    {
        public static WriteShareClass Create(ShareClass payload)
        {
            return new WriteShareClass
            {
                ShareClassId = payload.ShareClassId,
                PlatformCode = payload.ShareClassCode,
                PlatformSource = payload.SystemSource,
                Currency = payload.Currency,
                LegalName = payload.LegalName,
                ShareClassIdentifierType = payload.ShareClassIdentifierType,                
                LaunchDate = payload.LaunchDate,
                ClosureDate = payload.ClosureDate,
                ShareClassIncomeType = payload.ShareClassIncomeType,
                Bloomberg = payload.Bloomberg,
                Valoren = payload.Valoren,
                SedolNumber = payload.SedolNumber,
                CEDEL = payload.CEDEL,
                IsinNumber = payload.IsinNumber,
                Hedging = payload.Hedging
            };
        }

        public static ShareClass Create(FredaShareClasses payload)
        {
            return new ShareClass
            {
                ShareClassCode = payload.ShareClassCode,
                SystemSource = payload.SystemSource,
                Currency = payload.ShareClassCurrency,
                LegalName = payload.LegalName,
                LegalFundCode = payload.LegalFundCode,                
                ShareClassIncomeType = payload.ShareClassIncomeType,
                Bloomberg = payload.Bloomberg,
                CEDEL = payload.CEDEL,
                ClosureDate = payload.ClosureDate,
                Hedging = payload.Hedging,
                IsinNumber = payload.IsinNumber,
                LaunchDate = payload.LaunchDate,
                SedolNumber = payload.SedolNumber,
                ShareClassIdentifierType = payload.ShareClassIdentifierType,                 
                Valoren = payload.Valoren,
                Priips = payload.Priips
            };
        }

        public static ShareClass Create(WriteShareClass payload)
        {
            return new ShareClass
            {
                ShareClassId = payload.ShareClassId,
                ShareClassCode = payload.PlatformCode,
                SystemSource = payload.PlatformSource,
                Currency = payload.Currency,
                LegalName = payload.LegalName,                
                ShareClassIncomeType = payload.IncomeType.ToString(),
                ClosureDate = payload.ClosureDate,
                CEDEL = payload.CEDEL,
                Bloomberg = payload.Bloomberg,
                Hedging = payload.Hedging,
                IsinNumber = payload.IsinNumber,
                LaunchDate = payload.LaunchDate,
                LegalFundCode = payload.LegalName,
                SedolNumber = payload.SedolNumber,
                ShareClassIdentifierType = payload.ShareClassIdentifierType,
                Valoren = payload.Valoren                
            };
        }
    }
}


namespace ProductMaster.FredaSync.Commands.Dispatch
{
    using Schroders.Bus.Core;
    using Schroders.Bus.Core.Contracts;

    public class MessageDispatcher : IMessageDispatcher
    {
        private readonly IBus bus;

        public MessageDispatcher(IBus bus)
        {
            this.bus = bus;
        }

        public void Send<T>(T payload, string topic)
        {
            this.bus.Send(new BusMessage
            {
                TopicName = topic,
                Payload = payload
            });
        }
    }
}

namespace ProductMaster.FredaSync.Commands.Dispatch
{
    public interface IMessageDispatcher
    {
        void Send<T>(T payload, string topic);
    }
}
{
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": false,
    "copyToOutput": {
      "includeFiles": [
        "appsettings.json"
      ]
    }
  },
  "dependencies": {
    "Autofac": "4.3.0",
    "Autofac.Extensions.DependencyInjection": "4.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Logging.TraceSource": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "NServiceBus": "6.0.0",
    "NServiceBus.Autofac": "6.0.0",
    "ProductMaster.FredaSync.Commands": "1.0.0-*",
    "Productmaster.FredaSync.Common": "1.0.0-*",
    "ProductMaster.FredaSync.Data": "1.0.0-*",
    "ProductMaster.FredaSync.Repository": "1.0.0-*",
    "ProductMaster.FredaSync.Tasks": "1.0.0-*",
    "ProductMaster.FredaSync.Handlers": "1.0.0-*",
    "Schroders.Bus.Core": "1.0.0-6",
    "Schroders.Bus.NServiceBus": "1.0.0-4",
    "Schroders.ServiceBase.Hosting": "1.0.0-1",
    "Serilog": "2.3.0",
    "Serilog.Extensions.Logging": "1.4.0",
    "Serilog.Settings.Configuration": "2.2.0",
    "Serilog.Sinks.Literate": "2.1.0",
    "Serilog.Sinks.RollingFile": "3.3.0",
    "System.Linq": "4.0.0",
    "Topshelf": "4.0.3",
    "ProductMaster.FredaSync.Configuration": "1.0.0-*"
  },
  "frameworks": {
    "net461": {}
  },
  "publishOptions": {
    "include": [
      "appsettings.json"
    ]
  },
  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },
  "version": "1.0.0-*"
}


namespace ProductMaster.FredaSync
{
    using Autofac;
    using Microsoft.Extensions.Logging;
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;
    using Tasks;
    using Topshelf;
    public class SyncService : ServiceControl, IDisposable
    {
        private readonly SyncConfiguration configuration;
        private readonly ILifetimeScope scope;
        private readonly ManualResetEvent waitHandle = new ManualResetEvent(false);
        private readonly ManualResetEvent endHandle = new ManualResetEvent(false);
        private ILogger<SyncService> logger;
        private IContainer container;
        private volatile bool stopped = false;
        private CancellationTokenSource cancellationTokenSource;

        public SyncService(SyncConfiguration config)
        {
            this.configuration = config;
        }

        ~SyncService()
        {
            Dispose(false);
        }

        public string ApplicationName => configuration.ApplicationName;

        public bool Start(HostControl hostControl)
        {
            var started = true;

            try
            {
                this.container = Startup.ConfigureServices();

                using (var scope = container.BeginLifetimeScope())
                {
                    this.logger = scope.Resolve<ILogger<SyncService>>();

                    this.logger.LogInformation("Sync Service starting");

                    cancellationTokenSource = new CancellationTokenSource();

                    Task.Run(() =>
                    {
                        DoWork(hostControl);
                    }, cancellationTokenSource.Token);

                    this.logger.LogInformation("Sync Service started");
                }
            }
            catch (Exception ex)
            {
                this.logger.LogError("Sync Service failed during start : {@ex}", ex);
                started = false;
            }

            return started;
        }

        private void DoWork(HostControl hostControl)
        {
            try
            {
                this.logger.LogInformation("Sync Service worker started");

                var tasks = container.Resolve<IList<ISyncTask>>();

                do
                {
                    ExecuteTasks(cancellationTokenSource.Token, tasks);
                } while (!waitHandle.WaitOne(TimeSpan.FromSeconds(configuration.PollingInterval)));

                endHandle.Set();
            }
            catch (Exception ex)
            {
                this.logger.LogError("Sync Service failed with exception: {@ex}", ex);

                // cannot be in finally as otherwise not call and dead-lock process
                endHandle.Set();
                hostControl.Stop();
                throw;
            }

            this.logger.LogInformation("Sync Service worker terminated normally");
        }


        public bool Stop(HostControl hostControl)
        {
            // call twice by topshelf for some reason sometimes
            if (!stopped)
            {
                this.logger.LogInformation("Sync Service stopping");

                try
                {
                    // signal sub-tasks to finish
                    cancellationTokenSource.Cancel();

                    // signal schedulerTask to finish
                    waitHandle.Set();
                    endHandle.WaitOne();
                }
                catch (Exception ex)
                {
                    this.logger.LogError("Sync Service failed during stop : {@ex}", ex);
                    throw;
                }
                finally
                {
                    stopped = true;
                }

                this.logger.LogInformation("Sync Service stopped");
            }

            return stopped;
        }


        private void ExecuteTasks(CancellationToken cancelToken, IList<ISyncTask> tasks)
        {
            foreach (var task in tasks)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    this.logger.LogWarning("Sync Service cancel execution before task : {@task}", task);
                    break;
                }

                task.Execute(cancelToken);
            }
        }

        #region IDisposable

        private bool disposed = false;        

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        public virtual void Dispose(bool disposing)
        {
            if (disposed)
                return;

            if (disposing)
            {
                waitHandle?.Dispose();
                endHandle?.Dispose();
            }

            disposed = true;
        }


        #endregion
    }
}



namespace ProductMaster.FredaSync
{
    public class SyncConfiguration
    {
        public string ApplicationName { get; set; }
        public int PollingInterval { get; set; }
    }
}

namespace ProductMaster.FredaSync
{
    using Autofac;
    using FundShareClass.DataContracts.DomainModel;
    using FundShareClassRates.DataContracts.DomainModel;
    using Microsoft.Extensions.Configuration;
    using NServiceBus;
    using Productmaster.FredaSync.Common.Constants;
    using Schroders.Bus.Core;
    using Schroders.Bus.NServiceBus.Helpers;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;

    public static class SyncBusConfiguration
    {
        public static void Configure(IConfigurationRoot configuration, IContainer container)
        {
            // load any datacontracts in appdomain before starting nservicebus in order for handler to be able deserialize message
            AppDomain.CurrentDomain.Load(typeof(WriteShareClass).Assembly.FullName);
            AppDomain.CurrentDomain.Load(typeof(WriteShareClassRate).Assembly.FullName);

            NServiceBusEndpointHosting.StartConfiguredEndpoints(
                    configuration,
                    container,
                    new Dictionary<string, string[]>
                    {
                        {
                           ConfigQueueNames.ShareClass, new[] { ConfigTopicNames.AddUpdateShareClass, ConfigTopicNames.RemoveShareClass }
                        },
                        {
                           ConfigQueueNames.ShareClassRate, new[] { ConfigTopicNames.AddUpdateShareClassRate, ConfigTopicNames.RemoveShareClassRate }
                        },
                        {
                            ConfigQueueNames.PriipsShareClassId, new[] { ConfigTopicNames.PriipsSaveTopic, ConfigTopicNames.PriipsDeleteTopic }
                        },
                        {
                            "ProductMaster.FundShareClass.Events", new[] { "ShareClassCreated" }
                        },
                        {
                            "ProductMaster.FundShareClassRates.Events", new[] { "ShareClassRateCreated" }
                        },


                    },
                    allEndpointConfiguration =>
                    {
                        var directoryToScan = AppDomain.CurrentDomain.BaseDirectory;
                        var localFiles = Directory.GetFiles(directoryToScan);
                        var filteredFiles = localFiles.Select(Path.GetFileName).Where(fn => fn != "NServiceBus.Core.dll");

                        allEndpointConfiguration.ExcludeAssemblies(filteredFiles.ToArray());

                        allEndpointConfiguration.Conventions().DefiningMessagesAs(t => t == typeof(BusMessage));
                        allEndpointConfiguration.Conventions().DefiningEventsAs(t => t == typeof(BusEvent));
                    },
                    new Dictionary<string, Action<EndpointConfiguration>>
                    {
                        {
                             ConfigQueueNames.ShareClass, ep =>
                            {
                                ep.SendOnly();
                            }

                        },
                        {
                             ConfigQueueNames.ShareClassRate, ep =>
                            {
                                ep.SendOnly();
                            }

                        },
                        {
                            ConfigQueueNames.PriipsShareClassId, ep =>
                            {
                                ep.SendOnly();
                            }
                        },
                        {
                            "ProductMaster.FundShareClass.Events", ep =>
                            {
                                var transport = ep.UseTransport<MsmqTransport>();
                                var routing = transport.Routing();
                                routing.RegisterPublisher(typeof(BusEvent), "ProductMaster.FundShareClass.Publisher");

                            }
                        },
                        {
                            "ProductMaster.FundShareClassRates.Events", ep =>
                            {
                                var transport = ep.UseTransport<MsmqTransport>();
                                var routing = transport.Routing();
                                routing.RegisterPublisher(typeof(BusEvent), "ProductMaster.FundShareClassRates.Publisher");

                            }
                        }

                    });
        }
    }
}   
namespace ProductMaster.FredaSync
{
    using Autofac;
    using Microsoft.Extensions.Configuration;
    using Commands;
    using Data;
    using Schroders.Bus.Core.Contracts;
    using Schroders.Bus.NServiceBus;
    using Schroders.Bus.Core;
    using Repository;
    using System.Reflection;
    using Serilog;
    using Microsoft.Extensions.DependencyModel;
    using Microsoft.Extensions.Logging;
    using Microsoft.Extensions.DependencyInjection;
    using Autofac.Extensions.DependencyInjection;
    using Handlers;
    using System;
    using Commands.Dispatch;

    public static class Startup
    {
        public static IContainer ConfigureServices()
        {
            var builder = new ContainerBuilder();

            var configurationBuilder = new ConfigurationBuilder()
                .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddEnvironmentVariables();

            var configuration = configurationBuilder.Build();
            var fredaSyncConfig = new SyncConfiguration();
            configuration.GetSection("SyncConfiguration").Bind(fredaSyncConfig);
            builder.RegisterInstance(fredaSyncConfig);

            var syncDatabaseConfiguration = new SyncDatabaseConfiguration();
            configuration.GetSection("ConnectionStrings").Bind(syncDatabaseConfiguration);
            builder.RegisterInstance(syncDatabaseConfiguration);

            //todo check if there is nservicebus loaded and starting processing queues before loaded DataContract library
            builder.RegisterType<DefaultBusHandlerProvider>().As<IBusHandlerProvider>().SingleInstance();
            builder.RegisterType<NServiceBus>().As<IBus>().SingleInstance();
            builder.RegisterType<EndpointInstanceProvider>().As<IEndpointInstanceProvider>().SingleInstance();

            builder.RegisterType<ShareClassCreatedMessageHandler>().As<IBusHandler>();
            builder.RegisterType<ShareClassRateCreatedMessageHandler>().As<IBusHandler>();

            builder.RegisterModule(new DataModule(configuration));
            builder.RegisterModule(new RepositoryModule());
            builder.RegisterModule(new CommandModule());
            builder.RegisterModule(new TaskModule());

            var services = new ServiceCollection();
            services.AddLogging();
            builder.Populate(services);

            var container = builder.Build();

            // Workaround for mstest application domain
            var assembly = Assembly.GetEntryAssembly();
            var dependencyContext = (assembly == null)
                                        ? DependencyContext.Load(typeof(Startup).Assembly)
                                        : DependencyContext.Default;

            Log.Logger = new LoggerConfiguration()
                .ReadFrom.Configuration(configuration, dependencyContext)
                .CreateLogger();

            var loggerFactory = container.Resolve<ILoggerFactory>();
            loggerFactory.AddConsole()
                .AddSerilog();

            SyncBusConfiguration.Configure(configuration, container);

            return container;
        }
    }
}

namespace ProductMaster.FredaSync
{
    using Autofac;
    using System;
    using Microsoft.Extensions.Logging;
    using Topshelf;
    using Microsoft.Extensions.Configuration;

    public class Program
    {
        public static void Main(string[] args)
        {
            var contentRoot = AppDomain.CurrentDomain.BaseDirectory;

            var config = new ConfigurationBuilder()
               .SetBasePath(contentRoot)
               .AddJsonFile("appsettings.json", optional: false)
               .Build();

            var sectionConfig = config.GetSection(nameof(SyncConfiguration));
            var syncConfiguration = new SyncConfiguration();
            sectionConfig.Bind(syncConfiguration);

            HostFactory.Run((hostConfigurator) =>
            {
                var service = new SyncService(syncConfiguration);
                hostConfigurator.Service(() => service);

                hostConfigurator.SetServiceName(service.ApplicationName);                
            });
        }

    }
}

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "System": "Information",
        "Microsoft": "Information"
      }
    },
    "WriteTo": [
      {
        "Name": "LiterateConsole"
      },
      {
        "Name": "Seq",
        "Args": {
          "serverUrl": "http://localhost:5001/",
          "compact": true
        }
      },
      {
        "Name": "RollingFile",
        "Args": {
          "pathFormat": "D:\\Temp\\Logs\\pm-fredasync-log-{Date}.txt",
          "restrictedToMinimumLevel": "Information",
          "retainedFileCountLimit": 3
        }
      }
    ],
    "Enrich": [ "FromLogContext" ]
  },
  "ConnectionStrings": {
    "FredaSyncConnection": "Server=LUX8655;Database=FredaSyncNew;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "SyncConfiguration": {
    "ApplicationName": "FredaSyncService",
    "PollingInterval": 5
  },

  "NServiceBusConfiguration": {
    "Endpoints": [
      {
        "Name": "ProductMaster.FundShareClass.Commands",
        "FailedMessagesQueueName": "ProductMaster.FundShareClass.FailedMessages"
      },
      {
        "Name": "ProductMaster.FundShareClassRates.Commands",
        "FailedMessagesQueueName": "ProductMaster.FundShareClassRates.FailedMessages"
      },
      {
        "Name": "Priips.Costs.Config.Commands",
        "FailedMessagesQueueName": "Priips.Costs.Config.FailedMessages"
      },
      {
        "Name": "ProductMaster.FundShareClass.Events",
        "FailedMessagesQueueName": "ProductMaster.FundShareClass.Events.FailedMessages"
      },
      {
        "Name": "ProductMaster.FundShareClassRates.Events",
        "FailedMessagesQueueName": "ProductMaster.FundShareClassRates.Events.FailedMessages"
      }
    ]
  }
}

namespace ProductMaster.FredaSync.NServiceBusHandlers
{
    using Schroders.Bus.Core;
    using Schroders.Bus.Core.Contracts;
    using Schroders.Bus.NServiceBus;

    public class NServiceBusMessageHandler : BaseNServiceBusHandler<BusMessage>
    {
        public NServiceBusMessageHandler(IBusHandlerProvider busHandlerProvider, IBus bus)
            : base(
                busHandlerProvider,
                bus,
                nbusMessage => nbusMessage,
                message => message)
        {
        }
    }

    public class NServiceBusEventHandler : BaseNServiceBusHandler<BusEvent>
    {
        public NServiceBusEventHandler(IBusHandlerProvider busHandlerProvider, IBus bus)
            :
            base(
                busHandlerProvider,
                bus,
                nbusMessage => new BusMessage { TopicName = nbusMessage.TopicName, Payload = nbusMessage.Payload },
                message => new BusEvent { TopicName = message.TopicName, Payload = message.Payload })
        {
        }
    }
}

Comments