Posts

Using a Combo Box user control with autocomplete suggestions in WPF MVVM

Image
Create a new WPF project Install the Microsoft.Xaml.Behaviors.Wpf nuget package Download link: https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Wpf Copy the download link at the download page, open package manager console and enter the command: [code language="xml"] NuGet\Install-Package Microsoft.Xaml.Behaviors.Wpf -Version 1.1.39 [/code] Create the Command and event handling code BaseViewModel.cs [code language="csharp"] using System; using System.ComponentModel; using System.Diagnostics; namespace Autocomplete { public abstract class BaseViewModel : INotifyPropertyChanged { #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; #endregion protected void OnPropertyChanged(string propertyName) { VerifyPropertyName(propertyName); PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) ...

Navigating between views in WPF / MVVM using dependency injection

Image
A previous post described how to navigate between views in a WPF / MVVM project using the Mediator pattern as a means of passing data around and/or identifying the screen you wish to navigate to. I believe dependency injection is a cleaner and more SOLID-principled way of accomplishing the process of injecting dependencies into the objects of classes that depend on them. In using this, we lessen the need to create objects inside classes and make unit testing easier. The following example shows how to accomplish this as a Visual Studio 2022 WPF project. Step 1. Create a new WPF project Step 2. Install NuGet packages Install the packages necessary to enable dependency injection. In this example we use the ones from Microsoft Extensions, installing them via the Package Manager Console. You will need to install these two: https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/ https://www.nuget.org/packages/Microsoft.Extensions.Hosting Copy ...

How to containerize applications using Docker

Image
A container is a means of containing everything an application needs to run: binary files, libraries, configurations etc. Running your application within a container makes it highly portable. Deployment of updated software is often made complicated by certain infrastructure challenges such as trying to make applications behave consistently across different hosting environments. Containerization avoids this challenge by providing a standardized environment for the application to run in. A further advantage of containers is that they consume far less resource than other means of isolation, such as virtual machines (VMs). An example of how to create containerized application in Visual Studio Code. 1. Create and open a new working folder with application code Create the app folder and add the main.py file to the folder. Create a simple Flask application in the main.py file that displays some text that is displayed in your browser when you access the application. main.py...

Using Cisco WebEx Teams API to enable ChatOps

Image
ChatOps enables you to perform operation tasks on the infrastructure. You need an active WebEx Teams account if you have not already set one up: https://web.webex.com/ Here is a useful link on getting started with this topic if you find the Cisco documentation / training somewhat confusing, as I did: https://blog.wimwauters.com/networkprogrammability/2020-10-06_chatbot_python_local/ Basically this example shows you how to create a python application to listen for incoming messages coming from WebEx chat bot, and on receiving a message, create a new POST REST API to send a reply to the Chat Op. 1. Create a bot In the dashboard select visit help centre. Sign in, then go to https://developer.webex.com/ Click on Start building Apps: And select Create a Bot Create the bot: Copy the bot access token and store it somewhere. Save it somewhere given that this will be lost on closing the browser (though you can always generate and use a new one.) Go back into teams....

Python cheat sheet

Image
Pre-requisite Sounds obvious, but before you start, make sure you have Python installed. You can download it from from here: https://www.python.org/downloads/ I quite like using Notepad++ for testing my Python scripts, you can get it from here: https://notepad-plus-plus.org/downloads/ So in Windows for example, test if you have Python installed by using the '--version' command:

Using Ansible to Create, Delete and List Tenants

Image
Prepare the Environment In this demonstration I am using Cygwin to run the python/ansible scripts in a Windows environment. All my attempts to install ansible via ‘pip install’ in a Windows failed, the number of Stack Overflow posts reporting this problem seems to concur with this. Handy hint: To cd to a windows C: drive in Cygwin use: [code language="text"] cd /cygdrive/c [/code] To use Ansible with the APIC sandbox host, you will need to first establish a few files before you can start writing your playbooks. Verify that the installed ansible version is 2.8.x, and that it is using Python3: Create ansible.cfg file This file is used by Ansible to tell it that the inventory file is called hosts (unless overridden), to disable gathering of facts by default, and to disable the saving of retry files when playbooks stop with errors: ansible.cfg [code language="python"] [defaults] # Use local hosts file inventory = hosts # Disable automatic fac...