Example #1
0
        public Rater Create(Policy policy, IRatingContext context)
        {
            try
            {
                return((Rater)Activator.CreateInstance(
                           Type.GetType($"ArdalisRating.{policy.Type}PolicyRater"),
                           new object[] { context }));
            }
            catch (Exception ex)
            {
                return(new UnknownPolicyRater(new RatingUpdater()));
            }

            //switch (policy.Type)
            //{
            //    case PolicyType.Auto:
            //        return new AutoPolicyRater(engine, engine.Logger);

            //    case PolicyType.Land:
            //        return new LandPolicyRater(engine, engine.Logger);

            //    case PolicyType.Life:
            //        return new LifePolicyRater(engine, engine.Logger);

            //    case PolicyType.Flood:
            //        return new FloodPolicyRater(engine, engine.Logger);
            //    default:
            //        return new UnknownPolicyRater(engine, engine.Logger);
            //}
        }
        public Rater Create(Policy policy, IRatingContext context)
        {
            //switch (policy.Type)
            //{
            //    case PolicyType.Auto:
            //        return new AutoPolicyRater(engine, engine.Logger);
            //    case PolicyType.Flood:
            //        return new FloodPolicyRater(engine, engine.Logger);
            //    case PolicyType.Land:
            //        return new LandPolicyRater(engine, engine.Logger);
            //    case PolicyType.Life:
            //        return new LifePolicyRater(engine, engine.Logger);
            //    default:
            //        // TODO: Implement Null Object Pattern
            //        //Logger.Log("Unknown policy type");
            //        return new UnknownPolicyRater(engine, engine.Logger);
            //}

            // implementing through Reflection
            try
            {
                return((Rater)Activator.CreateInstance(Type.GetType($"ArdalisRating_ISP.{policy.Type}PolicyRater"),
                                                       new object[] { context }));
            }
            catch (Exception)
            {
                return(new UnknownPolicyRater(context));
            }
        }
        //public RatingEngine() : this(new ConsoleLogger())
        //{
        //    //Constructor chaining to the parameterized ILogger constructor below.
        //}

        public RatingEngine(ILogger logger, IPolicySource policySource, IPolicySerializer policySerializer, RaterFactory raterFactory)
        {
            _logger           = logger;
            _policySource     = policySource;
            _policySerializer = policySerializer;
            _raterFactory     = raterFactory;
            Context           = new DefaultRatingContext(_policySource, policySerializer);
            Context.Engine    = this;
        }
Example #4
0
 public void SetUp()
 {
     _iUserContext    = new UserMemoryContext();
     _mediaContext    = new MediaMemoryContext();
     _ratingContext   = new RatingMemoryContext();
     _playlistContext = new PlaylistMemoryContext();
     _playlistLogic   = new PlaylistLogic(_playlistContext, _mediaContext);
     _mediaLogic      = new MediaLogic(_mediaContext);
     _ratingLogic     = new RatingLogic(_ratingContext, _mediaLogic);
     _userLogic       = new UserLogic(_iUserContext, _playlistLogic, _ratingLogic);
 }
Example #5
0
 public Rater Create(Policy policy, IRatingContext context)
 {
     try
     {
         return((Rater)Activator.CreateInstance(Type.GetType($"ArdalisRating.{policy.Type}PolicyRater"),
                                                new object[] { context }));
     }
     catch
     {
         return(new UnknownPolicyRater(context));
     }
 }
Example #6
0
 public Rater CreateByReflection(Policy policy, IRatingContext context)
 {
     try
     {
         return((Rater)Activator.CreateInstance(Type.GetType($"OpenClosedPrinciple.OCP.{policy.Type}PolicyRater"),
                                                new object[] { context }));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         return(null);
     }
 }
Example #7
0
 public RatingEngine(IPolicyDeserializer policyDeserializer,
                     IRaterFactory raterFactory,
                     ILogger logger,
                     IPolicyReader policyReader)
 {
     _policyDeserializer = policyDeserializer;
     _raterFactory       = raterFactory;
     _logger             = logger;
     _policyReader       = policyReader;
     _ratingContext      = new DefaultRatingContext(_policyDeserializer,
                                                    _raterFactory,
                                                    _logger,
                                                    _policyReader);
     _ratingContext.Engine = this;
 }
Example #8
0
 public void Setup()
 {
     _iMovieContext    = new MovieMemoryContext();
     _iGenreContext    = new GenreMemoryContext();
     _iPlaylistContext = new PlaylistMemoryContext();
     _iMediaContext    = new MediaMemoryContext();
     _iRatingContext   = new RatingMemoryContext();
     _genreLogic       = new GenreLogic(_iGenreContext);
     _searchLogic      = new SearchLogic(_genreLogic);
     _playlistLogic    = new PlaylistLogic(_iPlaylistContext, _iMediaContext);
     _mediaLogic       = new MediaLogic(_iMediaContext);
     _ratingLogic      = new RatingLogic(_iRatingContext, _mediaLogic);
     _movieLogic       = new MovieLogic(_iMovieContext, _genreLogic, _searchLogic, _playlistLogic, _mediaLogic, _ratingLogic);
     _testGenre1       = new GenreModel("test1", 1);
 }
Example #9
0
        public void Rate()
        {
            context = new DefaultRatingContext();

            _logger.Log("Starting rate.");

            _logger.Log("Loading policy.");

            var policyJson = FilePolicySource.GetPolicyFromSource();

            var policy = JsonPolicySerializer.GetPolicyFromJsonString(policyJson);

            var rater = new RaterFactory().Create(policy, context);

            rater.Rate(policy);

            var rater2 = new RaterFactory().CreateByReflection(policy, context);

            rater2.Rate(policy);

            _logger.Log("Rating completed.");
        }
Example #10
0
        public Rater Create(Policy policy, IRatingContext context)
        {
            switch (policy.Type)
            {
            case PolicyType.Auto:
                return(new AutoPolicyRater(context));

            case PolicyType.Land:
                return(new LandPolicyRater(context));

            case PolicyType.Life:
                return(new LifePolicyRater(context));

            case PolicyType.Flood:
                return(new FloodPolicyRater(context));

            default:
                new ConsoleLogger().Log("Unknown policy type");
                break;
            }

            return(null);
        }
Example #11
0
 public RatingLogic(IRatingContext iRatingContext, MediaLogic mediaLogic)
 {
     _iRatingContext = iRatingContext;
     _mediaLogic     = mediaLogic;
 }
Example #12
0
 public RatingRepository(IRatingContext context)
 {
     _context = context;
 }
Example #13
0
 public Rater CreateRaterForPolicy(InterfaceSegregationPrinciple.Policy policy, IRatingContext context)
 {
     throw new System.NotImplementedException();
 }
Example #14
0
 public RatingEngine(IRatingContext context)
 {
     Context = context;
 }
 public Rater CreateRaterForPolicy(Policy policy, IRatingContext context)
 {
     return(new RaterFactory().Create(policy, context));
 }
 public FloodPolicyRater(IRatingContext context)
     : base(context)
 {
 }
 public AutoPolicyRater(IRatingContext context) : base(context)
 {
 }
 public Rater(IRatingContext context)
 {
     _context = context;
     _logger  = context.Logger;
 }
Example #19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSingleton(Configuration);

            services.AddTransient <IMovieContext, MovieSQLContext>(m =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new MovieSQLContext(c));
            });
            services.AddTransient <IGenreContext, GenreSQLContext>(g =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new GenreSQLContext(c));
            });
            services.AddTransient <IUserContext, UserSQLContext>(u =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new UserSQLContext(c));
            });
            services.AddTransient <IPlaylistContext, PlaylistSQLContext>(p =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new PlaylistSQLContext(c));
            });
            services.AddTransient <IMediaContext, MediaSQLContext>(m =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new MediaSQLContext(c));
            });
            services.AddTransient <IRatingContext, RatingSQLContext>(r =>
            {
                string c = Configuration.GetConnectionString("DefaultConnection");
                return(new RatingSQLContext(c));
            });

            services.AddTransient(m =>
            {
                IMovieContext mc = m.GetService <IMovieContext>();
                GenreLogic gl    = m.GetService <GenreLogic>();
                SearchLogic sl   = m.GetService <SearchLogic>();
                PlaylistLogic p  = m.GetService <PlaylistLogic>();
                MediaLogic me    = m.GetService <MediaLogic>();
                RatingLogic rl   = m.GetService <RatingLogic>();
                return(new MovieLogic(mc, gl, sl, p, me, rl));
            });

            services.AddTransient(g =>
            {
                IGenreContext gc = g.GetService <IGenreContext>();
                return(new GenreLogic(gc));
            });

            services.AddTransient(s =>
            {
                GenreLogic gl = s.GetService <GenreLogic>();
                return(new SearchLogic(gl));
            });

            services.AddTransient(s =>
            {
                IUserContext uc  = s.GetService <IUserContext>();
                PlaylistLogic pl = s.GetService <PlaylistLogic>();
                RatingLogic rl   = s.GetService <RatingLogic>();
                return(new UserLogic(uc, pl, rl));
            });

            services.AddTransient(p =>
            {
                IPlaylistContext pl = p.GetService <IPlaylistContext>();
                IMediaContext m     = p.GetService <IMediaContext>();
                return(new PlaylistLogic(pl, m));
            });

            services.AddTransient(me =>
            {
                IMediaContext m = me.GetService <IMediaContext>();
                return(new MediaLogic(m));
            });

            services.AddTransient(r =>
            {
                IRatingContext rc = r.GetService <IRatingContext>();
                MediaLogic m      = r.GetService <MediaLogic>();
                return(new RatingLogic(rc, m));
            });



            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath = "/User/Login";
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("Admin", p => p.RequireAuthenticatedUser().RequireRole("Admin"));
                options.AddPolicy("User", p => p.RequireAuthenticatedUser().RequireRole("User"));
            });
        }
Example #20
0
 public LifePolicyRater(IRatingContext ratingUpdater) : base(ratingUpdater)
 {
     _ratingUpdater = ratingUpdater;
 }
 public UnknownPolicyRater(IRatingContext context) : base(context)
 {
 }
 //UNIT TEST
 //Hier zet ik de ratingcontext in.
 //Ga door RatingMemoryHandler
 public RatingCollection(IRatingContext context)
 {
     this.db = context;
 }
 public LandPolicyRater(IRatingContext context)
     : base(context)
 {
 }
Example #24
0
 public RatingController(IRatingContext ratingRepository)
 {
     this.ratingContext = ratingRepository;
 }