Status & Roadmap
Authors & License
Funding Ultimate++
Search on this site
Search in forums

SourceForge.net Logo
Home » Community » Coffee corner » C# -> U++ conversion...
C# -> U++ conversion... [message #34100] Tue, 18 October 2011 18:31 Go to next message
mirek is currently offline  mirek
Messages: 13442
Registered: November 2005
Ultimate Member
Funny, today I had to rewrite some code (google authentization) from C# to U++:

private static string GetAuthToken() {
  WebRequest webRequest = HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin");
  webRequest.Method = "POST";
  webRequest.ContentType = "application/x-www-form-urlencoded";
  string postParams =
      "accountType=" + HttpUtility.UrlEncode("GOOGLE") +
      "&Email=" + HttpUtility.UrlEncode("INSERT_LOGIN_EMAIL_HERE") +
      "&Passwd=" + HttpUtility.UrlEncode("INSERT_PASSWORD_HERE") +
      "&service=" + HttpUtility.UrlEncode("adwords") +
      "&source=" + HttpUtility.UrlEncode(string.Format("{0}-{1}-{2}", "YOUR_COMPANY_NAME",
  byte[] postBytes = Encoding.UTF8.GetBytes(postParams);
  webRequest.ContentLength = postBytes.Length;
  using (Stream strmReq = webRequest.GetRequestStream()) {
    strmReq.Write(postBytes, 0, postBytes.Length);
  string retVal = "";
  try {
    WebResponse response = webRequest.GetResponse();
    using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
      string sResponse = reader.ReadToEnd();
      string[] splits = sResponse.Split('\n');
      foreach (string split in splits) {
        string[] subsplits = split.Split('=');
        if (subsplits.Length >= 2 && subsplits[0] == "Auth") {
          retVal = subsplits[1];
  } catch (WebException ex) {
    throw new ApplicationException("Could not generate auth token.", ex);
  return retVal;

String GetAuthToken() {
    String h =
                     "&Email=" + GetIniKey("google_email") +
                     "&Passwd=" + GetIniKey("google_passwd") +
    Vector<String> s = Split(h, '\n');
    for(int i = 0; i < s.GetCount(); i++)
            return s[i].Mid(5);
    return Null;

It is childish, but this always makes me feel good Wink

In this case, it is also a nice demonstration of difference between "properties" and U++...

Re: C# -> U++ conversion... [message #34990 is a reply to message #34100] Sat, 24 December 2011 08:14 Go to previous messageGo to next message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Good example!

NASA's WorldWind project started with C#.
I never did like M$'s mod of C/C++

Then NASA switched to Java so it can run on different OS's (and get away from C#).

Much of my code other than the Java display has been ported to U++, much faster, more powerful, better, etc.
Re: C# -> U++ conversion... [message #34995 is a reply to message #34100] Sat, 24 December 2011 12:18 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
U++ code is much easier to understand and shorter. And still doesn't require a VM to run.
Re: C# -> U++ conversion... [message #35026 is a reply to message #34100] Thu, 29 December 2011 23:06 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
It's funny, but sometimes C# looks pretty much like Visual Basic...
Re: C# -> U++ conversion... [message #35027 is a reply to message #35026] Fri, 30 December 2011 08:16 Go to previous message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
kropniczki wrote on Thu, 29 December 2011 23:06

It's funny, but sometimes C# looks pretty much like Visual Basic...
We ported a Visual Basic app to U++ and code was simpler and muuuch faster Smile.
So for me U++ code is usually more "basic" than Visual Basic Laughing

Best regards
Previous Topic: Web framework naming problem...
Next Topic: Intersrv/interlnk
Goto Forum:

Current Time: Thu Oct 21 04:13:20 CEST 2021

Total time taken to generate the page: 0.00827 seconds