private RecurrenceRuleException[] LoadExceptions(RecurrenceRule recurrence) { try { log.LogFunctionStart(); log.Log("Loading exceptions ...", LogLevel.Debug); recurrence.LoadRelation(RecurrenceRule.RelationNames.Exceptions, service, "*"); recurrence.LoadRelation(RecurrenceRule.RelationNames.ExceptionGroupings, service, "*"); var exceptions = new RecurrenceRuleException[0]; if (recurrence.Exceptions != null) { exceptions = exceptions.Union(recurrence.Exceptions).ToArray(); } if (recurrence.ExceptionGroupings != null) { log.Log("Loading exceptions in groupings ...", LogLevel.Debug); foreach (var grouping in recurrence.ExceptionGroupings) { grouping.LoadRelation(RecurrenceRuleExceptionGrouping.RelationNames.Exceptions, service, "*"); if (grouping.Exceptions != null) { exceptions = exceptions.Union(grouping.Exceptions).ToArray(); } } } log.Log($"Exceptions count: {exceptions.Length}"); return(exceptions); } catch (Exception ex) { log.Log(ex); throw; } finally { log.LogFunctionEnd(); } }
private void LoadRules(EntityReference exclusionRecord, List <RecurrenceRule> rules) { try { log.LogFunctionStart(); if (exclusionRecord.LogicalName == RecurrenceRuleExceptionGrouping.EntityLogicalName) { var record = new RecurrenceRuleExceptionGrouping { Id = exclusionRecord.Id }; record.LoadRelation(RecurrenceRuleExceptionGrouping.RelationNames.Rules, service); if (record.Rules != null) { rules.AddRange(record.Rules); } record.LoadRelation(RecurrenceRuleExceptionGrouping.RelationNames.Exceptions, service); if (record.Exceptions != null) { foreach (var exception in record.Exceptions) { exception.LoadRelation(RecurrenceRuleException.RelationNames.Rules, service); if (exception.Rules != null) { rules.AddRange(exception.Rules); } } } } else if (exclusionRecord.LogicalName == RecurrenceRuleException.EntityLogicalName) { var record = new RecurrenceRuleException { Id = exclusionRecord.Id }; record.LoadRelation(RecurrenceRuleException.RelationNames.Rules, service); if (record.Rules != null) { rules.AddRange(record.Rules); } record.LoadRelation(RecurrenceRuleException.RelationNames.ExceptionGroups, service); if (record.ExceptionGroups != null) { foreach (var group in record.ExceptionGroups) { group.LoadRelation(RecurrenceRuleExceptionGrouping.RelationNames.Rules, service); if (group.Rules != null) { rules.AddRange(group.Rules); } } } } } catch (Exception ex) { log.Log(ex); throw; } finally { log.LogFunctionEnd(); } }