コード例 #1
0
ファイル: MainfileTests.cs プロジェクト: samcragg/sharppaf
        public void SaveAllShouldCheckForNullArguments()
        {
            Mainfile mainfile = this.mainfileBuilder.Create();

            Assert.That(() => mainfile.SaveAll(null),
                        Throws.InstanceOf <ArgumentNullException>());
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            const string PathToExampleData = @"D:\PAF\Fixed PAF";
            var          mainfile          = new Mainfile(PathToExampleData);
            var          repository        = new MemoryRepository();

            // Load the PAF data (this could be changed to use the view in the
            // SqlServerExample).
            Console.Write("Creating repository...");
            var stopwatch = Stopwatch.StartNew();

            mainfile.SaveAll(repository);
            stopwatch.Stop();
            Console.WriteLine("finished ({0} inserted in {1:f1} secs.)", repository.Addresses.Count, stopwatch.Elapsed.TotalSeconds);

            // Create the Lucene.NET index
            Console.Write("Creating index...");
            DeleteExistingIndex();
            stopwatch.Restart();
            using (var indexer = new Indexer())
            {
                foreach (KeyValuePair <int, string> address in repository.Addresses)
                {
                    indexer.Add(address.Key, address.Value);
                }

                indexer.Optimize();
            }
            stopwatch.Stop();
            Console.WriteLine("finished ({0:f1} secs.)", stopwatch.Elapsed.TotalSeconds);

            // An example search
            using (var finder = new AddressFinder())
            {
                stopwatch.Restart();
                int[] addresses = finder.FindAddresses("2 Chuch St"); // Notice we've misspelled 'Church' and used an abbreviation for Street
                stopwatch.Stop();
                Console.WriteLine("{0} matches found in {1}ms.", addresses.Length, stopwatch.ElapsedMilliseconds);

                // This could be replaced with a call to SQL to get all the
                // addresses + postcodes.
                foreach (int addressKey in addresses)
                {
                    Console.WriteLine("{0}: '{1}'", addressKey, repository.FindAddress(addressKey));
                }
            }

            Console.ReadKey();
        }
コード例 #3
0
ファイル: MainfileTests.cs プロジェクト: samcragg/sharppaf
        public void SaveAllShouldSaveAddressFilesLast()
        {
            foreach (FieldInfo field in typeof(ExamplePafFileData).GetFields())
            {
                this.mainfileBuilder.AddFile(field.Name, (string)field.GetValue(null));
            }

            Mainfile mainfile   = this.mainfileBuilder.Create();
            var      repository = Substitute.For <PafRepository>();

            mainfile.SaveAll(repository);

            MethodInfo lastCalled = repository.ReceivedCalls().Select(c => c.GetMethodInfo()).Last();

            Assert.That(lastCalled.Name, Is.EqualTo("AddAddress"));
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            const string PathToExampleData = @"D:\PAF\Fixed PAF";
            var          addressFormatter  = new AddressFormatter();
            var          mainfile          = new Mainfile(PathToExampleData);
            var          repository        = new MemoryRepository(FormatOptions.Postcode | FormatOptions.TitleCase);

            var sw = System.Diagnostics.Stopwatch.StartNew();

            mainfile.SaveAll(repository);
            sw.Stop();
            Console.WriteLine("Converted {0} addresses in {1}ms", repository.Addresses.Count, sw.ElapsedMilliseconds);

            Console.WriteLine(
                string.Join(
                    "\n",
                    addressFormatter.Format(repository.Addresses[1])));

            Console.ReadKey();
        }