コード例 #1
0
ファイル: FileExtractor.cs プロジェクト: flippynips/EFZ
        /// <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();
            }
        }
コード例 #2
0
ファイル: SystemInformation.cs プロジェクト: flippynips/EFZ
        /// <summary>
        /// Get average statistics of the drive of the specified directory path. Resulting value units
        /// are bytes and per second.
        /// Note : This method writes a Megabyte to the Stream and then clears it.
        /// </summary>
        public static void GetStreamStats(string directory, out uint seeks, out uint writes, out uint reads)
        {
            // create a test file
            string filePath = ManagerResources.CreateFilePath(directory, ".drivetest");

            // get a stream to the created test file
            Teple <LockShared, ByteBuffer> resource;

            ManagerConnections.Get <ByteBuffer, ConnectionLocal>(filePath, out resource);

            ByteBuffer stream = resource.ArgB;

            // get a seek, read and write speed for the Author
            Timekeeper time = new Timekeeper();

            // write a Megabyte
            time.Start();
            stream.Write(Generic.Series <byte>((int)Global.Megabyte, 50));
            stream.Stream.Flush();
            time.Stop();

            // derive the number of bytes written per second
            writes = (uint)(Global.Megabyte / (time.Milliseconds / 1000));

            // perform a number of seeks
            time.Start();
            for (int i = 1000; i >= 0; --i)
            {
                stream.Position = 0;
                stream.Write((byte)0);
                stream.Stream.Flush();
                stream.Position = (long)Global.Megabyte - 1L;
                stream.Write((byte)0);
                stream.Stream.Flush();
            }
            time.Stop();

            // derive the number of seeks per second
            seeks           = (uint)(1000 / (time.Milliseconds / 1000));
            stream.Position = 0;

            // read the Megabyte
            time.Start();
            stream.ReadBytes((int)Global.Megabyte);
            stream.Stream.Flush();
            time.Stop();

            // derive the number of bytes read per second
            reads = (uint)(Global.Megabyte / (time.Milliseconds / 1000));

            // release the connection
            resource.ArgA.Release();

            // remove the files
            File.Delete(filePath);
        }
コード例 #3
0
ファイル: Configuration.cs プロジェクト: flippynips/EFZ
        /// <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;
            }
        }
コード例 #4
0
ファイル: Configuration.cs プロジェクト: flippynips/EFZ
        /// <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();
            }
        }
コード例 #5
0
ファイル: FileExtractor.cs プロジェクト: flippynips/EFZ
        /// <summary>
        /// Read addresses into the buffer for the crawlers to comsume.
        /// </summary>
        protected void Read(ByteBuffer reader)
        {
            // stop the timeout
            _timeout.Run = false;

            // read the next buffer
            int count = reader.ReadBytes(_buffer, 0, Global.BufferSizeLocal);

            // get the characters5
            count = Decoder.GetChars(_buffer, 0, count, _chars, 0);

            // run the parser
            _parser.Next(_chars, 0, count);

            // was the file finished?
            if (reader.Empty)
            {
                // yes, no longer running
                Running = false;

                // is the 'OnFile' callback set?
                if (OnFile != null)
                {
                    // yes, run
                    OnFile.ArgA = _files.Current;
                    OnFile.Run();
                }

                // read the next file
                Run();
            }
            else
            {
                // get the reader for the next buffer
                ManagerConnections.Get <ByteBuffer, ConnectionLocal>(_files.Current, new Act <ByteBuffer>(Read));
            }
        }