FakeBackend.cs :  » Windows-Presentation-Foundation » Caliburn » GameLibrary » Model » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Windows Presentation Foundation » Caliburn 
Caliburn » GameLibrary » Model » FakeBackend.cs
namespace GameLibrary.Model{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;
    using System.Linq;
    using System.Reflection;
    using System.Threading;

    [Export(typeof(IBackend))]
    public class FakeBackend : IBackend
    {
        private readonly IEnumerable<MethodInfo> _methods = typeof(FakeBackend).GetMethods().Where(x => x.Name == "Handle");

        //The 'Notes' are taken from the Game Spot reviews for each of these games.
        private readonly List<GameDTO> _games = new List<GameDTO>
        {
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Halo 1",
                Rating = 1,
                Notes = "Not only is this easily the best of the Xbox launch games, but it's easily one of the best shooters ever, on any platform.",
                AddedOn = DateTime.Today
            },
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Halo 2",
                Rating = .8,
                Notes = "Despite a rather short campaign and a disappointing storyline, Halo 2 is an exceptional shooter that frequently delivers thrilling, memorable, and unique moments in its online, co-op, and single-player modes.",
                AddedOn = DateTime.Today
            },
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Halo 3",
                Rating = .8,
                Notes = "Halo 3 builds upon the concepts of Halo 2 in ways that you'd expect, but there are also new modes and options that send the series in exciting new directions.",
                AddedOn = DateTime.Today
            },
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Mass Effect 1",
                Rating = .8,
                Notes = "An excellent story and fun battles make this a universe worth exploring.",
                AddedOn = DateTime.Today
            },
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Mass Effect 2",
                Rating = 1,
                Notes = "Once this intense and action-packed role-playing game pulls you into its orbit, you won't want to escape.",
                AddedOn = DateTime.Today
            },
            new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = "Final Fantasy XIII",
                Rating = .8,
                Notes = "The most beautiful Final Fantasy game yet is an imperfect but still impressive saga that will touch your heart.",
                AddedOn = DateTime.Today
            }
        };

        public void Send<TResponse>(IQuery<TResponse> query, Action<TResponse> reply)
        {
            Invoke(query, query, reply);
        }

        public void Send(ICommand command)
        {
            Invoke(command, command);
        }

        private void Invoke(object request, params object[] args)
        {
            ThreadPool.QueueUserWorkItem(state => {
                Thread.Sleep(1000);

                var requestType = request.GetType();
                var handler = _methods.Where(x => requestType.IsAssignableFrom(x.GetParameters().First().ParameterType)).First();

                handler.Invoke(this, args);
            });
        }

        public void Handle(SearchGames search, Action<IEnumerable<SearchResult>> reply)
        {
            reply(
                from game in _games
                where game.Title.ToLower().Contains(search.SearchText.ToLower())
                orderby game.Title
                select new SearchResult
                {
                    Id = game.Id,
                    Title = game.Title
                });
        }

        public void Handle(GetGame getGame, Action<GameDTO> reply)
        {
            reply(
                (from game in _games
                where game.Id == getGame.Id
                select game).FirstOrDefault()
                );
        }

        public void Handle(AddGameToLibrary addGame)
        {
            var game = new GameDTO
            {
                Id = Guid.NewGuid(),
                Title = addGame.Title,
                Notes = addGame.Notes,
                Rating = addGame.Rating,
                AddedOn = DateTime.Now,
            };

            _games.Add(game);
        }

        public void Handle(CheckGameIn checkIn)
        {
            var game = _games.FirstOrDefault(x => x.Id == checkIn.Id);
            if (game != null)
                game.Borrower = null;
        }

        public void Handle(CheckGameOut checkOut)
        {
            var game = _games.FirstOrDefault(x => x.Id == checkOut.Id);
            if(game != null)
                game.Borrower = checkOut.Borrower;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.