/// <summary>
 ///     Loads the CSV Extent out of the settings and stores the extent Uri
 /// </summary>
 /// <param name="extent">The uri being used for an extent</param>
 /// <param name="factory">Factory being used to create a new instance</param>
 /// <param name="path">Path being used to load the extent</param>
 /// <param name="settings">Settings to load the extent</param>
 /// <returns>The loaded extent</returns>
 public void Load(IUriExtent extent, IFactory factory, string path, CSVSettings settings)
 {
     using (var fileStream = new FileStream(path, FileMode.Open))
     {
         Load(extent, factory, fileStream, settings);
     }
 }
Example #2
0
        public void StoreExtent(IUriExtent extent, ExtentStorageConfiguration configuration)
        {
            var xmiConfiguration = configuration as XmiStorageConfiguration;
            if (xmiConfiguration != null)
            {
                var xmlExtent = extent as XmlUriExtent;
                if (xmlExtent == null)
                {
                    throw new InvalidOperationException("Only XmlUriExtents are supported");
                }

                // Deletes existing file
                if (File.Exists(xmiConfiguration.Path))
                {
                    File.Delete(xmiConfiguration.Path);
                }

                // Loads existing file
                using (var fileStream = File.OpenWrite(xmiConfiguration.Path))
                {
                    xmlExtent.Document.Save(fileStream);
                }
            }
            else
            {
                throw new ArgumentException("Configuration is of an unknown type");
            }
        }
Example #3
0
        public void StoreExtent(IUriExtent extent, ExtentStorageConfiguration configuration)
        {
            var csvConfiguration = (CSVStorageConfiguration) configuration;

            var provider = new CSVDataProvider(_workspaceCollection, _dataLayerLogic);
            provider.Save(extent, csvConfiguration.Path, csvConfiguration.Settings);
        }
        /// <summary>
        /// Gets an enumeration of creatable types for a given extent. 
        /// It navigates to the meta extent and looks for all classes
        /// </summary>
        /// <param name="extent">The extent into which a new instance shall be created</param>
        /// <returns>Enumeration of types</returns>
        public CreateableTypeResult GetCreatableTypes(IUriExtent extent)
        {
            var dataLayer = _dataLayerLogic.GetDataLayerOfExtent(extent);
            var typeLayer = _dataLayerLogic.GetMetaLayerFor(dataLayer);
            var umlLayer= _dataLayerLogic.GetMetaLayerFor(typeLayer);

            var uml = _dataLayerLogic.Get<_UML>(umlLayer);
            var classType = uml?.StructuredClassifiers.__Class;

            if (classType == null)
            {
                // We did not find the corresponding class type
                return new CreateableTypeResult()
                {

                    MetaLayer = typeLayer,
                    CreatableTypes = new IElement[] {}
                };
            }

            return new CreateableTypeResult
            {
                MetaLayer = typeLayer,
                CreatableTypes = _dataLayerLogic.GetExtentsForDatalayer(typeLayer)
                    .SelectMany(x => x.elements().WhenMetaClassIs(classType))
                    .Cast<IElement>()
                    .ToList()
            };
        }
Example #5
0
        /// <summary>
        /// Initializes the bootstrapper after having the the necessary extents
        /// </summary>
        /// <param name="primitiveInfrastructure">Extent reflecting the primitive structure XMI definition</param>
        /// <param name="umlInfrastructure">Extent reflecting the Uml infrastructure XMI definition</param>
        /// <param name="mofInfrastructure">Extent reflecting the MOF infrastructure XMI definition</param>
        /// <param name="dataLayerLogic">Datalayerlogic  being used</param>
        public Bootstrapper(
            IUriExtent primitiveInfrastructure,
            IUriExtent umlInfrastructure,
            IUriExtent mofInfrastructure,
            IDataLayerLogic dataLayerLogic)
        {
            if (dataLayerLogic == null) throw new ArgumentNullException(nameof(dataLayerLogic));
            if (umlInfrastructure == null)
            {
                throw new ArgumentNullException(nameof(umlInfrastructure));
            }
            if (mofInfrastructure == null)
            {
                throw new ArgumentNullException(nameof(mofInfrastructure));
            }
            if (primitiveInfrastructure == null)
            {
                throw new ArgumentNullException(nameof(primitiveInfrastructure));
            }

            _dataLayerLogic = dataLayerLogic;
            UmlInfrastructure = umlInfrastructure;
            MofInfrastructure = mofInfrastructure;
            PrimitiveInfrastructure = primitiveInfrastructure;
        }
