Ejemplo n.º 1
0
        private static void Get <T, C>(string path, IAction <T> onResource, Needle needle, bool tryLock) where C : Connection <C>, IGetValue <T>, new()
        {
            // get the lock
            if (tryLock && !(tryLock = _lock.TryTake))
            {
                _lock.TryLock(new ActionSet <string, IAction <T>, Needle, bool>(Get <T, C>, path, onResource, needle, false));
                return;
            }

            // 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)
            {
                // initialize a new connection
                connection      = new C();
                connection.Path = path;
                // add to connections
                source.Add(connection);
            }

            // unlock
            if (tryLock)
            {
                _lock.Release();
            }

            // get the resource
            connection.Get(onResource);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }