Sunday, August 10, 2008

.Net window form file uploader to webservice

Wanna Upload file in a asynchronise way in .Net ? Here I create a simple demo to upload your file to the webservice.
The code below is pretty useful especially creating three-tier applications and your desktop form application is not directly connecting to database.




public partial class FileUploader : Form
{
public FileUploader()
{
InitializeComponent();
}

private void btnBrowse_Click(object sender, EventArgs e)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Title = "Open File";
dialog.Filter = "All Files|*.*";
dialog.FileName = "";

try
{
dialog.InitialDirectory = "C:\\Temp";
}
catch
{
// skip it
}
dialog.ShowDialog();
if (dialog.FileName == "")
{
return;
}
else
{
txtFileName.Text = dialog.FileName;
}
}
}

private void UploadFile(string filename)
{

try
{
// get the exact file name from the path
String strFile = System.IO.Path.GetFileName(filename);

// create an instance of the web service
localhost_test.GetInfo ws = new formapp.localhost_test.GetInfo();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;

// get the file information form the selected file
FileInfo fInfo = new FileInfo(filename);

// get the length of the file to see if it is possible
// to upload it (with the standard 4 MB limit)

long numBytes = fInfo.Length;
double dLen = Convert.ToDouble(fInfo.Length / 1000000);

// Default limit of 128 MB on web server
// have to change the web.config to if
// you want to allow larger uploads
if (dLen < 128)
{

// set up a file stream and binary reader for the selected file
FileStream fStream = new FileStream(filename,FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);

// convert the file to a byte array
byte[] data = br.ReadBytes((int)numBytes);
br.Close();

// pass the byte array (file) and file name to the web service using asynchronise way
ws.UploadFileCompleted += new UploadFileCompletedEventHandler(this.UploadFileCompleted);
ws.UploadFileAsync(data, strFile);
fStream.Close();
fStream.Dispose();

//// pass the byte array (file) and file name to the web service using synchronise way
//string sTmp = ws.UploadFile(data, strFile);
//fStream.Close();
//fStream.Dispose();
//// this will always say OK unless an error occurs,
//// if an error occurs, the service returns the error message
//MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
}
else
{
// Display message if the file was too large to upload
MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
}
}
catch (Exception ex)
{
// display an error message to the user
MessageBox.Show(ex.Message.ToString(), "Upload Error");
}
}

private void btnUpload_Click(object sender, EventArgs e)
{
if (txtFileName.Text != string.Empty)
{
UploadFile(txtFileName.Text);
}
else
{
MessageBox.Show("You must select a file first.", "No File Selected");
}
}

private void UploadFileCompleted(object sender, UploadFileCompletedEventArgs args)
{
//Bind returned results to the UI data grid
MessageBox.Show("File Upload Status: " + args.Result + " File Uploaded.");
}
}




Saturday, August 9, 2008

Zhen Yang's Resume

Zhen Yang
yangzhen@gmail.com Mobile 0401924381

Objective

Seeking application development position where I can utilise my skills, qualifications, research experience, and abilities in IT field that offers professional growth.

