public ServerChatTCP(IRepositoryConnection _repository) { this._repository = _repository; server = new TcpListener(IPAddress.Any, Settings.Default.port); ThreadPool.SetMaxThreads(20, 20); }
public void TestCreate() { uint id; using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = new Person() { Name = "John", TelephoneNumber = "12345" }; Assert.IsFalse(person.HasIdentity, "Person does not yet have an identity"); repository.Create(person); Assert.IsTrue(person.HasIdentity, "Person now has an identity"); id = person.GetIdentity().Value; } using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = repository.Read(new Identity <uint>(typeof(Person), id)); Assert.AreEqual("John", person.Name, "Correct name"); } }
protected virtual void RegisterDataObject(IRepositoryConnection repo, IzNorthwindConn_BaseData dataObject) { if (dataObject != null) { dataObject.ConnectionProvider = repo.ConnectionProvider; } }
private IRepositoryConnection <TEntity> GetDisposableConnection() { if (disposableConnection == null) { disposableConnection = Service.OpenConnection(); } return(disposableConnection); }
protected IRepositoryConnection <TEntity> GetDisposableConnection() { if (disposableConnection == null) { disposableConnection = Repository.OpenConnection(); } return(disposableConnection); }
public virtual void BeginTransaction(IRepositoryConnection repo, string trans) { if (repo.ConnectionProvider.TransactionCount == 0) { repo.ConnectionProvider.OpenConnection(); repo.ConnectionProvider.BeginTransaction(trans); } repo.ConnectionProvider.TransactionCount += 1; }
public VacationOpportunityRepository(IConfiguration configuration, IRepositoryConnection repositoryConnection, ICareerRepository careerRepository, IProfessionalLevelRepository professionalLevelRepository, IOpportunityTypeRepository opportunityTypeRepository) { _configuration = configuration; _repositoryConnection = repositoryConnection; _careerRepository = careerRepository; _professionalLevelRepository = professionalLevelRepository; _opportunityTypeRepository = opportunityTypeRepository; }
/// <summary> /// <para>Initialises this unit of work to create connections to the default repository.</para> /// </summary> public UnitOfWork(IRepositoryConnection connection) { this.Connection = connection; _disposed = false; this.NewEntities = new List <IEntity>(); this.DeletedEntities = new List <IEntity>(); this.DirtyEntities = new List <IEntity>(); this.CleanEntities = new List <IEntity>(); }
/// <summary> /// <para> /// Overloaded. Creates this entity within the default repository, or if this entity is registered with a /// <see cref="UnitOfWork"/>, marks this entity for creation. /// </para> /// </summary> public virtual void Create() { if (_unitOfWork != null) { this.OnCreated(); } else { IRepositoryConnection connection = RepositoryFactories.Default.GetConnection(); this.Create(connection); } }
public IRepositoryConnection StartConnection() { try { repositoryConnection = factory.Resolve <IRepositoryConnection>(); return(repositoryConnection); } catch (Exception e) { throw e; } }
/// <summary> /// <para>If OpenConnection() has already been called and you wish to use the same connection</para> /// <para> (same DbContext), then use this.</para> /// </summary> /// <typeparam name="TOther">The type used in the other connection.</typeparam> /// <param name="connection">An instance of IRepositoryConnectionlt;TOther></param> /// <returns>An instance of IRepositoryConnectionlt;TEntity></returns> public virtual IRepositoryConnection <TEntity> UseConnection <TOther>(IRepositoryConnection <TOther> connection) where TOther : class { if (!(connection is EntityFrameworkRepositoryConnection <TOther>)) { throw new NotSupportedException("The other connection must be of type EntityFrameworkRepositoryConnection<T>"); } var otherConnection = (connection as EntityFrameworkRepositoryConnection <TOther>); return(new EntityFrameworkRepositoryConnection <TEntity>(otherConnection.Context, false)); }
/// <summary> /// <para> /// Overloaded. Creates this entity within the repository exposed by the given <paramref name="connection"/>. /// </para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> public virtual void Create(IRepositoryConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } IRepository repository = connection.GetRepository(this.GetType()); repository.Create(this); this.OnCreated(); }
public virtual void CommitTransaction(IRepositoryConnection repo) { if (repo.ConnectionProvider.TransactionCount > 0) { repo.ConnectionProvider.TransactionCount -= 1; } if (repo.ConnectionProvider.TransactionCount == 0) { repo.ConnectionProvider.CommitTransaction(); repo.ConnectionProvider.CloseConnection(false); } }
public virtual void RollbackTransaction(IRepositoryConnection repo, string trans) { if (repo.ConnectionProvider.TransactionCount > 0) { repo.ConnectionProvider.TransactionCount -= 1; } if (repo.ConnectionProvider.TransactionCount == 0) { repo.ConnectionProvider.RollbackTransaction(trans); repo.ConnectionProvider.CloseConnection(false); } }
public void Import(object item, SnapinNode node) { try { // Need to create a reader. IRepositoryReader fromReader = m_repositoryType.GetRepositoryConnection <IRepositoryReader>(true, m_parent); if (fromReader != null) { // Save selection. string selectedPath = ((SnapinNode)node.Snapin.CurrentScopeNode).GetPathRelativeTo(node); // Run it. IRepositoryWriter toWriter = m_repositoryLink.GetConnection <IRepositoryWriter>(); ImportRepositoryResultsRunner runner = new ImportRepositoryResultsRunner(fromReader, toWriter); runner.Run(); using (new LongRunningMonitor(node.Snapin)) { // Refresh the catalogue itself. IRepositoryConnection repositoryConnection = m_repositoryLink as IRepositoryConnection; if (repositoryConnection != null) { using (ConnectionState state = new ConnectionState()) { repositoryConnection.Connect(state).Refresh(); } } // Refresh the node and selection. node.Refresh(true); SnapinNode selectedNode = node.FindNodeInTree(selectedPath); if (selectedNode != null) { selectedNode.Select(); } } } } catch (System.Exception e) { new ExceptionDialog(e, "The following exception has occurred while trying to read the information:").ShowDialog(); } }
public void TestCreateWithIdentity() { using (IRepositoryConnection connection = this.Factory.GetConnection()) { IRepository <Person> repository = connection.GetRepository <Person>(); Person person = new Person() { Name = "John", TelephoneNumber = "12345" }; Assert.IsFalse(person.HasIdentity, "Person does not yet have an identity"); person.SetIdentity(1); repository.Create(person); Assert.Fail("Test should not reach this point"); } }
/// <summary> /// <para>Gets an <see cref="IRepository"/> suitable for the generic entity type.</para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> /// <returns> /// An <see cref="IRepository"/> /// </returns> public override IRepository <TEntity> GetRepository <TEntity> (IRepositoryConnection connection) { Type repositoryType = typeof(TEntity); IRepository <TEntity> output; lock (_syncRoot) { if (_repositories.ContainsKey(repositoryType)) { output = (IRepository <TEntity>)_repositories[repositoryType]; } else { output = new MemoryRepository <TEntity>(connection); _repositories.Add(repositoryType, output); } } return(output); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). if (disposableConnection != null) { disposableConnection.Dispose(); disposableConnection = null; } } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }
/// <summary> /// <para>Overloaded. Gets the repository for a specific <paramref name="entityType"/>.</para> /// </summary> /// <remarks> /// <para> /// This method provides a way of side-stepping into the generic <c>GetRepository</c> method, based on a /// <see cref="System.Type"/>. It uses reflection and a lightweight caching mechanism to discover the appropriate /// generic version of the GetRepository method to use and then invokes that method. /// </para> /// </remarks> /// <param name="entityType"> /// A <see cref="System.Type"/> that implements <see cref="IEntity"/> /// </param> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> /// <returns> /// An <see cref="IRepository"/> suitable for working with instances of the <paramref name="entityType"/> /// </returns> public virtual IRepository GetRepository(Type entityType, IRepositoryConnection connection) { if (entityType == null) { throw new ArgumentNullException("entityType"); } if (!this.GenericMethodMappingCache.ContainsKey(entityType)) { /* I'm performing this check inside the conditional to ensure that reflection is used as little as possible in * a 'cache hit' scenario - where the repository type has been seen before. */ if (entityType.GetInterface(typeof(IEntity).FullName) == null) { throw new ArgumentException("The type must implement IEntity", "entityType"); } lock (_syncRoot) { MethodInfo method = typeof(RepositoryFactoryBase).GetMethod(GET_REPOSITORY_METHOD_NAME, new Type[] { typeof(IRepositoryConnection) }); /* We can drop ArgumentException on the floor because all it means is that the key was already added. It * would indicate a highly-unlikely scenario where two threads get past the .ContainsKey check (above) at * the same time and then both try adding the new item. * * This is not problematic in itself, since in this scenario both threads are adding exactly the same data. */ try { this.GenericMethodMappingCache.Add(entityType, method.MakeGenericMethod(entityType)); } catch (ArgumentException) {} } } return((IRepository)this.GenericMethodMappingCache[entityType].Invoke(this, new object[] { connection })); }
public virtual IRepositoryConnection <TEntity> UseConnection <TOther>(IRepositoryConnection <TOther> connection) where TOther : class { return(repository.UseConnection(connection)); }
/// <summary> /// <para>Gets the appropriate <see cref="IRepository"/> for a generic <see cref="IEntity"/> type.</para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> /// <returns> /// An <see cref="IRepository"/> /// </returns> public override IRepository <TEntity> GetRepository <TEntity> (IRepositoryConnection connection) { return(new NHibernateRepositoryBase <TEntity>((NHibernateRepositoryConnection)connection)); }
public ProfessionalLevelRepository(IConfiguration configuration, IRepositoryConnection repositoryConnection) { _configuration = configuration; _repositoryConnection = repositoryConnection; }
/// <summary> /// /// </summary> public PaymentRepository(IRepositoryConnection dbConnection) { context = dbConnection.GetDataContext(); }
public CareerRepository(IConfiguration configuration, IRepositoryConnection repositoryConnection) { _configuration = configuration; _repositoryConnection = repositoryConnection; }
/// <summary> /// <para>Initialises the current instance.</para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> public MemoryRepository(IRepositoryConnection connection) { this.Connection = connection; _backingStore = new Dictionary <IIdentity, TEntity>(); _autoIncrement = 0; }
/// <summary> /// /// </summary> public UsersRepository(IRepositoryConnection dbConnection) { context = dbConnection.GetDataContext(); }
public OpportunityTypeRepository(IConfiguration configuration, IRepositoryConnection repositoryConnection) { _configuration = configuration; _repositoryConncetion = repositoryConnection; }
public void UseConnection(IRepositoryConnection repositoryConnection) { this.repositoryConnection = repositoryConnection; }
/// <summary> /// <para>Overloaded. Gets the repository for a specific entity type.</para> /// </summary> /// <param name="connection"> /// A <see cref="IRepositoryConnection"/> /// </param> /// <returns> /// An <see cref="IRepository"/> /// </returns> public abstract IRepository <TEntity> GetRepository <TEntity> (IRepositoryConnection connection) where TEntity : IEntity;
public Repository(IRepositoryConnection connection) { this._connection = connection; //this._retryStrategy = RetryStrategy.DefaultExponential; //this._retryStrategy.FastFirstRetry = true; }