/// <summary> /// Determines whether this instance can import the specified items. /// </summary> /// <param name="data"></param> /// <param name="format"></param> /// <returns></returns> public BoolErrorsItem <IList <T> > Load(IDictionary data, string format) { var errors = new ValidationResults(); var result = new BoolErrorsItem <IList <T> >(null, false, string.Empty, errors); // For each section. Try.CatchLog(() => { IMapper <T> mapper = _mappers[format]; IList <T> results = mapper.Map(data, errors); result = new BoolErrorsItem <IList <T> >(results, results != null && results.Count > 0, errors.Message(), errors); }); return(result); }
/// <summary> /// Determines whether this instance can import the specified items. /// </summary> /// <param name="text">The text to import( as csv, xml, ini)</param> /// <param name="format">csv, xml, ini, json</param> /// <returns></returns> public virtual BoolErrorsItem <IList <T> > LoadText(string text, string format) { if (!_mappers.ContainsKey(format.ToLower())) { return(new BoolErrorsItem <IList <T> >(null, false, "Format : " + format + " not supported.", null)); } BoolErrorsItem <IList <T> > canImport = new BoolErrorsItem <IList <T> >(null, false, "", null); // For each section. Try.CatchLog(() => { var mapper = _mappers[format.ToLower()]; var errors = new ValidationResults(); IList <T> items = mapper.MapFromText(text, errors); bool success = items != null && items.Count > 0; canImport = new BoolErrorsItem <IList <T> >(items, success, string.Empty, errors); }); return(canImport); }