SugarCRM and C# 2- Doing something- Logging in

•September 3, 2009 • Leave a Comment

Last time, we looked at importing the SugarCRM SOAP classes into Visual Studion Express 2008. Now, let’s actually make use of it

Most of the calls use some sort of session ID, which is a string that Sugar uses to determine the validity and possibly origin of a SOAP request. The SOAP interface is, after all publically available.

This is retrieved by a logon process, as follows-

private string session;
// user auth object
private user_auth user_authorisation = new user_auth();

private void doLogin()
{
// login stuff
// authorisation object

user_authorisation.user_name = “username”;
user_authorisation.password = computeMD5String(“mysecretpassword”);
sugar_SOAP_obj.loginCompleted += new loginCompletedEventHandler(sugar_SOAP_obj_loginCompleted);
sugar_SOAP_obj.loginAsync(user_authorisation, “”);
Console.WriteLine(“login initiated”);
}

// login completed actions
private void sugar_SOAP_obj_loginCompleted(object sender, loginCompletedEventArgs e)
{
sugar_SOAP_obj.loginCompleted -= new loginCompletedEventHandler(sugar_SOAP_obj_loginCompleted);
Console.WriteLine(“Login has completed with the result:” + e.Result.id);
session = e.Result.id;
}

The MD5 hash function is as follows:

private int i = 0;
// compute MD5 string for authentication
public string computeMD5String(string PlainText)
{
MD5 md5 = MD5.Create();
byte[] inputBuffer = System.Text.Encoding.ASCII.GetBytes(PlainText);
byte[] outputBuffer = md5.ComputeHash(inputBuffer);

//Convert the byte[] to a hex-string
StringBuilder builder = new StringBuilder(outputBuffer.Length);
for (int i = 0; i < outputBuffer.Length; i++)
{
builder.Append(outputBuffer[i].ToString(“X2″));
}

return builder.ToString();
}

The code above does the following:

1) Creates a string to hold the session.

2) Creates a new user authorisation object, which contains the username and *the hashed password*- I got stuck for half a day working out it needs to be hashed!

3) doLogin populates the user authorisation object with teh appropriate values, creates a listener for the completion of teh authorisation process, then actually initiates the process.

4) sugar_SOAP_obj_loginCompleted function assigns the session string to the session variable. This looks something like ueuqq9obclhbrbrbqk1mat0s07

You may notice that there are non-asynchronous functions available, but I prefer to use asynchronous calls, because they don’t ‘hang’ the application while waiting for a long call to complete. This may save you from calls from users whinging that the application is non-responsive, and async calls allow for triggering a progress bar or ‘Please Wait’ message or something similar.

Now we’re logged in, with a session ID, we can start to do more useful things. Next time, we’ll look at adding a contact using SOAP calls.

SugarCRM and c#

•September 2, 2009 • Leave a Comment

Hi there! Long time no see!

Things are going to get a little boring, sorry kids, as my life has taken a turn for the technical and I’m going to start documenting it a bit, for my own entertainment but as well as sharing with the world what I’ve learned. Some of this is important…

I’ve been playing with SugarCRM lately, specifically with the SOAP aspect of it.

SugarCRM is sort of a funky enterprise-class customer relationship tracking database, written in php and mysql. My work has a CRM, but it’s an Access database that is full of spaghetti code that someone, no-one knows who, wrote a decade ago, and it’s dying, slowly and painfully. Hence, workign on a replacement. SugarCRM, with a little modification, fits the bill.

I’m going to modify it by using SOAP, which is a sort of ’socket’ that the developers of SugarCRM programmed in (done in nuSOAP, something I’ve used before. It’s actually pretty rockin’, especially as Flex handles SOAP really well. The last project I did for the last mob I worked for used nuSOAP for data transfer to a php-driven database) to SugarCRM, that programming environments can use.

There’s stacks of stuff out there regarding tying in SugarCRM with php using SOAP, the best intro to which is this curious little woman called ‘LornaJane‘.

