Tuesday, July 31, 2007

So I run this blog from an old PC running Small Business Server 2003 (p3 2ghz 2gb 2x80gb).     I host this server on the end of a dynamic IP address provided by my local cable company.   On top of this I use DynaDNS.org to map my domain name of binaryrefinery.com to this server.

This all works nicely I host exchange, sharepoint, sql 2005 and anything else I'm playing with at that moment.   So today I went even more minimal...

My office needs to become another bedroom, so where to put the server?

We'll going for the slightly obscure,  it now been re-positioned to run headless (no screen, keyboard, love) on-top of my fridge freezer.

I'm a little worried about cooling, but if your reading this we're still up and running....

Tuesday, July 31, 2007 7:48:48 PM UTC  #    Comments [0]  | 
Monday, July 30, 2007

This macro opens up the current visual studio project's folder in Explorer.   

 

Public Sub OpenExplorer()

       Dim currentSlnFolder As String

       currentSlnFolder = DTE.Solution.FullName
       REM currentSlnFolder = DTE.ActiveDocument.Path
       If (String.IsNullOrEmpty(currentSlnFolder)) Then

           Return
       End If

       Debug.Print(currentSlnFolder)
       Dim lastpos = currentSlnFolder.LastIndexOf("\")
       currentSlnFolder = """" + currentSlnFolder.Substring(0, lastpos) + """"
       Shell("explorer.exe " + currentSlnFolder, AppWinStyle.NormalFocus, False, -1)
   End Sub

Monday, July 30, 2007 12:44:54 PM UTC  #    Comments [0]  | 
Wednesday, July 25, 2007

So often In Visual Studio  find myself needing to get to a DOS prompt with the directory set to the current solutions folder.   Strangely I find I do this with alarming regularity.

So today I just created a quick macro in visual studio that I've added to my main toolbar.

 

image

Here's the source

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module RJMacros
    Public Sub OpenDos()

        Dim currentSlnFolder As String

        currentSlnFolder = DTE.Solution.FullName
        REM currentSlnFolder = DTE.ActiveDocument.Path
        If (String.IsNullOrEmpty(currentSlnFolder)) Then

            Return
        End If

        Debug.Print(currentSlnFolder)
        Dim lastpos = currentSlnFolder.LastIndexOf("\")
        currentSlnFolder = currentSlnFolder.Substring(0, lastpos)
        currentSlnFolder = """CD /d " + currentSlnFolder + """"
        Shell("cmd /K " + currentSlnFolder, AppWinStyle.NormalFocus, False, -1)
    End Sub
End Module

 

Of course the same could be used with minor modification for opening PowerShell.

Wednesday, July 25, 2007 1:05:15 PM UTC  #    Comments [0]  | 
Friday, July 20, 2007

SI'm in the process of building a set of mobile applications that interact with a number of different data-sources using web-service calls.  

This is to provide real-time stock movement and allocation, so therefore things need to happen very quickly.    Every scan of a barcode, delivery drop needs to immediately fire back to our base data-sources.    Going web-services is the only real choice as the remit of this application means that I have to also use the Internet in certain locations to provide this link.   Ok, so where's this all going?

I've been using these words of Wisdom to tune my web-service calls -

http://msdn2.microsoft.com/en-us/library/ms979173.aspx

Its good advice for anyone out there doing this kind of programming.

Friday, July 20, 2007 5:54:16 AM UTC  #    Comments [0]  | 
Saturday, July 14, 2007

OK, I admit it after posting about cross browser mobile AJAX I ran into a BIG problem,

It seems that my mobile web portal was running out of steam processing large RSS feeds in Javascript to display on Pocket Internet Explorer.

In addition, Apple Safari seemed to suffer the same issue. (?!?#*! )

So I'm pleased to announce I've solved the problem and here are the results (or see for yourself at www.binaryrefinery.com/mobile )

image

Windows Mobile 5

 

image

I.E 7

 

image

Apple Safari (closet I've got to an iPhone)

 

So how did I get this working?   We'll I wrote a small scheduled task that runs periodically and saves on my web-server a cut down (last n articles) version of my RSS feed.   The mobile portal uses this cut down feed to display rather than the full RSS>  Here's the source of the command line driven schedule task.  I've called it RSS Cutter -

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;

namespace RSSCutter
{
  static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("RSSCutter <url of feed> <no of articles> <output path>");
                return;
            }
            int no_of_articles = 1;
            try
            {
                no_of_articles = Convert.ToInt32(args[1]);
            }
            catch
            {
            }
            RSSCutter r = new RSSCutter(args[0], no_of_articles, args[2]);
        }
    public class RSSCutter
    {
        public RSSCutter(string url, int no_of_articles, string outputpath)
        {
            WebRequest req = WebRequest.Create(url);
            WebResponse result = req.GetResponse();
            Stream receivestream = result.GetResponseStream();
           
            XmlDocument x = new XmlDocument();
            try
            {
                x.Load(receivestream);
                result.Close();
                receivestream.Close();
            }
            catch
            {

            }
            XmlNodeList nodes = x.GetElementsByTagName("item");
            if (nodes.Count == 0) return;

            int intcount = 0;
            foreach (XmlNode n in nodes)
            {
               if (intcount>no_of_articles) n.RemoveAll();
                intcount++;
               
            }

            x.Save(outputpath);
    
        }
    }
}
Technorati tags: ,
Saturday, July 14, 2007 9:53:15 PM UTC  #    Comments [0]  | 
Wednesday, July 11, 2007

Technorati tags:

I'm talking at the upcoming August Messaging and Mobility User Group (MMUG) in London.   Should be a hoot and great way to see the super cool new Microsoft offices/crib in Victoria.

I'm going to give a deep-dive into line of business mobile applications and a chance to experience some of latest developments in the world of Microsoft mobility.

Full details at -

http://www.mmmug.co.uk/forums/thread/1340.aspx

Wednesday, July 11, 2007 10:01:53 PM UTC  #    Comments [0]  | 

So today I have been working on a Windows Mobile project that uses an Oracle back-end database.   So the challenge how to directly call into Oracle from a Compact Framework application in real-time.  So here's the deal.  The .Net CF doesn't support native Oracle connectivity.    So in essence we have to call a web-service to then go on and talk to Oracle.  This technique works a treat.   More details to follow in upcoming posts.

 

Wednesday, July 11, 2007 9:48:56 PM UTC  #    Comments [0]  | 
Monday, July 09, 2007

So after detecting my first iPhone connect to my Blog,   I wondered whether the Mobile AJAX code that I wrote for Windows Mobile would work for other browsers.See  -

http://www.binaryrefinery.com/main/default,date,2007-04-23.aspx#a7c1ae14c-edd5-4306-b6e1-cf70952330ba

 

So, I decided to download the Apple Safari web browser for windows.   I thought that Safari would show up pretty well how my mobile Blog would appear on an iPhone.  Surprise, surprise my mobile AJAX blog just didn't load.  Safari can be obtained here -

http://www.apple.com/safari/download/

 

This was clearly due to the creation of Active X objects in the mobile page, like -

g_request= new ActiveXObject("Microsoft.XMLHTTP");

 

Anyhow following the Safari web developers guide I put in some basic browser detection, I won't bore you with all the code.   But if you interested have a look at the results at -

http://www.binaryrefinery.com/mobile

(then do a view source on the page)

Technorati tags: , ,
Monday, July 09, 2007 8:21:34 PM UTC  #    Comments [0]  | 
Thursday, July 05, 2007

So this is nice.

Try this

http://api.hostip.info/?ip=12.215.42.19

Returns the location for any given IP address as a nice bit of XML.  

Perfect For Virtual Earth applications or analyzing your web server logs. 

Technorati tags:
Thursday, July 05, 2007 7:17:17 PM UTC  #    Comments [0]  | 

I've needed to expand my automatic redirection script to direct iPhone users to mobile web pages in the same way that I do for Windows Mobile/WAP type devices.

Following Apple's guidelines at  -

http://developer.apple.com/iphone/designingcontent.html

I expanded my automatic redirection ASP.NET page that I blogged about awhile back to include this feature.  Previous post at -   

http://www.binaryrefinery.com/main/default,month,2007-03.aspx#a48c1e6c7-573c-4f68-993e-00aa6f600b7f

Its does the job.   + I am pleased to see that today I have my first iPhone user find my Blog,  I wonder what they think?

 

ASP.NET C# source below -

 

<%@ Page Language="C#" Trace="false" %>

<SCRIPT LANGUAGE="C#" RUNAT=SERVER>

    protected void Page_Load(Object sender, EventArgs e)
    {
        System.Web.Mobile.MobileCapabilities cur = (System.Web.Mobile.MobileCapabilities) Request.Browser;

        

        // this block of code is to detect if users are running Pocket PC 2003/CE or iPhone
        bool isce=false;
        bool isiphone=false;

        try    {
            isce = (Request.UserAgent.IndexOf("Windows CE")!=-1);
            isiphone = (Request.UserAgent.IndexOf("iPhone;")!=-1);
        }
        catch
        {

        }
    
        if (cur.IsMobileDevice||isce||isiphone)
        {                
            Response.Redirect("mobile");  // MOBILE PAGE
        }
        else
        {
            Response.Redirect("main"); // NORMAL PAGE
            
        }
        
        
    }

</SCRIPT>
Thursday, July 05, 2007 3:00:51 PM UTC  #    Comments [0]  | 

Today's mission has been to write a stored procedure that does a reverse DNS on various IP addresses that I need to process.   My stored proc is very simple and looks like the following -

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Net;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void SpProcessIP(SqlString ipaddr)
    {
        string ourip = ipaddr.Value;
        // first lookup if we have a resolved ip or not
        SqlConnection sconn = new SqlConnection("context connection=true");
        sconn.Open();
        string stringstrsql = "SELECT COUNT(*) FROM [IP Log] WHERE IP='" + ourip + "'";
        SqlCommand sc = new SqlCommand(stringstrsql,sconn);
        sc.CommandType = CommandType.Text;
        bool haveresolved = Convert.ToInt32(sc.ExecuteScalar().ToString())==1;
        sc.Dispose();
        if (!haveresolved)
        {
            
            string ourname = ourip;
            
                IPHostEntry i = Dns.GetHostEntry(ourip);
                ourname = i.HostName;
            
            
            stringstrsql = "INSERT INTO ";
            stringstrsql += "[IP Log]";
            stringstrsql += "(";
            stringstrsql += " IP";
            stringstrsql += ",[Resolved To]";
            stringstrsql += ")";
            stringstrsql += "VALUES ";
            stringstrsql += "(";
            stringstrsql += " '"+ourip+"'";
            stringstrsql += ",'" + ourname + "'";
            stringstrsql += ")";
            sc = new SqlCommand(stringstrsql, sconn);
            sc.CommandType = CommandType.Text;
            sc.ExecuteNonQuery();
            sc.Dispose();
        }
        sconn.Close();
        sconn.Dispose();

    }
}
However to get it installed in SQL server is a bit of a fiddle.   
Firstly you have to from the project properties in Visual Studio you have to switch on, that the sproc has external access.
See below.
image 
 
I then built the project,  copied the compiled DLL onto the SQL Server and ran the following (on the master database) -
 
CREATE ASYMMETRIC KEY LogFileDbComponentsManagedKey FROM
 EXECUTABLE FILE = 'C:\components\LogFileDbComponentsManaged.dll' CREATE LOGIN dbo 
FROM ASYMMETRIC KEY LogFileDbComponentsManagedKey 
GRANT EXTERNAL ACCESS ASSEMBLY TO dbo 
 
From this point on, its plain sailing, you can then deploy from Visual Studio and use the stored procedure quite happily.
Technorati tags: ,
Thursday, July 05, 2007 12:10:23 PM UTC  #    Comments [0]  | 
Wednesday, July 04, 2007

This little code snip, translates a Dynamics NAV regular expression into its  .Net equivalent.

 

public static string NavisionRegToRegex(string strtotest)
        {
            string navregex = strtotest;

            navregex = "(" + navregex + ")$"; // make sure we are testing to the end of the string
            navregex = navregex.Replace("*", ".*"); // 0 or more
            navregex = navregex.Replace("?", ".{1}"); // single char
            // or operator is a |
            navregex = navregex.Replace("&", "");
            return navregex;
        }

Technorati tags:
Wednesday, July 04, 2007 9:15:53 PM UTC  #    Comments [0]  | 

Probably reveals lots about who I am just from the url.

http://geekdad.com

Wednesday, July 04, 2007 9:00:49 PM UTC  #    Comments [0]  | 
Tuesday, July 03, 2007

So back in April I posted about building a Mobile RSS reader using AJAX.

See

http://www.binaryrefinery.com/main/default,month,2007-04.aspx#a7c1ae14c-edd5-4306-b6e1-cf70952330ba

I'm pleased to see I'm getting 15% of all hits to my blog coming in from mobile devices.

I guess this shows that mobile Ajax does work (well I have no complaints).   Please feel free to try my blog mobile from a desktop browser by going to:

http://www.binaryrefinery.com/mobile

Technorati tags: ,
Tuesday, July 03, 2007 7:05:02 PM UTC  #    Comments [0]  | 
Sunday, July 01, 2007

So today, I got a bit lost..

I got a bit lost while out driving looking for a kids indoor play area (for our children :-) ).

The road was right but I couldn't find where we supposed to be heading,  even using the Sat Nav in our car.    So I turned to a better alternative.   I switched Live Search Mobile on, on my phone.   I then centered the map on our GPS location,  searched for recreation areas near me.   30 seconds later I had driving directions and realisation that I had typed slightly the wrong location into my Sat Nav.

Thank you Live Search Mobile...

Sunday, July 01, 2007 7:37:32 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: