Exemple #1
0
        internal REstateMachine(
            IConnectorResolver <TState, TInput> connectorResolver,
            IRepositoryContextFactory <TState, TInput> repositoryContextFactory,
            ICartographer <TState, TInput> cartographer,
            IEnumerable <IEventListener> listeners,
            string machineId)
        {
            _connectorResolver        = connectorResolver;
            _repositoryContextFactory = repositoryContextFactory;
            _listeners = listeners.ToList();

            MachineId = machineId;

            CachedValues = new Lazy <Task <(ISchematic <TState, TInput> schematic, IReadOnlyDictionary <string, string> metadata)> >(
                async() =>
            {
                using (var context = await _repositoryContextFactory.OpenContextAsync(CancellationToken.None)
                                     .ConfigureAwait(false))
                {
                    var machineStatus = await context.Machines.GetMachineStatusAsync(machineId, CancellationToken.None)
                                        .ConfigureAwait(false);

                    return(machineStatus.Schematic,
                           new ReadOnlyDictionary <string, string>(machineStatus.Metadata));
                }
            });
        }
Exemple #2
0
 public void InitLocationTypes(IRepositoryContextFactory ContextFactory, string ConnectionString)
 {
     using (var context = ContextFactory.CreateDBContext(ConnectionString))
     {
         if (!context.LocationTypes.Any())
         {
             context.LocationTypes.AddRange(
                 new LocationType
             {
                 Id   = 1,
                 Name = "Организация"
             },
                 new LocationType
             {
                 Id   = 2,
                 Name = "Здания"
             },
                 new LocationType
             {
                 Id   = 3,
                 Name = "Комната"
             });
             try
             {
                 context.Database.OpenConnection();
                 context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT LocationTypes ON;");
                 context.SaveChanges();
                 context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT LocationTypes OFF;");
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
 public MessagesRepository(string connectionString,
                           IRepositoryContextFactory contextFactory,
                           string filePath) :
     base(connectionString, contextFactory)
 {
     FilePath = filePath;
 }
 public MessageStateRepositoryTests()
 {
     _messageId                = UniqueKeyUtility.Generate();
     _subscriberName           = UniqueKeyUtility.Generate();
     _entityConnectionConfig   = new EntityConnectionConfig(new DatabaseConnectionConfig(@"(localdb)\MSSQLLocalDB", "Grumpy.RipplesMQ.Database_Model"));
     _repositoryContextFactory = new RepositoryContextFactory(NullLogger.Instance, _entityConnectionConfig);
 }
        /// <summary>
        /// Returns the option instance with a configured context factory.
        /// </summary>
        /// <param name="contextFactory">The context factory.</param>
        /// <returns>The same option instance.</returns>
        public RepositoryOptions With([NotNull] IRepositoryContextFactory contextFactory)
        {
            var clone = Clone();

            clone._contextFactory = Guard.NotNull(contextFactory, nameof(contextFactory));

            return(clone);
        }
        public ProviderRepository(string connectionString, IRepositoryContextFactory contextFactory)
        {
            using (var context = ContextFactory.CreateDbContext(ConnectionString))
            {
                UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
https:          //habr.com/company/microsoft/blog/279985/
            }
        }
        public RepositoriesFactoryTests()
        {
            var config = Substitute.For <IEntityConnectionConfig>();

            config.ConnectionString(Arg.Any <string>(), Arg.Any <string>()).Returns("metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=\"data source=(localdb)\\MSSQLLocalDB;initial catalog=Grumpy.RipplesMQ.Database_Model;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework\"\" providerName=\"System.Data.EntityClient");

            _repositoryContextFactory = new RepositoryContextFactory(NullLogger.Instance, config);
        }
Exemple #8
0
 /// <inheritdoc />
 public MessageBrokerBuilder()
 {
     _logger                   = NullLogger.Instance;
     _processInformation       = new ProcessInformation();
     _serviceName              = _processInformation.ProcessName;
     _remoteQueueName          = _serviceName.Replace("$", ".") + ".Remote";
     _repositoryContextFactory = new NullRepositoryContextFactory();
 }
        public FeatureToggle(ILogger logger, IMessageBus messageBus, IRepositoryContextFactory repositoryContextFactory)
        {
            _logger     = logger;
            _messageBus = messageBus;
            _repositoryContextFactory = repositoryContextFactory;

            messageBus.SubscribeHandler <Api.Dto.FeatureToggle>(FeatureToggleConfig.UpdateFeatureToggle, Update);
            messageBus.RequestHandler <FeatureToggleRequest, FeatureToggleResponse>(FeatureToggleConfig.RequestFeatureToggle, IsEnabled);
        }
 public BaseRepository(string connectionString, IRepositoryContextFactory contextFactory)
 {
     this.ConnectionString = connectionString;
     this.ContextFactory   = contextFactory;
     using (var context = this.CreateContext())
     {
         DbInitialization.Initialize(context).Wait();
     }
 }
Exemple #11
0
 public REstateMachineFactory(
     IConnectorFactoryResolver connectorFactoryResolver,
     IRepositoryContextFactory repositoryContextFactory,
     DotGraphCartographer cartographer)
 {
     _connectorFactoryResolver = connectorFactoryResolver;
     _repositoryContextFactory = repositoryContextFactory;
     _cartographer             = cartographer;
 }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="databaseServer"></param>
        /// <param name="databaseName"></param>
        /// <returns>Builder for Message Broker Server</returns>
        public MessageBrokerBuilder WithRepository(string databaseServer, string databaseName = "RipplesMQ")
        {
            if (!databaseServer.NullOrEmpty())
            {
                _repositoryContextFactory = new RepositoryContextFactory(_logger, new EntityConnectionConfig(new DatabaseConnectionConfig(databaseServer, databaseName)));
            }

            return(this);
        }
Exemple #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RepositoryOptions" /> class.
        /// </summary>
        /// <param name="options">The repository options to clone.</param>
        public RepositoryOptions([NotNull] IRepositoryOptions options)
        {
            Guard.NotNull(options, nameof(options));

            _interceptors    = options.Interceptors.ToDictionary(x => x.Key, x => x.Value);
            _cachingProvider = options.CachingProvider;
            _loggerProvider  = options.LoggerProvider;
            _contextFactory  = options.ContextFactory;
            _conventions     = options.Conventions;
        }
Exemple #14
0
 public REstateMachineFactory(
     IConnectorResolver <TState, TInput> connectorResolver,
     IRepositoryContextFactory <TState, TInput> repositoryContextFactory,
     ICartographer <TState, TInput> cartographer,
     IEnumerable <IEventListener> listeners)
 {
     _connectorResolver        = connectorResolver;
     _repositoryContextFactory = repositoryContextFactory;
     _cartographer             = cartographer;
     _listeners = listeners;
 }
Exemple #15
0
 public StateEngine(
     IStateMachineFactory <TState, TInput> stateMachineFactory,
     IRepositoryContextFactory <TState, TInput> repositoryContextFactory,
     IConnectorResolver <TState, TInput> connectorResolver,
     IEnumerable <IEventListener> listeners)
 {
     _stateMachineFactory      = stateMachineFactory;
     _repositoryContextFactory = repositoryContextFactory;
     ConnectorResolver         = connectorResolver;
     _listeners = listeners.ToList();
 }
Exemple #16
0
        public StateEngineFactory(
            IStateMachineFactory stateMachineFactory,
            IRepositoryContextFactory repositoryContextFactory,
            StringSerializer stringSerializer,
            IPlatformLogger logger)
        {
            _StateMachineFactory      = stateMachineFactory;
            _RepositoryContextFactory = repositoryContextFactory;

            _StringSerializer = stringSerializer;

            _Logger = logger;
        }
Exemple #17
0
        public StateEngine(
            IStateMachineFactory stateMachineFactory,
            IRepositoryContextFactory repositoryContextFactory,
            StringSerializer stringSerializer,
            IPlatformLogger logger,
            string apiKey)
        {
            _stateMachineFactory      = stateMachineFactory;
            _repositoryContextFactory = repositoryContextFactory;

            _stringSerializer = stringSerializer;

            _Logger = logger;

            _apiKey = apiKey;
        }
Exemple #18
0
        public static async Task Initialize(IRepositoryContextFactory repositoryContextFactory)
        {
            using (var context = repositoryContextFactory.CreateDbContext())
            {
                await context.Database.MigrateAsync();

                var itemsCount = await context.Items.CountAsync();

                if (itemsCount == 0)
                {
                    IItemRepository itemRepository = new ItemRepository(repositoryContextFactory);
                    IGenerationRule generationRule = new Random500KGenerationRule();

                    await itemRepository.FillRepositoryAsync(new ItemGenerator(generationRule));
                }
            }
        }
Exemple #19
0
        public REstateMachine(
            IConnectorFactoryResolver connectorFactoryResolver,
            IRepositoryContextFactory repositoryContextFactory,
            DotGraphCartographer cartographer,
            string apiKey,
            string machineId,
            IDictionary <State, StateConfiguration> stateMappings)
        {
            _connectorFactoryResolver = connectorFactoryResolver;
            _repositoryContextFactory = repositoryContextFactory;
            _cartographer             = cartographer;

            ApiKey    = apiKey;
            MachineId = machineId;

            StateMappings = stateMappings;
        }
Exemple #20
0
        internal REstateMachine(
            IConnectorResolver <TState, TInput> connectorResolver,
            IRepositoryContextFactory <TState, TInput> repositoryContextFactory,
            ICartographer <TState, TInput> cartographer,
            IEnumerable <IEventListener> listeners,
            string machineId,
            ISchematic <TState, TInput> schematic,
            IReadOnlyDictionary <string, string> metadata)
        {
            _connectorResolver        = connectorResolver;
            _repositoryContextFactory = repositoryContextFactory;
            _metadata  = metadata;
            _listeners = listeners.ToList();

            MachineId = machineId;

            Schematic = schematic;
        }
Exemple #21
0
        internal REstateMachine(
            IConnectorResolver <TState, TInput> connectorResolver,
            IRepositoryContextFactory <TState, TInput> repositoryContextFactory,
            ICartographer <TState, TInput> cartographer,
            IEnumerable <IEventListener> listeners,
            string machineId,
            ISchematic <TState, TInput> schematic,
            IReadOnlyDictionary <string, string> metadata)
        {
            _connectorResolver        = connectorResolver;
            _repositoryContextFactory = repositoryContextFactory;
            _listeners = listeners.ToList();

            MachineId = machineId;

            CachedValues = new Lazy <Task <(ISchematic <TState, TInput> schematic, IReadOnlyDictionary <string, string> metadata)> >(
                () => Task.FromResult((schematic, metadata)));
        }
Exemple #22
0
 public void InitEquipTypes(IRepositoryContextFactory ContextFactory, string ConnectionString)
 {
     using (var context = ContextFactory.CreateDBContext(ConnectionString))
     {
         if (!context.EquipmentTypes.Any())
         {
             context.EquipmentTypes.AddRange(
                 new EquipmentType
             {
                 Id   = 1,
                 Name = "Монитор"
             },
                 new EquipmentType
             {
                 Id   = 2,
                 Name = "МФУ"
             },
                 new EquipmentType
             {
                 Id   = 3,
                 Name = "Системный блок"
             },
                 new EquipmentType
             {
                 Id   = 4,
                 Name = "Кондиционер"
             });
             try
             {
                 context.Database.OpenConnection();
                 context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT EquipmentTypes ON;");
                 context.SaveChanges();
                 context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT EquipmentTypes OFF;");
             }
             catch (Exception ex)
             {
             }
         }
     }
 }
Exemple #23
0
        public StorageRepository(string connectionString, IRepositoryContextFactory contextFactory) : base(connectionString, contextFactory)
        {
            DefaultData defaultData = new DefaultData();

            using (var context = ContextFactory.CreateDBContext(ConnectionString))
            {
                if (!context.LocationTypes.Any())
                {
                    defaultData.InitLocationTypes(ContextFactory, ConnectionString);
                }

                if (!context.Locations.Any())
                {
                    defaultData.InitLocations(ContextFactory, ConnectionString);
                }

                if (!context.EquipmentTypes.Any())
                {
                    defaultData.InitEquipTypes(ContextFactory, ConnectionString);
                }
            }
        }
Exemple #24
0
        public CurrencyRepository(string connectionString, IRepositoryContextFactory contextFactory, IOptions <CurrencyOptions> currencyOptions) : base(connectionString, contextFactory)
        {
            using (var dbContext = ContextFactory.CreateDBContext(ConnectionString))
            {
                try
                {
                    foreach (var item in currencyOptions.Value.Currency)
                    {
                        if (dbContext.Currencies.Where(x => x.Currency == item).Count() == 0)
                        {
                            dbContext.Currencies.Add(new Currencies {
                                Currency = item
                            });
                        }
                    }

                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
 public HobbiesRepository(string connectionString, IRepositoryContextFactory contextFactory)
     : base(connectionString, contextFactory)
 {
 }
 public BaseRepository(string connectionString, IRepositoryContextFactory contextFactory)
 {
     ConnectionString = connectionString;
     ContextFactory   = contextFactory;
 }
Exemple #27
0
 public CustomerRepository(string connectionString, IRepositoryContextFactory contextFactory)
     : base(connectionString, contextFactory)
 {
 }
Exemple #28
0
 public CatalogRepository(string connectionString, IRepositoryContextFactory contextFactory)
     : base(connectionString, contextFactory)
 {
 }
 protected BaseRepository(string connectionString, IRepositoryContextFactory contextFactory)
 {
     ContextFactory = contextFactory;
     Context        = ContextFactory.CreateDbContext(connectionString);
 }
Exemple #30
0
 protected BaseRepository(string connectionString, IRepositoryContextFactory repositoryContextFactory)
 {
     ConnectionString         = connectionString;
     RepositoryContextFactory = repositoryContextFactory;
 }