Div Border With Rounded Corners And Gradient Background

Getting a div to have rounded corners with CSS is not too difficult of a task. I came across a solution I would like to share quickly and briefly. Please note I found it only works in IE9, Firefox and Chrome. It’s really only a couple lines of CSS so lets’ take a look.

.roundedCorners {
   -webkit-border-radius:10px;
    -moz-border-radius:10px;
    border-radius: 10px;
}

By setting these 3 values, you get a pretty nice rounded edge. Now here is a weird edge case I came across. I used a gradient background through CSS in a div and in IE9 the gradient was not rounded off. So the fix for that was to surround it with a div and use an overflow: hidden to mask the colors.


<div class="roundedCorners mask">
    <div class=" roundedCorners gradientBackground">
    </div>
</div>

//CSS
.gradientBackground {
    /* for IE */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ccc', endColorstr='#fff');
    
    /* for webkit browsers */
    background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#fff)); /* for webkit browsers */
    
    /* for firefox 3.6+ */
    background: -moz-linear-gradient(top,  #ccc,  #fff); /* for firefox 3.6+ */
}

.mask {
     overflow: hidden;
}

The above code properly rounded the corners of my div and provided a gradient with rounded corners as well in IE9, Firefox, and Chrome.  The rounded corners don’t work in older versions of IE.


Reinstalling and Moving Windows Services using bat file

Utilizing this bat file really makes moving windows services and re-installing them in a new location a fairly easy and quick task. I had an instance where I needed to move a currently running windows service to a new folder in a directory. I found that an easy way to do this was to just uninstall and reinstall the service itself. For this I used a .bat file that includes a couple commands. First, we have to stop the running service.

net stop "Adam's Windows Service"

The next command is using InstallUtil.exe to uninstall the current service. This is the full line for uninstalling.

c:\windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe -u "D:\Adams\AdamsWindowsService.exe"

As you can see, the ‘-u’ signifies uninstall.  Now that we have the service uninstalled we want to reinstall it using the new directory location.  This line looks almost exactly the same as above, however, there is no ‘-u’.  Have a look at the following to install.

c:\windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "D:\AdamsNewDirectory\AdamsWindowsService.exe"

My service is now running from a new directory at D:\AdamsNewDriectory. The last thing to do is to restart the service.  This is almost the exact same as the first line except it includes a start.

net start "Adam's Windows Service"

Now that we have an AdamsServiceMove.bat (naming doesn’t matter) we can easily modify it for any service to and from any location as well.  Have a look at the full file below.

net stop "Adam's Windows Service" 
c:\windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe -u "D:\Adams\AdamsWindowsService.exe"
echo.
echo Please verify uninstallation ...
pause

c:\windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "D:\AdamsNewDirectory\AdamsWindowsService.exe"

echo.
echo Starting Adam’s Windows Service...
pause

net start "Adam's Windows Service"

pause


Targeting IE6 and IE7 in CSS

Targeting IE6 and IE7 in CSS, as many of you know, becomes an extremely useful yet hack type of way of coding when you have to support these old browsers.  Some CSS hacks have made it a lot easier to handle the little quirks and override the main CSS to target a specific version.  There are two characters, one for IE6 and one for IE7.  Here is how it looks.

#divName
{
     padding: 5px;  /* shows in all browsers */
     *padding: 5px; /* shows in IE7 and earlier */
      _padding: 5px; /* shows in IE6 and earlier */
}

Really simple; by adding the preceding characters, it can change your CSS world.  I try at all costs to avoid doing such things because I don’t like how it clutters up my CSS page.  However, sometimes it’s just the easiest/quickest way to get the desired result you need when you have a deadline to meet.

There is another way to try and force CSS that is not working at that is by using a modifier called !important. However, this can make code messy and hard to maintain and I recommend avoiding at all costs.

Here is an example:

p {
    color: blue !important;
}

This means, regardless of what color style you use on an paragraph tag in other CSS, it will be trumped and will show up blue. Use wisely my friends.


KoGrid with KnockoutJS Simple Grid Set Up

Recently we took a look at implementing KoGrid which utilizes KnockoutJS.  This is a brief set up that I go going by pulling a data set from our controller.  First let’s look into the JavaScript and how all this happens.  Let’s look at the document initialization method first.

$(function () {
    var $scvm = new ConfigsViewModel();  //Create New Instance of our ViewModel
    $scvm.LoadConfigurations();  //Calls the load function in our ViewModel
});

This is all pretty straight forward.  So let’s take a bit deeper look into the ConfigsViewModel().  In here we will create our observableArray() and load our data.

var ConfigsViewModel = function () {
var self = this;

    //#region Observables
    self.ConfigurationsMin = ko.observableArray();
    //#endregion

    self.LoadConfigurations = function () {
        $.post("/Config/Search", function (data) {
            var viewModel = {
                ConfigurationsMin: ko.observableArray(JSON.parse(data))
            };

            //Activates knockoutjs so the browser knows what to do with data-bind in markup html.
            ko.applyBindings(viewModel); 
        });
    };
};

Here you can see the LoadConfigurations function that gets call when the dom loads.  Within this function it’s doing an Ajax post which returns a serialized result.


JavaScriptSerializer s = new JavaScriptSerializer();
string json = s.Serialize(results);

return json;

Since we are serializing the results we do a quick JSON.parse which will split the data out into a JSON object that the grid will recognize.  This is all relatively simple and gets a start to pull data back.  Now let’s look at the mark up of the grid.

Here is the whole mark up and we will dig into it.

<div id="table_words" class="someStyles" data-bind="koGrid: { 'data': ConfigurationsMin }">
</div>

There are a few key points for this intro into KoGrid.  First, you can see using the data-bind element we are signaling koGrid which has an element called data.  Here we assign data with the observableArray of ConfigurationsMin.  If you remember, we created and applied our data to this object. ConfigurationsMin: ko.observableArray(data).  This is the bare bones of KoGrid and knockout; but it gets a grid up and running with doing an Ajax call to get some data to populate the grid with.


Ensure Threads Finish Before Method Continues Thread Join

So I wrote a post a few weeks back using a different method for the same thing.  I used a counter to count how many threads I started, and then decremented them as they finished.  Once the counter was equal to zero, I let the method continue and finish.  However, I realized since then that using Thread.Join() (Thread Join) was a lot easier to use and manage to handle the same task.

So the set up is that we are spinning off a handful of threads, but we don’t want the method, such as Main() to continue until all threads are finished. So we start off by needing a list to add all the threads to once we start them.

protected List _threadList = new List();

Then in our methods where we create and start the threads we will add them to this list we just created.

//Create new thread
Thread logThread = new Thread(LogServiceCall);

//Start new thread
logThread.Start(logParams);

//Add thread to thread list
_threadList.Add(checkThread);

So after we have spun off all our threads; the next call in the method basically calls Thread.Join() on all threads within that list.  What Thread.Join() does is block the calling thread from terminating before all the other threads do.  So by doing this we can ensure that the main method won’t be able to finish until all the threads have since we cause the calling thread to hang.
This is the little snippet to call Thread.Join() on the thread list.

foreach (Thread thread in _threadList){
     thread.Join();
}

Once this completes, all the threads we started have to finish before the main calling thread can continue and terminate allowing the method to continue.  I find this to be a more compact and less heavy way to complete this task instead of using a counter.


StackOverflow Profile