Software development

33
Software development

description

Software development. Chapter 5 – Data management. Contents❷❸. Basics of data binding Using online data SQL databases What is OData? Assignments Questions and answers. Need for data binding. The most simple method to display data on screen is to display static data - PowerPoint PPT Presentation

Transcript of Software development

Page 1: Software development

Software development

Page 2: Software development

Chapter 5 – Data management

Page 3: Software development

Contents ❷❸• Basics of data binding• Using online data• SQL databases• What is OData?• Assignments• Questions and answers

Page 4: Software development

Need for data binding• The most simple method to display data on

screen is to display static data• This simple method is suitable for some

applications, such as e-readers or some simple games

• On a larger scale applications like these are not very versatile

Page 5: Software development

Basics of data binding• Data binding is an essential method for

displaying data in Windows 8 applications• You can always write code that sets some

interface component to display data as programmed, in larger projects this might get troublesome

Page 6: Software development

Data binding and XAML• Data binding can make two things less arduous

– Displaying data (from code to screen) – The situation where the user edits displayed data

through a component such as TextBox (from screen to code)

• Data binding is processed in the code through co-operation between classes and XAML strings

Page 7: Software development

Startin point: C# class ”Student”public class Student{ public int Student ID { get; set; } public string Name { get; set; } public string Social security ID { get; set; } public string Email { get; set; }}

Page 8: Software development

XAML definition• You need to know two things to write the

correct XAML definition1. Which source file property needs to be set as the

source2. Which property of which interface component

should be set as the destination• For example

– Student.Name --> TextBlock.Text

Page 9: Software development

XAML syntax• You can recognize data binding processes in

XAML interfaces from the word Binding inside curly brackets { and }

• {Binding} definition is connected to that target component's property, which will be the destination of the data bond

Page 10: Software development

Example<TextBlock x:Name="StudentIDTextBlock" Text="{Binding Student ID}" ... <TextBlock x:Name="NameTextBlock”Text="{Binding Name}" ...<TextBlock x:Name="SocialIDTextBlock" Text="{Binding Social security ID}" ...<TextBlock x:Name="EmailTextBlock" Text="{Binding Email}" ...

Page 11: Software development

Defining data contents• Once the XAML data bond has been defined,

you must still tell the code which object instance the data bond will be connected to

• This is done by using the XAML page's DataContext property

Page 12: Software development

Creating an object instance• Typically an object's data is fetched from a

data base, the Internet, or they are formed during processing

• You can also use static objects as an easy method to try how data binding works

Page 13: Software development

ExampleStudent o = new Student(){ Student ID = 12345, Name = "Olli Opiskelija", Social security ID = "010290-123A", Email = "[email protected]"};

Page 14: Software development

Connecting the DataContext property

• You can connect any object to a page's DataContext property

• Data binding definitions in XAML will start looking for defined properties in the set object

• Example– this.DataContext = o;

Page 15: Software development

Using online data• Your Windows 8 applications will come alive

after you connect them to online data• The online data feed can take many forms

– A Twitter feed, the day's news headlines in an RSS feed, or data produced by some background process in the XML format, etc.

Page 16: Software development

Many possibilities• Windows 8 applications are capable of

versatile use of online data• Usually online data is fetched by using the

HTTP protocol– It is also possible to use socket or tcp/ip interfaces

or ftp

Page 17: Software development

HttpClient class• A class titled HttpClient is available for Windows 8

applications– Found in the namespace Windows.Web.Http

• The class works asynchronously– The application will not stop and wait for the data to be

downloaded, but allows the user to continue using the application

• Supports also encrypted https protocol connections

Page 18: Software development

ExampleHttpClient client = new HttpClient();Uri uri = new Uri("http://www.bing.com/");string data = await client.GetStringAsync(uri);

Page 19: Software development

Application example: RSS reader• Let's look at a sample application that reads

the Yleisradio main news feed through an RSS feed– RSS = Really Simple Syndication

• Data can be downloaded with the HTTP protocol and data in RSS format is based on XML

Page 20: Software development

Downloading RSS data with HTTPHttpClient client = new HttpClient();Uri uri = new Uri( "http://yle.fi/uutiset/rss/paauutiset.rss");string data = await client.GetStringAsync(uri);XmlDocument xml = new XmlDocument();xml.LoadXml(data);

