/// <summary> /// Begin reading the files. /// </summary> public void Run() { _lock.Take(); // is the extraction already running? yes, skip if (Running) { // did a connection timeout? if (_timeout.Run) { // no, interrupted _lock.Release(); return; } // nullify connection if (_connection != null) { _connection.Close(); _connection = null; } // notify of the connection timeout Log.Warning("Connection to file was unable to be established '" + _files.Current + "'."); } // no, start running Running = true; // are there more files? if (_files.Dequeue()) { // yes, get a parser for the file _parser = Extractor.GetParser(); // reset the decoder Decoder.Reset(); // reset timeout _timeout.Reset(Timeout); _connection = null; _lock.Release(); // get a reader for the next file ManagerConnections.Get <ConnectionLocal>(_files.Current, new Act <ConnectionLocal>(OnConnection)); } else { // no, is the callback set? run if (OnComplete != null) { OnComplete.Run(); } _lock.Release(); } }
/// <summary> /// Load the configuration inline if the callback is null. /// </summary> public void Load(IAction <Configuration> onLoad = null) { _lock.Take(); // check state switch (State) { case AssetState.Unloaded: case AssetState.Broken: State = AssetState.Loading; // inline load or callback? if (onLoad == null) { // no callback so load immediately // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.OpenOrCreate; connection.FileAccess = System.IO.FileAccess.Read; // get the stream Teple <LockShared, ByteBuffer> resource; connection.Get(out resource); // run load logic OnLoad(resource.ArgB); resource.ArgA.Release(); } else { _onLoad += onLoad; // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.OpenOrCreate; connection.FileAccess = System.IO.FileAccess.Read; // callback load connection.Get(new Act <ByteBuffer>(OnLoad)); } break; case AssetState.Loading: _onLoad += onLoad; _lock.Release(); break; default: _lock.Release(); onLoad.ArgA = this; onLoad.Run(); break; } }
//-------------------------------------------// /// <summary> /// On connection. /// </summary> protected void OnConnection(ConnectionLocal connection) { // reset the timeout _timeout.Reset(Timeout); // persist the connection _connection = connection; // get a stream to the connection _connection.Get(new Act <ByteBuffer>(Read)); }
/// <summary> /// Save the configuration. /// </summary> public void Save(Act <Configuration> onSave = null) { _lock.Take(); if (State.Is(AssetState.Loaded) || State.Is(AssetState.Unloaded)) { State = AssetState.Saving; if (onSave == null) { // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.Truncate; connection.FileAccess = System.IO.FileAccess.Write; connection.FileShare = System.IO.FileShare.Read; // get the stream Teple <LockShared, ByteBuffer> resource; connection.Get(out resource); // run save logic OnSave(resource.ArgB); resource.ArgA.Release(); } else { onSave.ArgA = this; // get the connection ConnectionLocal connection = ManagerConnections.Get <ConnectionLocal>(_path); // ensure the file modes are right connection.FileMode = System.IO.FileMode.Create; connection.FileAccess = System.IO.FileAccess.Write; // callback save connection.Get(new Act <ByteBuffer>(new ActionPair <ByteBuffer>(OnSave, s => onSave.Run()))); } } else { _lock.Release(); } }