Inheritance: ICloneable
        public void give_document_with_5_words_execute_ReadNextWord_3_times_assume_result_equals_3d_word_from_doc()
        {
            var reader = new DocumentReader();

            reader.Load("Abc, ght. TTTk    fgh   lkj  ");
            reader.ReadNextWord();
            reader.ReadNextWord();

            Assert.Equal("TTTk", reader.ReadNextWord());
        }
Exemplo n.º 2
0
        public void _synth_SpeakProgressTest()
        {
            DocumentReader dr = new DocumentReader();

            dr.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(dr_PropertyChanged);

            // Set up a document
            var doc    = new FlowDocument();
            var line01 = new Run("Hey");
            var line02 = new Run("Yo there");
            var line03 = new Run("");
            var line04 = new Run("I'm good");

            doc.Blocks.Add(new Paragraph(line01));
            doc.Blocks.Add(new Paragraph(line02));
            doc.Blocks.Add(new Paragraph(line03));
            doc.Blocks.Add(new Paragraph(line04));

            readWords = new Dictionary <TextPointer, string>();

            dr.StartReading(doc.ContentStart);

            DateTime startTime = DateTime.Now;
            TimeSpan timeout   = new TimeSpan(0, 0, 30);

            while (dr.State != ReaderState.NotSpeaking && DateTime.Now.Subtract(startTime).CompareTo(timeout) < 0)
            {
                Thread.Sleep(new TimeSpan(0, 0, 2));
            }
            if (dr.State != ReaderState.NotSpeaking)
            {
                Assert.Inconclusive("Reader didn't stop in time, so inconclusive.");
            }
            if (readWords.Count != 6)
            {
                Assert.Fail("Too meny or few words read");
            }
            // tests that it is ral words
            // don't really test that it read the right words.
            foreach (var word in readWords)
            {
                if (!word.Key.IsInSameDocument(doc.ContentStart))
                {
                    Assert.Fail("Return an invalid word");
                }

                char[] textBuffer = new char[word.Value.Length];
                word.Key.GetTextInRun(LogicalDirection.Forward, textBuffer, 0, word.Value.Length);
                var value = new String(textBuffer);
                if (word.Value != value)
                {
                    Assert.Fail("Read a wrong word");
                }
            }
        }
Exemplo n.º 3
0
        private object InterpretDocument(Document document)
        {
            if (document == null)
            {
                return(null);
            }

            DocumentReader documentReader = new DocumentReader(document);

            return(DebugInfo.tachyProg.Eval(documentReader));
        }
Exemplo n.º 4
0
        public void ReaderTest1()
        {
            DummyRender render = new DummyRender();
            Document    doc    = new Document();

            doc.LayoutLines.Render = render;
            doc.Append("a");
            DocumentReader reader = doc.CreateReader();

            Assert.IsTrue(reader.Read() == 'a');
            Assert.IsTrue(reader.Peek() == -1);
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        DocumentReader reader = new DocumentReader(new Uri("http://bbc.co.uk"));

        reader.PrintPageData();

        DocumentReader readerClone = reader.Clone() as DocumentReader;

        readerClone.PrintPageData();

        Console.ReadKey();
    }
Exemplo n.º 6
0
        public override void Load(DocumentReader reader)
        {
            base.Load(reader);
            Name = reader.ReadString();
            int count = reader.ReadInt();

            for (int i = 0; i < count; i++)
            {
                Drawable item = reader.ReadPersistable <Drawable>();
                items.Add(item);
            }
        }
