Visual Studio – Xamarin – Traffic Light

Background

Here we go with our first small CSC 101 application in Xamarin.

Outline

  1. addControls
    • instantiate Button Object
    • If in manual mode
      • Add event handler for Button Click
    • Instantiate StackLayout
      • Add Button
  2. OnButtonClick
    • handle buttonclick event
      • call triggerNextState
  3. triggerNextState
    • Call Device.BeginInvokeOnMainThread
      • Have next method be processed on main thread
  4. reflectState
    • Update Button Text
    • Base next procession based on whether manual or automated
      • Enable Button
      • Update Button Background Color
  5. initializeData
    • Instantiate each trafficLightState
    • Add trafficLightState object to collection list
  6. initializeTimer
    • Instantiate timer
    • instantiate Time Event Handler
  7. Process Timer Event
    • call triggerNextState

Code

Add Controls


 void addControls()
{

	btnTL = new Button
	{

		  Text = btnLTText + " " + strMode
		, HorizontalOptions = LayoutOptions.StartAndExpand

	};

	if (bManualOrAutomated == false)
	{
		btnTL.Clicked += OnButtonClicked_btnTL;

	}

	// Assemble the page.
	this.Content = new StackLayout
	{

		Children =
		{
			new StackLayout
			{

				  // Stack Orientation
				  Orientation = StackOrientation.Horizontal

				  // Add Children
				, Children =
				{
					btnTL
				}

			 } // Stack Layout
		} // Children

	}; // Assemble the page.

} // addControls() 

OnButtonClicked_btnTL


void OnButtonClicked_btnTL(object sender, EventArgs args)
{

	Button button = (Button)sender;

	if (button == btnTL)
	{

		triggerNextState();

	}

}

triggerNextState


void triggerNextState()
{

	//prepare for next transition
	iTrafficLightStateCurrent = iTrafficLightStateCurrent + 1;

	try
	{
		Device.BeginInvokeOnMainThread
			(
				() =>
				{
					reflectState();
				}
			);
	}
	catch (Exception)
	{

	}

}

reflectState


void reflectState()
{

	try
	{

		//reset display
		//btnTL.Text = btnLTText;
		btnTL.Text = btnLTText + " " + strMode;

		if (dtSignalTime != null)
		{
			btnTL.Text += " ("
							+ dtSignalTime.ToLongTimeString().TrimStart()
							+ " )"
							;
		}

		btnTL.IsEnabled = (bManualOrAutomated == false);

		//reset marker if at end of line
		if (
				(iTrafficLightStateCurrent > iTrafficLightStatesCountZeroBased)
		   )
		{
			iTrafficLightStateCurrent = 0;
		}

		// get object at current node
		objTLSCurrent = objTLS[iTrafficLightStateCurrent];

		// if valid object
		if (objTLSCurrent != null)
		{

			//set background color
			btnTL.BackgroundColor = objTLSCurrent.color;

		}

	}
	catch (Exception ex)
	{

		//show exception
		btnTL.Text = ex.Message;

		//reset counter
		iTrafficLightStateCurrent = 0;

	}
}

initializeData


void initializeData()
{

	tlStateRed = new trafficLightState();
	tlStateRed.color = Color.Red;
	objTLS.Add(tlStateRed);

	tlStateGreen = new trafficLightState();
	tlStateGreen.color = Color.Green;
	objTLS.Add(tlStateGreen);

	tlStateYellow = new trafficLightState();
	tlStateYellow.color = Color.Yellow;
	objTLS.Add(tlStateYellow);

	// Get Number of Elements
	iTrafficLightStatesCount = objTLS.Count;

	// Get Number of Elements ( 0 Based )
	iTrafficLightStatesCountZeroBased = objTLS.Count - 1;

	// Set Current at 0
	iTrafficLightStateCurrent = 0;

}

initializeTimer


void initializeTimer(Boolean bTimer)
{

	if (bTimer)
	{

		// Create a timer with a two second interval.
		objTimer = new System.Timers.Timer(lSecondsInThousands);

		// Hook up the Elapsed event for the timer.
		objTimer.Elapsed += OnTimedEvent;

	}
	else
	{

		if (objTimer != null)
		{

			//unsubscribe
			objTimer.Elapsed -= OnTimedEvent;

			objTimer = null;

		}

	}

	if (objTimer != null)
	{

		objTimer.AutoReset = bTimer;

		objTimer.Enabled = bTimer;

	}

}

OnTimedEvent


private void OnTimedEvent(Object source, ElapsedEventArgs e)
{

    dtSignalTime = e.SignalTime;

    triggerNextState();

}

Source Code Control

GitHub

VS Studio Xamarin Traffic Light
Link

References

  1. Microsoft
    • Microsoft | Docs
      • Docs / .NET / .NET API Browser / Xamarin.Forms / Device / Methods / BeginInvokeOnMainThread
        Link

 

Visual Studio – Installation – Mobile Applications with Xamarin

Background

Last week tackled creating a Windows Service with Visual Studio.

This week wanted to explore creating Mobile Applications with same.

Visual Studio

Product

Our Product is Visual Studio 2017.

Edition

As always, no bootleg, nevertheless Free; as in Community Edition.

Launch

Launched Visual Studio.

New Project

Accessed menu options and chose New \ Project.

Image

Here are the Project Type options :-

NewProject.20181206.0829PM.PNG

Explanation

  1. Project Types
    • Missing
      • Mobile
  2. Framework
    • .Net Framework 4.6.1

 

Remediation

Outline

  1. Exit Visual Studio
  2. Control Panel \ Programs & Features
    • Launch Control Panel
    • Access Programs and Features Applet
    • Visual Studio
      • From  the list of Applications choose Visual Studio
        • Choose to modify Application
          • Select Mobile, specifically Xamarin
  3. Close Installer
  4. Restart Visual Studio

 

Steps

Exit Visual Studio

Exit Visual Studio.

Programs & Features

Launch Control Panel and access the Programs & Features Applet.

Visual Studio Installer

Modify

Let us modify our install.

Workloads

Outline
  1. We will stay on the Workloads tab
    • Mobile Development with .Net
      • Confirm that Mobile Development with .Net is not currently checked
      • Check that option
      • Review additional storage requirement ( 10 GB )
    • Mobile Development with JavaScript
      • Confirm that Mobile Development with JavaScript is not currently checked
      • Check that option
      • Review additional storage requirement ( 17 MB )
Images
Workloads – Original

modify.workloads.20181206.0830PM.PNG

Workloads – Mobile Development with .Net ( Post )

modify.workloads.mobileDevelopementWithNet.20181206.0831PM.PNG

Workloads – Mobile Development with JavaScript ( Post )

modify.workloads.mobileDevelopementWithJavaScript.20181206.0834PM.PNG

Installing

Installing – Images
Image – Close Visual Studio

installing.BeforeWeGetStarted.20181206.0838PM.PNG

Image – Installing – 01

installing.Downloading.20181206.0840PM.PNG

Image – Installing – 02

installing.Downloading.20181206.0854PM.PNG

 

Image – Installing – 03

installing.Downloading.20181206.0901PM.PNG

Image – Installed

installing.Downloading.20181206.0909PM.PNG

Review Installed Components

Relaunched Visual Studio and access Menu/About.

Image

About.20181207.720AM

Explanation

Confirmed the following installed products :-

  1. Xamarin
  2. Xamarin Designer
  3. Xamarin Templates
  4. Xamarin.Android SDK
  5. Xamarin.iOS and Xamarin.Mac SDK

 

Service Application via Visual Studio ( Day 1 )

Background

Let us lay out a lithe Service Application using Visual Studio Community Edition.

Visual Studio

Overview

  1. Install Visual Studio Community Edition
  2. Create New Project ( Windows Service )
  3. Installer Module
    • Add Installer Module
    • Customize Installer Module
  4. App.Config
    • Add Application Configuration Items
  5. Application
    • Configuration Items
      • Read Configuration Items
      • Log Configuration Items
  6. Install Service
  7. Configure Service
  8. Start Service

Download Install

Download & Install Visual Studio Community Edition if you don’t have it yet.

Usage

Create New Project – Service Application

Outline

  1. Create New Project
    • Visual C#
      • Windows Desktop
        • Type :- Windows Service (.Net Framework )

Image

newProject.20181130.0836AM.PNG

Add Installer

Outline

