Beispiel #1
0
        /// <summary>
        /// Integrates the Types into the extent
        /// </summary>
        /// <param name="typeExtent">Extent to be used</param>
        public void Into(IExtent typeExtent)
        {
            var layerOfTypes = _dataLayerLogic.GetDataLayerOfExtent(typeExtent);
            var layerOfUml = _dataLayerLogic.GetMetaLayerFor(layerOfTypes);
            var uml = _dataLayerLogic.Get<_UML>(layerOfUml);
            var factory = new MofFactory();

            var typeProvider = new DotNetTypeGenerator(factory, uml);
            var typeForZipCodes = typeProvider.CreateTypeFor(typeof (Model.ZipCode));
            typeExtent.elements().add(typeForZipCodes);
        }
        /// <summary>
        ///     Reads the file from the stream
        /// </summary>
        /// <param name="path">Path being used to load the file</param>
        /// <param name="extent">Extet being stored</param>
        /// <param name="settings">Settings being used to store it.</param>
        private void ReadFromStream(IExtent extent, IFactory factory, Stream stream, CSVSettings settings)
        {
            if (settings == null)
            {
                settings = new CSVSettings();
            }

            var columns = settings.Columns;
            var createColumns = false;

            using (var streamReader = new StreamReader(stream, Encoding.GetEncoding(settings.Encoding)))
            {
                if (columns == null)
                {
                    createColumns = true;
                }

                // Reads header, if necessary
                if (settings.HasHeader)
                {
                    columns.Clear();
                    // Creates the column names for the headline
                    var ignoredLine = streamReader.ReadLine();
                    var columnNames = SplitLine(ignoredLine, settings);
                    foreach (var columnName in columnNames)
                    {
                        columns.Add(columnName);
                    }
                }

                // Reads the data itself
                string line;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var values = SplitLine(line, settings);

                    var csvObject = factory.create(null);

                    // we now have the created object, let's fill it
                    var valueCount = values.Count;
                    for (var n = 0; n < valueCount; n++)
                    {
                        string foundColumn;

                        // Check, if we have enough columns, if we don't have enough columns, create one
                        if (columns.Count <= n && (createColumns || !settings.HasHeader))
                        {
                            // Create new column
                            foundColumn = $"Column {n + 1}";
                            columns.Add(foundColumn);
                        }
                        else
                        {
                            foundColumn = columns[n];
                        }

                        csvObject.set(foundColumn, values[n]);
                    }

                    extent.elements().add(csvObject);
                }
            }
        }
 public static IEnumerable<IObject> getDescendents(IExtent extent)
 {
     return getDescendents(extent.elements());
 }