예제 #1
0
        private static void LoadConfig(string path, Act <Configuration> onLoad, bool takeLock)
        {
            // get the lock
            if (takeLock && !(takeLock = _lock.TryTake))
            {
                _lock.TryLock(new Act <string, Act <Configuration>, bool>(LoadConfig, path, onLoad, false));
                return;
            }

            // 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)
            {
                onLoad.ArgA = config;
            }
            else
            {
                config.Load(onLoad);
            }

            if (takeLock)
            {
                _lock.Release();
            }
        }
예제 #2
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);
        }
예제 #3
0
 /// <summary>
 /// Try and get the pocket value.
 /// </summary>
 public void TryGet(IAction <A> onGet)
 {
     _lock.TryLock(new Act <IAction <A> >(OnAvailable, onGet));
 }
예제 #4
0
 /// <summary>
 /// Non-blocking method of getting the web resource stream. Only use immediate IActions.
 /// </summary>
 public void GetStream(IAction <Stream, Lock> onStream)
 {
     _lock.TryLock(ActionSet.New(OnGetStream, onStream), null, false);
 }