IEnumerable <IService> exec <TRegister, TResolve>()
        {
            Type registerType = typeof(TRegister);
            Type resolveType  = typeof(TResolve);

            ServicesGenerator generator = new ServicesGenerator(new TypeIsClassValidator(), new ImplementationsFinder(new TypeImplementsInterfaceValidator()),
                                                                new ServiceGenerator(
                                                                    new ServiceFlagsGenerator(new ServiceFlagsProvider(new AttributesFinder(), new MemberGenerator(new MemberFlagsGenerator())),
                                                                                              new ServiceFlagsIssuesResolver()),
                                                                    new ServiceRegistrationGenerator(new ServiceRegistrationFlagGenerator(new BaseTypeFinder(), new ServiceRegistrationInterfacesGenerator(new RegistrationInterfacesFilter(new NamespaceInterfaceValidator()), new TypeContainsGenericParametersChecker(), new TypeGenericParametersProvider(), new InterfaceGenerator(new TypeGenericParametersProvider(), new TypeContainsGenericParametersChecker())), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator())), new ConstructorInfoListGenerator(), new DefaultConstructorInfoProvider())),
                                                                    new ServiceInfoGenerator(), new ClassHasServiceFactoryChecker(),
                                                                    new ServiceFactoryProvider(new InstancesCreator(new ConstructorInstanceCreator(new ConstructorInvoker(),
                                                                                                                                                   new ConstructorParametersGenerator(new TypedMemberValueProvider(), new ConstructorParameterByTypeFinder(),
                                                                                                                                                                                      new ServiceHasConstructorParametersChecker()),
                                                                                                                                                   new ConstructorProvider(new ConstructorChecker(), new DefaultConstructorProvider(),
                                                                                                                                                                           new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ConstructorInfoListGenerator(),
                                                                                                                                                   new ConstructorFinder(), new ConstructorListGenerator(new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))),
                                                                                                                                                   new ParametersValuesExtractor()))),
                                                                    new ServiceFactoryInvoker()
                                                                    ));

            IEnumerable <IService> services = generator.GenerateServices(registerType, new AssemblyList());
            ServiceList            list     = new ServiceList();

            list.AddServices(services.ToArray());

            GenericClassFinder finder = new GenericClassFinder(new TypeGenericParametersProvider());

            return(finder.FindClasses(list, resolveType));
        }
Ejemplo n.º 2
0
        public static void Seed(HotelDbContext db)
        {
            bool alreadySeeded = db.Citys.Any();

            if (alreadySeeded)
            {
                return;
            }

            var servicesGenerator = new ServicesGenerator();
            var citiesGenerator   = new CitiesGenerator();
            var hotelsGenerator   = new HotelsGenerator();
            var reviewGenerator   = new ReviewGenerator();

            // Seed hotel services
            var hotelServices = servicesGenerator.GetAllHotelService();

            foreach (var service in hotelServices)
            {
                db.HotelServices.Add(service);
            }
            db.SaveChanges();

            // Seed room services
            var roomServices = servicesGenerator.GetRoomServices();

            foreach (var service in roomServices)
            {
                db.RoomServices.Add(service);
            }
            db.SaveChanges();

            // Seed cities
            var cities = citiesGenerator.GetCities();

            foreach (var city in cities)
            {
                db.Citys.Add(city);
            }
            db.SaveChanges();

            var hotels = hotelsGenerator.GetHotels(cities);

            hotels.ForEach(h => db.Hotels.Add(h));
            db.SaveChanges();

            var reviews = reviewGenerator.GetReviews(hotels);

            reviews.ForEach(r => db.Reviews.Add(r));
            db.SaveChanges();
        }
Ejemplo n.º 3
0
        public static void Seed(HotelsDbContext db)
        {
            // Проверка на заполненность
            var alreadySeeded = db.Cities.Any();

            if (alreadySeeded)
            {
                return;
            }

            var servicesGenerator = new ServicesGenerator();
            var citiesGenerator   = new CitiesGenerator();
            var hotelsGenerator   = new HotelsGenerator();
            var reviewGenerator   = new ReviewGenerator();

            // Заполняем отельные сервисы
            var hotelServices = servicesGenerator.GetAllHotelServices();

            foreach (var service in hotelServices)
            {
                db.HotelServices.Add(service);
            }
            db.SaveChanges();

            // Заполняем сервисы для номеров
            var roomServices = servicesGenerator.GetRoomServices();

            foreach (var service in roomServices)
            {
                db.RoomServices.Add(service);
            }
            db.SaveChanges();

            // Заполняем города
            var cities = citiesGenerator.GetCities();

            cities.ForEach(city => db.Cities.Add(city));
            db.SaveChanges();

            var hotels = hotelsGenerator.GetHotels(cities);

            hotels.ForEach(hotel => db.Hotels.Add(hotel));
            db.SaveChanges();

            var reviews = reviewGenerator.GetReviews(hotels);

            reviews.ForEach(review => db.Reviews.Add(review));
            db.SaveChanges();
        } // Seed
        object exec <T>()
        {
            TypedMemberValueProvider typedMemberValueProvider = new TypedMemberValueProvider();

            ServicesGenerator      generator = new ServicesGenerator(new TypeIsClassValidator(), new ImplementationsFinder(new TypeImplementsInterfaceValidator()), new ServiceGenerator(new ServiceFlagsGenerator(new ServiceFlagsProvider(new AttributesFinder(), new MemberGenerator(new MemberFlagsGenerator())), new ServiceFlagsIssuesResolver()), new ServiceRegistrationGenerator(new ServiceRegistrationFlagGenerator(new BaseTypeFinder(), new ServiceRegistrationInterfacesGenerator(new RegistrationInterfacesFilter(new NamespaceInterfaceValidator()), new TypeContainsGenericParametersChecker(), new TypeGenericParametersProvider(), new InterfaceGenerator(new TypeGenericParametersProvider(), new TypeContainsGenericParametersChecker())), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator())), new ConstructorInfoListGenerator(), new DefaultConstructorInfoProvider())), new ServiceInfoGenerator(), new ClassHasServiceFactoryChecker(), new ServiceFactoryProvider(new InstancesCreator(new ConstructorInstanceCreator(new ConstructorInvoker(), new ConstructorParametersGenerator(typedMemberValueProvider, new ConstructorParameterByTypeFinder(), new ServiceHasConstructorParametersChecker()), new ConstructorProvider(new ConstructorChecker(), new DefaultConstructorProvider(), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ConstructorInfoListGenerator(), new ConstructorFinder(), new ConstructorListGenerator(new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ParametersValuesExtractor()))), new ServiceFactoryInvoker()));
            IEnumerable <IService> service   = generator.GenerateServices(typeof(T), new AssemblyList(), null, null);

            InstancesCreator creator = new InstancesCreator(new ConstructorInstanceCreator(new ConstructorInvoker(), new ConstructorParametersGenerator(typedMemberValueProvider, new ConstructorParameterByTypeFinder(), new ServiceHasConstructorParametersChecker()), new ConstructorProvider(new ConstructorChecker(), new DefaultConstructorProvider(), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ConstructorInfoListGenerator(), new ConstructorFinder(), new ConstructorListGenerator(new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ParametersValuesExtractor()));

            IContainer container = ContainerFactory.Container();

            container.Register <T>();
            container.Register <Dep1>();
            container.Register <TestClass>();

            object instance = creator.CreateInstance(service.First().Flags, service.First().Registration.TargetType, container);

            return(instance);
        }
Ejemplo n.º 5
0
        bool exec <T>()
        {
            ServicesGenerator generator = new ServicesGenerator(new TypeIsClassValidator(), new ImplementationsFinder(new TypeImplementsInterfaceValidator()),
                                                                new ServiceGenerator(new ServiceFlagsGenerator(new ServiceFlagsProvider(new AttributesFinder(), new MemberGenerator(new MemberFlagsGenerator())), new ServiceFlagsIssuesResolver()),
                                                                                     new ServiceRegistrationGenerator(new ServiceRegistrationFlagGenerator(new BaseTypeFinder(), new ServiceRegistrationInterfacesGenerator(new RegistrationInterfacesFilter(new NamespaceInterfaceValidator()), new TypeContainsGenericParametersChecker(), new TypeGenericParametersProvider(), new InterfaceGenerator(new TypeGenericParametersProvider(), new TypeContainsGenericParametersChecker())), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator())), new ConstructorInfoListGenerator(), new DefaultConstructorInfoProvider())),
                                                                                     new ServiceInfoGenerator(), new ClassHasServiceFactoryChecker(),
                                                                                     new ServiceFactoryProvider(new InstancesCreator(new ConstructorInstanceCreator(new ConstructorInvoker(),
                                                                                                                                                                    new ConstructorParametersGenerator(new TypedMemberValueProvider(), new ConstructorParameterByTypeFinder(), new ServiceHasConstructorParametersChecker()),
                                                                                                                                                                    new ConstructorProvider(new ConstructorChecker(), new DefaultConstructorProvider(), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))),
                                                                                                                                                                    new ConstructorInfoListGenerator(), new ConstructorFinder(), new ConstructorListGenerator(new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ParametersValuesExtractor()))), new ServiceFactoryInvoker()));
            IService test1Service = generator.GenerateServices(typeof(Test1), new AssemblyList(), null).First();

            ServiceList list = new ServiceList();

            list.AddService(test1Service);

            TypeExisterChecker checker = new TypeExisterChecker(new ServiceFinder(new TypeContainsGenericParametersChecker(), new GenericServiceFinder(new TypeIsClassValidator(), new GenericClassFinder(new TypeGenericParametersProvider()), new GenericInterfaceFinder(new GenericTypesComparer(new TypeGenericParametersProvider(), new GenericArgumentsComparer()), new InterfacesExtractor())), new ServiceByInterfaceFinder(new InterfacesExtractor(), new GenericTypesComparer(new TypeGenericParametersProvider(), new GenericArgumentsComparer())), new ServiceByClassFinder(), new TypeIsClassValidator()));

            return(checker.Check(list, typeof(T)));
        }
        IService exec <T>()
        {
            ServiceList       list      = new ServiceList();
            ServicesGenerator generator = new ServicesGenerator(new TypeIsClassValidator(), new ImplementationsFinder(new TypeImplementsInterfaceValidator()), new ServiceGenerator(new ServiceFlagsGenerator(new ServiceFlagsProvider(new AttributesFinder(), new MemberGenerator(new MemberFlagsGenerator())), new ServiceFlagsIssuesResolver()), new ServiceRegistrationGenerator(new ServiceRegistrationFlagGenerator(new BaseTypeFinder(), new ServiceRegistrationInterfacesGenerator(new RegistrationInterfacesFilter(new NamespaceInterfaceValidator()), new TypeContainsGenericParametersChecker(), new TypeGenericParametersProvider(), new InterfaceGenerator(new TypeGenericParametersProvider(), new TypeContainsGenericParametersChecker())), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator())), new ConstructorInfoListGenerator(), new DefaultConstructorInfoProvider())), new ServiceInfoGenerator(), new ClassHasServiceFactoryChecker(), new ServiceFactoryProvider(new InstancesCreator(new ConstructorInstanceCreator(new ConstructorInvoker(), new ConstructorParametersGenerator(new TypedMemberValueProvider(), new ConstructorParameterByTypeFinder(), new ServiceHasConstructorParametersChecker()), new ConstructorProvider(new ConstructorChecker(), new DefaultConstructorProvider(), new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ConstructorInfoListGenerator(), new ConstructorFinder(), new ConstructorListGenerator(new ConstructorGenerator(new ParametersGenerator(new ParameterGenerator()))), new ParametersValuesExtractor()))), new ServiceFactoryInvoker()));

            IEnumerable <IService> services1 = generator.GenerateServices(typeof(Test1), new AssemblyList(), null);
            IEnumerable <IService> services2 = generator.GenerateServices(typeof(Test2), new AssemblyList(), null);

            foreach (IService service in services1)
            {
                list.AddService(service);
            }

            foreach (IService service in services2)
            {
                list.AddService(service);
            }

            ServiceByInterfaceFinder finder = new ServiceByInterfaceFinder(new InterfacesExtractor(), new GenericTypesComparer(new TypeGenericParametersProvider(), new GenericArgumentsComparer()));

            return(finder.FindByInterface(list, typeof(T)));
        }