Link

  1. In Solution Explorer, access Design view for the service for which you want to add an installation component.

  2. Click the background of the designer to select the service itself, rather than any of its contents.
  3. With the designer in focus, right-click, and then click Add Installer.
    • A new class, ProjectInstaller, and two installation components, ServiceProcessInstaller and ServiceInstaller, are added to your project, and property values for the service are copied to the components.
  4. Click the ServiceInstaller component and verify that the value of the ServiceName property is set to the same value as the ServiceName property on the service itself.
  5. To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.

Customize Installer

Outline

  1. serviceInstaller
    • Solution Explorer
      • Customize Service Installer Property Sheet
    •  constructor
      • InitializeComponent()
        • Make sure that you preserve the call to InitializeComponent
      • Customize Service
        • serviceName
        • displayName
        • description

Solution Explorer

Service Installer Property Sheet

Outline
  1. Access Solution Explorer
    • Access Item :- serviceInstaller.cs
      • Access Properties page
        • Adjust Service Properties
Image

serviceInstaller.20181130.0634PM.PNG

 

Code


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;

namespace journalBible
{
    [RunInstaller(true)]
    public partial class serviceJournalInstaller : System.Configuration.Install.Installer
    {

        static string appName = "journalBible";
        static string appDisplayName = "journal Bible";
        static string appDescription = "journal Bible Application ( Sample)";

        public serviceJournalInstaller()
        {

            InitializeComponent();

            this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

            this.serviceInstaller1.ServiceName = appName;

            this.serviceInstaller1.DisplayName = appDisplayName;

            this.serviceInstaller1.Description = appDescription;

        }

        private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {

        }

        private void serviceProcessInstaller1_AfterInstall(object sender, InstallEventArgs e)
        {

        }
    }
}

Configuration

App.Config

Outline

  1. Add appSettings section
    • add Keys
      • smtpServer
      • emailAddress

Code

App.Config.20181130.0235PM

Main Code

Outline

  1. serviceInstaller
    • Methods
      • OnStart
        • Initialize
          • configurationRead
            • read configuration data from app.config file
          • configurationLog
            • write configuration data into Application Event Log

Code


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

using System.Configuration;
using System.IO;
using System.Security;

namespace journalBible
{
    public partial class ServiceJournalBible : ServiceBase
    {

        static String strAppName;

        /*
         * Configuration App.Config - ID
        */
        static String ID_STMP_SERVER = "smtpServer";
        static String ID_EMAIL_ADDRESS = "emailAddress";

        /*
         * Configuration in App.Config - Variables
        */
        static String strSMTPServer;
        static String strEmailAddress;

        public ServiceJournalBible()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            initialize();
        }

        protected override void OnStop()
        {
        }

        protected void initialize()
        {

            try
            {

                configurationRead();

                configurationLog();

            }
            catch (Exception)
            {

            }

        }

        /*
         * Get Application Name
        */
        private String getAppName()
        {

            String strAppFriendlyName;
            String strAppName;

            strAppFriendlyName = AppDomain.CurrentDomain.FriendlyName;

            strAppName = Path.GetFileNameWithoutExtension(strAppFriendlyName);

            return (strAppName);

        }

        /*
         * https://docs.microsoft.com/en-us/dotnet/framework/windows-services/how-to-log-information-about-services
        */

        public System.Diagnostics.EventLog customLogging()
        {

            System.Diagnostics.EventLog objEventLog = new System.Diagnostics.EventLog();

            Boolean bEventLogSourceExist = false;

            // Turn off autologging
            this.AutoLog = false;

            strAppName = getAppName();

            // create an event source, specifying the name of a log that
            // does not currently exist to create a new, custom log
            bEventLogSourceExist = System.Diagnostics.EventLog.SourceExists(strAppName);

            if (bEventLogSourceExist == false)
            {
                System.Diagnostics.EventLog.CreateEventSource
                (
                      strAppName
                    , strAppName
                );

            }

            // configure the event log instance to use this source name
            objEventLog.Source = strAppName;

            //objEventLog.Log = strAppName;

            return (objEventLog);

        } //customLogging() 

        protected void configurationRead()
        {

            System.Collections.Specialized.NameValueCollection objAppSettings;

            objAppSettings = System.Configuration.ConfigurationManager.AppSettings;

            strSMTPServer = objAppSettings[ID_STMP_SERVER];

            strEmailAddress = objAppSettings[ID_EMAIL_ADDRESS];

        } //configurationRead()

