private void OnProfile(DataProfile profile) { Debug.Log(profile.Name); Model.StartGame(profile); View.Disable(); }
public DataConfigurationTests() { var roles = new DataProfile<Role>(() => new Role()) .ForMember(x => x.Id, (r) => Guid.NewGuid()) .GenerateForEach(_dataConfiguration, _roleNames, (name, role) => role.Name = name).ToList(); var products = new DataProfile<Product>(() => new Product()) .ForMember(x => x.Id, (r) => Guid.NewGuid()) .ForMember(x=>x.Amount, new DecimalRandomValueCreator(5, 500)) .GenerateForEach(_dataConfiguration, _productNames, (name, product) => product.Name = name).ToList(); _dataConfiguration = new DataConfiguration(); _dataConfiguration.CreateProfileFor(() => new OrderItem()) .ForMember(x => x.Product, new CollectionItemValueCreator<Product>(products)) .ForMember(x => x.Quantity, new IntRandomValueCreator(1, 10)); _dataConfiguration.CreateProfileFor(() => new Order()) .ForMember(x => x.CreatedOn, (x) => DateTime.UtcNow) .FollowPath(x => x.Items, 1, (o) => new OrderItem(o)); _dataConfiguration.CreateProfileFor(() => new User()) .FollowPath(x => x.Role) .ForMember(x => x.Id, (u) => Guid.NewGuid()) .ForMember(x => x.FirstName, new RandomStringValueCreator(4, 8)) .ForMember(x => x.Surname, new CollectionItemValueCreator<string>(_names)) .ForMember(x => x.Role, new CollectionItemValueCreator<Role>(roles)) .ForMember(x => x.LogonCount, new IntRandomValueCreator(1, 200)) .FollowPath(x => x.Orders, 3, 200, (u) => new Order(u)); }
public void Setup(DataProfile dataProfile, DataProfile.SubProfile dataSubProfile) { profile = dataProfile; subProfile = dataSubProfile; RedrawPreviewImg(); }
/// <summary> /// Updates the graph with a new data point. /// </summary> /// <param name="newData">New data.</param> public void UpdateData(DataProfile newData) { var newDataIndex = _refreshCursorPosition; var newDataValue = newData.Value; InvokeOnMainThread(() => { _data[newDataIndex].Value = newDataValue; }); }
public Aggregator(KeyValuePair <int, string> projectInfo) { this.downloadQueue = new BlockingCollection <Task <string> >(); this.killSwitch = false; this.projectInfoPair = projectInfo; this.dataProfile = null; this.processingTask = AggregateData(); }
/// <summary> /// Процедура запуска начала игровой сессии. /// </summary> public void StartGame(DataProfile worldProfile) { Storage.SetLocal(worldProfile); InitializeData(); LoadWorld("world"); }
public void Constructor_ProfileDirectory_AppDataPathTest() { var profile = new DataProfile("test"); var provider = new DataProvider(profile, Application.dataPath); Assert.AreEqual(Application.dataPath + "/test/", provider.RootFolder); }
/// <summary> /// Dequeues the data and writes into the filesystem. /// </summary> /// <param name="q">Q.</param> public void PopAndWrite(Queue <DataProfile> q) { _log.DebugFormat("Writing data into file. Queue Count: {0}", q.Count); while (q.Count != 0) { DataProfile data = q.Dequeue(); //_fileManagementModel.WriteToFile(data).Wait(); } }
void Start() { DontDestroyOnLoad(gameObject); for(int i = 0 ; i < ProfilesLoaded.Length; i++) { ProfilesLoaded[i] = new DataProfile("empty"); ProfilesLoaded[i].LoadProfile(i); } }
static HomeController() { var profile = new ProfileResolver(); var sampleProfile = new DataProfile<SampleItem>(() => new SampleItem()) .ForMember(x => x.Name, new RandomStringValueCreator(4, 8)) .ForMember(x => x.Group, new RandomStringValueCreator(4, 8)) .Generate(profile, 2050); _demoItems = sampleProfile.ToList(); }
static HomeController() { var profile = new ProfileResolver(); var sampleProfile = new DataProfile <SampleItem>(() => new SampleItem()) .ForMember(x => x.Name, new RandomStringValueCreator(4, 8)) .ForMember(x => x.Group, new RandomStringValueCreator(4, 8)) .Generate(profile, 2050); _demoItems = sampleProfile.ToList(); }
public DataProfile GetProfile(RequestProfile request) { try { DataProfile dataProfile = new DataProfile(); using (WantgoProdEntities ctx = new WantgoProdEntities()) { var query = (from u in ctx.usuario join pa in ctx.pais on u.id_Pais equals pa.id_Pais join per in ctx.perfil on u.id_usuario equals per.id_usuario into Perfil from pe in Perfil.DefaultIfEmpty() where u.id_usuario == request.UserId select new DataProfile { UserId = u.id_usuario, Names = pe.nombre_usuario, UserName = u.usuario1, Sex = u.Sexo, PhoneNumber = u.telefono, Email = u.correo, Description = pe.descripcion, UserPhoto = u.foto_Perfil, CountryPhoto = pa.ruta_logo, CountryDeal = pa.deal_Pais.ToString() }).FirstOrDefault(); if (query != null) { dataProfile = query; dataProfile.ListPreferences = new List <string>(); var preferences = (from p in ctx.preferencias_usuario join pre in ctx.preferencias on p.id_Preferencias equals pre.id_Preferencias where p.id_usuario == query.UserId select pre).ToList(); foreach (var item in preferences) { dataProfile.ListPreferences.Add(item.descripcion); } } } return(dataProfile); } catch (Exception ex) { throw; } }
private void uiComboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { uiComboBox2.Items.Clear(); if (uiComboBox1.SelectedItem != null) { selectedProfile = (DataProfile)uiComboBox1.SelectedItem.Value; textBox1.Text = selectedProfile.Desc; foreach (DataProfile.SubProfile sProfile in selectedProfile.SubProfiles) { uiComboBox2.Items.Add(new UIComboBoxItem(sProfile.Name, sProfile)); } uiComboBox2.SelectedIndex = 0; } else { textBox1.Text = ""; } }
public void Read_Profile_Ok() { string json = LoadProfile("SampleProfile.json"); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(json); // facets Assert.Single(profile.Facets); FacetDefinition facetDef = profile.Facets[0]; Assert.Equal("facet-default", facetDef.Id); Assert.Equal("default", facetDef.Label); Assert.Equal("The default facet", facetDef.Description); Assert.Equal("FF0000", facetDef.ColorKey); Assert.Equal(7, facetDef.PartDefinitions.Count); // TODO: check each facet definition // flags Assert.Single(profile.Flags); FlagDefinition flagDef = profile.Flags[0]; Assert.Equal(1, flagDef.Id); Assert.Equal("to revise", flagDef.Label); Assert.Equal("The item must be revised.", flagDef.Description); Assert.Equal("F08080", flagDef.ColorKey); // thesauri Assert.Equal(2, profile.Thesauri.Length); Thesaurus thesaurus = Array.Find(profile.Thesauri, t => t.Id == "categories@en"); Assert.NotNull(thesaurus); Assert.Equal(16, thesaurus.GetEntries().Count); // TODO: check each entry thesaurus = Array.Find(profile.Thesauri, t => t.Id == "languages@en"); Assert.NotNull(thesaurus); Assert.Equal(8, thesaurus.GetEntries().Count); // TODO: check each entry }
/// <summary> /// Creates the database. /// </summary> /// <param name="source">The database source.</param> /// <param name="profile">The database profile.</param> /// <exception cref="ArgumentNullException">null source or profile /// </exception> public void CreateDatabase(string source, DataProfile profile) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (profile == null) { throw new ArgumentNullException(nameof(profile)); } EnsureClientCreated(source); // store facets, flags, and tag sets IMongoDatabase db = Client.GetDatabase(GetDatabaseName(source)); if (profile.Facets?.Length > 0) { var collFacets = db.GetCollection <MongoFacetDefinition>( MongoFacetDefinition.COLLECTION); collFacets.InsertMany(profile.Facets.Select( f => new MongoFacetDefinition(f))); } if (profile.Flags?.Length > 0) { var collFlags = db.GetCollection <MongoFlagDefinition>( MongoFlagDefinition.COLLECTION); collFlags.InsertMany(profile.Flags .Select(f => new MongoFlagDefinition(f))); } if (profile.Thesauri?.Length > 0) { var collSets = db.GetCollection <MongoThesaurus>( MongoThesaurus.COLLECTION); collSets.InsertMany(profile.Thesauri .Select(s => new MongoThesaurus(s))); } // add indexes CreateIndexes(db); }
private void PrepareDatabase() { // create or clear MongoDatabaseManager manager = new MongoDatabaseManager(); if (manager.DatabaseExists(CONNECTION)) { manager.ClearDatabase(CONNECTION); } else { DataProfile profile = new DataProfile { Facets = new FacetDefinition[] { new FacetDefinition { Id = "default", ColorKey = "303030", Description = "Default facet", Label = "default", PartDefinitions = new List <PartDefinition> { new PartDefinition { ColorKey = "F08080", Description = "Hierarchy", GroupKey = "general", IsRequired = true, Name = "hierarchy", SortKey = "hierarchy", TypeId = new HierarchyPart().TypeId } } } } }; manager.CreateDatabase(CONNECTION, profile); } }
private static async Task SeedCadmusDatabaseAsync( IServiceProvider serviceProvider, IConfiguration config, ILogger logger) { // build connection string string connString = config.GetConnectionString("Default"); string databaseName = config["DatabaseNames:Data"]; if (string.IsNullOrEmpty(databaseName)) { return; } connString = string.Format(connString, databaseName); // nope if database exists IDatabaseManager manager = new MongoDatabaseManager(); if (manager.DatabaseExists(connString)) { return; } // load seed profile (nope if no profile) string profileSource = config["Seed:ProfileSource"]; if (string.IsNullOrEmpty(profileSource)) { return; } Console.WriteLine($"Loading seed profile from {profileSource}..."); logger.LogInformation($"Loading seed profile from {profileSource}..."); ResourceLoaderService loaderService = new ResourceLoaderService(serviceProvider); Stream stream = await loaderService.LoadAsync(profileSource); if (stream == null) { Console.WriteLine("Error: seed profile could not be loaded"); return; } // deserialize the profile string profileContent; using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { profileContent = reader.ReadToEnd(); } IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); // issue warning on invalid profile Console.WriteLine("Validating profile..."); string error = profile.Validate(); if (error != null) { logger.LogWarning(error); } // create database Console.WriteLine("Creating database..."); logger.LogInformation($"Creating database {connString}..."); manager.CreateDatabase(connString, profile); Console.WriteLine("Database created."); logger.LogInformation("Database created."); // get the required services Console.WriteLine("Creating seeders factory..."); Serilog.Log.Information("Creating seeders factory..."); IPartSeederFactoryProvider seederService = serviceProvider.GetService <IPartSeederFactoryProvider>(); PartSeederFactory factory = seederService.GetFactory( loaderService.ResolvePath(profileSource)); Console.WriteLine("Creating repository..."); Serilog.Log.Information("Creating repository..."); IRepositoryProvider repositoryProvider = serviceProvider.GetService <IRepositoryProvider>(); ICadmusRepository repository = repositoryProvider.CreateRepository(databaseName); // get seed count int count = 0; string configCount = config["Seed:ItemCount"]; if (configCount != null && int.TryParse(configCount, out int n)) { count = n; } // if required, seed data if (count > 0) { Console.WriteLine($"Seeding {count} items..."); CadmusSeeder seeder = new CadmusSeeder(factory); foreach (IItem item in seeder.GetItems(count)) { Console.WriteLine($"{item}: {item.Parts.Count} parts"); repository.AddItem(item, true); foreach (IPart part in item.Parts) { repository.AddPart(part, true); } } Console.WriteLine("Seeding completed."); } // import data if required IList <string> sources = factory.GetImports(); if (sources?.Count > 0) { PartImporter importer = new PartImporter(repository); foreach (string source in sources) { foreach (string resolved in SourceRangeResolver.Resolve(source)) { Console.WriteLine($"Importing from {resolved}..."); using Stream jsonStream = await loaderService.LoadAsync(resolved); importer.Import(jsonStream); } } } }
public void DataUpdate(byte[] data, DataType type, SensorDevice senderDevice) { var senderDeviceType = senderDevice.Type; // Create a new list with a collection for each data type for holding incoming data. var incomingData = new Dictionary <DataType, List <DataProfile> >(); foreach (DataType dataType in ValidSensorDataTypes) { incomingData.Add(dataType, new List <DataProfile>()); } var outputID = Tuple.Create(senderDevice.SlotIndex, type).GetHashCode(); //_log.Debug($"{senderDevice.SlotIndex}"); // Parse incoming data. if (senderDeviceType == DeviceType.Stroke) { if (type == DataType.accl) { try { for (int i = 0; i < 4; i++) { outputID = Tuple.Create(senderDevice.SlotIndex, DataType.accl_z).GetHashCode(); incomingData[DataType.accl_z].Add(new DataProfile(type, _dataTime[outputID]++, (Int16)((data[1 + i * 6] << 8) | data[0 + i * 6]))); outputID = Tuple.Create(senderDevice.SlotIndex, DataType.accl_x).GetHashCode(); incomingData[DataType.accl_x].Add(new DataProfile(type, _dataTime[outputID]++, (Int16)((data[3 + i * 6] << 8) | data[2 + i * 6]))); outputID = Tuple.Create(senderDevice.SlotIndex, DataType.accl_y).GetHashCode(); incomingData[DataType.accl_y].Add(new DataProfile(type, _dataTime[outputID]++, (Int16)((data[5 + i * 6] << 8) | data[4 + i * 6]))); } } catch (IndexOutOfRangeException) { _log.Error($"Invalid data range received from device {senderDevice.SlotIndex}. Count: {data.Length} Data: {string.Join(" ", data)}"); if (senderDevice.SlotIndex >= 0) { DataErrorCount[senderDevice.SlotIndex]++; } return; } catch (KeyNotFoundException) { _log.Error($"Invalid key detected for device {senderDevice.SlotIndex}. Keys in scope: outputID {outputID}"); if (senderDevice.SlotIndex >= 0) { DataErrorCount[senderDevice.SlotIndex]++; } return; } } } //Task.Run(async () => await _dataLoggingService.WritePackage(incomingData, senderDeviceType)); //_dataLoggingService.AddCollectionAsync(incomingData, senderDeviceType); // DataRefreshPointers for each data collection of data points. foreach (KeyValuePair <DataType, List <DataProfile> > incomingDataforType in incomingData) { DataType dataType = incomingDataforType.Key; List <DataProfile> dataPoints = incomingDataforType.Value; outputID = Tuple.Create(senderDevice.SlotIndex, dataType).GetHashCode(); if (dataPoints.Count > 0) { // The Limit of the databuffer queue. int queueDataPointLimit = _blePacketLimit * NumDataPointsPerPacket[dataType] / (int)DownSamplingRate[dataType]; // If the downsampling amount was specified. (i.e. accl_z) if (DownSamplingRate[dataType] > 1) { // Calculate how many data points should be left after the downsampling. int numOfDownsampledDataPoints = NumDataPointsPerPacket[dataType] / (int)DownSamplingRate[dataType]; for (int i = 0; i < dataPoints.Count; i += (int)DownSamplingRate[dataType]) { int dataCount = Math.Min((int)DownSamplingRate[dataType], dataPoints.Count - i); var partialData = dataPoints.GetRange(i, dataCount); if (partialData.Count <= 0) { continue; } DataProfile downsampledData = partialData[partialData.Count - 1]; // Remove a datapoint from the queue if it's beyond the databuffer queue point limit. if (GraphDataBuffer[outputID].Count > queueDataPointLimit) { GraphDataBuffer[outputID].TryDequeue(out DataProfile dequeuedData); } // Add the new downsampled data. GraphDataBuffer[outputID].Enqueue(downsampledData); } DataProfile downsample = dataPoints[dataPoints.Count - 1]; // Remove a datapoint from the queue if it's beyond the databuffer queue point limit. if (GraphDataBuffer[outputID].Count > queueDataPointLimit) { GraphDataBuffer[outputID].TryDequeue(out DataProfile dequeuedData); } // Add the new downsampled data. GraphDataBuffer[outputID].Enqueue(downsample); } // Else the downsampling amount was not specified. else { foreach (var dataPoint in dataPoints) { // Remove a datapoint from the queue if it's beyond the databuffer queue point limit. if (GraphDataBuffer[outputID].Count > queueDataPointLimit) { GraphDataBuffer[outputID].TryDequeue(out DataProfile dequeuedData); } // Add the new data point. GraphDataBuffer[outputID].Enqueue(dataPoint); } } } } var timeStamp = ((data[27] << 24) | (data[26] << 16) | (data[25] << 8) | data[24]) / 4.0; _dataLoggingService.UpdateTimeStamp(timeStamp); }
public void LoadVisualization(DataProfile dataProfile, DataProfile.SubProfile subProfile, IDataSourceReader dataSrcReader, DataSourceInfo dataSrcInfo) { renderFrame = true; renderingThread.Start(); controlStatus = ControlStatus.Loading; rContext.LoadingLayer.SetProgress(0); rContext.LoadingLayer.SetText("Loading... DEM Geometry"); rContext.LoadingLayer.Visible = true; Render(); // load data from dlg into database database = new RasterDatabase.RasterDatabase(); object filteredData = subProfile.Filter.FilterData(dataSrcReader); if (filteredData is byte[]) { DataLayer dataLayer = new DataLayer("DEM", 8, "byte"); dataLayer.AddArea(new ByteArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution), new RectangleF(0, 0, 1, 1), (byte[])filteredData, dataSrcReader.Info.Resolution)); database.AddLayer(dataLayer); } else if (filteredData is float[]) { DataLayer dataLayer = new DataLayer("DEM", 32, "float"); dataLayer.AddArea(new FloatArea(new Rectangle(new Point(), dataSrcReader.Info.Resolution), new RectangleF(0, 0, 1, 1), (float[])filteredData, dataSrcReader.Info.Resolution)); database.AddLayer(dataLayer); } // load data source(s) DataSourceItem item = new DataSourceItem(dataSrcInfo.BppType, (Bitmap)PreviewRasterizer.DrawRotatedBandPreview(dataSrcInfo.Bands, 64, dataSrcInfo)); heightDataSrcs.Add(item); // load diffuse sources // grey-scale for height GreyScaleDEMSampler srcImgSampler = new GreyScaleDEMSampler(); Bitmap srcImg = srcImgSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0]); item = new DataSourceItem("Height", srcImg); item.DEMSampler = srcImgSampler; //(Bitmap)PreviewRasterizer.DrawRotatedBandPreview(new DataSourceInfo.DataBandInfo[] { new DataSourceInfo.DataBandInfo("Source", srcImg) }, //64, null)); diffuseDataSrcs.Add(item); // load colour image if possible as other source (i.e the original if an RGB img) if (dataSrcReader.Info.SupportsRGB()) { item = new DataSourceItem("SourceRGB", SourceDataDiffuseSampler.SampleRGBDiffuseMap((GDALReader)dataSrcReader, new Size(64, 64))); diffuseDataSrcs.Add(item); reader = (GDALReader)dataSrcReader; } // height band range HeightBandRange hbr = new HeightBandRange(); hbr.AddBand(0, Color.DarkGreen); hbr.AddBand(0.25f, Color.Blue); hbr.AddBand(0.4f, Color.DarkGreen); hbr.AddBand(0.5f, Color.Green); hbr.AddBand(0.8f, Color.Gray); hbr.AddBand(1, Color.White); HeightBandDEMSampler hBandSampler = new HeightBandDEMSampler(hbr); item = new DataSourceItem("HeightBands", hBandSampler.GenerateBitmap(new Size(64, 64), database.Layers[0].Areas[0])); item.DEMSampler = hBandSampler; diffuseDataSrcs.Add(item); // load database into visualization dem = new DigitalElevationMap(database.Area.Size, database, rContext.DevIf, (GDALReader)dataSrcReader/*, * hBandSampler.GenerateBitmap(new Size(512, 512), * database.Layers[0].Areas[0])*/ ); rContext.SetDEM(dem); // setup geometry layers geometryLayers.Add(new GeometryVisLayer("Diffuse", item.Thumbnail, true)); geometryLayers.Add(new GeometryVisLayer("Overlay Grid", null, true)); rContext.DevIf.LocalSettings["GeometryVisLayer.Diffuse"] = geometryLayers[0]; rContext.DevIf.LocalSettings["GeometryVisLayer.Overlay"] = geometryLayers[1]; // now load default texture SetDiffuseSource(0); rContext.LoadingLayer.SetProgress(100); Render(); Thread.Sleep(500); rContext.LoadingLayer.Visible = false; controlStatus = ControlStatus.Idle; Render(); }
public void OnProfileClick(DataProfile profile) { OnProfile(profile); }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("IMPORT JSON TEXT AND APPARATUS\n"); Console.ResetColor(); Console.WriteLine( $"Text dir: {_txtFileDir}\n" + $"Text mask: {_txtFileMask}\n" + $"Apparatus dir: {_appFileDir}\n" + $"Profile file: {_profilePath}\n" + $"Database: {_database}\n" + $"Dry run: {_dry}\n"); ILoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddSerilog(Log.Logger); Log.Logger.Information("IMPORT JSON TEXT AND APPARATUS"); if (!_dry) { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profilePath); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, profile); Console.WriteLine("Database created."); Log.Information("Database created."); } } else { if (!File.Exists(_profilePath)) { string error = "Profile path not found: " + _profilePath; Console.WriteLine(error); Log.Error(error); return(Task.CompletedTask); } } ICadmusRepository repository = _repositoryService.CreateRepository(_database); JsonImporter importer = new JsonImporter(repository) { Logger = loggerFactory.CreateLogger("json-importer"), IsDry = _dry }; int inputFileCount = 0; // 1) import text string[] files = FileEnumerator.Enumerate( _txtFileDir, _txtFileMask, _regexMask).ToArray(); HashSet <string> fileNames = new HashSet <string>(); Console.WriteLine($"Importing text from {files.Length} file(s)..."); foreach (string txtFilePath in files) { fileNames.Add( StripFileNameNr( Path.GetFileNameWithoutExtension(txtFilePath))); Console.WriteLine(txtFilePath); inputFileCount++; using (Stream stream = new FileStream(txtFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportText(stream); } } // 2) import apparatus Console.WriteLine("Importing apparatus..."); foreach (string fileName in fileNames) { Console.WriteLine(fileName); foreach (string appFilePath in Directory.EnumerateFiles( _appFileDir, fileName + "-app_*.json")) { Console.WriteLine(" " + appFilePath); using (Stream stream = new FileStream(appFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { importer.ImportApparatus(stream); } } } return(Task.CompletedTask); }
public void CopyTo(DataProfile target) { gameData.CopyTo(target.gameData); gameSetting.CopyTo(target.gameSetting); }
public Task Run() { Console.WriteLine("IMPORT DATABASE\n" + $"Input directory: {_inputDir}\n" + $"Database: {_database}\n" + $"Profile file: {_profileText}\n" + $"Preflight: {(_preflight? "yes" : "no")}"); Serilog.Log.Information("IMPORT DATABASE: " + $"Input directory: {_inputDir}, " + $"Database: {_database}, " + $"Profile file: {_profileText}, " + $"Preflight: {_preflight}"); try { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profileText); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); _profile = serializer.Read(profileContent); if (!_preflight) { if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Serilog.Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, _profile); Console.WriteLine("Database created."); Serilog.Log.Information("Database created."); } } Console.WriteLine("Creating repository..."); Serilog.Log.Information("Creating repository..."); ICadmusRepository repository = _repositoryService.CreateRepository(_database); foreach (string lexFile in Directory.GetFiles(_inputDir, "??.xml").OrderBy(s => s)) { XDocument doc = XDocument.Load(lexFile, LoadOptions.PreserveWhitespace); if (doc.Root == null) { continue; } foreach (XElement itemElement in doc.Root.Elements("item")) { // read essential metadata string id = itemElement.Attribute("id").Value; string sid = itemElement.Attribute("sid").Value; string lemma = itemElement.Element("lemma").Value; int hom = GetHomographNumber(itemElement); int flags = itemElement.ReadOptionalAttribute("flags", 0); // TODO parent... // item Item item = new Item { Id = id, Title = BuildWordKey(lemma, hom), Description = BuildItemDescription(itemElement), FacetId = "facet-lex-word", SortKey = sid, UserId = USERID, Flags = flags }; Console.WriteLine(item.Title); // read parts // first remove all the _bm so we don't accidentally include metatext XElement filtered = XElement.Parse(itemElement.ToString(SaveOptions.DisableFormatting), LoadOptions.PreserveWhitespace); foreach (XElement bm in filtered.Descendants("_bm").ToList()) { bm.Remove(); } ReadParts(filtered, item); if (!_preflight) { repository.AddItem(item, false); foreach (IPart part in item.Parts) { repository.AddPart(part, false); } } } } Console.WriteLine(" completed."); Serilog.Log.Information("Import completed"); return(Task.FromResult(0)); } catch (Exception ex) { Serilog.Log.Error(ex, ex.Message); throw; } }
public Task Run() { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("SEED DATABASE\n"); Console.ResetColor(); Console.WriteLine($"Database: {_database}\n" + $"Profile file: {_profilePath}\n" + $"Count: {_count}\n" + $"Dry run: {_dry}\n" + $"History: {_history}\n"); Serilog.Log.Information("SEED DATABASE: " + $"Database: {_database}, " + $"Profile file: {_profilePath}, " + $"Count: {_count}, " + $"Dry: {_dry}, " + $"History: {_history}"); if (!_dry) { // create database if not exists string connection = string.Format(CultureInfo.InvariantCulture, _config.GetConnectionString("Mongo"), _database); IDatabaseManager manager = new MongoDatabaseManager(); string profileContent = LoadProfile(_profilePath); IDataProfileSerializer serializer = new JsonDataProfileSerializer(); DataProfile profile = serializer.Read(profileContent); if (!manager.DatabaseExists(connection)) { Console.WriteLine("Creating database..."); Serilog.Log.Information($"Creating database {_database}..."); manager.CreateDatabase(connection, profile); Console.WriteLine("Database created."); Serilog.Log.Information("Database created."); } } Console.WriteLine("Creating repository..."); Serilog.Log.Information("Creating repository..."); ICadmusRepository repository = _dry ? null : _repositoryService.CreateRepository(_database); Console.WriteLine("Seeding items"); PartSeederFactory factory = _seederService.GetFactory(_profilePath); CadmusSeeder seeder = new CadmusSeeder(factory); foreach (IItem item in seeder.GetItems(_count)) { Console.WriteLine($"{item}: {item.Parts.Count} parts"); if (!_dry) { repository.AddItem(item, _history); foreach (IPart part in item.Parts) { repository.AddPart(part, _history); } } } Console.WriteLine("Completed."); return(Task.CompletedTask); }
string[] AddProfile(DataProfile profile) => (string[])BotSpawn?.CallHook("CreateNewProfile", "DynamicPVP", profile);