But, due to the unhealthy obsession with all things M$ here, I’ve got to use .NET. And, to make things as painless as possible, I’m going to do it in C#, using Visual C# 2008 Express.

First, we’re going to look at importing the SOAP service into Visual C#. It’s done as a Web Reference, and to add it, I selected the ‘Project’ menu item, then selected ‘Add Web Reference’.

I then entered the url of my SugarCRM instance, followed by /soap.php?wsdl , ie http://mysugarcrminstace/soap.php?wsdl

Visual C# then happily retrieved the exposed methods and properties, and made all the appropriate classes.

Next, we’ll look at actually doing soemthing with it…

What I did on my weekend

•June 25, 2009 • 3 Comments

I have a new job.

I think I mentioned that before… my last boss couldn’t manage his way out of a wet paper bag with a map in a brewery next to a brothel, but because he was a clinical psychopath this didn’t stop him from from ignoring the tax office’s increasingly strident and panicky demands, various software vendor’s legal demands for actually *buying* thier product that we use to mmake our stuff, and the complete lack of any actual business income to wank on to anyone that’ll listen about how rich he’d be, just as soon as the business took off.

So, like CinnKitty (not the same kitty as before, it seems) I jumped ship, to a lovely environmental monitoring company.

Or so I thought, the guy who had the job before I, was either a madman or a genius, had coded eveything to work, exactly as it was, forever.

Which was fine, unless you wanted to put something that wasn’t XP on the network, or upgrade to Office 2007, or, god forbid, change an admin password, killing the lovingly hand-crafted Intranet which had the domain admin password in plaintext in it, to gain write access to a protected directory.

So, it was out of the pan of evil bosses, into the fire of a place that has to be rebuilt, essentially from the ground up.

But, I not only have the might of God on my side (I’m rebuilding with Linux boxes :) ) I also have a new co-worker with a powerful weapon…

Spiceworks, which, amongst other things is a ticketing system for help desk requests- and it’s seriously amazing how the help requests drop off when it’s discovered that just dropping in for a chat, and by the way the printer’s running slow again, can you just pop round and have a look? is logged and reported and accounted for.

Plus the more serious issues stay remembered- no more forgetting that you were workign on a site-to-site vpn that’s worth $20,000 a day in production for the company because someone’s 100 mb email attachment has clogged thier outbox.

Add the full time parenthood (5 months now, seems like a lifetime!) to the mix, with no respite, as his mum has actually been deployed (who’d have thought there’d be a need for short, slightly manic medics in far north Queensland? But apparently there is) and all of a sudden, I have no time for this blog..

But there’s much to tell, so very very much…

We’re talking J-lo size here

•April 9, 2009 • 2 Comments

I’ve got a big-ass new plasma TV! I’ve always wanted one! And… get this, it was free! (well, kinda, I had to set up a web filter for a community college, in exchange. For the record- SME server with Dansguardian works a treat)

The community centre where a friend fo mine works was about to chuck it out, because it was too big… so I claimed it pronto, stuck it to the wall, and plugged it in… and it works! Except…

The reason it was free, is that they also got it for nix, from Cityrail (train company). It was one of the monitors that gave arrival times.

It has burn-in…

It always tells me, in ghostly letters across the top of the screen, that it’s Arrivals, and across the bottom, that the next train is due in (blur) minutes.

Nice to know…

The moving finger, having writ…

•March 26, 2009 • 1 Comment

Moves on…

Misstress M appears to have hidden from us…

and I miss her.

Silly I know, to miss someone who I have never, and will never meet, talk to, or otherwise interact with other than via text, but I followed her antics every day at my old job. It was lovely to lose myself in her new loves, imagine myself at the beaches she photographed, cheer her on as she took on a law degree and set her sights firmly beyond the glass ceiling.

But, after the obligatory “what the fuck have i done i don’t have a sodding clue how to do this new job and they’re going to figure it out and sack me, I know it” time, which tends to last about 3 months for me , I looked up to see where my favourite soap opera was, and it was gone…

Oh well. Good luck M, I hope things are all good for you :)

You used to be cool, man…

