Saturday, August 7, 2010

Can Any One Share Yamaha Psr Indian Style

NHibernate 3.0 and FluentNHibernate first steps and first problems ... Interface Design

Since I decided to use my application to NHibernate 3.0, consequently, also wanted to be able to use FluentNhibernate. And there appeared a little problem. Since the authors do not officially support the new version of NHibernate yet because it is alpha. But when I wanted to use the current version is throwing errors on the version of the library he is not responding. Poszperałem a little on the internet and found solution. Well, just download the source FluentNHibernate, then in that project to replace the old library to new with NHibernate 3.0. Then build and everything works.

As already solved the problem I posted earlier basic classes of service database, such as DatabaseContext and DatabaseFactory. The investments were largely modeled on the CodePlex project shrinkr.


Database Context
DatabaseContext contains basic methods such as saving, deleting objects from the database, approving amendments. Public class
ISession _session;
private ITransaction _transaction;

private IQueryable<User> _users;
public DatabaseContext(ISession session) {
Check.Argument.IsNotNull(session, "session");
         _session = session; 
}

public IQueryable<User> Users
{
[DebuggerStepThrough]
get
{
return _users ?? (_users = CreateQuery<User>());
}
}

public virtual IQueryable<TEntity> CreateQuery<TEntity>() where TEntity : class, IEntity
{
return _session.Query<TEntity>();
}

public virtual TEntity GetById<TEntity>(long id) where TEntity : class, IEntity
{
Check.Argument.IsNotNegative(id, "id");
return _session.Get<TEntity>(id);
}

public virtual void Save<TEntity>(TEntity entity) where TEntity : class, IEntity
{
Check.Argument.IsNotNull(entity, "entity");
EnsureTransaction();
_session.SaveOrUpdate(entity);
}

public virtual void Delete<TEntity>(TEntity entity) where TEntity : class, IEntity
{
Check.Argument.IsNotNull(entity, "entity");
EnsureTransaction();
_session.Delete(entity);
}

public virtual void Commit()
{
EnsureTransaction();
_transaction.Commit();
}

private void EnsureTransaction()
{
if (_transaction == null
{
_transaction _session.BeginTransaction = ();

}}}





Database Factory

DatabaseFactory contrast is the main object associated with the management of the database because it is the whole configuration Nhibernate using the previously mentioned syntax Fluent . It is located in a private method, but I will not show it here. The interface of this class has only one method by means of which we can get DatabaseContext. Public interface

IDatabaseFactory

DatabaseContext {Get ();}


Unit of Work
last object associated with the database which is now added UnitOfWork. Since most operations on the data held by the transaction. We must have an object that allows us to approve the changes. When it is this objective has been created. The interface looks like this: public interface
 IUnitOfWork 

{void Commit ();}

implementations of the same class after invite to the sources.
Oh, and even added to the walkthrough test project associated with Nhibernatem. That's all for today. In the next post will be a little bit about how to implement the underlying repositories and probably Pre Implementation repository user.

My Leopard Gecko Wont Eat Anything

connected with the database.

Today we will be designing the basic interface of the business logic and database. Among other things, implementation of the entity, the interface repository.
 

Entities

Let's start with the creation of an entity. For the purpose of building the application architecture so far only a creature entities. It will be you. Let's start by implementing an interface entity. Part of it is common for each entity id. So, our interface will have just the box.

public interface IEntity

To help realize we create The base entities which will be implemented the above interface. This we do not have to write in each entity id field. In the event that there are other fields that will be shared as easily, you can modify the underlying entities, which will affect all entities have.
's implementation of core entities: public abstract class BaseEntity: IEntity
{public virtual Guid
Id {get; set;}}
 


As I have the basic types from which they will inherit our entities, we can now implement the first of them:
public class User: BaseEntity, IEntity
{
public virtual string Username { get; set; }
  
public virtual string Password { get; set; }

public virtual string Email { get; set; }
public virtual string PasswordQuestion { get; set; }

public virtual string PasswordAnswer { get; set; }
  
public virtual bool isLockedOut { get; set; }

public virtual DateTime LastActivityDate { get; set; }

public virtual DateTime LastLoginDate { get; set; }

public virtual DateTime LastLockedOutDate { get; set; }

public virtual DateTime CreatedDate { get; set; }

}



Repositories

Then I would like to say something about the objects that can be found in my project. These are the repositories. The repository is a class that directly have access to the database. It provides basic CRUD and other directly related to the entity. Mediates between the base and the services which these data will be needed. This allows the decoupling of the project on a specific ORM-a. Substitution requires only implement the context database and the various repositories. Implementation of the interface repository looks like this: public interface

IRepository \u0026lt;TEntity> where TEntity : class
{
TEntity GetById(Guid id);
IEnumerable<TEntity> GetBySpec(ISpecification<TEntity> spec);
void Add(TEntity entity);
void Delete(Guid id);
void Delete(TEntity entity); IEnumerable<TEntity> GetPagedElements<S>(int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderExpression, bool ascending); IEnumerable<TEntity> GetPagedElements<S>(int pageIndex, int pageSize, Expression<Func<TEntity, S>> orderExpression, ISpecification \u0026lt;TEntity> specification, bool ascending);
IEnumerable \u0026lt;TEntity> All ();}
 