Ejemplo n.º 7
0
    internal static CompilationUnitSyntax CreateCompilationUnitSyntax(string nameSpace, IReadOnlyCollection <HassState> entities, IReadOnlyCollection <HassServiceDomain> services)
    {
        var orderedEntities       = entities.OrderBy(x => x.EntityId).ToArray();
        var orderedServiceDomains = services.OrderBy(x => x.Domain).ToArray();

        var code = CompilationUnit()
                   .AddUsings(UsingDirective(ParseName("System")))
                   .AddUsings(UsingDirective(ParseName("System.Collections.Generic")))
                   .AddUsings(UsingNamespaces.OrderBy(s => s).Select(u => UsingDirective(ParseName(u))).ToArray());

        var namespaceDeclaration = NamespaceDeclaration(ParseName(nameSpace)).NormalizeWhitespace();

        namespaceDeclaration = namespaceDeclaration.AddMembers(EntitiesGenerator.Generate(orderedEntities).ToArray());
        namespaceDeclaration = namespaceDeclaration.AddMembers(ServicesGenerator.Generate(orderedServiceDomains).ToArray());
        namespaceDeclaration = namespaceDeclaration.AddMembers(ExtensionMethodsGenerator.Generate(orderedServiceDomains, entities).ToArray());

        code = code.AddMembers(namespaceDeclaration);

        code = code.NormalizeWhitespace(Tab.ToString(), eol: "\n");

        return(code);
    }
Ejemplo n.º 8
0
        private RoomType GetRoomType(int type)
        {
            var      serviceGenerator = new ServicesGenerator();
            RoomType room             = null;

            switch (type)
            {
            case HotelSeedMetada.ROOMTYPE_SINGLE:
                room = new RoomType
                {
                    Name        = "Single room",
                    Capacity    = 1,
                    Description = "Our single rooms have an area of 26m² with a 1.60m Queen size bed.",
                    Price       = 180,
                    NumPhotos   = 3,
                    SingleBeds  = 1
                };
                room.Services = serviceGenerator.GetRoomServices()
                                .Select(rs => new ServicePerRoom()
                {
                    RoomType = room, Service = rs
                }).ToList();
                return(room);

            case HotelSeedMetada.ROOMTYPE_DOUBLE:
                room = new RoomType
                {
                    Name        = "Double room",
                    Capacity    = 2,
                    Description = "The doubles are 32m² with French Size twin beds of 1.40m",
                    Price       = 300,
                    NumPhotos   = 4,
                    TwinBeds    = 2
                };
                room.Services = serviceGenerator.GetRoomServices()
                                .Select(rs => new ServicePerRoom()
                {
                    RoomType = room, Service = rs
                }).ToList();
                return(room);

            case HotelSeedMetada.ROOMTYPE_DOUBLE2:
                room = new RoomType
                {
                    Name        = "Double room",
                    Capacity    = 2,
                    Description = "The doubles are 40m² with a 3.20m double Queen size bed",
                    Price       = 400,
                    NumPhotos   = 2,
                    TwinBeds    = 2,
                };
                room.Services = serviceGenerator.GetRoomServices()
                                .Select(rs => new ServicePerRoom()
                {
                    RoomType = room, Service = rs
                }).ToList();
                return(room);

            case HotelSeedMetada.ROOMTYPE_LUXURY:
                room = new RoomType
                {
                    Name        = "Luxury room",
                    Capacity    = 2,
                    Description = "Luxury room is 42m² with a 3.20m double Queen size bed.",
                    Price       = 500,
                    NumPhotos   = 3,
                    DoubleBeds  = 1,
                };
                room.Services = serviceGenerator.GetRoomServices()
                                .Select(rs => new ServicePerRoom()
                {
                    RoomType = room, Service = rs
                }).ToList();
                return(room);

            default:
                return(null);
            }
        }
