/// <summary> /// Initializes the meta data store. /// </summary> protected override void InitializeMetaDataStore() { // Values for adding a custom field to the metadata store List <FieldSchema> fields = new List <FieldSchema>(); SyncId id = ReplicaId; string replicaMetadataFile = _activeSyncSetting.replicaStoreFileName; // Create or open the metadata store, initializing it with the id formats we'll use to reference our items and endpoints if (!File.Exists(replicaMetadataFile)) { fields.Add(new FieldSchema(TIMESTAMP_COLUMNNAME, typeof(System.UInt64))); fields.Add(new FieldSchema(URI_COLUMNNAME, typeof(string), 1024)); _metaDataStore = SqlMetadataStore.CreateStore(replicaMetadataFile); _metaDataStore.InitializeReplicaMetadata(IdFormats, ReplicaId, fields, new IndexSchema[] { new IndexSchema(URI_COLUMNNAME, true) }); } else { _metaDataStore = SqlMetadataStore.OpenStore(replicaMetadataFile); } _metaData = _metaDataStore.GetReplicaMetadata(IdFormats, ReplicaId); //Если ReplicaId изменилась то необходимо пересоздать хранилище if (_metaData.ReplicaId != ReplicaId) { CloseMetaDataStore(); File.Delete(replicaMetadataFile); InitializeMetaDataStore(); } }
private void CloseMetadataStore() { if (_metadataStore != null) { _metadataStore.Dispose(); } _metadataStore = null; }
static void Main(string[] args) { System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; var interaction = new ConsoleUserInteraction(); interaction.ReportStatus("Placeless console app starting."); // add the framework services var services = new ServiceCollection() .AddLogging(); if (!System.IO.File.Exists(Path.Combine(AppContext.BaseDirectory, "appsettings.json"))) { interaction.ReportError("Missing config file: appsettings.json"); return; // exit app } string settingsFile = "appsettings.json"; #if DEBUG settingsFile = "appsettings.Development.json"; #endif var builder = new ConfigurationBuilder() .SetBasePath(Path.Combine(AppContext.BaseDirectory)) .AddJsonFile(settingsFile, optional: false); var configuration = builder.Build(); var config = new AspDotNetConfiguration(configuration); var blobStore = new FileSystemBlobStore(config); var store = new SqlMetadataStore(config, interaction, blobStore); var source = new FlickrSource(store, config, interaction); ////var generator = new Generator.Generator(store); ////generator.Generate(new CreatedYearAttributeGenerator()); ////generator.Generate(new MediumThumbnailGenerator()); var collector = new Collector <FlickrSource>(store, source, interaction); var discoveryTask = collector.Discover(); var rootPercent = collector.DiscoveredRoots == 0 ? 0 : 100 * collector.ProcessedRoots / collector.DiscoveredRoots; var filePercent = collector.DiscoveredFiles == 0 ? 0 : 100 * collector.ProcessedFiles / collector.DiscoveredFiles; while (!discoveryTask.Wait(1000)) { rootPercent = collector.DiscoveredRoots == 0 ? 0 : 100 * collector.ProcessedRoots / collector.DiscoveredRoots; filePercent = collector.DiscoveredFiles == 0 ? 0 : 100 * collector.ProcessedFiles / collector.DiscoveredFiles; System.Console.WriteLine($"Roots: {collector.ProcessedRoots}/{collector.DiscoveredRoots} ({rootPercent}%); Files: {collector.ProcessedFiles}/{collector.DiscoveredFiles} ({filePercent}%)"); } rootPercent = collector.DiscoveredRoots == 0 ? 0 : 100 * collector.ProcessedRoots / collector.DiscoveredRoots; filePercent = collector.DiscoveredFiles == 0 ? 0 : 100 * collector.ProcessedFiles / collector.DiscoveredFiles; System.Console.WriteLine($"Roots: {collector.ProcessedRoots}/{collector.DiscoveredRoots} ({rootPercent}%); Files: {collector.ProcessedFiles}/{collector.DiscoveredFiles} ({filePercent}%)"); }
void CloseMetadataStore() { if (_metadataStore == null) { return; } _metadataStore.Dispose(); _metadataStore = null; }
protected override void CommitTransaction() { if (_metaDataStore == null) { throw new ArgumentNullException("metadata store not initialized"); } SqlMetadataStore metaDataStore = _metaDataStore as SqlMetadataStore; metaDataStore.CommitTransaction(); }
internal void CloseMetadataStore() { if (_metadata != null) { _metadata = null; } if (_metadataStore != null) { _metadataStore.Dispose(); _metadataStore = null; } }
private void InitializeMetadataStore() { SyncId id = ReplicaId; if (!File.Exists(_replicaMetadataFile)) { _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); } }
private void InitializeMetadataStore() { SyncId id = ReplicaId; // Create or open the metadata store, initializing it with the id formats we'll use to reference our items and endpoints if (!File.Exists(_replicaMetadataFile)) { _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); } }
private void InitializeMetadataStore() { // Values for adding a custom field to the metadata store List <FieldSchema> fields = new List <FieldSchema>(); SyncId id = ReplicaId; // Create or open the metadata store, initializing it with the id formats we'll use to reference our items and endpoints if (!File.Exists(_replicaMetadataFile)) { fields.Add(new FieldSchema(TIMESTAMP_COLUMNNAME, typeof(System.UInt64))); _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); _metadata = _metadataStore.InitializeReplicaMetadata(_idFormats, _replicaId, fields, null /*No indexes to create*/); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); _metadata = _metadataStore.GetReplicaMetadata(_idFormats, _replicaId); } }
private void btnNewDatabase_Click(object sender, RoutedEventArgs e) { string connectionString = getConnectionString(); string rootPath = SqlMetadataStore.GetSqlPath(connectionString); var createDatabaseForm = new CreateDatabase(rootPath); if (createDatabaseForm.ShowDialog().GetValueOrDefault()) { SqlMetadataStore.CreateDatabase(connectionString, createDatabaseForm.DatabaseName, createDatabaseForm.DatabaseFile, createDatabaseForm.LogFile ); _config.SetValue(FileSystemBlobStore.BLOB_ROOT_PATH, System.IO.Path.Combine(rootPath, createDatabaseForm.DatabaseName + "_Files")); } }
public void InitializeMetadataStore() { List<FieldSchema> fields = new List<FieldSchema>(); if (!File.Exists(_replicaMetadataFile)) { fields.Add(new FieldSchema(ID_COLUMNNAME, typeof(string), idLength)); fields.Add(new FieldSchema(PATH_COLUMNNAME, typeof(string), pathLength)); _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); var indexes = new List<IndexSchema>{ new IndexSchema(ID_COLUMNNAME, false) }; _metadata = _metadataStore.InitializeReplicaMetadata(_idFormats, new SyncId(Guid.NewGuid()), fields, indexes); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); _metadata = _metadataStore.GetSingleReplicaMetadata(); } ReplicaId = _metadata.ReplicaId; }
public void InitializeMetadataStore() { List <FieldSchema> fields = new List <FieldSchema>(); if (!File.Exists(_replicaMetadataFile)) { fields.Add(new FieldSchema(ID_COLUMNNAME, typeof(string), idLength)); fields.Add(new FieldSchema(PATH_COLUMNNAME, typeof(string), pathLength)); _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); var indexes = new List <IndexSchema> { new IndexSchema(ID_COLUMNNAME, false) }; _metadata = _metadataStore.InitializeReplicaMetadata(_idFormats, new SyncId(Guid.NewGuid()), fields, indexes); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); _metadata = _metadataStore.GetSingleReplicaMetadata(); } ReplicaId = _metadata.ReplicaId; }
private void CreateMetadataStore( string metadataFilePath ) { if (metadataFilePath == null) { throw new ArgumentNullException("metadataFilePath"); } SqlMetadataStore result; // Create or open the metadata store, initializing it with the ID formats // that are used to reference items and replicas. if (!File.Exists(metadataFilePath)) { result = SqlMetadataStore.CreateStore(metadataFilePath); } else { result = SqlMetadataStore.OpenStore(metadataFilePath); } _metadataStore = result; }
private void CloseMetadataStore() { _metadataStore.Dispose(); _metadataStore = null; }
private void wizDatabaseCreate_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e) { var createDatabaseTask = new Task(() => { try { using (var localDB = new SqlLocalDbApi()) { ReportStatus("Searching for Localdb instance", 1); ReportStatus("Checking default Instance", 2); var connected = false; string instance = localDB.DefaultInstanceName; List <string> instanceNames = new List <string>(localDB.GetInstanceNames()); instanceNames = instanceNames.Where(n => n != instance).ToList(); // only non-default instances SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); int iInstance = 0; while (!connected) { builder.DataSource = $"(LocalDb)\\{instance}"; builder.InitialCatalog = "Master"; builder.IntegratedSecurity = true; ReportStatus($"Connecting to {instance}", 2); var con = new SqlConnection(builder.ConnectionString); try { con.Open(); connected = true; } catch { connected = false; if (iInstance >= instanceNames.Count) { ReportStatus("Error: No LocalDb database instances could be connected to.", 0); return; } instance = instanceNames[iInstance]; iInstance++; } } ReportStatus($"Successfully connected to {instance}", 20); string databaseName = "Placeless"; int i = 0; var databaseNames = getDatabaseList(builder.ConnectionString); string mdf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.mdf"); string ldf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.ldf"); ReportStatus($"Selecting a unique database name", 30); while ( System.IO.File.Exists(mdf) || System.IO.File.Exists(ldf) || databaseNames.Contains(databaseName) ) { i++; databaseName = $"Placeless{i:D2}"; mdf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.mdf"); ldf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.ldf"); } ReportStatus($"Creating database {databaseName}.", 35); ReportStatus($"Data File: {mdf}", 35); ReportStatus($"Log File: {ldf}", 35); SqlMetadataStore.CreateDatabase(builder.ConnectionString, databaseName, mdf, ldf); builder.InitialCatalog = databaseName; ReportStatus($"Database Created, migrating", 80); var _dbContextOptions = SqlServerDbContextOptionsExtensions.UseSqlServer( new DbContextOptionsBuilder(), builder.ConnectionString, options => options.CommandTimeout(120) ).Options; using (var dbContext = new ApplicationDbContext(_dbContextOptions)) { dbContext.Database.Migrate(); } ReportStatus($"Migrations executed, updating config", 90); _config.SetValue(SqlMetadataStore.CONNECTION_STRING_SETTING, builder.ConnectionString); _config.SetValue(FileSystemBlobStore.BLOB_ROOT_PATH, System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}_Files")); ReportStatus($"Configuration Updated", 100); this.Invoke((MethodInvoker) delegate { wizardControl1.NextPage(); }); } } catch (Exception ex) { this.Invoke((MethodInvoker) delegate { txtCreateDatabaseOutput.Text += ex.Message + "\r\n"; txtCreateDatabaseOutput.Text += ex.StackTrace + "\r\n"; }); } }, TaskCreationOptions.LongRunning); createDatabaseTask.Start(); }
private void InitializeMetadataStore() { // Create or open the metadata store, initializing it with the id formats we'll use to reference our items and endpoints _metadataStore = !File.Exists(_replicaMetadataFile) ? SqlMetadataStore.CreateStore(_replicaMetadataFile) : SqlMetadataStore.OpenStore(_replicaMetadataFile); }
private void InitializeMetadataStore() { // Values for adding a custom field to the metadata store List<FieldSchema> fields = new List<FieldSchema>(); SyncId id = ReplicaId; // Create or open the metadata store, initializing it with the id formats we'll use to reference our items and endpoints if (!File.Exists(_replicaMetadataFile)) { fields.Add(new FieldSchema(TIMESTAMP_COLUMNNAME, typeof(System.UInt64))); _metadataStore = SqlMetadataStore.CreateStore(_replicaMetadataFile); _metadata = _metadataStore.InitializeReplicaMetadata(_idFormats, _replicaId, fields, null/*No indexes to create*/); } else { _metadataStore = SqlMetadataStore.OpenStore(_replicaMetadataFile); _metadata = _metadataStore.GetReplicaMetadata(_idFormats, _replicaId); } }