Page 21: Software development

RSS feed's title elements

Page 22: Software development

Fetching titles from RSS feed• In the previous example the fetched RSS data

was input into an XML component• With this kind of component certain elements

can be found using the XML file's tree structure

Page 23: Software development

Using an XML component• Finding title elements

– XmlNodeList nodes = xml.SelectNodes("//channel/item/title");

• Listing the contents of title elements, that is the news headlines– List<string> titles = nodes.Select(n =>

n.InnerText).ToList();

Page 24: Software development

SQL databases• SQL is the most important query language especially for

database, which can be used to search for and update data in the database– Short for Structured Query Language

• SQL databases can be accessed in many ways– LAN databases typical, cloud-based SQL databases also widely used

• If an application is intended to be used• If the application is intended to be used outside an intranet, the

database connection is generally established through public Internet by using web technologies

Page 25: Software development

Ways to access data

Web interfacesSocket connections

(tcp/ip)

Local installation Proxy server

SQL database

Page 26: Software development

Options in a nutshell• The most simple option is to install the

database on the same device as the application

• The more common solution is to have a Windows 8 application access a separate server running the database over a network

Page 27: Software development

Connection methods• Traditional LAN databases may require the use

of so called socket connections• More modern cloud-era databases allow

forming connections through HTTP• HTTP can also be used to access the database

through the Internet

Page 28: Software development

OData• ODataor Open Data is a standard launched by

Microsoft and other IT operators• Odata can be used to transfer database data

(”SQL data”) over the Internet• The Odata standard is intended to work

especially with HTTP and XML and JSON data formats

Page 29: Software development

OData platform support• Odata standard's newest version is 3.0• It is already supported by many different platforms

– The device itself is platform and device independent• Supported platforms include Windows, Mac OS X

and Linux• Applications supportin OData include Excel, PHP,

Ruby, and naturally Microsoft's .NET ja C# (and therefore Windows 8 applications)

Page 30: Software development

Assignments• List at least three different methods to save data in a

Windows 8 application. What advantages and disadvantages does each method have?

• How can you build an application that are functional even when an Internet connection is not available?

• What advantages do open standards such as OData have for data transfer? What other data transfer standards can you name?

Page 31: Software development

Questions and answers 1My application requires only simple data saving. What saving methods should I use?• For simple programs it can be enough to have a local XML file as a part of the

application. You can process XML files for example by using XmlDocument class, which is found in the namespace Windows.Data.Xml.Dom.

• You can also use some light SQL-based databases, such as SQLite. This database is easily introduced into your application with the so called NuGet package. You can find by using running a search for "SQLite for Windows Runtime" in Visual Studio.

• You might also want to take a look at the new Windows Azure Mobile Services, which can be used to quickly implement a web background system to your application

Page 32: Software development

Questions and answers 2I'm developing a Windows 8 application and I'm writing my code using Visual Studio. The application should communicate with the background system by using the HTTP protocol. Do I have to use Visual Studio to also create the background system.• The advantage of open technologies (such as HTTP) is that that the used

development tools don't matter as long as standards are followed. Therefore your can write your Windows 8 application's interface in Visual Studio and the background system in Python or PHP if you so wish.

• There are, however, several advantages to writing also the background system in Visual Studio, as you don't need to use two development tools or more. Additionally, you can make use of efficient data transfer methods such as OData.

• You might want to familiarize yourself with Microsoft's ASP.NET technologies. They can be programmed in, for example, C#.

Page 33: Software development

Questions and answers 3I've heard that many background systems have been attacked and account names and passwords have been stolen form them. How can I avoid such mistake?• This is a multifaceted, but important question. Especially the large background

systems and databases of popular applications are alluring targets to criminals.

• It is important that users' account names and passwords are appropriately encrypted. All encryption method are not equally good, and therefore you should carefully choose the most efficient encryption for your applications. Many other elements affect the security of background applications, and many books have been written on the subject.

• You can read more on the subject in, for example, "Building Secure ASP.NET Applications," which can be found on Microsoft's developer site at http://msdn.microsoft.com/en-us/library/ff649100.aspx.