예제 #1
0
        /// <summary>
        /// Get a supported class from the connection. Resource is unlocked after the action called is ended.
        /// </summary>
        public static void Get <T, C>(string path, out Teple <LockShared, T> resource) where C : Connection <C>, IGetValue <T>, new()
        {
            _lock.Take();

            // get the type of connection
            Type sourceType = typeof(C);
            ArrayRig <IConnection> source;

            // check if there are currently any types of connections like this
            if (!_sources.TryGetValue(sourceType, out source))
            {
                // create the dictionary
                source = new ArrayRig <IConnection>();
                _sources[sourceType] = source;
            }

            // try get the connection
            C connection = source.GetSingle(c => c.Path == path) as C;

            // if the connection doesn't exist
            if (connection == null)
            {
                // create a new connection
                connection      = new C();
                connection.Path = path;
                // add to the source
                source.Add(connection);
            }

            // unlock the sources lock
            _lock.Release();

            // get the resource
            connection.Get(out resource);
        }
예제 #2
0
        /// <summary>
        /// Append the resource to the specified stream.
        /// </summary>
        public void CopyTo(Stream stream)
        {
            _lock.Take();

            if (_reset)
            {
                Load();
                if (_reset)
                {
                    _lock.Release();
                    Log.Warning("Stream wasn't able to be resolved '" + FullPath + "'.");
                    return;
                }
            }

            // copy the stream content
            _stream.CopyTo(stream);

            // the stream must be reloaded
            _reset = true;
            // release the lock
            _lock.Release();
        }
예제 #3
0
        /// <summary>
        /// Get a configuration by path synchronously/asynchronously.
        /// </summary>
        public static Configuration LoadConfig(string path)
        {
            // get the lock
            _lock.Take();

            // get the reference to the configuration
            WeakReferencer <Configuration> reference;

            if (!_configurations.TryGetValue(path, out reference))
            {
                reference = _configurations[path] = new WeakReferencer <Configuration>(new FuncSet <string, Configuration>(GetConfiguration, path));
            }

            Configuration config = reference.Item;

            // check if the configuration was loaded
            if (config.State != AssetState.Loaded)
            {
                config.Load();
            }

            _lock.Release();
            return(config);
        }