Exemplo n.º 7
0
        public void OnCompleted(int action, DocumentReaderResults results, string error)
        {
            if (action == DocReaderAction.Complete)
            {
                if (loadingDialog != null && loadingDialog.IsShowing)
                {
                    loadingDialog.Dismiss();
                }

                //Checking, if nfc chip reading should be performed
                if (doRfid && results != null && results.ChipPage != 0)
                {
                    if (DocumentReader.Instance().ProcessParams.RfidScenario == null)
                    {
                        DocumentReader.Instance().ProcessParams.RfidScenario = new RfidScenario();
                    }

                    //setting the chip's access key - mrz on car access number
                    string accessKey = null;
                    if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStrings)) != null && !String.IsNullOrEmpty(accessKey))
                    {
                        accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtMrzStrings).Replace("^", "");
                        DocumentReader.Instance().ProcessParams.RfidScenario.Mrz = accessKey;
                        DocumentReader.Instance().ProcessParams.RfidScenario.PacePasswordType = ERFID_Password_Type.PptMrz;
                    }
                    else if ((accessKey = results.GetTextFieldValueByType(EVisualFieldType.FtCardAccessNumber)) != null && !String.IsNullOrEmpty(accessKey))
                    {
                        DocumentReader.Instance().ProcessParams.RfidScenario.Password = accessKey;
                        DocumentReader.Instance().ProcessParams.RfidScenario.PacePasswordType = ERFID_Password_Type.PptCan;
                    }

                    //starting chip reading
                    DocumentReader.Instance().StartRFIDReader(this);
                }
                else
                {
                    DisplayResults(results);
                }
            }
            else
            {
                //something happened before all results were ready
                if (action == DocReaderAction.Cancel)
                {
                    Toast.MakeText(this, "Scanning was cancelled", ToastLength.Long).Show();
                }
                else if (action == DocReaderAction.Error)
                {
                    Toast.MakeText(this, "Error:" + error, ToastLength.Long).Show();
                }
            }
        }
        public void CanGenerateSolutionWithExternalDefineConstants()
        {
            DocumentReader sol          = generator.Reader;
            const string   constantName = "MY_EXTERNAL_DEFINE_CONSTANT";

            generator.GenerateSolution("everything", new [] { constantName }, null);

            string projectDir  = Path.Combine(sol.SolutionConfigDir, "MyModule");
            string projectPath = Directory
                                 .GetFiles(projectDir, "*.csproj").First(f => Path.GetFileName(f).Contains("MyModule"));

            Assert.Contains(constantName, File.ReadAllText(projectPath));
        }
Exemplo n.º 9
0
 /* ----------------------------------------------------------------- */
 ///
 /// Count
 ///
 /// <summary>
 /// Gets the number of pages.
 /// </summary>
 ///
 /* ----------------------------------------------------------------- */
 private int Count(string src, string password, int degree)
 {
     using (var reader = new DocumentReader(src, password))
     {
         Assert.That(reader.File.Count, Is.EqualTo(reader.Pages.Count()));
         Assert.That(
             reader.Pages.Select(e => e.Rotation.Degree),
             Is.EquivalentTo(Enumerable.Repeat(degree, reader.File.Count)),
             nameof(Page.Rotation)
             );
         return(reader.File.Count);
     }
 }
Exemplo n.º 10
0
        /* ----------------------------------------------------------------- */
        ///
        /// ExtractImages
        ///
        /// <summary>
        /// Extracts images from the specified PDF document.
        /// </summary>
        ///
        /* ----------------------------------------------------------------- */
        private KeyValuePair <int, int> ExtractImages(IProgress <Message <int> > progress)
        {
            var query   = new Query <string>(e => throw new NotSupportedException());
            var options = new OpenOption {
                IO = IO, FullAccess = true
            };

            using (var reader = new DocumentReader(Source, query, options))
            {
                ExtractImages(reader, progress);
                return(KeyValuePair.Create(reader.Pages.Count(), _core.Count));
            }
        }
Exemplo n.º 11
0
        private void PageNumberTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != Key.Enter)
            {
                return;
            }

            int pageNumber;

            if (int.TryParse(PageNumberTextBox.Text, out pageNumber))
            {
                DocumentReader.GoToPage(pageNumber);
            }
        }
Exemplo n.º 12
0
        protected void InitReader()
        {
            var bytes = default(byte[]);

            using (var streamReader = new StreamReader(Assets.Open("regula.license")))
            {
                using var memstream = new MemoryStream();
                streamReader.BaseStream.CopyTo(memstream);
                bytes = memstream.ToArray();
            }

            initDialog = ShowDialog("Initializing");
            DocumentReader.Instance().InitializeReader(this, new DocReaderConfig(bytes), this);
        }
        protected void InitReader()
        {
            var bytes = default(byte[]);

            using (var streamReader = new StreamReader(Android.App.Application.Context.Assets.Open("regula.license")))
            {
                using (var memstream = new MemoryStream())
                {
                    streamReader.BaseStream.CopyTo(memstream);
                    bytes = memstream.ToArray();
                }
            }

            DocumentReader.Instance().InitializeReader(Android.App.Application.Context, bytes, this);
        }