        protected void configurationLog()
        {

            String strLog;

            EventLog objEventLog;

            objEventLog = customLogging();

            //Set Source Name
            //objEventLog.Source = strAppName;

            //Prepare Log Entry
            if (strSMTPServer != String.Empty)
            {
                strLog = ID_STMP_SERVER + " :- " + strSMTPServer;

                //Write Log Entry
                objEventLog.WriteEntry(strLog);
            }

            //Prepare Log Entry
            if (strEmailAddress != String.Empty)
            {

                strLog = ID_EMAIL_ADDRESS + " :- " + strEmailAddress;

                //Write Log Entry
                objEventLog.WriteEntry(strLog);

            }

        } //configurationLog()

    }
}

Install Service

Outline

  1. use InstallUtil.exe to install Service

Code

Syntax


C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe [exe-name]

Sample


setlocal

	set "_appInstallerFolder=C:\Windows\Microsoft.NET\Framework64\v4.0.30319"
	set "_appInstallerTargeted=InstallUtil.exe"

	set "_appInstaller=%_appInstallerFolder%\%_appInstallerTargeted%"

	set "_appTargetedFolder=bin\Release"
	set "_appTargetedModule=journalBible.exe"

	set "_appTargeted=%_appTargetedFolder%\%_appTargetedModule%"

	%_appInstaller% %_appTargeted%

endlocal

Source Control

GitHub

DanielAdeniji/svcjournalApp
Link

Referenced Work

  1. Microsoft
    1. Docs > .NET > .NET Framework > Developing Windows Service Applications
      • How to: Install and Uninstall Services
        Link
      • How to: Add Installers to Your Service Application
        Link

Visual Studio – Build – Warning – “The referenced component ‘Microsoft.Web.Infrastructure’ could not be found.”

Background

Downloaded a new Application.  One that I will have to build myself.

Launched Visual Studio and issued Build Command via menu.

Error

Ran into build errors.

The first one reads:

The referenced component ‘Microsoft.Web.Infrastructure’ could not be found.

Remediation

Have a lot of work to do this Saturday morning.

And, so let us address.

Package Manager Console

Running Visual Studio 2017 Community Edition, and the steps to access the Package Manager Console are:

  1. Navigate to the top menu
  2.  Menu Item
    • Tools
    • NuGet Package Manger
    • Package Manager Console

 

Install-Package

Code


Install-Package Microsoft.Web.Infrastructure

 

 

Output

Image

Textual
Attempting to gather dependency information for package 'Microsoft.Web.Infrastructure.1.0.0' with respect to project '[ProjectA]', targeting '.NETFramework,Version=v4.5.1'
Gathering dependency information took 120.25 ms
Attempting to resolve dependencies for package 'Microsoft.Web.Infrastructure.1.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.Web.Infrastructure.1.0.0'
Resolved actions to install package 'Microsoft.Web.Infrastructure.1.0.0'
Retrieving package 'Microsoft.Web.Infrastructure 1.0.0' from 'nuget.org'.
Adding package 'Microsoft.Web.Infrastructure.1.0.0' to folder '<app>\\packages'
Added package 'Microsoft.Web.Infrastructure.1.0.0' to folder '<app>\\packages'
Added package 'Microsoft.Web.Infrastructure.1.0.0' to 'packages.config'
Successfully installed 'Microsoft.Web.Infrastructure 1.0.0' to <ProjectA>
Executing nuget actions took 5.42 sec
Time Elapsed: 00:00:07.5704133
PM> 

Credit

Crediting Joshua Davis per “FileNotFoundException: Could not load file or assembly ‘Microsoft.Web.Infrastructure“.  Here is the Link.

Joshua Davis’s about page is worthy of good, congratulatory read.  Here is the link to that page.

 

References

  1. NuGet.Org
    • Microsoft.Web.Infrastructure 1.0.0
      • This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time.
        Link
  2. fsprojects/Paket
    • Problem referencing Microsoft.Web.Infrastructure #1393
      Link

Visual Studio – Error – “Unable to find manifest signing certificate in the certificate store”

Background

Downloaded Source Code of an Application that I will be using, but unable to successfully compile it.

