PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/Commanding/Commanding.Tests.AcceptanceTests/TestInfrastructure/DataProviderBase.cs

#
C# | 82 lines | 54 code | 11 blank | 17 comment | 4 complexity | f77c3633fdd3033dfd03ffa1fedfd24f MD5 | raw file
  1. //===============================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation
  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. //===============================================================================
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Xml.Serialization;
  22. using System.Xml;
  23. namespace Commanding.AcceptanceTests.TestInfrastructure
  24. {
  25. public abstract class DataProviderBase<TEntity> : IDataProvider<TEntity>,IDisposable
  26. {
  27. XmlSerializer xmlSerializer = null;
  28. XmlTextReader xmlReader = null;
  29. protected DataProviderBase()
  30. {
  31. xmlSerializer = new XmlSerializer(typeof(List<TEntity>));
  32. string dataFilePath = GetDataFilePath();
  33. if (!(String.IsNullOrEmpty(dataFilePath)))
  34. {
  35. xmlReader = new XmlTextReader(dataFilePath);
  36. }
  37. }
  38. public virtual List<TEntity> GetData()
  39. {
  40. return (List<TEntity>)(xmlSerializer.Deserialize(xmlReader));
  41. }
  42. public virtual List<TEntity> GetDataForId(string id)
  43. {
  44. throw new NotImplementedException();
  45. }
  46. public virtual int GetCount()
  47. {
  48. return ((List<TEntity>)xmlSerializer.Deserialize(xmlReader)).Count;
  49. }
  50. public abstract string GetDataFilePath();
  51. #region IDisposable Members
  52. public void Dispose()
  53. {
  54. Dispose(true);
  55. GC.SuppressFinalize(this);
  56. }
  57. #endregion
  58. protected virtual void Dispose(bool disposing)
  59. {
  60. if (disposing)
  61. {
  62. if (null != xmlReader)
  63. {
  64. xmlReader = null;
  65. //Close the reader.
  66. xmlReader.Close();
  67. }
  68. }
  69. }
  70. }
  71. }