/// <summary> /// Create new or get existing sub-repo from the current repo. /// </summary> /// <remarks> /// When a sub-repo already exists the <paramref name="metadata"/> parameter is ignored. /// Returning existing repo is for convenience instead of throwing when a repo already exists. /// This call is idempotent and could be used at the beginning of a program many times. /// </remarks> /// <param name="newRepoName">Repo name inside the current repo.</param> /// <param name="metadata"> /// Optional metadata. Provide description with relevant keywords for easier full-text search. /// Provide tags that you could use for search filtering. /// </param> /// <returns></returns> public async ValueTask <Repo> CreateRepoAsync(string newRepoName, Metadata metadata = null) { var dataPath = _dataPathPrefix.Combine(newRepoName, true); var mdr = await _dataStore.MetadataManager.CreateRepoAsync(dataPath, metadata); if (mdr.PK == null) { mdr = await _dataStore.MetadataManager.GetMetadataRecordByPathAsync(dataPath); } if (mdr.PK != null) { var repo = new Repo(_dataStore, dataPath, mdr); return(repo); } throw new ArgumentException($"Cannot create a new Repo {dataPath}."); }
public void LoadTextResources(DataHub dataHub, Assembly assembly, Regex regex, DataPath?basePath = null) { var resourceNames = embeddedResourceUtils.GetLocalEmbeddedResourceNames(assembly, regex); foreach (var resourceName in resourceNames) { var content = embeddedResourceUtils.GetLocalEmbeddedResourceText(assembly, resourceName); var contentPath = new DataPath(regex.Match(resourceName).Groups[1].Value.Split('.')); var path = DataPath.Combine(basePath, contentPath); dataHub.Add(path, content); } }
public void Init() { var storePath = _parameters.Keys.Contains("file") ? Convert.ToString(_parameters.GetValuesForKey("file").First()):DefaultFileName; if (!Path.IsPathRooted(storePath)) { storePath = DataPath.Combine(storePath); } _storeFile = new FileInfo(storePath); _logger.NoticeFormat("Opening [{0}] Store...", _storeFile); _db = RaptorDB <string> .Open(_storeFile.FullName, false); }
private ServerListViewItem[] LoadDescriptors() { List <ServerDescription> rv; try { rv = XmlHelper.FromFile <List <ServerDescription> >(DataPath.Combine(descriptorFile)); } catch (Exception) { rv = Config.Descriptors; } return((from d in rv let i = new ServerListViewItem(httpServer, cacheFile, d) select i).ToArray()); }
private void AddJsonElementValuesToDataHub(DataHub dataHub, DataPath basePath, JsonElement jsonElement) { if (jsonElement.ValueKind == JsonValueKind.Object) { foreach (var jsonProperty in jsonElement.EnumerateObject()) { var path = DataPath.Combine(basePath, new DataPath(jsonProperty.Name)); AddJsonElementValuesToDataHub(dataHub, path, jsonProperty.Value); } } else { dataHub.Add(basePath, GetJsonElementValue(jsonElement)); } }
private void SaveConfig() { try { var descs = (from ServerListViewItem item in listDescriptions.Items select item.Description).ToArray(); var file = DataPath.Combine(descriptorFile + ".tmp"); XmlHelper.ToFile(descs, file); var outfile = DataPath.Combine(descriptorFile); File.Copy(file, outfile, true); File.Delete(file); } catch (Exception ex) { log.Error("Failed to write descriptors", ex); } Config.Save(); }
public void LoadJsonResources(DataHub dataHub, Assembly assembly, Regex regex, bool includeResourceName = true, DataPath?basePath = null) { var resourceNames = embeddedResourceUtils.GetLocalEmbeddedResourceNames(assembly, regex); foreach (var resourceName in resourceNames) { var content = embeddedResourceUtils.GetLocalEmbeddedResourceText(assembly, resourceName); var contentPath = new DataPath(regex.Match(resourceName).Groups[1].Value.Split('.')); var fullBasePath = includeResourceName ? DataPath.Combine(basePath, contentPath) : basePath ?? DataPath.Empty; using var jsonDocument = JsonDocument.Parse(content); AddJsonElementValuesToDataHub(dataHub, fullBasePath, jsonDocument.RootElement); } }