PageRenderTime 28ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/V2.2/trunk/RI/StockTraderRI.Tests.AcceptanceTest/StockTraderRI.Tests.AcceptanceTest/TestInfrastructure/DataProvider/DataProviderBase.cs

#
C# | 80 lines | 53 code | 11 blank | 16 comment | 5 complexity | 41c0a197eeb6066c0f89725ac84c8070 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.Xml.Serialization;
22using System.Xml;
23
24namespace StockTraderRI.Tests.AcceptanceTest.TestInfrastructure
25{
26    public abstract class DataProviderBase<TEntity> : IDataProvider<TEntity>, IDisposable
27    {
28        XmlSerializer xmlSerializer = null;
29        XmlTextReader xmlReader = null;
30
31        protected DataProviderBase()
32        {
33            xmlSerializer = new XmlSerializer(typeof(List<TEntity>));
34            xmlReader = new XmlTextReader(GetDataFilePath());
35        }
36
37        public virtual List<TEntity> GetData()
38        {
39            return (List<TEntity>)(xmlSerializer.Deserialize(xmlReader));
40        }
41
42        public virtual List<TEntity> GetDataForId(string id)
43        {
44            throw new NotImplementedException();
45        }
46
47        public virtual int GetCount()
48        {
49            return ((List<TEntity>)xmlSerializer.Deserialize(xmlReader)).Count;
50        }
51
52        public abstract string GetDataFilePath();
53
54        #region IDisposable Members
55
56        public void Dispose()
57        {
58            Dispose(true);
59            GC.SuppressFinalize(this);
60        }
61
62        #endregion
63
64        protected virtual void Dispose(bool disposing)
65        {
66            if (disposing)
67            {
68                if (null != xmlSerializer)
69                {
70                    xmlSerializer = null;
71                }
72
73                if (null != xmlReader)
74                {
75                    xmlReader = null;
76                }
77            }
78        }
79    }
80}