Example #6
0
 public void Load(IUriExtent extent, string filePath)
 {
     using (var stream = new FileStream(filePath, FileMode.Open))
     {
         Load(extent, stream);
     }
 }
 public ReadOnlyUriExtent(IUriExtent extent)
     : base(extent)
 {
     ActivateObjectConversion(
         x => new ReadOnlyElement(x),
         x => new ReadOnlyReflectiveSequence(x),
         x => x.GetProxiedElement());
 }
Example #8
0
 public void Copy(IUriExtent source, IUriExtent target)
 {
     var copier = new ObjectCopier(_factory);
     foreach (var element in source.elements())
     {
         var elementAsElement = element as IElement;
         var copiedElement = copier.Copy(elementAsElement);
         target.elements().add(copiedElement);
     }
 }
        /// <summary>
        ///     Creates a C# source code. Not to be used for recursive
        ///     call since the namespace is just once created
        /// </summary>
        /// <param name="element">
        ///     Regards the given element as a package
        ///     and returns a full namespace for the package.
        /// </param>
        public override void Walk(IUriExtent extent)
        {
            WriteUsages(new[]
            {
                "DatenMeister.EMOF.Interface.Reflection",
                "DatenMeister.EMOF.InMemory"
            });

            base.Walk(extent);
        }
Example #10
0
        /// <summary>
        ///     Loads the document from an XDocument
        /// </summary>
        /// <param name="extent">Extent to which the data is loaded</param>
        /// <param name="document">Document to be loaded</param>
        public void Load(IUriExtent extent, XDocument document)
        {
            _idToElement.Clear();

            // Skip the first element
            foreach (var element in document.Elements().Elements())
            {
                extent.elements().add(LoadElement(element));
            }
        }
 public void DetachExtent(IUriExtent extent)
 {
     lock (_data.LoadedExtents)
     {
         var information = _data.LoadedExtents.FirstOrDefault(x => x.Extent == extent);
         if (information != null)
         {
             _data.LoadedExtents.Remove(information);
             Debug.WriteLine($"- Detaching: {information.Configuration}");
         }
     }
 }
        /// <summary>
        ///     Creates a C# class instance for all the packages and classes within the extent
        /// </summary>
        /// <param name="extent">Extent to be used</param>
        public virtual void Walk(IUriExtent extent)
        {
            var stack = new CallStack(null);

            StartNamespace(ref stack);
            foreach (var element in extent.elements())
            {
                var elementAsObject = element as IObject;
                Walk(elementAsObject, stack);
            }

            EndNamespace(ref stack);
        }
        /// <summary>
        /// Saves the extent into database.
        /// </summary>
        /// <param name="extent">Extent to be stored</param>
        /// <param name="path">Path, where file shall be stored</param>
        /// <param name="settings">Settings being used</param>
        public void Save(IUriExtent extent, string path, CSVSettings settings)
        {
            var columns = new List<string>();

            // Retrieve the column headers
            if (settings.HasHeader && settings.Columns.Any())
            {
                // Column headers given by old extent
                columns.AddRange(settings.Columns);
            }
            else
            {
                // Column headers given by number by asking each object about the number of properties and
                // then use the maximum value of the elements. This assumes that every element has the same type
                columns = extent.GetProperties().ToList();
            }

            // Open File
            using (var streamWriter = new StreamWriter(File.OpenWrite(path), Encoding.GetEncoding(settings.Encoding)))
            {
                // Writes the header
                if (settings.HasHeader)
                {
                    WriteRow(streamWriter, settings, columns, x => x.ToString());
                }

                // Writes the elements
                foreach (var element in extent.elements().Select(x => x as IObject))
                {
                    WriteRow(
                        streamWriter,
                        settings,
                        columns,
                        x => element.isSet(x) ? element.get(x) : string.Empty);
                }
            }
        }
