ScheduleStore.cs 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Comal.Classes;
  2. namespace Comal.Stores
  3. {
  4. internal class ScheduleStore : BaseStore<Schedule>
  5. {
  6. //private void UpdateActiveScheduleCount(Schedule entity)
  7. //{
  8. // Type doctype = entity.DocumentType();
  9. // var linktype = CoreUtils.TypeList(
  10. // AppDomain.CurrentDomain.GetAssemblies(),
  11. // x => (typeof(IEntityLink).GetTypeInfo().IsAssignableFrom(x) && (x.BaseType.GenericTypeArguments.Length == 1) && (x.BaseType.GenericTypeArguments[0] == doctype))
  12. // ).FirstOrDefault();
  13. // if (linktype == null)
  14. // return;
  15. // var link = Activator.CreateInstance(linktype) as IEntityLink;
  16. // link.ID = entity.DocumentID;
  17. // if (entity.HasOriginalValue(x=>x.DocumentID))
  18. // ((BaseObject)link).OriginalValues["ID"] = entity.GetOriginalValue(x=>x.DocumentID);
  19. // ParameterExpression parameter = Expression.Parameter(doctype, "x");
  20. // MemberExpression property = Expression.Property(parameter, "ActiveSchedules");
  21. // var delegateType = typeof(Func<,>).MakeGenericType(doctype, typeof(int));
  22. // var tgt = Expression.Lambda(delegateType, property, parameter);
  23. // //var tgt = CoreUtils.CreateMemberExpression(entity.DocumentType, "ActiveSchedules");
  24. // Type aggtype = typeof(IntegerAggregate<,>).MakeGenericType(entity.GetType(), doctype);
  25. // var agg = Activator.CreateInstance(aggtype, null, tgt, AggregateType.Count);
  26. // Array arr = Array.CreateInstance(aggtype, 1);
  27. // arr.SetValue(agg, 0);
  28. // MethodInfo method = this.GetType().GetMethod("UpdateAggregate");
  29. // MethodInfo generic = method.MakeGenericMethod(doctype);
  30. // generic.Invoke(this, new object[] { entity, link, arr });
  31. //}
  32. //private enum ScheduleAction
  33. //{
  34. // Update,
  35. // Delete
  36. //}
  37. //private void CheckScheduleActive(Schedule entity, ScheduleAction action)
  38. //{
  39. // if (action == ScheduleAction.Delete)
  40. // {
  41. // // Is the stored version of this schedule Active?
  42. // bool bActive = entity.OriginalValues.ContainsKey("Active") ? (bool)entity.OriginalValues["Active"] : entity.Active;
  43. // if (bActive)
  44. // {
  45. // entity.DocumentID = Guid.Empty;
  46. // UpdateActiveScheduleCount(entity);
  47. // }
  48. // }
  49. // else
  50. // {
  51. // // Is this a new schedule that has already been set to active?
  52. // if (entity.ID.Equals(Guid.Empty) && entity.Active)
  53. // UpdateActiveScheduleCount(entity);
  54. // // Has the Active flag been changed?
  55. // else if (entity.OriginalValues.ContainsKey("Active"))
  56. // {
  57. // bool bOrig = false;
  58. // bool.TryParse(entity.OriginalValues["Active"].ToString(), out bOrig);
  59. // bool bCurrent = entity.Active;
  60. // if (bOrig != bCurrent)
  61. // {
  62. // Guid id = entity.DocumentID;
  63. // if (!bCurrent)
  64. // entity.DocumentID = Guid.Empty;
  65. // UpdateActiveScheduleCount(entity);
  66. // entity.DocumentID = id;
  67. // }
  68. // }
  69. // }
  70. //}
  71. protected override void BeforeSave(Schedule entity)
  72. {
  73. base.BeforeSave(entity);
  74. //CheckScheduleActive(entity,ScheduleAction.Update);
  75. }
  76. protected override void BeforeDelete(Schedule entity)
  77. {
  78. base.BeforeDelete(entity);
  79. //CheckScheduleActive(entity, ScheduleAction.Delete);
  80. }
  81. }
  82. }