Exemple #1
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name='args'>
        /// The command-line arguments.
        /// </param>
        public static void Main(string[] args)
        {
            // Go through any arguments.
            for (var idx = 0; idx < args.Length; idx++)
            {
                switch (args[idx].ToLower())
                {
                    default:
                        _baseUri = args[idx];
                        break;
                }
            }

            // Validate inputs.
            if (string.IsNullOrWhiteSpace(_baseUri))
            {
                throw new ArgumentNullException("baseUri", "Missing the base URI!");
            }

            // Create a new API handler.
            var api = new MediaWikiApi(_baseUri);

            // Iterate through captured images and commit them to permanent storage.
            foreach (var img in api.AllImages())
            {
                var file = new FileInfo(img.Name);
                var bytes = img.Download();

                if (bytes != null && bytes.Length > 0)
                {
                    using (var stream = file.OpenWrite())
                    {
                        // Attempt to write if we can.
                        if (stream.CanWrite)
                        {
                            stream.Write(bytes, 0, bytes.Length);

                            Console.WriteLine(
                                "{0}, {1} bytes",
                                file.Length,
                                file.FullName);
                        }

                        // Always close the file.
                        stream.Close();
                    }
             	}
            }
        }
        public void CanGetAllImages()
        {
            var count = 0;
            var wikiApi = new MediaWikiApi(this._baseUri);

            foreach (var img in wikiApi.AllImages("z"))
            {
                count++;
                Debug.WriteLine(
                    "{0}{1}{2}  {3}",
                    count.ToString().PadRight(20),
                    img.Name,
                    Environment.NewLine,
                    img.Url);
            }

            Assert.That(count, Is.GreaterThan(0));
        }