Error

Error Message

Error
Unable to find manifest signing certificate in the certificate store
Unable to find code signing certificate in the current user’s Windows certificate store.

Error Image

TroubleShooting

pfx file Missing

Solution Explorer

DiagManager

Image

Explanation
File Diagnosis
DiagManager_TemporaryKey.pfx DiagManager_TemporaryKey.pfx file is missing

 

Remediation

Project \ Signing

Uncheck “Sign the ClickOnce manifests

Summary

ClickOnce requires code signing.

As Microsoft is availing the Source code, they have opted not to include their PFX file.

References

  1. StackOverflow.com
    • Why am I getting “Unable to find manifest signing certificate in the certificate store” in my Excel Addin?
      Link

UML & Visual Studio

Background

My brother has a couple of Applications that he wanted to generate UML Models for.

And, so went online and downloaded both the Community ( Actual ) and Enterprise Edition ( Trial ).

 

Download

The latest version v2017, is available here.

Installed

Installed both versions.

And, was surprised that access to UML is no longer available under the Architecture menu.

Missed Functionality

UML to be ejected from Microsoft Visual Studio
Link

Not Supported post Visual Studio 2015 …

Stay with Visual Studio 2015

 

References

  1. Infoworld
    • Paul Krill
      • UML to be ejected from Microsoft Visual Studio
        Link
  2. Microsoft Developer Community
    • UML use case diagram in vs2017 RC Enterprise Edition
      Link
  3. Microsoft Developer Network
    • Create UML Class Diagrams from Code
      Link

Visual Studio 2010 – Upgrade from RTM to SP1

Background

Just as yourself, got a lot to do, but occasionally get pulled back in.

 

SQL Server 2008-R2 Upgrade

My manager has signed us up to upgrade all SQL Servers to the most recent version, 2016. Or at minimum the version that precedes the latest; btw, that is 2014.

The SQL Instance that I am looking at currently is v2008-R2 and the OS is 2008/R2.

That latest SQL Server supported on Windows 2008-R2 is SQL Server 2014.

 

Upgrade 2008-R2 to 2014

Trying to upgrade v2008-R2 to v2014, but ran into a constraint right away.

Features Rules

Textual

This computer has an installation of Visual Studio 2010 that requires a Service Pack 1 update that is needed for a successful installation of SQL Server based on your feature selection.

To continue, install the required Visual Studio 2010 Service Pack 1 from SQL Server media or from http://go.microsoft.com/fwlink/?LinkID=220649.

Image

Download Visual Studio 2010 SP1

Tried a drive by visiting https://www.microsoft.com/en-us/download/details.aspx?id=23691.

Redirected to https://www.microsoft.com/en-us/download/details.aspx?id=23691.

Download Visual Studio 2010 SP1 – Download 23691

Textual

We are sorry, this download is no longer available.

Image

 

Download Links

Source Link Works
go.microsoft.com/fwlink/?LinkID=220649 Link No
http://www.microsoft.com/en-us/download/details.aspx?id=23691 Link No
download.microsoft.com/download/E/B/A/EBA0A152-F426-47E6-9E3F-EFB686E3CA20/VS2010SP1dvd1.iso  Link  No
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5&displaylang=en Link  No
 my.visualstudio.com/Downloads?q=visual%20studio%202010%20service%20pack%201  ( All ) Link  Yes
my.visualstudio.com/Downloads?pid=2300 ( Visual Studio 2010 Service Pack 1 ) Link  Yes

 

Downloaded

Please download the online installer availed here.

BTW the link noted above is from my.visualstudio.com web site.

And, you need a registered user.

If you have yet to register for my.visualstudio.com, please do so.

It is a free.

 

Downloaded Results

Here are results that matches “Visual Studio Service Pack 1

Downloaded

Visual Studio 2010 Service Pack 1 – Details

File Specification

The file’s name is mu_visual_studio_2010_sp1_web_installer_x86_651694.exe.

It is a relatively small file, 795 KB.

It is an online installer and it is a bootstrap as it simply connects to the website and downloads the actual install media.

 

Install Visual Studio 2010 – SP1

Screen Shot

Welcome

Microsoft Visual Studio 2010 Service Pack 1 Setup

Installation Progress

Installation Is Complete