Example #14
0
 public ExtentModel(IUriExtent extent, WorkspaceModel workspace)
 {
     url = extent.contextURI();
     this.workspace = workspace;
 }
Example #15
0
 public static IFactory FindFactoryFor(this IFactoryMapper mapper, ILifetimeScope scope, IUriExtent extent)
 {
     return mapper.FindFactoryFor(scope, extent.GetType());
 }
 /// <summary>
 ///     Loads the CSV Extent out of the settings and stores the extent Uri
 /// </summary>
 /// <param name="extent">The uri being used for an extent</param>
 /// <param name="factory">Factory being used to create a new instance</param>
 /// <param name="stream">Path being used to load the extent</param>
 /// <param name="settings">Settings to load the extent</param>
 /// <returns>The loaded extent</returns>
 public void Load(IUriExtent extent, IFactory factory, Stream stream, CSVSettings settings)
 {
     ReadFromStream(extent, factory, stream, settings);
 }
Example #17
0
 /// <summary>
 ///     Loads the file from a stream
 /// </summary>
 /// <param name="extent">Extent to which the data is loaded</param>
 /// <param name="stream">Stream to be used for loading</param>
 public void Load(IUriExtent extent, Stream stream)
 {
     var document = XDocument.Load(stream);
     Load(extent, document);
 }
        private void AddToWorkspaceIfPossible(ExtentStorageConfiguration configuration, IUriExtent loadedExtent)
        {
            if (_workspaceCollection != null)
            {
                var workspace = _workspaceCollection.GetWorkspace(configuration.Workspace);
                if (workspace == null)
                {
                    throw new InvalidOperationException($"Workspace {configuration.Workspace} not found");
                }

                workspace.AddExtentNoDuplicate(loadedExtent);
            }
        }
        /// <summary>
        /// Stores the extent according to the used configuration during loading. 
        /// If loading was not performed, an exception is thrown. 
        /// </summary>
        /// <param name="extent">Extent to be stored</param>
        public void StoreExtent(IUriExtent extent)
        {
            ExtentStorageData.LoadedExtentInformation information;
            lock (_data.LoadedExtents)
            {
                information = _data.LoadedExtents.FirstOrDefault(x => x.Extent == extent);
            }

            if (information == null)
            {
                throw new InvalidOperationException($"The extent '{extent}' was not loaded by this instance");
            }

            Debug.WriteLine($"- Writing: {information.Configuration}");

            var extentStorage = _map.CreateFor(_diScope, information.Configuration);
            extentStorage.StoreExtent(information.Extent, information.Configuration);
        }
 /// <summary>
 ///     Creates a C# source code. Not to be used for recursive
 ///     call since the namespace is just once created
 /// </summary>
 /// <param name="element">
 ///     Regards the given element as a package
 ///     and returns a full namespace for the package.
 /// </param>
 /// <param name="stack">Used as the callstack</param>
 public override void Walk(IUriExtent extent)
 {
     Result.AppendLine("using System.Collections.Generic;");
     Result.AppendLine("using DatenMeister.EMOF.Interface.Reflection;");
     base.Walk(extent);
 }
Example #21
0
 public ColumnCreationResult FindColumnsForTable(IUriExtent extent)
 {
     return FindColumnsForTable(extent.elements());
 }