As part of working on a team, expect to have code reviewed before checking it into the repository. If you happen to check in before a code review, I’ll show how to still submit a review request on that change set.
In the Team Explorer tab, go to the Pending Changes panel.
If you have pending changes, you can select Request Review from the Actions list.
In the New Code Review panel, select a reviewer and leave a description of the change.
The reviewer can compare changes by clicking the file names and send back comments.
The reviewer can mark the status as complete.
Finally, you can check in the change.
If the change was checked in before you requested a review, just go into source control explorer and view the change set in the project’s history. Right click the change set and request a review.
I used Git for version control and Jira for ticketing in my previous organization. Now, I am getting used to TFS and DevOps. Luckily, you can start using these at home without installing anything, assuming you have Visual Studio and an account at VisualStudio.com.
Log in to VisualStudio.com and navigate to the My Benefits section. Using My.VisualStudio.com works for now. You’ll be presented with various account benefits in the form of tools or resources. Click on Azure DevOps to get started.
Be careful to use the free tier or you can wind up incurring charges from Azure.
When creating a project, you have the choice between Git and Team Foundation Server Control.
Now you’ll be able to connect to this project from Visual Studio under Team Explorer > Manage Connections > Connect to a Project
Find the project in the Source Control Explorer under the Team Explorer tab. Click the title in the Team Explorer window to toggle between Home, My Work, Pending Changes and Source Control Explorer.
To add an application to your DevOps project, right-click it and select Add New Items to Folder. Navigate to the folder and select finish. Then you should be able to open the solution file from solution control where you have a playground to start branching, merging, shelving and checking in changes.
As a new developer on an existing .NET project, I have run into a few errors while trying to get Visual Studio, Entity Framework and Oracle to play nice together. Things are finally working now and I have a couple of lessons learned that will resolve these errors.
‘Oracle.ManagedDataAccess.Client’ is either not registered in the machine or application config file, or could not be located.
Installing Oracle Managed Data Access Client from NuGet is not all you need. Visual Studio requires the Oracle Data Provider, part of Oracle Data Access Components.
In Visual Studio, go to Help > About and see if Oracle Developer Tools is listed under Installed Products. If not, get it here or look for “Developer Tools for Visual Studio” at oracle.com/downloads/.
Your project references the latest version of Entity Framework however an Entity Framework database provider compatible with this version could not be found.
NuGet will default to the latest version of a package, but in this case you need to match the version installed on the project with the version of Oracle Developer Tools installed on Visual Studio. In this case, NuGet originally defaulted to 19.3.0 but downgrading to 18.3.0 fixed the error.
In the MVVM pattern, the ViewModel is aware of the Model and the View interacts with the Model through the ViewModel. Instantiating the ViewModel in the App class allows all the various pages to interact with the single object. With that in place, although it’s not a prerequisite, I’ll move on to store contacts in a SQLite database and Views will interact with the DB through the VM.
Contact Model
Define the object in a class. This becomes the model.
Contact class
1
2
3
4
5
6
7
8
9
namespaceApp3
{
publicclassContact
{
publicintId{get;set;}
publicstringName{get;set;}
publicintPhone{get;set;}
}
}
Get and Set Contacts
Keeping the list in the Main Page, we can add records to it and send it to a ListView to display them.
Now, rather than creating a list in the Main Page to store contacts, move it to the ViewModel which will instantiate the list and handle interactions with it. The ListViewContacts will no longer take a List<Contact> argument and instead get the list from App.vm.GetContacts();
The MVVM will manage how views interact with the information in memory, but we still need a database to store data when the application is closed. Luckily, SQLite will help us with that. We need to add it to our project from NuGet, then create a db interface that defines a connection and a platform specific class that implements it. Lastly, we’ll add a couple of data attributes to the Contact model.
Now the relationship between the ViewModel and the database needs to be established. Since the contact list will reside in the database, we’ll use the ViewModel to pass new contacts to it and retrieve existing contacts from it. The DB will be instantiated in App.xaml.cs to make it accessible everywhere and the VM will be called by the pages as they need it, MainPage and ListViewContacts.
Xamarin will allow you to build mobile applications for Android, iOS and UWP in Visual Studio. With VS2017 installed, you can get started pretty quickly, although getting the SDK and emulator set up may take some troubleshooting.
Install Mobile Development with .NET
If not already installed, you may need to go back to the Visual Studio Installer to get Mobile Development with .NET. After clicking the Modifying option, it should be under the Mobile & Gaming section.
Start a Xamarin.Forms Project
In Visual Studio, start a project with File > New > Project. I like to use the search function to find my project type, obviously “xamarin” should do the trick, but it can be found under Web > Cross-platform too.
Update NuGet packages
On start up, VS will likely display a long list of errors. Most, if not all, can be taken care of by simply updating the project’s default packages using NuGet.
Incompatible Haxm
The Intel Hardware Accelerator Manager threw an error for me. So, although it appeared that Visual Studio Installer was taking care of the Intel HAXM, finding the .exe and running it fixed the error for me. Mine is located at C:\Program Files (x86)\Android\android-sdk\extras\intel\Hardware_Accelerated_Execution_Manager\intelhaxm-android.exe, but your SDK folder my be elsewhere. The path can be seen in Tools > Android > SDK Manager.
Android-sdk
Likewise, if the installer and SDK manager are not playing nice, try getting the Android SDK from the Android Studio installer at https://developer.android.com/studio/
Hello World
Start with a label, an input field, a button and an event handler to process the click.
Go back the the MainPage.xaml and add a new Button that will show us the About Page. Pressing F12 inside “OnAbout” will generate the method for us. Right click the project in the Solution Explorer and Add > New Item > Content Page. Before you can start handling new pages, the MainPage needs to be upgraded from Content Page to Navigation Page. One way to do this is cast it when calling it in App.xaml.cs
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
namespaceApp3
{
publicpartial classApp:Application
{
publicApp()
{
InitializeComponent();
MainPage=newNavigationPage(newMainPage());
}
// etc.
}
MainPage with About Button
1
2
3
4
5
6
7
8
<StackLayout>
<Labelx:Name="Greeting"Text="Hello."/>
<Entryx:Name="MyName"Placeholder="Your Name"/>
<StackLayout Orientation="Horizontal">
<Button Text="Send"Clicked="OnSend"/>
<Button Text="About"Clicked="OnAbout"/>
</StackLayout>
</StackLayout>
MainPage.xaml.cs OnAbout method
1
2
3
4
privatevoidOnAbout(objectsender,EventArgse)
{
Navigation.PushAsync(newAboutPage());
}
Data Binding
Data binding will link the xaml view with the data in the scope of the xaml.cs. Just be sure the BindindContext is assigned after any variables you’re referencing.
A List View does just about what it sounds like it should. In this case, notice that the Binding Context is defined in the xaml and not the code behind. Either way will work.
The Selenium library is a workhorse for automating your web browser. I use it to automate data entry and integration testing, but you could do much more with it as long as the task involves your browser. Scrape the DOM? Yes. Click buttons? Yes. Fill out forms? Yes. Handle alerts? Yes. Switch windows? Yes. Want more? Go read the docs. We’re just going to scrape the surface.
This book store really needs a search function. One notable difference is whether to return a single value, e.g. one person matching a phone number, or multiple values, e.g. a list of books.
A little modification to the Home Controller and the Index View will get us an input field and an output field for displaying results. For now, this will involve a full postback, reloading the page. In the single result example, it will send the user to the detail page for that item. In the list example, it will refresh the index page with the result. In case there are no results, I’ll provide some feedback that nothing was found.
Index
XHTML
1
2
3
4
5
6
7
8
<label class="control-label">Search Author by ID</label>
Assuming that SQL Server is installed, SQLExpress will work too, the following shows how to publish an application to a local file folder and make that accessible across the local network. It will also specify an instance of SQL Server, not the default LocalDb. I found this useful to quickly demo a prototype for managers and get their feedback using just the IIS on my computer and our local network. Note that the steps here open up the app to everyone on the network, so it would not be useful if confidential information were involved.
Share the folder with Everyone. Navigate to your folder location. Right click it and click Give Access To > Specific People… Select Everyone from the drop down list and click Add, then Share
Turn on ASP.NET 4.7 (if not already enabled)
Create a SQL Login & User with permissions. The username from the connection string needs to be created and granted access or you will be faced with an error: Login failed for user ‘Foo’. Oddly, I found that when using Windows Authentication, the username was the machine and not the user’s domain account.
Mapping the User Login should create a User for the DB as well. And if it tells you that user you just made cannot login, check the SQL Log.
An attempt to login using SQL authentication failed