public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { base.Initialize(name, config); _appName = ProviderUtil.GetAppName(config); _connectionString = ProviderUtil.GetConnectionString(config); ProviderUtil.CheckUnrecognizedAttributes(config); }
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { base.Initialize(name, config); _connectionString = ProviderUtil.GetConnectionString(config); this.WorldName = ProviderUtil.GetAndRemoveStringAttribute(config, "worldName"); ProviderUtil.CheckUnrecognizedAttributes(config); }
protected override void ProcessRecord() { Database db = Client.NosDB.InitializeDatabase(ProviderUtil.GetConnectionString(_databaseName)); Collection <JSONDocument> collection = db.GetCollection(_collectionName); RecoveryOperationStatus status = collection.Export(_databaseName, _collectionName, Query, _queryParam, Path, FileName, _dataType); if (status.Status == RecoveryStatus.Success) { WriteObject("Exported successfully"); } else { WriteObject("failed to export data " + status.Message); } db.Dispose(); }
protected override void BeginProcessing() { ConfigurationConnection.UpdateClusterConfiguration(); List <string> shards = new List <string>(ConfigurationConnection.ClusterConfiguration.Deployment.Shards.Keys); if (shards == null || shards.Count == 0) { throw new Exception("No shard exist"); } if (string.IsNullOrEmpty(Shard)) { Shard = shards[0]; } else if (!shards.Contains(Shard)) { throw new Exception("Specified shard doesn't exist"); } _collectionName = GetCollectionName(Shard); string[] paramArray = null; NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } //NodeDetail thisNode; if (new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode)) { if (thisNode.NodeType.Equals(PathType.Database)) { if (_drop) { _databaseName = thisNode.NodeName; _connectionString = ProviderUtil.GetConnectionString(_databaseName); _database = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString); ConfigurationConnection.UpdateClusterConfiguration(); if (((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection( _collectionName)) { String query = "DROP COLLECTION $" + _collectionName + "$ {\"Database\":\"" + thisNode.NodeName + "\"}"; _database.ExecuteNonQuery(query); Thread.Sleep(5000); ConfigurationConnection.UpdateClusterConfiguration(); } } else { _databaseName = thisNode.NodeName; _connectionString = ProviderUtil.GetConnectionString(_databaseName); _database = Alachisoft.NosDB.Client.NosDB.InitializeDatabase(_connectionString); ConfigurationConnection.UpdateClusterConfiguration(); pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode); if (!((DatabaseConfiguration)thisNode.Configuration).Storage.Collections.ContainsCollection( _collectionName)) { String query = "CREATE COLLECTION $" + _collectionName + "$ {\"Database\":\"" + thisNode.NodeName + "\", \"Shard\": \"" + Shard + "\"}"; try { _database.ExecuteNonQuery(query); } catch (Exception e) { if (!e.Message.Contains("Collection with name: " + _collectionName + " already exists")) { throw e; } } do { Thread.Sleep(2000); ConfigurationConnection.UpdateClusterConfiguration(); pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); new NoSDbDetail(pathChunks, s1.Drive.Current).TryGetNodeDetail(out thisNode); } while ( !((DatabaseConfiguration)thisNode.Configuration).Storage.Collections .ContainsCollection( _collectionName)); } } } else { throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress."); } } } else { throw new Exception("You must be in NosDB:\\databasecluster\\databases\\database> for Test-Stress."); } }
protected override void BeginProcessing() { if (Query.Equals(string.Empty) && InputFile.Equals(string.Empty)) { throw new Exception("Invoke the command with argument Query|InputFile"); } if (Query != string.Empty && InputFile != string.Empty) { throw new Exception("The Query and the InputFile options are mutually exclusive"); } string dbName = string.Empty; NodeDetail thisNode = null; SessionState s1 = this.SessionState; string[] pathChunks = ProviderUtil.SplitPath(s1.Path.CurrentLocation.Path, (PSDriveInfo)s1.Drive.Current); if (s1.Drive.Current is NosDBPSDriveInfo) { if (ConfigurationConnection.ConfigCluster == null) { throw new Exception(ProviderUtil.CONFIG_NOT_CONNECTED_EXCEPTION); } new NoSDbDetail(pathChunks, (PSDriveInfo)s1.Drive.Current).TryGetNodeDetail(out thisNode); if (thisNode is IDatabaseContext) { dbName = ((IDatabaseContext)thisNode).DatabaseName; _databaseContext = true; } else { dbName = "$sysdb"; } //conString = "nosdb://" + ConfigurationConnection.Current.ConfigServerIP + ":" + // ConfigurationConnection.Current.Port + "/" + // ConfigurationConnection.ClusterConfiguration.Name + "/" + dbName; bool localInstance; if (ConfigurationConnection.ClusterConfiguration.Name.Equals("local", StringComparison.InvariantCultureIgnoreCase)) { localInstance = true; } else { localInstance = false; } conString = ProviderUtil.GetConnectionString(dbName); //conString = "Data Source=" + ConfigurationConnection.Current.ConfigServerIP + ";" + "Port=" + // ConfigurationConnection.Current.Port + ";" + "Database=" + dbName + ";" + "Local Instance="+localInstance+";"; } if (InputFile != string.Empty) { if (!File.Exists(InputFile)) { throw new Exception("Input file does't exist"); } string text = File.ReadAllText(InputFile); text = text.Replace("\r\n", ""); queryArr = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); } }