/// <summary>
        /// Gets the mapping from existing dataset.
        /// </summary>
        /// <param name="dataContext">The data context.</param>
        /// <returns></returns>
        private string GetMappingFromExistingDataset(DatasetContext dataContext)
        {
            string mappingXmlToUse = null;

            using (var session = dataContext.Provider.SessionFactory.OpenStatelessSession())
            {
                mappingXmlToUse = session.CreateCriteria <Dataset>()
                                  .Add(Restrictions.Eq("Id", dataContext.SelectedMappingDatasetId))
                                  .SetMaxResults(1)
                                  .SetProjection(Projections.Property("SummaryData"))
                                  .UniqueResult <string>();
            }
            return(mappingXmlToUse);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TargetMapperFactory"/> class.
        /// </summary>
        /// <param name="targetDefinition">The target definition.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="InvalidOperationException"></exception>
        public TargetMapperFactory(Target targetDefinition, DatasetContext context = null)
        {
            TargetDefinition = targetDefinition;
            if (!TargetDefinition.IsCustom)
            {
                TypetoMap = Type.GetType(TargetDefinition.ClrType);
            }
            else if (TargetDefinition.IsCustom && context != null)
            {
                TypetoMap = context.TargetType;
            }
            else
            {
                throw new InvalidOperationException(string.Format("This target can't be mapped due to an invalid target type \"{0}\".", TargetDefinition.Name));
            }

            ValidationEngine = new InstanceValidator(TypetoMap);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DatasetSummaryHelper"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="progress">The progress.</param>
        /// <param name="required">The required.</param>
        /// <param name="optional">The optional.</param>
        public DatasetSummaryHelper(
            DatasetContext context,
            ProgressState progress,
            MappingDictionary required,
            MappingDictionary optional)
        {
            Progress       = progress ?? new ProgressState(0, 1);
            MappingsHelper = new MappingsHelper(required, optional);
            var attrs = new List <XAttribute>();

            if (!string.IsNullOrEmpty(context.Year))
            {
                attrs.Add(new XAttribute("Year", context.Year ?? string.Empty));
            }

            if (context.Quarter.HasValue)
            {
                attrs.Add(new XAttribute("Quarter", context.Quarter.GetValueOrDefault()));
            }
            ReportingPeriod = new XElement("ReportingPeriod", attrs.ToArray());
        }