Exemplo n.º 14
0
        private string[] ReadNextSegment()
        {
            string segment = DocumentReader.ReadLine((char)EDIDelimiters.SegmentDelimiter, true);

            if (string.IsNullOrEmpty(segment))
            {
                return(null);
            }

            CurrentSegment = segment;

            CurrentSegmentNumber++;

            return(segment.Split((char)EDIDelimiters.FieldSeperator));
        }
Exemplo n.º 15
0
        public int Save(string filename, string password, int degree)
        {
            var src  = GetSource(filename);
            var dest = Path(Args(filename));

            using (var w = new DocumentWriter(IO))
                using (var r = new DocumentReader(src, password))
                {
                    w.UseSmartCopy = true;
                    w.Set(r.Metadata);
                    w.Set(r.Encryption);
                    w.Add(Rotate(r.Pages, degree));
                    w.Save(dest);
                }
            return(Count(dest, password, degree));
        }
Exemplo n.º 16
0
        public void ReaderTest2()
        {
            DummyRender render = new DummyRender();
            Document    doc    = new Document();

            doc.LayoutLines.Render = render;
            doc.Append("abc");
            DocumentReader reader = doc.CreateReader();

            char[] buf   = new char[2];
            int    count = reader.Read(buf, 1, 2);

            Assert.IsTrue(buf[0] == 'b' && buf[1] == 'c');
            Assert.IsTrue(count == 2);
            Assert.IsTrue(reader.Peek() == -1);
        }
        public void given_test_sentence_read_to_the_end_assume_number_of_words_equals_25()
        {
            var document = "The big brown fox number 4 jumped over the lazy dog. THE BIG BROWN FOX JUMPED OVER THE LAZY DOG. The Big Brown Fox 123.";
            var reader   = new DocumentReader();

            reader.Load(document);

            var counter = 0;

            while (!string.IsNullOrWhiteSpace(reader.ReadNextWord()))
            {
                counter++;
            }

            Assert.Equal(25, counter);
        }
Exemplo n.º 18
0
        public void Extract() => Open("SampleRotation.pdf", "", vm =>
        {
            Destination = Get(Args("Sample"));
            Assert.That(IO.Exists(Destination), Is.False, Destination);

            vm.Value.Images.Skip(1).First().Selected = true;
            vm.Value.Images.First().Selected         = true;
            Assert.That(Wait.For(() => vm.Ribbon.Extract.Command.CanExecute()));

            vm.Test(vm.Ribbon.Extract);

            using (var r = new DocumentReader(Destination))
            {
                Assert.That(r.GetPage(1).GetViewSize().Width, Is.EqualTo(595.0f).Within(1.0f));
                Assert.That(r.GetPage(2).GetViewSize().Width, Is.EqualTo(842.0f).Within(1.0f));
            }
        });
Exemplo n.º 19
0
        public int Merge(string f0, string f1, int degree)
        {
            var r0   = new DocumentReader(GetSource(f0), "", false, IO);
            var r1   = new DocumentReader(GetSource(f1), "", false, IO);
            var dest = Path(Args(r0.File.BaseName, r1.File.BaseName));

            using (var w = new DocumentWriter(IO))
            {
                foreach (var p in r0.Pages)
                {
                    w.Add(Rotate(p, degree), r0);
                }
                w.Add(Rotate(r1.Pages, degree), r1);
                w.Save(dest);
            }
            return(Count(dest, "", degree));
        }
Exemplo n.º 20
0
        public int Merge_Image(string doc, string image, int degree)
        {
            var r0   = new DocumentReader(GetSource(doc), "", false, IO);
            var dest = Path(Args(r0.File.BaseName, IO.Get(image).BaseName));

            using (var w = new DocumentWriter(IO))
                using (var r = new DocumentReader(GetSource(doc), "", false, IO))
                {
                    foreach (var p in r0.Pages)
                    {
                        w.Add(Rotate(p, degree));
                    }
                    w.Add(Rotate(IO.GetImagePages(GetSource(image)), degree));
                    w.Save(dest);
                }
            return(Count(dest, "", degree));
        }
Exemplo n.º 21
0
        protected override void OnResume()
        {
            base.OnResume();

            var bytes = default(byte[]);

            using (var streamReader = new StreamReader(Assets.Open("regula.license")))
            {
                using (var memstream = new MemoryStream())
                {
                    streamReader.BaseStream.CopyTo(memstream);
                    bytes = memstream.ToArray();
                }
            }

            initDialog = showDialog("Initializing");
            DocumentReader.Instance().InitializeReader(this, bytes, this);
        }
