Configuring a cloud-based secure multi-domain web and e-mail server

Standard

Introduction

As I’ve mentioned previously, I own an HP MediaSmart server. Up until recently I’ve used it to host both my jkshay.com domain as well as my wife’s thebumbleshack.com domain. If you’ve seen thebumbleshack.com, you’ll see that we’re currently in the process of downsizing, reducing our possessions and living a simpler, more harmonious lifestyle. That being said, I knew I was likely taking my server off-line (it’s a HUGE power hog) and needed a replacement solution.

We’ve used cloud servers at my current employer for several years, hosting several sites with e-mail and web services without issue. I just didn’t want to pay the high prices (upwards of $100/mo minimum) to replace something I *could* do for the cost of electricity, so I set out to find an affordable alternative – and I did. Continue reading

Implement WebClient’s asynchronous download with cancellation capability

Standard

When I wrote my article regarding use of the BackgroundWorker to keep the UI responsive, I used the WebClient’s DownloadString method as an example of a long-running process. I used this as an example in explaining how to use the BackgroundWorker, which simply allows for thread-blocking code to be run in a separate thread.

As it turns out, this is a terrible idea. Not the whole thread-blocking code in a separate thread, but the use of a WebClient in a BackgroundWorker. You see, the WebClient class implements a DownloadStringAsync() method. This allows the calling code to continue to run, and the asynchronous process will eventually return a string. But since it’s asynchronous, our UI thread will never get blocked by a long-running process. And since it too supports asynchronous cancellation, there’s no reason to embed it inside a BackgroundWorker. Continue reading

Implement cancellation ability on BackgroundWorker

Standard

As I mentioned in my article on implementing the BackgroundWorker to keep your WPF user interface responsive, the BackgroundWorker class supports cancellation. I will illustrate here how easy it is to accomplish.

I’ll build this example by continuing the example in the previous article. First, let’s add a BackgroundWorker property to our DataModel class. Continue reading

Easily create a WPF splash screen with status updates via MVVM

Standard

I was in search of an easy implementation of a splash screen for my current project. I wanted to be able to show a splash screen and update it with current status information as my application initialized.

The standard SplashScreen class provided by Microsoft does not support showing dynamic content on the SplashScreen. For this reason, I was not able to use the supplied class. Instead I decided to create my own.

The splash screen I created is simply a regular window bound to a view model. I’ve created a SplashScreenHelper static class that we’ll use to send status updates to the splash screen. Continue reading

Embedding an Axis brand camera into WordPress

Standard

[showAxisCamera url=”208.42.203.54″ port=”8588″]
After I posted my article about embedding a video feed into my WordPress site, I received an e-mail from a reader in the UK looking for assistance configuring an Axis brand camera in a WordPress site. Ultimately, I ended up creating a more robust version of my original code, but for Axis brand cameras. I thought I would share that code here, with a brief explanation of the changes from the original article and a few examples of implementation.

I’m not claiming authorship of this code; rather, I just tweaked existing code the reader provided to get it working in WordPress (including the creation of a short code).

In this code, I implement the ability to use a single shortcode with multiple cameras at different subdomains. I won’t go into how to add this code to your WordPress site (I explain how to do this in the original article). Just know that it should be added to your theme’s functions.php file. Continue reading

Creating a flexible custom WPF dialog

Standard

In my current project, we had a need to create a custom WPF dialog box. Writing our own provides us the ability to easily skin the window with our application’s theme as well as gives us the ability to generate any buttons we wanted.

We wanted our custom dialog box to be able to:

  1. Display a message to the user
  2. Provide various button options (OK, OK/Cancel, Yes/No, Yes/No/Cancel, etc)
  3. Return the button clicked by the user
  4. Display an optional CheckBox
    • Display text next to the optional CheckBox
    • Accept a boolean property for the default IsChecked state of the optional CheckBox
    • Provide the IsChecked value of the optional CheckBox as an out parameter

Continue reading

Closing a WPF Window using MVVM and minimal code-behind

Standard

The other day I started moving all my event handlers in my application from the View’s code-behind file to the ViewModel. I accomplished this using command binding. This was all easy enough – until I came to my Close method.

You see, in the MVVM (Model – View – View Model) design pattern, the ViewModel – a class that typically contains the values you want to display in your View – shouldn’t know anything about the View. It’s OK (and quite necessary!) for the View to be aware of the ViewModel, however.

So let’s take a look at the Close button’s event handler as it originally existed in code-behind:

private void Close_Click(object sender, RoutedEventArgs e)
{
    this.Close();
}

Continue reading

WordPress plug-in Anti-Spam

Standard

On my wife’s site, we were getting hit from numerous (15+) spam messages a day. We figured this was an acceptable number to just handle manually, but quickly grew tired of taking the time to moderate these comments, marking them as trash.

We tried various CAPTCHA plugins but none were very graceful. From difficult-to-read CAPTCHA strings to stark, unstyled “You have entered an invalid CAPTCHA” message, none of the CAPTCHA plugins we implemented really worked for us.

Then I found this plugin. It’s so simple in its implementation that it’s almost laughable. There’s beauty in what it does, though. It’s not overly complicated, it doesn’t affect the aesthetic of the site AT ALL, and most importantly, it just works.

I’ve had this plugin installed for over 11 years, 0 months and have only received 36657 spam comments. I give it five stars all day long. Continue reading

Embed IP camera stream into WordPress pages/posts

Standard

[showCamera width=”300″]I was looking for a way to show my local IP network camera stream in my site (and my wife’s site). Sure, it was easy enough to find the necessary code on Google and embed in a post through the text editor, but I wanted something more.

I can’t expect my wife to write her posts without the Visual editor (which would have butchered the HTML required to show the stream), so I decided to convert the camera-generating HTML code to a PHP function and put it in our sites’ functions.php files. Why would I want to do this?

Continue reading

Implementing an ISAPI rewrite for IIS 6

Standard

In an effort to clean up the URLs my WordPress-based site generated, I wanted to implement an ISAPI rewrite. You see, because I host my site on IIS 6, turning on WordPress’ Permalinks required an “/index.php/” in all of my URLs. I wanted a way to eliminate the “/index.php/” portion of the URL.  If I were hosting this site on an Apache server, it would be a no-brainer as Apache has the mod_rewrite module available, and would be able to serve URLs without the /index.php/ out of the box.  According to http://httpd.apache.org, the mod_rewrite module “uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly.”  It is this module that allows the intricate URLs created by WordPress to be presented in a friendly, cleaner manner – allowing http://jkshay.com/index.php/implementing-an-isapi-rewrite-for-iis to be accessed with a URL such as http://jkshay.com/implementing-an-isapi-rewrite-for-iis-6.

Continue reading