Chapter 6. Cross-platform Development

Microsoft platforms are not the only platforms that can execute C# code. With the Mono framework, you can target other platforms, such as Linux, Mac OS, iOS, and Android. In this chapter, we will explore the tools and frameworks needed to build a Mac app. Some of the tools we will look at here are:

  • MonoDevelop: This is a C# IDE that lets you write C# on other non-Windows platforms
  • MonoMac: This provides bindings to the Mac libraries so you can use native APIs from C#
  • Cocoa: This is the framework used to create Mac apps

The application we are going to build in this chapter is a utility that you can use to look for text on a website. Given a URL, the application will look for links and will follow them to look for specific trigger text. We will take a look at displaying the results using Mac OS' UI SDK, AppKit.

Building a web scraper

If you have C# experience and need to build an application or utility, Mono can give you a head start at creating it quickly, using existing skillsets. Let's say you have a need to keep an eye on a website so that you can act when a new post containing a given piece of text shows up. Rather than sitting there and refreshing the page manually all day, you want to build an automated system to do this. If the website does not provide an RSS feed or other API to give you programmatic access, you can always fall back on a tried and true method of getting remote data—writing an HTTP scraper.

It sounds more complex than it is, all that this utility will do is let you put in a URL and some parameters, so the app knows what to search for. Then, it will take care of going out to the website, requesting all of the relevant pages, and searching for your target text.

Start by creating the project. Open MonoDevelop and create a new project from the File | New | Solution menu item which brings up the New Solution dialog. In that dialog, choose MonoMac Project from the C# | MonoMac list on the left-hand panel. When you create the solution, the project template initializes it with the basics of a Mac application, as shown in the following screenshot:

Building a web scraper

As with the web app we built in the previous chapter, Mac applications use the Model-View-Controller pattern to organize themselves. The project template has created the controller (MainWindowControl) and the view (MainWindow.xib); it is up to you to create the model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.170.134