•March 26, 2009 • Leave a Comment

Wow, a long time between drinks… but there is a reason for all this…

1) a new job- I’ve been quietly seething at the insanity of the workplace I was at- CinnnKitty may have worked for a Morally Corrupt Mortgage Broker, but I worked for a serious psychopath- and like most psychopaths you find in industry he was initially witty and charming, but after a while, the true scale of his insanity was revealed…I could rant for hours on the curiously and profoundly illegal activities that went on in there, and the promises, and disappointments, but it’s seriously not worth it.

I just get.. angry and they’re going down anyway- you can’t just.. not pay taxes or super (401k to you ‘Merkin types) and get away with it… nor can you use pirated software as company policy and expect pissed off ex-employees tokeep quiet about it…

I’m now an IT manager for an environmental monitoring company, which is entertaining in it’s own right- no office psychopaths, but an evil legacy from an ex-employee- Microsoft Dynamics.

If you ever get asked to manage this particular piece of hell, run, run away. Screaming is encouraged.

It’s a horrid, clunky thing that takes 3 Windows 2003 or higher servers to run (database server, Terminal Server, and Internet portal service), costs in excess of $100,000 plus $10,000 pa to get a support plan (which you need, we use it every day), and, only 7 people can have a go on it at any given point in time.

This week, the internet portal died in the ass and I ended up having to rebuild the entire machine, operating system, IIS, SharePoint web extensions, custom web application installation, all coached by this guy in India and then it still didn’t work, but then it magically did and I lost 3 days of my life I’ll never get back.

But, now it’s working there’s going to be Ghost images made, so that I’ll never have to deal with this ever again… just a restore…

I also had to write my first.NET/ ASPX page yesterday, and I feel dirty on the inside…

2) I’m a full time parent, to a child that is essentially, me. No kidding- there’s a photo of him in the hallway, a snapshot of me at that age tucked beside it, and it’s the same kid.

His mum is in the military, and got deployed, so he’s here now for the indefinite future. But, his mum made some curious choices in raising him- she read lots of child raising manuals and practiced what she read- she negotiated everything, explained her choices, and let him ‘be himself’

He’s a pretty bright kid so this translated into pretty much finding out the right words to say to get what he wanted, and saying them a lot.

And one of the things he wanted to do was be vegetarian. He asked ‘where does meat come from’, and his mum showed him on the Internet. The next day he vowed not to touch any animal products again. This is fine when you’re a parent that doesn’t have to work (she has been inactive for the past few years, and got a phenomenal inheritance so didn’t need to work unless she wanted to) but, not when you’re a full time worker with a house with a kitchen that looks like one of those photos of a house in Israel after a rocket attack, complete with blood stains after the inlaws gave me half a cow for the dog. Didn’t bother to skin it or anything first but…

So, vegetarianism is out, except…

I used to be vegetarian, for exactly the same reasons, when I was young, and idealistic. I lived with Hare Krsnas, danced naked on the beach, played with, and breathed fire in the rainforests and was going to change the world.  So, sometimes I tell the child that he eats what he’s given, and if he doesn’t he misses out on icecream, then I take his computer privileges away, and so on until he gives in, and I hear my parents voice coming out of my mouth, and I feel…
sad… compromised… growed up and, well,
old.
I wonder what else I have to look forward to, where I have to watch the child do the same things I did,and I wonder, will I still be cool? Am I destined, like my parents before me to be out of touch, responsible…
respectable?

Money can’t buy me love

•January 31, 2009 • Leave a Comment

But this does:

Separate 3 egg yolks into a large ceramic or metal bowl. Stir in half a cup of caster sugar, and vigorously whisk with a fork- it’ll go slightly creamy.

Pour a 300 ml tub of thickened cream and a littel under half a cup of full cream milk into a saucepan. Slooowly heat it until it’s hot, but don’t boil it.

Slowly pour the milk/cream mix into the egg/sugar mix while vigorously stirring, so there’s no lumps.

