Exemplo n.º 1
0
        ///<summary>
        /// Find the next occurence of the byte pattern. Works asynchronously.
        ///</summary>
        public IAsyncResult FindNext(AsyncCallback ac)
        {
            if (dataBook.NPages == 0 || inUse)
            {
                FindNextOperation op = new FindNextOperation(strategy, null, FindAsyncCallback);
                return(HandleProblematicOp(op, ac));
            }

            inUse = true;

            userFindAsyncCallback = ac;
            findFinishedEvent.Reset();

            // if this is the first time we are checking
            // for a valid pattern, emit the event
            if (firstTime == true && strategy.Pattern.Length > 0)
            {
                firstTime = false;
                if (FirstFind != null)
                {
                    FirstFind();
                }
            }     // is pattern acceptable?
            else if (strategy.Pattern.Length == 0)
            {
                return(null);
            }

            DataView dv = ((DataViewDisplay)dataBook.CurrentPageWidget).View;

            strategy.Buffer = dv.Buffer;

            // decide where to start searching from
            if (!dv.Selection.IsEmpty())
            {
                strategy.Position = dv.Selection.Start + 1;
            }
            else
            {
                strategy.Position = dv.CursorOffset;
            }

            SetUpFindProgressReport();


            FindNextOperation fno = new FindNextOperation(strategy, progressCallback, FindAsyncCallback);

            // lock the buffer, so user can't modify it while
            // searching
            strategy.Buffer.ModifyAllowed         = false;
            strategy.Buffer.FileOperationsAllowed = false;

            // start find thread
            Thread findThread = new Thread(fno.OperationThread);

            findThread.IsBackground = true;
            findThread.Start();

            return(new ThreadedAsyncResult(fno, findFinishedEvent, false));
        }
Exemplo n.º 2
0
        public KeyValuePair <IData, IData>?FindNext(IData key)
        {
            var operation = new FindNextOperation(key);

            Execute(operation);

            return(operation.KeyValue);
        }
Exemplo n.º 3
0
        private void WriteFindNextOperation(BinaryWriter writer, FindNextOperation operation)
        {
            KeyPersist.Write(writer, operation.FromKey);
            writer.Write(operation.KeyValue.HasValue);

            if (operation.KeyValue.HasValue)
            {
                KeyPersist.Write(writer, operation.KeyValue.Value.Key);
                RecordPersist.Write(writer, operation.KeyValue.Value.Value);
            }
        }
Exemplo n.º 4
0
        void FindNextAsyncCallback(IAsyncResult ar)
        {
            ThreadedAsyncResult tar = (ThreadedAsyncResult)ar;

            FindNextOperation state = (FindNextOperation)tar.AsyncState;

            if (state.Result == FindNextOperation.OperationResult.Finished && state.Match == null)
            {
                InformationAlert ia = new InformationAlert(Catalog.GetString("The pattern you requested was not found."), Catalog.GetString("End of file reached."), mainWindow);
                ia.Run();
                ia.Destroy();
            }
        }
Exemplo n.º 5
0
        void FindNextAsyncCallback(IAsyncResult ar)
        {
            ThreadedAsyncResult tar = (ThreadedAsyncResult)ar;

            FindNextOperation state = (FindNextOperation)tar.AsyncState;

            if (state.Result == FindNextOperation.OperationResult.Finished && state.Match == null)
            {
                InformationAlert ia = new InformationAlert("The pattern you requested was not found.", "End of file reached.", null);
                ia.Run();
                ia.Destroy();
            }

            this.Sensitive = true;
            this.Visible   = false;
            this.Visible   = true;
        }