public void StoreExtent(IUriExtent extent, ExtentStorageConfiguration configuration) { var csvConfiguration = (CSVStorageConfiguration) configuration; var provider = new CSVDataProvider(_workspaceCollection, _dataLayerLogic); provider.Save(extent, csvConfiguration.Path, csvConfiguration.Settings); }
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"); } }
public IUriExtent LoadExtent(ExtentStorageConfiguration configuration, bool createAlsoEmpty = false) { var xmiConfiguration = (XmiStorageConfiguration) configuration; XDocument xmlDocument; if (!File.Exists(xmiConfiguration.Path)) { if (createAlsoEmpty) { // We need to create an empty Xmi file... Not the best thing at the moment, but we try it. xmlDocument = new XDocument( new XElement(XmlUriExtent.DefaultRootNodeName)); } else { throw new InvalidOperationException( $"File not found: {xmiConfiguration.Path}"); } } else { xmlDocument = XDocument.Load(xmiConfiguration.Path); } var result = new XmlUriExtent(xmlDocument, xmiConfiguration.ExtentUri) { Workspaces = _workspaceCollection }; return result; }
public IExtentStorage CreateFor(ILifetimeScope scope, ExtentStorageConfiguration configuration) { Func<ILifetimeScope, IExtentStorage> foundType; if (!_mapping.TryGetValue(configuration.GetType(), out foundType)) { throw new InvalidOperationException("ExtentStorage for the given type was not found"); } return foundType(scope); }
public IUriExtent LoadExtent(ExtentStorageConfiguration configuration, bool createAlsoEmpty) { var csvConfiguration = (CSVStorageConfiguration) configuration; var provider = new CSVDataProvider(_workspaceCollection, _dataLayerLogic); var mofExtent = new MofUriExtent(csvConfiguration.ExtentUri); var factory = new MofFactory(); var doesFileExist = File.Exists(csvConfiguration.Path); if (doesFileExist) { provider.Load(mofExtent, factory, csvConfiguration.Path, csvConfiguration.Settings); } else if (!createAlsoEmpty) { throw new InvalidOperationException( $"File does not exist and empty extents is not given in argument {nameof(createAlsoEmpty)}"); } return mofExtent; }
/// <summary> /// Loads the extent by using the extent storage by using the configuration and finding /// the correct storage engine /// </summary> /// <param name="configuration">Configuration being used to load</param> /// <param name="createAlsoEmpty">true, if also empty extents will be created, if the file does not exist</param> /// <returns>The loaded extent</returns> public IUriExtent LoadExtent(ExtentStorageConfiguration configuration, bool createAlsoEmpty = false) { // Check, if the extent url is a real uri if (!Uri.IsWellFormedUriString(configuration.ExtentUri, UriKind.Absolute)) { throw new InvalidOperationException($"Uri is not well-formed: {configuration.ExtentUri}"); } // Creates the extent storage, being capable to load or store an extent var extentStorage = _map.CreateFor(_diScope, configuration); // Loads the extent var loadedExtent = extentStorage.LoadExtent(configuration, createAlsoEmpty); Debug.WriteLine($"- Loading: {configuration}"); if (loadedExtent == null) { throw new InvalidOperationException("Extent for configuration could not be loaded"); } AddToWorkspaceIfPossible(configuration, loadedExtent); // Stores the information into the data container var info = new ExtentStorageData.LoadedExtentInformation() { Configuration = configuration, Extent = loadedExtent }; lock (_data.LoadedExtents) { _data.LoadedExtents.Add(info); } return loadedExtent; }
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); } }