Ejemplo n.º 9
0
        public List <Hotel> GetHotels(IEnumerable <City> cities, int hotelsPerCity = 3)
        {
            var pointGenerator     = new GeoPointGenerator();
            var hotelNameGenerator = new HotelMetadataGenerator();
            var addressGenerator   = new AddressGenerator();
            var cityGenerator      = new CitiesGenerator();
            var servicesGenerator  = new ServicesGenerator();
            var hotels             = new List <Hotel>();

            foreach (var city in cities)
            {
                var hotelTypes = cityGenerator.GetHotelTypesPerCity(city.Id);


                foreach (var hotelType in hotelTypes)
                {
                    var hotelmetadata = hotelNameGenerator.Data.Single(hmd => hmd.HotelType == hotelType);
                    var random        = new Random();
                    var rating        = hotelmetadata.Rating;
                    var location      = pointGenerator.GetClosePoint((city.Latitude, city.Longitude), 1000);
                    var(latitude, longitude) = location;


                    var hotel = new Hotel
                    {
                        Name        = $"{hotelmetadata.Prefix} {city.Name}",
                        Description = $"Is a {rating}-Star luxury hotel located in {city.Name} which was opened in {hotelmetadata.Year}. It has quality rooms and a modern, well equipped conference area which can host events of every kind for up to 100 persons. Its an ideal stopover on your journey. Is set in the heart of the lush is perfect for holiday or business. If you just wish to relax there are many walks, cycle rides or car excursions to local quaint and historical villages and towns in picturesque surroundings. If you don't feel like outdoor exercise you can relax either in our Finnish sauna, bio sauna, infrared sauna, jacuzzi. Or, if your feeling up to it, why not work out gently in the gym. After a relaxing dinner and a quiet drink in our Bistro bar sleep should be no problem in one of our cosy and comfortable rooms. Our young and friendly staff are here to welcome and serve you. Hope to see you soon!",
                        City        = city,
                        Address     = new Address
                        {
                            PostCode = addressGenerator.GetPostCode(),
                            Street   = addressGenerator.GetStreet()
                        },
                        CheckinTime  = new TimeSpan(15, 0, 0),
                        CheckoutTime = new TimeSpan(12, 0, 0),
                        Location     = new Location {
                            Latitude = latitude, Longitude = longitude
                        },
                        Rating    = rating,
                        Visits    = random.Next(10000, 30000),
                        NumPhotos = 1,
                        RoomTypes = new RoomType[] {
                            GetRoomType(hotelmetadata.RoomTypes.single),
                            GetRoomType(hotelmetadata.RoomTypes.@double)
                        },
                        ConferenceRooms = new[]
                        {
                            new ConferenceRoom
                            {
                                Name         = $"{HotelMetadataGenerator.GetConferenceRoomName(hotelType)} room",
                                Rating       = rating,
                                Capacity     = 40,
                                PricePerHour = 190,
                                NumPhotos    = 3
                            }
                        }
                    };
                    hotel.Services = servicesGenerator.GetHotelServicesByHotelType(hotelType)
                                     .Select(hs => new ServicePerHotel()
                    {
                        Service = hs,
                        Hotel   = hotel
                    }).ToList();
                    hotels.Add(hotel);
                }
            }

            return(hotels);
        }