/// <summary> /// Adds a new Collection. /// </summary> /// <param name="type">The type must be of type ADatabaseCollection</param> /// <returns>The created Collection</returns> /// <exception cref="Exception"></exception> public ADatabaseCollection Add(Type type) { if (Collections.ContainsKey(type)) { throw new Exception($"Database already contains a collection for type [{type}]"); } if (!type.IsSubclassOf(typeof(ADatabaseCollection))) { throw new Exception($"[{type}] must be of type DatabaseCollection"); } var newCollection = (ADatabaseCollection)Activator.CreateInstance(type); if (newCollection.DefaultValues != null) { foreach (var i in newCollection.DefaultValues) { newCollection.Add(i.Value); } } Collections.Add(type, newCollection); return(newCollection); }
/// <summary> /// Gets a template record using Record Object /// </summary> /// <param name="recordID">The Record Object</param> /// <returns>The referenced template record or null if not found</returns> public Template GetTemplate(ARecord recordID) { if (!Collections.ContainsKey(recordID.Collection)) { throw new ArgumentOutOfRangeException($"Database does not contain a collection for type {recordID.Collection}"); } return(Collections[recordID.Collection].Get(recordID.ID)); }
private IMongoCollection <T> GetCollection(IDatabaseSettings dbSettings = null) { if (dbSettings == null) { dbSettings = new DatabaseSettings() { CollectionName = typeof(T).Name, ConnectionString = Environment.GetEnvironmentVariable("MONGO_URI"), DatabaseName = Environment.GetEnvironmentVariable("MONGO_DB"), }; } string key = string.Format("{0}/{1}.{2}", dbSettings.ConnectionString.TrimEnd('/'), dbSettings.DatabaseName, dbSettings.CollectionName); object collection = null; _collecionLocker.EnterReadLock(); try { if (Collections.ContainsKey(key)) { collection = Collections[key]; } else { _collecionLocker.ExitReadLock(); _collecionLocker.EnterWriteLock(); try { if (!Collections.ContainsKey(key)) { IMongoDatabase database = GetDatabase(dbSettings); if (database.GetCollection <T>(typeof(T).Name) == null) { database.CreateCollection(typeof(T).Name); } collection = database.GetCollection <T>(typeof(T).Name); Collections.Add(key, collection); } collection = Collections[key]; } finally { _collecionLocker.ExitWriteLock(); } } } finally { if (_collecionLocker.IsReadLockHeld) { _collecionLocker.ExitReadLock(); } } return(collection as IMongoCollection <T>); }
/// <summary> /// Deletes a collection with given name or throws an arango exception /// </summary> /// <exception cref="ArangoException"></exception> public void DeleteCollection(string collectionName) { if (!Collections.ContainsKey(collectionName)) { throw new ArangoException(404, 1203, "collection or view not found"); } Collections.Remove(collectionName); }
/// <summary> /// Returns a collection by name or throws an arango exception /// </summary> /// <exception cref="ArangoException"></exception> public Collection GetCollection(string collectionName) { if (!Collections.ContainsKey(collectionName)) { throw new ArangoException(404, 1203, "collection or view not found"); } return(Collections[collectionName]); }
protected override Resource _create( string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Collections.NameValuePairList createParams ) { string paramSyntax = string.Empty; string paramType = string.Empty; if ( createParams == null || createParams.ContainsKey( "syntax" ) == false || createParams.ContainsKey( "type" ) == false ) { throw new AxiomException( "You must supply 'syntax' and 'type' parameters" ); } else { paramSyntax = createParams[ "syntax" ]; paramType = createParams[ "type" ]; } CreateGpuProgramDelegate iter = null; if ( this._programMap.ContainsKey( paramSyntax ) ) { iter = this._programMap[ paramSyntax ]; } else { // No factory, this is an unsupported syntax code, probably for another rendersystem // Create a basic one, it doesn't matter what it is since it won't be used return new GLES2GpuProgram( this, name, handle, group, isManual, loader ); } GpuProgramType gpt; if ( paramType == "vertex_program" ) { gpt = GpuProgramType.Vertex; } else { gpt = GpuProgramType.Fragment; } return iter( this, name, handle, group, isManual, loader, gpt, paramSyntax ); }
public bool IsCollectionVisibleFor(string collectionName) { bool result = false; try { if (Collections.ContainsKey(collectionName)) { result = Collections[collectionName]; } } catch { } return(result); }
public static long CurrentCollectionSize() { if (!hakchi.Shell.IsOnline) { return(-1); } if (ConfigIni.Instance.SeparateGameStorage) { if (Collections.ContainsKey(ConfigIni.Instance.ConsoleType)) { return(Collections[ConfigIni.Instance.ConsoleType]); } return(0); } return(NonMultibootGamesSize); }
/// <summary> /// Creates new collection of given type or throws an arango exception /// </summary> /// <exception cref="ArangoException"></exception> public Collection CreateCollection( string collectionName, CollectionType type ) { if (Collections.ContainsKey(collectionName)) { throw new ArangoException(409, 1207, "duplicate name"); } ArangoUtils.ValidateCollectionName(collectionName); Collections[collectionName] = new Collection(collectionName, type); return(Collections[collectionName]); }
/// <summary> /// Gets a Database Collection By Type /// </summary> /// <param name="type">The Database Collection Type</param> /// <returns>The Database Collection</returns> public ADatabaseCollection Get(Type type) { if (type == null) { throw new ArgumentNullException("A Database Collection Type must not be NULL"); } if (!type.IsSubclassOf(typeof(ADatabaseCollection))) { throw new ArgumentException($"Type {type} is not a Database Collection Type"); } if (!Collections.ContainsKey(type)) { throw new ArgumentOutOfRangeException($"Database does not contain a collection for type {type}"); } return(Collections[type]); }
public async Task <AzureCosmosCollection> GetCollectionAsync(string containerName) { containerName = ResolveCollectionName(containerName); await Semaphore.WaitAsync(); try { if (!Collections.ContainsKey(containerName)) { var result = await CreateCollectionAsync(containerName); Collections.Add(containerName, new AzureCosmosCollection(result.Container, Settings)); } return(Collections[containerName]); } finally { Semaphore.Release(); } }
public bool LoadCollection <T>() where T : UnifiedIMObject <T> { if (!Collections.ContainsKey(typeof(T))) { string col = UnifiedCollectionAttribute.GetCollection <T>(); if (string.IsNullOrEmpty(col)) { throw new Exception($"Missing UnifiedCollectionAttribute on type {typeof(T).Name}"); } RegisterClass <T>(); UnifiedIMDerivesAttribute derived = UnifiedIMDerivesAttribute.GetAttribute <T>(); if (derived != null) { foreach (Type type in derived.Derived) { Method.CallGeneric(typeof(BsonClassMap).GetMethod("RegisterClassMap", new Type[] { }), null, new Type[] { type }); } } Collections.Add(typeof(T), mongo.GetCollection <T>(col)); } return(true); }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="handle"></param> /// <param name="group"></param> /// <param name="isManual"></param> /// <param name="loader"></param> /// <param name="createParams"></param> /// <returns></returns> protected override Resource _create( string name, ulong handle, string group, bool isManual, IManualResourceLoader loader, Collections.NameValuePairList createParams ) { if ( createParams == null || !createParams.ContainsKey( "syntax" ) || !createParams.ContainsKey( "type" ) ) { throw new NotImplementedException( "You must supply 'syntax' and 'type' parameters" ); } GpuProgramType gpt = 0; CreateGpuProgramDelegate iter = _programMap[ createParams[ "syntax" ] ]; if ( iter == null ) { return null; } string syntaxcode = string.Empty; foreach ( KeyValuePair<string, CreateGpuProgramDelegate> pair in _programMap ) if ( pair.Value == iter ) { syntaxcode = pair.Key; break; } if ( createParams[ "type" ] == "vertex_program" ) { gpt = GpuProgramType.Vertex; } else if ( createParams[ "type" ] == "fragment_program" ) { gpt = GpuProgramType.Fragment; } else { throw new AxiomException( "Unknown GpuProgramType : " + createParams[ "type" ] ); } return iter( this, name, handle, group, isManual, loader, gpt, syntaxcode ); }