- gpstracerserver.zip
- Article.gif
- article.html
- GpsTracerServer.sln
- GpsTracerStoredCreation.sql
- Source
- Business Logic
- GpsTracerServer.BusinessEntities
- GpsTracerServer.BusinessLogic
- Resource Access
- GpsTracerServer.DataAccess
- Service Interface
- GpsTracerServer.DataTypes
- GpsTracerServer.Host
- GpsTracerServer.ServiceContracts
- GpsTracerServer.ServiceImplementation
- Tests
- Functional Tests
- GpsTracerServer.Client
- Unit Tests
|
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using GpsTracerServer.BusinessEntities;
using System.Data.SqlClient;
using System.Diagnostics;
using GpsTracerServer.DataAccess.SQLServer;
namespace GpsTracerServer.DataAccess
{
/// <summary>
/// Respository that lets you find Device in the
/// CRM database.
/// </summary>
public class DeviceRepository : Repository<Device>
{
private string databaseName;
public DeviceRepository(string databaseName)
: base(databaseName)
{
this.databaseName = databaseName;
}
public List<Device> GetAllFromDevice()
{
ISelectionFactory<NullableIdentity> selectionFactory = new GetAllFromDeviceSelectionFactory();
try
{
NullableIdentity nullableIdentity = new NullableIdentity();
return base.Find(selectionFactory, new GetAllFromDeviceFactory(), nullableIdentity);
}
catch (SqlException ex)
{
HandleSqlException(ex, selectionFactory);
}
return new List<Device>();
}
public void Add(Device device)
{
DeviceInsertFactory insertFactory = new DeviceInsertFactory();
try
{
base.Add(insertFactory, device);
}
catch (SqlException ex)
{
HandleSqlException(ex, insertFactory);
}
}
public void Remove(System.Guid iD)
{
IDeleteFactory<System.Guid> deleteFactory = new DeviceDeleteFactory();
try
{
base.Remove(deleteFactory, iD);
}
catch (SqlException ex)
{
HandleSqlException(ex, deleteFactory);
}
}
public void Save(Device device)
{
DeviceUpdateFactory updateFactory = new DeviceUpdateFactory();
try
{
base.Save(updateFactory, device);
}
catch (SqlException ex)
{
HandleSqlException(ex, updateFactory);
}
}
private void HandleSqlException(SqlException ex, IDbToBusinessEntityNameMapper mapper)
{
if (ex.Number == ErrorCodes.SqlUserRaisedError)
{
switch (ex.State)
{
case ErrorCodes.ValidationError:
string[] messageParts = ex.Errors[0].Message.Split(':');
throw new RepositoryValidationException(
mapper.MapDbParameterToBusinessEntityProperty(messageParts[0]),
messageParts[1], ex);
case ErrorCodes.ConcurrencyViolationError:
throw new ConcurrencyViolationException(ex.Message, ex);
}
}
throw new RepositoryFailureException(ex);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.