Qualifications Summary

  • Technical proficiency in .Net (C#) Technology, and SQL database technologies. Over six years experiences in designing and developing web and desktop applications.
  • Demonstrated capability to explore solutions and solve problems. Comprehensive industry knowledge on both Windows and Linux platform.
  • Well established team work skills and management experience. Highly motivated and productive team player with client facing experience.
  • Extensive knowledge on OO concepts, Design Patterns, Agile development, SDLC

Skills

l  Language: C#, ASP.Net, SQL, XML/XSLT, HTML/JQuery/CSS, WCF, UML, C++,
l  Software:   Visual Studio 2003-2010, SQLServer, IIS, TFS, WebMatrix, MySQL
l  Tools:         NHibernate, Enterprise Library, LINQ, ASP.Net MVC, Entity Framework

Technical Experiences Details

2009.07-Now   Software Developer in the Commonwealth Scientific and Industrial Research Organisation (CSIRO), Land and Water Lab, Canberra
l  Working in a multi-disciplinary team of software developers and researchers. Working with large code base solutions in C# consisting multiple projects of libraries and components for various calibration, optimization, and simulation models, persistence of data. Familiar with the full software development life circle.
l  Daily responsibilities include developing new features for the enterprise level river modelling software according to plan. (C#, WCF, NHibernate)
l  Designed and developed standalone GUI calibration tools. (C#, SQLServer)
l  Product integration, bug fixing, performance tuning on existing code base
2007.10-2009.06 Software Developer in National ICT Australia (NICTA), Canberra
l  Constructed a customised software system for the Australian Institute of Sports as the core engineer. This multi-tier system collects data from device, analyses and stores results on central server, and allows coaches to manage and visualise athletes training sessions. It employed both Asp.Net and Windows Form technology, and used Web Service and SQLServer database as the backend.
l  Developed a GUI application to dynamically map GPS positions into formations for Defence Science Technology Organization.
l  Built various automation tools to support researcher team. Great attention to teamwork and customer service skills.
2006.01-2007.09 Part-time Programmer of Callidus Corp, Canberra, Australia
l  Created a multi-level backup utility with Web interface. (PHP, Python)
2005.01-2005.10 Technical director of FeedSky Corp, Beijing, China
l  Constructed Web2.0 site, Web Services, Web Crawler. (Asp.Net, XML/XSLT, JavaScript, SQLServer, IIS)
l  Supervised 6 software developers to deliver according to the business plan
2003.11-2004.12 Part-time Asp.Net Developer of Baihe Corp, Beijing, China
l  Developed a Quiz & Match module for the network site.(Asp.Net, SQLServer)
l  Maintained existing pages and applied bug fixes.

Education Background

2005.11-2007.09 Master by Research of Computer Science and Information Technology, Australian National University
l  Designed and constructed a Mind-Attention Software Interface, which includes data collection, processing and application plug-in modules. (C++)
l  Assisted in Virtual Reality demonstration applications development. (C#)
2001.09-2005.06 Bachelor of Computer Science, Tsinghua University, Beijing
l  No.4 in the college entrance exam to study at the best university in China.
l  Extensively studied subjects that form the basis of computer science, and actively utilised knowledge in industry during study.

Side Projects

2010            Reengineered archived projects by using ASP.NET MVC and Entity Framework
2009            Developed websites using Joomla Content Management System. (Html, CSS)
2008            Managed a team of 5 to build a Time Management system to validate my agile development knowledge. (.Net, Web Service, SQLServer)

Additional Experiences

2006-2007  Tutor in the Department of Computer Science, ANU
l  “New media and the Web” , “Automating Tools for New Media”
2007            Apple's WebObjects technology Training, Sydney
2006            Volunteer of ANU Consulting Center “Get up and Go” program

Honours and Awards

2009-2010  Member of RiverManager Software Development team which won two “Team of the Year” Awards 
2007            Publication: “Mind-modulated music in the mind attention interface”, OZCHI
2007            ANU Miscellaneous Scholarship and Vice-Chancellor Travel Grants

Yet Another Ipod Touch Jailbreak tutorial

When you buy a brand new Ipod Touch (called ipod later in this tutorial) nowadays is Version 1.1.5  (Version can be checked in iTunes)

To be able to run customised applications on your iPod, you can either upgrade your ipod to 2.0.1 and pay money to Apple app store and buy the application, or, you jailbreak you ipod at the current firmware and install applications that is free. (Unfortunately doesn't mean open source)  The disadvantage is that you won't be able to buy and run 2.0 applications.

 

Now, some details about method A, upgrade.

When you choose to upgrade, you pay $12 upfront. With the application development kit SDK 2.0 published weeks ago, programmers can develop in-house applications for iphone and ipod, and sell then on Apple app store. $99 is needed to join this development agreement. But I am sure that we can develop applications and run it on ipod without publishing it to Apple store. The requirement to develop using the SDK is also critical, such as intel CPU Mac with 10.5.3 OS and Xcode 3.1. It seems difficult to even meet these requirements. Some sample code using Accelerometer can be found at http://developer.apple.com/iphone/samples/index.action#AccelerometerGraph

The AccelerometerGraph sample application graphs the motion of the device along each of three axes. It demonstrates how to use the UIAccelerometer class as well as how to render Quartz 2D graphics in a UIView that continually updates. It also demonstrates a technique to "remove" the gravity influence from the accelerometer values using a basic high-pass filter.

 

Method B, jailbreak

Jailbreak is what 80% people do to their ipod. I jailbreak my ipod using a software called Ziphone and it works fine. There are both Mac and Windows Version of this software, and it can be downloaded from http://download.ziphone.org/

After installing it to the computer, connects ipod with your computer. Run the software and ONLY CLICK "JAILBREAK",  don't try to activate or do it all, those are the options for iphone.

Now you need to wait about 90 seconds and wish yourself good luck. Ipod will flashing and restart during the time and if no drama happens, Ziphone should report "Done" on your computer when it finishes.

Disconnected the jailbreak ipod and give it a restart. You will notice few more little icon on your screen, look for something called "installer".  This is an "application management" application, and you can install all other applications through this application. It is extremely convenient for users to search for softwares and install softwares. Before you run this application, check your wi-fi connections. You might need VPN to actually access the network (particularly at work).

Open the application and do a search on "AcceleroLog", and click install. Now at least we have something to quickly show the accelerometer functions. Files can be logged to disk and we can download it by ssh to your ipod. The standard usr:pwd is

root:alpine

 

Thursday, August 7, 2008

Life: Pollution in China

There are lots of discussions about pollutions in Beijing. Seriously, I think those who haven't been to Beijing had no reason to criticize the situation.
I agree that the air is not as good as Canberra, the sky is not as blue as Australia, but it is no way close to what I've seen in the pictures taken by
Aussie news site such as this post smh.com.au
People have their own judgment and it is not so easy to fool people with such stupid photo, which only shows a cloudy day with fog. If that is what
so called pollution,
  • There are similar pollutions anywhere in the world
  • Could 16 million people possibly live in that dark city without an abnormal death rate?
I spend almost 5 years in Beijing and my lung is not suffering and hey, I am still alive. Oh, I forgot to mention that Beijing Welcome all visitors. Seeing is believing.




using MD5 to compare folder python script

I have been working with linux for almost 1 year now. Still, I like Windows better. Haha

This is a problem i recently trying to solve. When I using cp -r command to copy a folder, or burn a folder onto dvd, i wonder if the copy that i created is 100% correct. To do this, I use md5sum to calculate md5 of the individual files in this folder.

Here is the python script :


#!/usr/bin/python


# perform a shell command and get it's output
from commands import getoutput
# perform a shell command and get it's status (error code)
from commands import getstatusoutput
# get exit, and command line args
from sys import exit,argv

#oldPWD=getoutput('pwd')

p1md5=getoutput('(cd "' + argv[1] + '"; find . ) | sort | md5sum -b')
#print p1md5

p2md5=getoutput('(cd "' + argv[2] + '"; find . ) | sort | md5sum -b')
#print p2md5

#getstatusoutput('cd "' + oldPWD + '"')

if p1md5 == p2md5:
print "Success"
exit (0)
else:
print "Fail"
exit (1)