Author Archives: cbro234@gmail.com

Requesting a Code Review in Visual Studio

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.

Go to Pending Changes

If you have pending changes, you can select Request Review from the Actions list.

Request Review

In the New Code Review panel, select a reviewer and leave a description of the change.

New Code Review

The reviewer can compare changes by clicking the file names and send back comments.

File Compare

Comment Review

The reviewer can mark the status as complete.

Review Complete

Finally, you can check in the change.

Check-in 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.

Change history

Request review on checked in change

TFVC with Azure DevOps

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.

VisualStudioMyBenefits

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.

AzureDevops

DevOpsDashboard

 

Now you’ll be able to connect to this project from Visual Studio under Team Explorer > Manage Connections > Connect to a Project

ConnectToAProject

 

 

 

 

 

 

 

 

 

 

 

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.

SourceControlExplorer

 

Oracle, Entity Framework and Visual Studio

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/.

Visual Studio About Page
Oracle Developer Tools Download Page
 
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.

NuGet Oracle and Entity Framework packages

Xamarin Forms – MVVM & SQLite

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.

  1. Contact Model

    Define the object in a class. This becomes the model.

  2. 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.

    Add Contacts

    List Contacts

  3. Interact with Model through MVVM

    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();

  4. Import SQLite

    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.

    Get Sqlite



  5. Create, Read and Delete

    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.





    Stored data

Xamarin Projects – Setup & Pages

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.

  1. 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.

  2. 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.New Xamarin project

  3. 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.Update Packages

  4. 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.

  5. 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/

  6. Hello World

    Start with a label, an input field, a button and an event handler to process the click.



     
  7. Navigation Pages push New Pages around.

    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




    Add About Page
  8. 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.



    Cats on Staff
  9. Displaying a List with Binding

    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.




  10. Implementing Styles

    Just like HTML, elements can be styled individually, but that doesn’t scale. You can define some global styles (or other resources) in App.xaml.


    Resources Styles

ASP.NET MVC Project – Restaurants at the End of the Universe

It’s been a little while since I made a new MVC project, so why not start at the end of the universe?

    1. Start a new MVC project

      New Project screenshot

    2. Give it a model

       

    3. Pass the model to the View

       

    4. Display model properties in the View

       

    5. Test that the model exists


      Unit test screenshot

    6. Apply fresh paint to Site.css

       

    7. Run it

      About restaurants screenshot

    8. How did we get here?

      With the help of Global.asax and RouteConfig.cs

       

       

    9. Make a new Route with matching Controller

       

       

       

 

Testing with Python and Selenium

There are three kinds of lazy.

Let’s make sure we’re in the last category.

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.

  1. From the Windows terminal

  2. Download Chrome Driver

    https://sites.google.com/a/chromium.org/chromedriver/downloads
    Make sure to get the version that matches your chrome version.
    What version of chrome do I have?
    Extract the zip and take note of the destination folder. You’ll need the .exe path in the next step.

  3. Open Python and import selenium


     
  4. Selenium + Unittest

    What is the answer to life, the universe and everything?
    Calculator says 42

  5. Run TestDemo.py from the CLI


     

Essential Git: Clone Commit Push Pull Checkout

For this example, I’ll use my binoculars page to demo the basic commands I use to track changes and move code between my laptop, github and my server.

In a new project folder

Make some changes and save them

I went down a rabbit hole and I wanna go home

Create a branch to track bug fix

Put this gem in GitHub

Create Repository

 

Make Dolly proud

Sheep

Clone repo to web server

Taking Search Input and Returning Result(s)

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.


SearchSingle

 

 

Resulting redirect to /Authors/Details/1

Redirect to Details

 


SearchListItems

 

 

Users should be alerted in the event nothing is found, i.e. when results.Count == 0.

No Unicorns

Publish .NET MVC to File System

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.

  1. Create the connection string in Web.config
  2. Publish the app to a folder
    Publish App
  3. Assign that folder a name in IIS
    IIS Add Application
    IIS Add Address
  4. 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
  5.  Turn on ASP.NET 4.7 (if not already enabled)
    Turn On Features ASP.NET
  6. 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.
    Failed to LoginSQL2014 LoginDB UserMapping the User Login should create a User for the DB as well.
    DB UserAnd if it tells you that user you just made cannot login, check the SQL Log. SQL Log

    And continue to troubleshoot.

  7. Enable SQL Server Authentication if not on

    SQL Server Authentication

  8. Now you can navigate to localhost/BookStore
    Create AuthorUntil next time…