Skip to content

Commit

Permalink
[TaskyPro] split into separate 'shared-code' examples: Portable, Link…
Browse files Browse the repository at this point in the history
…ed, Cloned
  • Loading branch information
conceptdev committed Jul 3, 2012
1 parent 8965253 commit 1e9b4d6
Show file tree
Hide file tree
Showing 223 changed files with 14,284 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
*/*/*/bin/*
*/*/*/obj/*
*_ReSharper.*/

*/*/Resource.designer.cs
*/*/*/Resource.designer.cs
*/*/*/*/Resource.designer.cs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/About.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The Tasky.Core library is the reusable portion of the Tasky application. It contains the Business
Layer (BL), Data Access Layer (DAL), and Data Layer (DL). All of the Tasky.Core code is shared between
the iOS and Android versions of the application without modification.
15 changes: 15 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/BL/About.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Business Layer (BL)
===================
Sometimes also called the Business Logic Layer (BLL), the BL contains entitiy definitions and
business logic.

Business Entities
-----------------
Business entites are classes that represent real-world objects. They're the core of
Object-Oriented-Programming (OOP).

Manager Classes
---------------
In this particular architecture, we're using the façade pattern (like we did with the DAL)
which is represented by static Manager classes. The manager classes are an abstraction on
the DAL and SAL layers and perform any business logic.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using Tasky.DL.SQLite;

namespace Tasky.BL.Contracts {
/// <summary>
/// Business entity base class. Provides the ID property.
/// </summary>
public abstract class BusinessEntityBase : IBusinessEntity {
public BusinessEntityBase ()
{
}

/// <summary>
/// Gets or sets the Database ID.
/// </summary>
[PrimaryKey, AutoIncrement]
public int ID { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;

namespace Tasky.BL.Contracts {
public interface IBusinessEntity {
int ID { get; set; }
}
}

34 changes: 34 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/BL/Managers/TaskManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using Tasky.BL;

namespace Tasky.BL.Managers
{
public static class TaskManager
{
static TaskManager ()
{
}

public static Task GetTask(int id)
{
return DAL.TaskRepository.GetTask(id);
}

public static IList<Task> GetTasks ()
{
return new List<Task>(DAL.TaskRepository.GetTasks());
}

public static int SaveTask (Task item)
{
return DAL.TaskRepository.SaveTask(item);
}

public static int DeleteTask(int id)
{
return DAL.TaskRepository.DeleteTask(id);
}

}
}
24 changes: 24 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/BL/Task.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Tasky.BL.Contracts;
using Tasky.DL.SQLite;

namespace Tasky.BL
{
/// <summary>
/// Represents a Task.
/// </summary>
public class Task : IBusinessEntity
{
public Task ()
{
}

[PrimaryKey, AutoIncrement]
public int ID { get; set; }
public string Name { get; set; }
public string Notes { get; set; }
// new property
public bool Done { get; set; }
}
}

13 changes: 13 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/DAL/About.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Data Access Layer (DAL)
=======================
The data access layer is responsible for providing an abstraction to the data layer. It makes
sure that no matter what technology(ies) are used for data persistance, a single entry point
that is technology agnostic exists.

Often, the façade pattern is used, and many times the underlying data persistence technology is
actually more than one. for example, you might have some data store in xml, other data stored in
a SQL database, etc. The DAL makes sure that any complexity associated with accessing and aggregating
these technologies is isolated from the rest of the application.

The DAL is also considered a sibling to the Service Access Layer (SAL), which is responsible for
access to cloud services, and other network related resources.
70 changes: 70 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/DAL/TaskRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.IO;
using Tasky.BL;

namespace Tasky.DAL {
public class TaskRepository {
DL.TaskDatabase db = null;
protected static string dbLocation;
protected static TaskRepository me;

static TaskRepository ()
{
me = new TaskRepository();
}

protected TaskRepository()
{
// set the db location
dbLocation = DatabaseFilePath;

// instantiate the database
db = new Tasky.DL.TaskDatabase(dbLocation);
}

public static string DatabaseFilePath {
get {
var sqliteFilename = "TaskDB.db3";
#if SILVERLIGHT
// Windows Phone expects a local path, not absolute
var path = sqliteFilename;
#else

#if __ANDROID__
// Just use whatever directory SpecialFolder.Personal returns
string libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); ;
#else
// we need to put in /Library/ on iOS5.1 to meet Apple's iCloud terms
// (they don't want non-user-generated data in Documents)
string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
string libraryPath = Path.Combine (documentsPath, "../Library/"); // Library folder
#endif
var path = Path.Combine (libraryPath, sqliteFilename);
#endif
return path;
}
}

public static Task GetTask(int id)
{
return me.db.GetItem<Task>(id);
}

public static IEnumerable<Task> GetTasks ()
{
return me.db.GetItems<Task>();
}

public static int SaveTask (Task item)
{
return me.db.SaveItem<Task>(item);
}

public static int DeleteTask(int id)
{
return me.db.DeleteItem<Task>(id);
}
}
}

19 changes: 19 additions & 0 deletions TaskyProCloned/Tasky.Core.Cloned/DL/About.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Data Layer:
===========
The data layer is typically the lowest level layer of an application. Typically it consists
of data persistence/retreival code. In this particular application, it contains two classes:
- SQLite.cs
- TaskDatabase.cs

SQLite
------
This is the SQLite.NET library, created by Frank Krueger. It's a lightweight Object Relational
Model (ORM) that allows you to define your database schema via classes and automatically
handles the nitty gritty of data persistance and retrieval into/from SQLite as well as actual
database creation. It also has limited support for LINQ queries.

TaskDatabase
------------
TaskDatabase builds on SQLite.Net and represents a specific database, in our case, the Task DB.
It contains methods for retreival and persistance as well as db creation, all based on the
underlying ORM.
Loading

0 comments on commit 1e9b4d6

Please sign in to comment.