Return all the mixture to the saucepan and heat until nearly, but not quite boiling again. When the mixture is a little thicker, so that it has a consistency that might give Misstress M and Cinkitty ideas and/or giggles, chill it in the fridge for a few hours.

Obtain an icecream maker. They’re pretty cheap- I found one for about $50 that has a metal bowl full of antifreeze or something, that you put in the freezer overnight, and this goes into a machine that basically stirs whatever is in there while it freezes.

When the mixture is cool (this is actually important- warm mixture will take too long to freeze and the ice cream maker bowl will warm up before it’s done) flavour it with something- dark drinking chocolate, coffee, smooshed up and stewed mango/strawberries, vanilla, whatever, and put it into the icecream maker until it’s done.

If you really want, freeze some chocolate treats and hit them with a hammer so that they smash into a million bits and add those, but right at the end or they’ll clog the icecream maker.

Stick the icecream into a plastic container, lick the stirrer (but not the bowl as it’s still probably cold enough to stick your tongue to it) and put the icecream in the freezer for a few hours until it’s hard.

Then, serve it in a cone to the 10 year old son who’s mother unexpectedly turned up one day and gave him to you, saying, essentially it’s your turn now.

Unexpected entertainment

•November 28, 2008 • 2 Comments

Sally works for a Job Nework provider. Here, in Australia, these organisations are contracted by the government to provide services to the unemployed, and get a fee per client.

Lately, business has been good.

So good, in fact, that as a Christmas present to thier employees, last weekend they flew them *all*, and thier partners (yes, this includes yours truly) to a city, put us all up in a 5 star hotel, then hired out a town hall for a 3 course banquet.

Then, they opened the bar, with an unlimited tab. I don’t remember much after that- it all started off all nice and civilised: entrees, champagne, even some impromptu opera from a woman whose teeth I still have nightmares about.

Then, it all quickly degenerated when an local band came on, and started ripping into some Fleetwood Mac covers, then some of thier own songs.

And all of a sudden I was 20 again, bopping away, pashing a pretty girl in the mosh pit (Sally, of course!), hundreds of kilometres from home, drunk off my ass and just not giving a shit.

Woo!

Shell shock

•November 9, 2008 • Leave a Comment

.308 Magnum + absolutely no experience + fox@100 yards = bruised shoulder, bum (where I fell on it) and a surprisingly large, sticky crater.

Gotta love the rural life… once my ears stop ringing.

Damn you Adobe…

•November 2, 2008 • 1 Comment

The thing I do for money is program, in Adobe Flex. And one of the little niches I’ve carved for myself is doing 3D interfaces.

I’ve hacked Papervision3D pretty extensively to make this niche- Papervision is a pretty revolutionary 3D engine for Flash/Flex, although it *is* a little obscure to use.

For simpler things Away3D is probably easier, Papervision is quicker however.

But enough of those comparisons. Most (actually all) of the 3D stuff is based around navigational interfaces- menus and so on. It’s sort of a ‘wow factor’ kind of thing.

So, after studying and hacking at this 3D stuff for about 6 months, I reckon I’m pretty good at it. I can quickly and effectively whip up a nice 3D animated menu, secure in the knowledge that it would take someone else AGES to reproduce, giving me an edge so that my increasingly insane boss can’t actually fire me, regardless of how many reality checks I throw his way (which never end up well- the promises of riches and stock options are wearing thin, given that these guys, in an effort to save money, simply stopped paying tax one day, about a year ago. This can not end well, and I said as much once, and got screamed at for about half an hour).

Then yesterday, I decide to check out the new Adobe Flash Player- the thing that plays those funky little animations in web pages, and noticed it can do this.

Simple Flash Player 3D demo

It does, natively and in about 3 lines, what it took me a full week to code and do in Papervision. What you’re looking at there is Flash having 3D capability, built in.

I should be happy that my life became so much easier. And I will be.

After I get that time back I spent learning something I don’t need anymore…

Nah, it’s all good. I’ll have to start putting some demos together playing with this new Flash and posting them here. It will make a nice change from bitching about the boss and old girlfriends :)