PageRenderTime 77ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/ContentRenderingApi/Data/DefaultData.cs

#
C# | 131 lines | 90 code | 18 blank | 23 comment | 9 complexity | 6ba98f16dec2e214d028ddff75ddfda4 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using Com.ContentRendering.Api.DataEngine;
  4. using ContentRenderingApi.Configuration;
  5. namespace ContentRenderingApi.Data
  6. {
  7. /// <summary/>
  8. internal class DefaultData : AbstractData
  9. {
  10. private IEnumerator<KeyValuePair<string, object>> _namedParameters;
  11. private IEnumerator<object> _parameters;
  12. /// <summary/>
  13. internal DefaultData(
  14. ReflectionCache reflectionCache,
  15. TransformationConfiguration transformationConfiguration,
  16. bool isCaching,
  17. IEnumerator<KeyValuePair<string, object>> namedParameters,
  18. IEnumerator<object> parameters)
  19. : base(
  20. reflectionCache,
  21. transformationConfiguration,
  22. isCaching,
  23. null)
  24. {
  25. this._namedParameters = namedParameters;
  26. this._parameters = parameters;
  27. }
  28. /// <summary/>
  29. protected override void ResolveChildData(List<object> values, string name)
  30. {
  31. // move the enumerator index to the start
  32. this._namedParameters.Reset();
  33. // check for matching parameters
  34. while (this._namedParameters.MoveNext())
  35. {
  36. // does the name match ... if not move on
  37. if (this._namedParameters.Current.Key != name)
  38. {
  39. continue;
  40. }
  41. // if the value is null we treat it differently .... that is the data engine isn't used
  42. // this is because the parameter has been explicitly defined via the add atribute method
  43. // so treat the value as a null value and move on
  44. if (this._namedParameters.Current.Value == null)
  45. {
  46. values.Add(null);
  47. // process the next input
  48. continue;
  49. }
  50. // find the child data of the current data for the given name
  51. IEnumerator<object> enumerator = SelfReflection.Translate(
  52. base.ReflectionCache,
  53. this._namedParameters.Current.Value);
  54. // move each element to the new list
  55. while (enumerator.MoveNext())
  56. {
  57. values.Add(enumerator.Current);
  58. }
  59. }
  60. // move the enumerator index to the start
  61. this._parameters.Reset();
  62. // check for matching parameters
  63. while (this._parameters.MoveNext())
  64. {
  65. // expand the object
  66. IEnumerator<object> enumerator = SelfReflection.Translate(
  67. base.ReflectionCache,
  68. this._parameters.Current);
  69. while (enumerator.MoveNext())
  70. {
  71. // find the child data of the current data for the given name
  72. object newValue = ChildReflection.Translate(
  73. base.ReflectionCache,
  74. enumerator.Current,
  75. name);
  76. // expand the object
  77. IEnumerator<object> newEnumerator = SelfReflection.Translate(
  78. base.ReflectionCache,
  79. newValue);
  80. while (newEnumerator.MoveNext())
  81. {
  82. values.Add(newEnumerator.Current);
  83. }
  84. }
  85. }
  86. }
  87. /// <summary/>
  88. protected override string Name
  89. {
  90. get { return null; }
  91. }
  92. /// <summary/>
  93. internal override object RawValue
  94. {
  95. get { return null; }
  96. }
  97. /// <summary/>
  98. internal override int Length
  99. {
  100. get { return Constant.DEFAULT_LENGTH; }
  101. }
  102. /// <summary/>
  103. internal override int Position
  104. {
  105. get { return Constant.DEFAULT_POSITION; }
  106. }
  107. /// <summary/>
  108. protected override void AssignPosition(int position)
  109. {
  110. // nothing to do
  111. }
  112. }
  113. }