Archive
Com Reflection
The article provides an example of using reflection to uncover hidden
properties and methods of the Speech library, and also explains how the
elusive System.__ComObject can give up its goodies, so to speak.
It
works fine on the sample Speech API DLL on the site, however, it isn’t
so hot when it comes to Sage. I tried plugging in some common CLSID’s
from Sage’s inner workings, but it gave up no further information. I
then tried passing a System.__ComObject to it, with the following code;
Dim oUnknown As Object = o.GetCompanies("C:Program FilesSageAccounts")
DumpCOMObject(oUnknown)
However, it crashed out when IDispatch::GetTypeInfoCount returned 0. According to MSDN reference this is done to prevent run-time inspection of the DLL, perhaps for security purposes.
So,
I guess this is a bit of an anti-pattern when it comes to Sage
development, but I hope that this research saves another developer some
time when it comes to trying to figure out the million dollar question
‘what do I cast this object to now?
AppAnalyze launched on SourceForge
After a while when you start going down one path of maybe one or two larger projects, many of the components you developed once, no longer apply.
Therefore I decided to dig into my old toolkit and publish some of the components I once relied on for my bread-and-butter development work.
The first of which is AppAnalyze, which is now released under GPL open source on sourceforge
http://sourceforge.net/projects/appanalyze/
I hope this provides as much benefit to you as it did for me.
Firing an onchange event from a HTMLSelectElement
Javascript redirect after images have loaded
This is a handy piece of javascript that can be used to execute a redirect only after all images have loaded on a page, up to a maximum of 10 seconds. I put in this maximum threshold, to account for the possibility of a bad link on the page, or a user with images turned off on their browser.
waitForImages();
var imageLoadTimeout = 10; // max 10 seconds;
var timeWaited = 0;
function waitForImages()
{
var AllLoaded=true;
if (timeWaited>imageLoadTimeout)
{
// redirect after 10 seconds, regardless of whether images are loaded.
ImagesLoaded();
return;
}
for(i=0;i<document.images.length;i++)
{
var image = document.images[i];
if (!image.complete && image.name != "brokenImage" )
{
AllLoaded=false;
break;
}
}
if (AllLoaded)
{
ImagesLoaded();
}
else
{
timeWaited += 0.5;
setTimeout(‘waitForImages()’,500);
}
}
function ImagesLoaded()
{
RedirectPage();
}
Useful c# function – remove duplicates
public
ArrayList RemoveDups(ArrayList items){
ArrayList noDups =
new ArrayList(); foreach(string strItem in items){
if (!noDups.Contains(strItem.Trim())){
noDups.Add(strItem.Trim());
}
}
noDups.Sort();
return noDups;}
Handy!
del.icio.us auto-post
private
void SubmitDelicious(string url,string description,string username,string password,string tags){
#region
postdata /*POST /login HTTP/1.1
Host: secure.del.icio.us
user_name=nora344
password=lokiju
jump=no
url=http%3A%2F%2Fwww.envoyez.com
login=log+in
GET /nora344?url=http%3A%2F%2Fwww.envoyez.com
jump=no
POST /nora344?636480 HTTP/1.1
Host: del.icio.us
url=http%3A%2F%2Fwww.envoyez.com
oldurl=http%3A%2F%2Fwww.envoyez.com
description=envoyez+sms
notes=
tags=
jump=no
key=6c7b3c42b196c8e3ebc90130317786eb
*/
#endregion
// step 1. login string strUrl = "https://secure.del.icio.us/login"; string strPostdata = "user_name=" + username + "&";strPostdata += "password=" + password + "&";
strPostdata += "jump=no&";
strPostdata += "url=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "login=log+in&";
HTTPRequest hrWeb =
new HTTPRequest();hrWeb.blnExpect100Continue =
false; string html = hrWeb.Request(strUrl,"POST",strPostdata); // at this point, we may need to transfer cookies from secure.delicious to delicious?CookieCollection ckCol = hrWeb.RequestCookies.GetCookies(
new Uri("https://secure.del.icio.us"));
Cookie ckAccept =
new Cookie("_accept_s_cookies","1","/",".icio.us");Cookie ckInstall =
new Cookie("_ext_install_redir","1","/",".icio.us");Cookie ckRegister =
new Cookie("_register_id","1248967165","/",".icio.us"); // _register_id?Cookie ckUser =
new Cookie("_user",ckCol["_user"].Value,"/",".icio.us");Cookie ckBM =
new Cookie("_bm_url",HttpUtility.UrlEncode(url),"/",".icio.us"); // BX=4ehl0pt2i6vse&b=3&s=dr – already sethrWeb.RequestCookies.Add(ckAccept);
hrWeb.RequestCookies.Add(ckInstall);
hrWeb.RequestCookies.Add(ckRegister);
hrWeb.RequestCookies.Add(ckUser);
hrWeb.RequestCookies.Add(ckBM);
// step 2. redirectstrUrl = "http://del.icio.us/";
strUrl += username;
strUrl += "?url=" + HttpUtility.UrlEncode(url) + "&jump=no";
html = hrWeb.Request(strUrl);
if (html.IndexOf("in order to save an item, you have to log in")!=-1){
return;}
string strIDRegex = @"action…w+?(?<ID>d+)"; string strID = Regex.Match(html,strIDRegex).Groups["ID"].Value; string strKeyRegex = @"key..value..(?<KEY>w+)"; string strKey = Regex.Match(html,strKeyRegex).Groups["KEY"].Value; // step 3. poststrUrl = "http://del.icio.us/" + username + "?" + strID;
strPostdata = "url=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "oldurl=" + HttpUtility.UrlEncode(url) + "&";
strPostdata += "description=" + HttpUtility.UrlEncode(description) + "&";
strPostdata += "notes=&";
strPostdata += "tags=" + HttpUtility.UrlEncode(tags) + "&";
strPostdata += "jump=no&";
strPostdata += "key=" + strKey;
html = hrWeb.Request(strUrl,"POST",strPostdata);
}
Java Midlet for .NET web services
Visitor Tracker in ASP.NET
ON RecentVisitors
FOR INSERT
AS
BEGIN
— note this will track hits not unique visitors.
select @VisitorsToday = count(*) from RecentVisitors
where dateDiff(day,Date,getdate())=0
and websiteId=@websiteID
delete from AggregatedVisitors where
websiteID = @websiteID
and
Datediff(day,date,getDate())=0
values (@VisitorsToday,@websiteID)
delete from recentVisitors where dateDiff(day,Date,getdate())>1
END
<script language="javascript">
var WebsiteID = 1;
var Tracker = window.document.images["Tracker"];
Tracker.src = "default.aspx?WebsiteId=" + WebsiteID + "&Referrer=" + escape(document.referrer);
</script>
{
string strReferrer = Request.QueryString["Referrer"].ToString();
int intWebsiteID = Convert.ToInt32(Request.QueryString["WebsiteID"]);
string strSQL = "insert into RecentVisitors (IP,Referrer,websiteId) values (";
strSQL += "’" + Request.ServerVariables["REMOTE_ADDR"] + "’,";
strSQL += "’" + strReferrer.Replace("’","”") + "’,";
strSQL += intWebsiteID + ")";
base.ExecuteNonQuery(strSQL);
Session["FirstTime"]=false;
}
Bitmap bmpCanvas = new Bitmap(1,1);
Response.ContentType = "image/gif";
bmpCanvas.Save(Response.OutputStream,ImageFormat.Gif);
ExcecuteNonQuery is a function I wrote to run a statement against the database, and is outside the scope of this blog.
Then, to view this data in a meaningful way, I created a page with two dataGrids, dgRecentVisitors and dgAggregatedVisitors, which used the following SQL to display their results:
select top 20 rv.id,referrer,date from recentvisitors rv
join websites w on w.id = rv.websiteid
where charindex(w.websiteaddress,rv.referrer)=0
order by date desc
and
select * from aggregatedVisitors order by date desc.
and, that suffices for a tracker for my purposes, and I have access to the raw data, should I need to run queries to work out sales conversion rates etc. The only downfall is that it does not correctly measure visitors rather than hits, but that’s work for another day.
Njoy.
Reconnecting ADSL programatically
http://192.168.1.2/doc/loginout.htm?
WINDWEB_URL = %2Fdoc%2Floginout.htm&
simple_ppp_username = xxxx&
simple_ppp_pwd = xxxx&
wanAdapterSelection = 0&
wan_encapsulation = 0&
wan_VPI = 0&
wan_VCI = 38&
PPP_connection_number = 1&
New_PPP_Action = 0