Posts Tagged ‘Networking’
18
Nov

Simple File Upload Solution

Post a comment » Popularity: 4%

Gergely Orosz target to implement a simple solution in uploading file using Silverlight. The upload control contains a progress indicator where you can keep track of the upload progress. The sample also showed you how you can collect the uploaded file using PHP or C#.

Simple File Upload Solution

12
Nov

ADO.NET Data Services

Post a comment » Popularity: 3%

A Game catalog which demonstrated how to use ADO.NET Data Services. You are able to witch between NHibernate and Entity Framework as well.

ADO.NET Data Services

View Demo: New Window
08
Oct

Getting Twitter Updates

Post a comment » Popularity: 12%

A Twitter updates collection tool created by pay4foss. The app will collect the updates from http://twitter.com/statuses/public_timeline.xml and display the messages with some interesting arm circles. The app also demonstrated how to get a cross domain XML file using web services.

Getting Twitter Updates 

07
Oct

Datagrid Activity Control

Post a comment » Popularity: 12%

 David Poll shared a comprehensive business application on presenting customer data. A very good sample to take reference to start your own business app.

Datagrid Activity Control

View Demo: New Window
28
Sep

Checking Image Download Progress

Post a comment » Popularity: 2%

This application demonstrated how we may check the download progress of an image. The progress is visualized with a Progress Bar.

Checking Image Download Progress

View Demo: New Window
Check the download progress:
// C#
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DownloadProgress += new EventHandler<downloadprogresseventargs>(bitmapImage_DownloadProgress);
bitmapImage.UriSource = new Uri(URL, UriKind.Absolute);
Image newImage = new Image() { Source = _bitmapImage };  

void bitmapImage_DownloadProgress(object sender, DownloadProgressEventArgs e)
{
    int progress = e.Progress; // 0 = 100  

    if (e.Progress == 100)
    {
        // finish
    }
}
28
Sep

Connecting Drupal and Silverlight

Post a comment » Popularity: 2%

Mattserbinski attempted to integrate Silverlight with Drupal. He created a module in Drupal which makes use of XML PRC functionalities to check login credential via Silverlight.

The Drupal module provides the following features:

  1. Check if user is signed in
  2. Create User
  3. Sign out user
  4. Check the login Credentials In Silverlight

Connecting Drupal and Silverlight 

25
Sep

Upload file using File Dialog

Post a comment » Popularity: 1%

The coding below demonstrating how you might utilize your FileDialog to upload files from your local disk to server.

The code demonstrated the following:

  1. Limited the selection of JPG and PNG files only
  2. Only 1 file can be selected
  3. Upload the file with the corresponding file name
  4. How to get the file data inside PHP

Upload file using File Dialog 

Select and upload file in c#:
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "Image Files (.jpg,.png)|*.JPG;*.jpg;*.PNG;*.png";
dialog.FilterIndex = 1;
bool? userClickedOK = _imageDialog.ShowDialog();

// Process input if the user clicked OK.
if (userClickedOK == true)
{
    UploadFile(dialog.File.Name, dialog.File.OpenRead());
}

private void UploadFile(string filename, Stream data)
{
    UriBuilder ub = new UriBuilder(UPLOAD_PATH);
    ub.Query = string.Format("filename={0}", filename);

    WebClient c = new WebClient();
    c.OpenWriteCompleted += (sender, e) =>
    {
        PushData(data, e.Result);
        e.Result.Close();
        data.Close();
    };
    c.OpenWriteAsync(ub.Uri, "Post");
}

private void PushData(Stream input, Stream output)
{
    byte[] buffer = new byte[4096];
    int bytesRead;

    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
    {
        output.Write(buffer, 0, bytesRead);
    }
}
Get and save file in PHP:
$filepath = $_REQUEST['filename'];
$handle = fopen("php://input", "r");
$file = fopen($filepath,"w");

if($file != null && $handle != null)
{
        while ($data = fread($handle, 8192)) fwrite($file, $data);
        fclose($handle);
        fclose($file);
}
24
Sep

Loading external assembly

Post a comment » Popularity: 1%

Terence Tsang demonstrated how to load an external assembly library (Usually a dll or xap file) into your own Silverlight application. This is a very effective method to minimize the application file size.

Loading external assembly

Loading external library in C#:
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(onDownloadCompleted);
downloader.OpenReadAsync(new Uri(DLL_PATH, UriKind.Absolute));  

// Once the assembly is downloaded
private void onDownloadCompleted(object o, OpenReadCompletedEventArgs args)
{
    try
    {
        AssemblyPart ap = new AssemblyPart();
        Assembly assembly = ap.Load(args.Result);
        Object control = assembly.CreateInstance(CLASS_NAME);
    }
    catch (Exception e){}
}
19
Sep

HTTP Post Request

Post a comment » Popularity: 1%

This coding below demonstrated how you can POST data to the target remote server. Terence Tsang also provided a simple sample letting you to search the feed items of your blog (Only works for Wordpress).

 

If you are new to Silverlight networking,  remember to check out Network Security Access Restrictions in Silverlight.

HTTP Post Request

View Demo: New Window
Sending Post Data to Server:
// Create a request object
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(POST_ADDRESS, UriKind.Absolute));
request.Method = "POST";
// don't miss out this
request.ContentType = "application/x-www-form-urlencoded";
request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);  

// Sumbit the Post Data
void RequestReady(IAsyncResult asyncResult)
{
    HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
    Stream stream = request.EndGetRequestStream(asyncResult);  

    // Hack for solving multi-threading problem
    this.Dispatcher.BeginInvoke(delegate()
    {
        // Send the post variables
        StreamWriter writer = new StreamWriter(stream);
        writer.WriteLine("key1=value1");
        writer.WriteLine("key2=value2");
        writer.Flush();
        writer.Close();  

        request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
    });
}  

// Get the result  from the server
void ResponseReady(IAsyncResult asyncResult)
{
    HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);  

    this.Dispatcher.BeginInvoke(delegate()
    {
        Stream responseStream = response.GetResponseStream();
        StreamReader reader = new StreamReader(responseStream);
        // get the result text
        string result = reader.ReadToEnd();
    });
}  
17
Sep

Silverlight Multiple File Upload

Post a comment » Popularity: 1%

Darick shared a very nice application which enables you to upload multiple files concurrently.It has a rich user interface with a lot of configurable options.

Silverlight Multiple File Upload