Exemplo n.º 22
0
        public int Overwrite(string filename, string password, int degree)
        {
            var dest = Path(Args(filename));

            IO.Copy(GetSource(filename), dest, true);

            var r = new DocumentReader(dest, password, false, IO);

            using (var w = new DocumentWriter(IO))
            {
                w.UseSmartCopy = false;
                w.Set(r.Metadata);
                w.Set(r.Encryption);
                w.Add(Rotate(r.Pages, degree), r);
                w.Save(dest);
            }
            return(Count(dest, password, degree));
        }
Exemplo n.º 23
0
        private void NightMode_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (DocumentReader == null)
            {
                return;
            }

            _state.NightMode = !_state.NightMode;
            _mainWindowViewModel.NightMode = _state.NightMode;
            if (_state.NightMode)
            {
                DocumentReader.SetNightMode();
            }
            else
            {
                DocumentReader.SetDayMode();
            }
        }
Exemplo n.º 24
0
        public void Render(string filename, int pagenum, double ratio, int width, int height)
        {
            var src  = GetSource(filename);
            var dest = Get($"{IO.Get(src).BaseName}-{pagenum}.png");

            using (var reader = new DocumentReader(GetSource(filename)))
            {
                var page = reader.GetPage(pagenum);
                using (var image = reader.Render(page, ratio))
                {
                    Assert.That(image.Width, Is.EqualTo(width));
                    Assert.That(image.Height, Is.EqualTo(height));
                    image.Save(dest, ImageFormat.Png);
                }
            }

            Assert.That(IO.Exists(dest), Is.True);
        }
Exemplo n.º 25
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == Result.Ok)
            {
                //Image browsing intent processed successfully
                if (requestCode == REQUEST_BROWSE_PICTURE && data.Data != null)
                {
                    var selectedImage = data.Data;
                    var bmp           = GetBitmap(selectedImage, 1920, 1080);

                    loadingDialog = showDialog("Processing image");

                    DocumentReader.Instance().StopScanner(this);
                    DocumentReader.Instance().RecognizeImage(bmp, this);
                }
            }
        }
Exemplo n.º 26
0
        private void _btnImport1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                DocumentReader reader = new DocumentReader(_txtPwd.Text);
                reader.LoadFromFile(dialog.FileName);

                ClearState state = reader.State;

                SecurityCenterDocument2 doc2 = new SecurityCenterDocument2();
                IterateDoc1Group(doc2, state.ClearGroup);

                Program.ThePassword = _txtPwd.Text;
                Program.CurrentDoc  = doc2;
                FormAction.Instance.OnDocLoaded(doc2);
                FormAction.Instance.OnStateChanged();
            }
        }
Exemplo n.º 27
0
        public MainWindowViewModel(ReadDocumentManager docsMan)
        {
            // Add commandbindings
            _reader = new DocumentReader();
            _reader.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_reader_PropertyChanged);

            _commandBindings = new CommandBindingCollection();

            CommandBinding NewCmdBinding = new CommandBinding(
                ApplicationCommands.New, (t, e) => _docsMan.Add());

            this.CommandBindings.Add(NewCmdBinding);

            CommandBinding PlayCmdBinding = new CommandBinding(
                MediaCommands.Play, PlayCmdExecuted, PlayCmdCanExecute);

            this.CommandBindings.Add(PlayCmdBinding);

            CommandBinding PauseCmdBinding = new CommandBinding(
                MediaCommands.Pause, PauseCmdExecuted, PauseCmdCanExecute);

            this.CommandBindings.Add(PauseCmdBinding);

            CommandBinding StopCmdBinding = new CommandBinding(
                MediaCommands.Stop, (t, e) => _reader.StopReading());

            this.CommandBindings.Add(StopCmdBinding);


            _docsMan = docsMan;
            _rdvms   = new ObservableCollection <ReadDocumentViewModel>();

            //The easiest way to republate the viewmodel is to call the delegate that manages the changes
            MainWindowViewModel_CollectionChanged(_docsMan.Documents, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

            // To keep our ViewModelCollection up to date we need to listen for changes
            ((INotifyCollectionChanged)(_docsMan.Documents)).CollectionChanged += new NotifyCollectionChangedEventHandler(MainWindowViewModel_CollectionChanged);

            // Select the first document if any.
            Document = Documents.FirstOrDefault();
        }
Exemplo n.º 28
0
        public IEnumerable <Document> ReadDocuments(
            DocumentReader documentReader,
            HashSet <string> select,
            int skip = 0,
            int take = 0)
        {
            var docCount = documentReader.DocumentCount();

            if (take == 0)
            {
                take = docCount;
            }

            var  took  = 0;
            long docId = skip;

            while (docId <= docCount && took++ < take)
            {
                yield return(ReadDocument((documentReader.CollectionId, docId++), select, documentReader));
            }
        }
Exemplo n.º 29
0
        private void ParseSolutionConfig(string configText, string rootDir)
        {
            Log.Heading("Parsing main solution document");
            using (new CompositeDisposable(
                       new Log.ScopedIndent(),
                       new Log.ScopedTimer(Log.Level.Info, "Parse Solution Config")))
            {
                IResult <ConfigDocument> result = DocumentParser.Document.TryParse(configText);
                if (!result.WasSuccessful)
                {
                    throw new DocumentParseException("<in-memory>", $"Solution config could not be parsed: {result}");
                }

                ConfigDoc = result.Value;
                Reader    = new DocumentReader(ConfigDoc, rootDir);
                Reader.ParseSolution();
                Solution = Reader.Solution;

                Log.Info("Finished parsing solution named '{0}'", Reader.Solution.Name);
            }
        }
Exemplo n.º 30
0
        public void SetEncryption(EncryptionMethod method, long permission)
        {
            var src  = GetSource("Sample.pdf");
            var dest = Path(Args(method, permission));
            var op   = new OpenOption {
                SaveMemory = false
            };
            var cmp = new Encryption
            {
                OwnerPassword    = "******",
                UserPassword     = "******",
                OpenWithPassword = true,
                Method           = method,
                Enabled          = true,
                Permission       = new Permission(permission),
            };

            using (var w = new DocumentWriter(IO))
            {
                w.Set(cmp);
                w.Add(new DocumentReader(src, "", op));
                w.Save(dest);
            }

            using (var r = new DocumentReader(dest, cmp.OwnerPassword))
            {
                Assert.That(r.Encryption.Enabled, Is.True);
                Assert.That(r.Encryption.OwnerPassword, Is.EqualTo(cmp.OwnerPassword));
                Assert.That(r.Encryption.Method, Is.EqualTo(cmp.Method));

                var x = r.Encryption.Permission;
                var y = cmp.Permission;
                Assert.That(x.Print, Is.EqualTo(y.Print), nameof(x.Print));
                Assert.That(x.CopyContents, Is.EqualTo(y.CopyContents), nameof(x.CopyContents));
                Assert.That(x.ModifyContents, Is.EqualTo(y.ModifyContents), nameof(x.ModifyContents));
                Assert.That(x.ModifyAnnotations, Is.EqualTo(y.ModifyAnnotations), nameof(x.ModifyAnnotations));
                Assert.That(x.InputForm, Is.EqualTo(y.InputForm), nameof(x.InputForm));
                Assert.That(x.Accessibility, Is.EqualTo(y.Accessibility), nameof(x.Accessibility));
            }
        }
Exemplo n.º 31
0
        public void TestFolderContentFired()
        {
            DocumentReader reader = new DocumentReader();
            string folderName = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\PutSeparateTestInSeparateFolder");
            IFile folder = FileFactory.Create(folderName, folderName);
            Assert.IsNotNull(folder);
            Assert.IsTrue(folder.IsCollection);
            AddFilesToFolder(folder, folder);

            using (folder)
            {
                folder.Read(reader);
                List<DocumentReader.StringWithLowerCase> context = reader.Context("DocumentStatistic");
                Assert.IsTrue(context.Count > 0);

                context = reader.Context("Paragraph");
                Assert.IsTrue(context.Count > 0);
            }
        }
Exemplo n.º 32
0
    static void Main(string[] args)
    {
        DocumentReader reader = new DocumentReader(new Uri("http://bbc.co.uk"));
        reader.PrintPageData();

        DocumentReader readerClone = reader.Clone() as DocumentReader;
        readerClone.PrintPageData();

        Console.ReadKey();
    }