Most of the features here is quite understandable. The only puzzle is possible to be ISpecifcation interface. Look at the example implementations: public class

UserOnlineUsersSpecification: Specification \u0026lt;user>
{private DateTime
_onlineTime;

public UserOnlineUsersSpecification () {


}
public override Expression \u0026lt;Func \u0026lt;User , bool>> SatisfiedBy () {
 _onlineTime = DateTime.Now.AddMinutes (-5); 

return x => x.LastActivityDate> = _onlineTime;
}}


This specification is intended to refer lamba expression that will allow us to find the currently registered users online. How widzymy every specification consists SatisfiedBy method that returns the lamba expression. This expression is used in the database to retrieve the data. In short this is a small part of the business logic wrapped in a class which makes it can be used in many places and avoid repetition in the code. More on this pattern can be found on Wikipedia



In the following we will deal with entries already concrete implementation classes associated with NHibernate and the database.


Friday, August 6, 2010

Relieve Endometriosis Bloating

project and the basic structure of helpers and extensions.

In this post I will try to bring home the project structure as well as to describe the basic helpers and extensions that I use most of my projects.


Project Structure: - mForum.Core
- Here you will find all the class / structure / methods that are common to the entire walkthrough and be used in each project.
- -
mForum.Infrasturcture.Automapper
- This project will need to initialize the class library AutoMapper - mForum.Infrastructure.NHibernate
- Here znowuż find everything related to the mapping data and base. So implementations of repositories, objects, initiating database. - mForum.Services
- This is an intermediary layer between business logic and presentation layer which is Asp.net MVC in this project. You will find here mostly all the classes, methods that are mediated the circulation of data between the business logic layer and presentation layer. - mForum.Web
- Here we have the presentation layer. In this project we will find views, scripts, js, css templates. In general, everything related to web design from the graphic. - mForum.Web.Common
- This is a project in which objects are directly related to the presentation layer from the developer. Here, we will be able to find their own attributes, MVC controllers, the tasks to be performed just prior to application (called Bootstrapper Taski). As I mentioned earlier have already added the class / method that I usually use in each project, such universal support class work.
The first of these is a class check. This class has methods sprawdzajace The input data and in case the condition of inconsistency in the method throws an appropriate exception. A simple example of checking whether the inputs are not null: testMethod void (object testProperty)
{if (testProperty == null) throw new ArgumentException (testProperty can not be null ");
... }
In the case of a single argument that is not too onerous and in larger quantities can cause a slight accumulation of conditional statements. This is solved by the same class Check:

testMethod void (object testProperty)
{
 Check.Argument.IsNotNull (testProperty, "testProperty"); 
...
}

Check class has many more methods for validation of input data. Once more I invite you to familiarize yourself with the code.

addition, I added a couple of extension methods for classes:
-
 DateTime: a method of verifying the correctness of the dates. Check class directly using these methods. 
-
String
: methods such as validation of the string as a url or e-mail address. Check the class uses them.
-
IEnumerable
: I added the extension that allows you to execute a line of code iterates through all elements of the collection and enforcement of any action on them. Foreach loop in condensed form.

That's it for today. Here comes the weekend so you can probably expect more entries. Oh and one more thing I have published a project on CodePlex so now everyone will have access to it. It is true that much still there but hey:)

Wednesday, August 4, 2010

Tech Deck Online Compotition

few words about the planning application and the selected technologies.

I mentioned earlier I made an extensive forum system. One might ask why it was just a forum when it is full of them? Mainly because they already quite a long time I had planned to write just such a project, but somehow I could not get together and start writing. The contest was just such an impulse to start.
main environment in which I wrote:
- Visual Web Developer 2010 Express - Microsoft Sql Server 2008 Express

Another thing I wanted to mention a few words about the chosen technology for this project :
-
ASP.NET MVC 2: Here the case was fairly simple because I decided to write this project . NET is I had to choose ASP.NET WebForms and MVC's. I personally will never accounted for my taste style and WebForms programming. Many of the problems caused for example the absence of a direct impact on the generated code, not very possibility of design patterns which resulted in more difficult applications testing. -
NHibernate
: Now to the issue of ORM-s. I took into account two NHibernate and the Entity Framework. After a careful analysis of their capabilities and how to create projects in it I think the Entity Framework, NHibernate can not be matched in the current version. However, recently started to appear in the CTP versions of the EF-a the so-called Code-First I must admit to going to be pretty good. Possible with future versions of NHibernate far short. The only problem Nhibernate LINQ provider is weaker than in the EF but I'm going to use for this project Nhibernate alpha version which was released recently. This should be corrected. It will be what to test:)
-
Automapper : Here is silent as to discuss. Nothing is more programmer's life easier as automatic mapping of objects such as the DTO to Domain Objects. For this purpose, is precisely the collection. - Microsoft Unity Container

: As my IoC container chose Unity. Mainly due to the relatively I use it a long time now and if I like the way it is setup and ease of use. -
MVC Extensions: In this library there is a lot of useful tools that can help / assistance in the design of applications such as Bootstrapping, Global filters, etc.. More on this subject I will probably describe the design-time application. This list may grow steadily as the project develops. For now, that's it. In the next post I will try to now bring the overall structure of the project and officially published sources (for now mostly empty:)) on CodePlex.
Welcome to the blog