amuck
amuck
amuck
amuck

Programming

Insane Invoke Issues of StatusBar Control in .NET

October 4, 2011
By

This post has 342 words. It will take approximately 3 minutes, 25 secondes for reading it.

I’ve been playing around with an application that changes subcontrols of the StatusBar in .NET (using C#). One of the first things I learned about .NET and Windows Forms is that if you do anything cross-thread you had better use an Invoke method with delegates or you get annoying errors. Now the first control I added to the StatusBar is a ToolStripStatusLabel which basically is a label in the status bar (duh). If I want to change the text of the label then I have to do an invoke, but the invoke is not on the label itself but on the parent (i.e. the status bar) so my code to change the label looks something like this:

        public void changeStatusMethod(String message)
        {
            if (statusbar.InvokeRequired)
            {
                statusbar.Invoke(changeStatusDelegate,new object[] {message});
            }
            else
            {
                lblNumIncoming.Text = message;
            }
        }

Now this works and it works exactly as I expected. So the next thing I wanted to do is work with a ToolStripProgressBar which is (I’m sure you’ve guessed it already) a progress bar that appears in the status bar (wow amazing huh?). Now I wanted to increment and basically control this progress bar from another thread (yep just like every other application that displays a progress bar). So I assumed the code would look like this:

        public void updateProgMethod(int value)
        {
            if (statusbar.InvokeRequired)
            {
                statusbar.Invoke(updateProgDelegate, new Object[] { value });
            }
            else
            {
                if (tsProg.Value + value < tsProg.Maximum)
                {
                    tsProg.Increment(value);
                }
            }
        }

GUESS WHAT?!? This doesn’t work! What happens is that the invoke is called and then nothing happens. The delegate does not call the method again to actually do the work? So naturally I did a bit of research, and no one seems to explain why this doesn’t work. It seems most everyone prefers to do things with a BackgroundWorker. While I’ve since refactored my code to use a BackgroundWorker, it isn’t really what I wanted. Now if anyone can properly explain why the invoke doesn’t work but a BackgroundWorker does work, you will win the World!

PHP5 Serialized Cookies, How and Why?

February 18, 2011
By

This post has 58 words. It will take approximately 34 secondes for reading it.

Cookies, a very important part of web application development. Why would someone want to serialize the information stored in a cookie, and how would they do it? That’s what I want to discuss in this article. First let’s take a look at what cookies are and how they are manipulated inside of PHP. Read more »

How to use PHP $_SERVER['REQUEST_URI'] Parsing to Make SEO Freindly URLs.

November 22, 2010
By

This post has 260 words. It will take approximately 2 minutes, 36 secondes for reading it.

We all have seen dynamic URL (URI being the proper term but I still like URL better) where you have the web address followed by the file name and then the question mark followed by a bunch of variable setting. If not here’s a bit of an example: http://someserver.com/index.php?var1=true&var2=103&var3=sometext

The problem with this type of URL is that search engines don’t really care for them. Why? I’m not sure I’ve heard a lot of reasons and since I neither work for a search engine nor am I an expert on search engines I really don’t care. What I do care about is that most experts agree that search engines like URLs to look like a directory structure and with a file name at the end. Now I’m not sure if I can pull off the file name at the end but I can pull off a dynamic URL that looks like a standard directory structured URL.

Now many of you are saying “Yeah Yeah you use the Mod ReWrite of Apache to pull it off, but what happens if you can’t do that?” Well that’s the point. I know that there are lots of hosts out there that do not permit the use of the .htaccess file or allow you to change their Apache server settings. I can make a URL look like a directory structure without rewriting them. How? Well I’m planning on describing that below.
Read more »

How to build your own practically fully contained Session Handling class in PHP 5

November 20, 2010
By

This post has 48 words. It will take approximately 28 secondes for reading it.

In this article I’m going to explain how to build your own PHP session handler class where your session data will be stored to the database. This article assumes that you already know how to access and start PHP sessions for your web application.
Read more »

Interesting Tutorial on Java RMI

October 29, 2010
By

This post has 131 words. It will take approximately 1 minute, 18 secondes for reading it.

I’ve got a Java project at work that requires me to pass information between a server and a client. I’ve never really done this before but someone had told me about using RMI. SO I went to Google and looked to see what I could find. What I found was a very clean and clearly written tutorial on how to work with RMI using both Remote and Serializable classes. I’m still working through the material, but from what I’ve read so far the material could be understood from even a first year programming student. So I would like to pass the link to the tutorial here http://www.eg.bucknell.edu/~cs379/DistributedSystems/rmi_tut.html and thank Mr. Ken Baclawski for writing such a nice article.

Updating and Refreshing a TableViewer in Eclipse RCP from Another Thread

July 19, 2010
By

This post has 182 words. It will take approximately 1 minute, 49 secondes for reading it.

I’m going to post this here mostly for my own memory. I’m guessing it is actually described somewhere but I had to have the help of a colleague to get this to work.

Problem:

I have a thread that is displayed in a TableViewer in my Eclipse RCP application. This thread has a status and will change its status as necessary and I want the status to be displayed in the TableViewer, however I keep getting an Illegal Thread Access Exception when I perform the TableViewer.refresh() or TableViewer.update(Object, String[]) calls.

The Fix:

The proper way to fix this is in your own update or refresh function to create a local “Runnable” class that will perform the update. Here’s some code to show you what I mean:

@Override
public void update(Object o)
{
     // This will update a specific object in the TableViewer without reloading the entire model.
     Display.getDefault().asyncExec(new Runnable() {
                @Override
                 public void run()
                 {
                        MyClass.this.viewer.update(o, null);
                 }
     });
}

There are some more parts to this to prevent errors but this is the basics.

Proper Deployment of Sharepoint Webpart?

March 24, 2009
By

This post has 98 words. It will take approximately 58 secondes for reading it.

So does anyone know how to do this? It seems there are about 500 people with tutorials on how to do it, and every tutorial is different. Microsoft doesn’t even clearly describe this.

Anyone?

No?

Fine, then I’m going to do this myself and then I’ll post here on how to DO IT RIGHT!

Just so you people know:

  • Simply dropping the DLL into the bin folder of the web application and clicking “new” under the webpart gallery DOES NOT WORK!
  • .webpart and .dwp files are not the same and are required for uploading to sharepoint.

Sharepoint and the "Browseris is not defined" Browser Error

March 23, 2009
By

This post has 396 words. It will take approximately 3 minutes, 57 secondes for reading it.

While building my default masterpage for my company’s sharepoint installation I started (as well as everyone else) an annoying little error displaying in IE (usually as a small yellow triangle down in the status bar of the browser). When you clicked it a message came up and said “Browseris is not defined” (or something to those words it was in German).

Now the funny thing is that everything displayed correctly only this little error that although not serious enough to cause problems with the rendering of the site was annoying me to no end. SO I started the big search about the “Browseris” error. I hit Google and apparently this has been going on since about 2004 and nobody really knows where it is coming from (at least if you read the posts on forums all over the place). So what did I do? I went straight to the source and made a post on the Sharepoint forums at Microsoft (by the way if you didn’t know this is a great place to find information). We tested the problem on IE6, IE7, and IE8 Beta. The results were that the error showed up in both IE6 and 7, but IE 8 never showed the error. We are not sure as to why, however, since we mostly target for < IE 8 in house as of now I needed to find a solution.

It was here I was informed on where to find the “Browseris” variable and function (yep the silly buggers used the same name twice one as “browseris” the other “Browseris”). It can be found in the INIT.JS file. This file can be found in the following location: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\{LANGUAGECODE}\.

Replace {LANGUAGECODE} with the correct number for the language you are working with. US English is 1033, German is 1031. You can find more information from Microsoft documentation.

Now the problem is that for some reason other Javascripts that call the Browseris function are called BEFORE init.js has been loaded by the browser. So how to fix this? Simply by adding a new script tag at the very top of your head tag in your masterpage. When you do this the Browseris goes away. Basically do as follows:

<script src="~/_LAYOUTS/1031/init.js" type="javascript/text"></script>Sometitle

HttpWebRequest and Proxies.

March 20, 2009
By

This post has 635 words. It will take approximately 6 minutes, 21 secondes for reading it.

One of the things I can’t stand about many applications that work over the internet is that they by default will use Internet Explorer’s proxy settings. Examples of this is Yahoo! Messenger. Even if you tell it to use “No Proxies” then it will use IE’s proxy settings. With the explosion of Twitter apps that need access this problem is there too. For example I’m using TweetDeck currently, and there is no place in the application for me to manually set the proxy settings. They only assume that I’m going to be using IE as my main browser and use whatever IE is set for.

So why is this a problem? Here’s my reasons:

  • I’ve got a company laptop, proxy settings are set by the company net’s group policies. When I travel or am at home the proxy is of course not in use. Since I use Firefox for most of my browsing needs I don’t care to change the proxy settings of IE.
  • Web products of any sort should have their own parameters for overriding defaults. Since I don’t use IE I would prefer that any web application that I’m using either let me choose for my self what proxy settings to use OR to pick them up from Firefox.
  • To change IE settings requires about 7 different clicks (just to access the properties and make the settings change). Changing them on Firefox is only two (one to launch the program and a second to change turn off the proxy). When I’m forced to use IE for a third web application that can get a bit annoying.

So in the process of building my own Twitter application (since TweetDeck is nice but not exactly what I want) I of course read some wonderful information on how to use the HttpWebRequest function and most importantly its Proxy property.

The Proxy property of the HttpWebRequest class uses a WebProxy class, now here’s the thing, if you do NOT set this property to null it will automatically assume that you wish to use IE’s proxy settings. You can find this information here: HttpWebRequest.Proxy Property. NOW here’s the tricky thing. In the linked article from MSDN library online it suggests that if you don’t want to use a proxy settings you should set the proxy property by calling the GlobalProxySelection.GetEmptyWebProxy however doing so in Visual Studio 2008 will generate the warning that the GlobalProxySelection class and GetEmptyWebProxy method are now DEPRECIATED. This is not stated anywhere on MSDN library online.

If you really want to use an empty web proxy you need to set it to null;

So how am I handling this in my application? Simply I’m putting the proxy parameters in the settings portion of the application. There I test if the settings are asking for No proxy, IE Proxy or Local Proxy settings. I then have a function that returns the specified WebProxy. Here’s an example of how I’m doing it:

private WebProxy GetProxySettings()
{
WebProxy proxy = new WebProxy();
if (Properties.Settings.Default.proxy_selection == 0)
{
// No proxy selected
proxy = null;
}
else if (Properties.Settings.Default.proxy_selection == 2)
{
// Local Proxy Settings
string prxyAddr = Properties.Settings.Default.Proxy_Address;
string prxyPort = Properties.Settings.Default.Proxy_Port;
string prxyUser = Properties.Settings.Default.Proxy_username;
string prxyPass = Properties.Settings.Default.Proxy_password;
if (!string.IsNullOrEmpty(prxyAddr) && !string.IsNullOrEmpty(prxyPort))
{
if (prxyAddr.Substring(0, 7).ToLower() != “http://”)
{
prxyAddr = “http://” + prxyAddr;
}
string proxyAddress = prxyAddr + “:” + prxyPort;
Uri proxyUri = new Uri(proxyAddress);
proxy.Address = proxyUri;
if (!string.IsNullOrEmpty(prxyUser))
{
NetworkCredential proxyCred = new NetworkCredential(prxyUser, prxyPass);
proxy.Credentials = proxyCred;
}
}
else
{
// If not filled out then we use No Proxy Settings
proxy = null;
}
}
else
{
// Otherwise we use IE’s proxy information
proxy = (WebProxy) WebRequest.GetSystemWebProxy();
}
return proxy;
}

Challenge #1 Make a decent looking master page.

March 20, 2009
By

This post has 366 words. It will take approximately 3 minutes, 39 secondes for reading it.

My first challenge for our company Sharepoint was to make a nice looking master page. Since we don’t want our company intranet to look like it belongs to Microsoft I needed to come up with something with our company logo and colors, and make sure it works with Sharepoint. So I started reading up on Masterpages. There is tons of information on masterpages on the internet, most of them say “modify one of the ones that comes with Sharepoint”. So I took my Sharepoint Designer and opened a Masterpage to see what it looked like. My first thought …. ick. The mixture of ASP tags and HTML was pretty hard to follow. While looking through the code I realized that the HTML markup was horrible. It was pretty old stuff with in-line styles as well as using tables for the layout. Now as a pretty much W3C standards nut case I decided “Nope I’m not going to work with that!” So I started looking into building a masterpage from scratch.

Thankfully I found some information on the Minimal Master Page. My first stop was MSDN online for their How To: Create a Minimal Master Page. The information was basically “Copy our example into your masterpage file and it should work”. After reading the comments however, I realized that there were plenty of errors in MSDN’s article which I was able to fix. What I should have done is visit Heather Solomon’s website. She has a wonderful ready to customize minimal master page available for download.

My original plan was to build a simple two column page. My problem is that I didn’t yet understand all the concepts for the navigation, in particular the so called “QuickLaunch” navigation on the left side of the site. So I made a very simple master page with only a banner area for the company logo, a small area for the topnav where I used the pretty much default Asp:Menu, and finally an area for the Main Content. Super, super simple but not exactly what I wanted. However until I better understood the navigation the rest of this challenge had to be put onto hold.

Search

Important Pages

Calendar

February 2012
M T W T F S S
« Oct    
 12345
6789101112
13141516171819
20212223242526
272829