Exemple #1
0
        /// <summary>
        /// Takes data from the specified document and adds it to the Catalog
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public IList <IError> MapDocument(Model.Document document)
        {
            Errors = new List <IError>();

            foreach (Model.ShippedItemInstance shippedItemInstance in document.ShippedItemInstances)
            {
                MapShippedItemInstance(shippedItemInstance);
            }
            return(Errors);
        }
Exemple #2
0
        public IList <ApplicationDataModel.ADM.ApplicationDataModel> Import(string dataPath, Properties properties = null)
        {
            IList <ApplicationDataModel.ADM.ApplicationDataModel> models = new List <ApplicationDataModel.ADM.ApplicationDataModel>();

            List <IError> errors = new List <IError>();

            List <string> fileNames = GetInputFiles(dataPath);

            fileNames.Sort(); // required to ensure OS file system sorting differences are handled

            foreach (string fileName in fileNames)
            {
                try
                {
                    string jsonText = File.ReadAllText(fileName);

                    Model.Document document = JsonConvert.DeserializeObject <Model.Document>(jsonText);
                    if (document.ShippedItemInstances != null)
                    {
                        //Each document will import as individual ApplicationDataModel
                        ApplicationDataModel.ADM.ApplicationDataModel adm = new ApplicationDataModel.ADM.ApplicationDataModel();
                        adm.Catalog = new Catalog()
                        {
                            Description = fileName
                        };

                        //Map the document data into the Catalog
                        Mapper mapper = new Mapper(adm.Catalog);
                        errors.AddRange(mapper.MapDocument(document));

                        models.Add(adm);
                    }
                    else
                    {
                        errors.Add(new Error(null, $"Importing {fileName}", "Couldn't parse ShippedItemInstances", null));
                    }
                }
                catch (Exception ex)
                {
                    errors.Add(new Error(null, $"Exception Importing {fileName}", ex.Message, ex.StackTrace));
                }
            }

            //Read the Errors property after import to inspect any diagnostic messages.
            Errors = errors;

            return(models);
        }