Permalink
Browse files

added the silverlight uploader. I need to refresh my memory...

  • Loading branch information...
nathanb committed Nov 19, 2010
1 parent 2f62050 commit 4a9bd6f22edf8d582875710371343ab3eb0867ff
Showing with 4,816 additions and 0 deletions.
  1. +10 −0 UploaderSL/LICENSE.txt
  2. +8 −0 UploaderSL/src/Uploader.Client/App.xaml
  3. +66 −0 UploaderSL/src/Uploader.Client/App.xaml.cs
  4. +27 −0 UploaderSL/src/Uploader.Client/Items.cs
  5. +11 −0 UploaderSL/src/Uploader.Client/ListItem.xaml
  6. +223 −0 UploaderSL/src/Uploader.Client/ListItem.xaml.cs
  7. +11 −0 UploaderSL/src/Uploader.Client/Page.xaml
  8. +56 −0 UploaderSL/src/Uploader.Client/Page.xaml.cs
  9. +6 −0 UploaderSL/src/Uploader.Client/Properties/AppManifest.xml
  10. +35 −0 UploaderSL/src/Uploader.Client/Properties/AssemblyInfo.cs
  11. +4 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/FileReceiver.disco
  12. +77 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/FileReceiver.wsdl
  13. +46 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/FileReceiver.xsd
  14. +42 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/FileReceiver1.xsd
  15. +98 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/FileReceiver11.xsd
  16. +748 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/Reference.cs
  17. +35 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/Reference.svcmap
  18. +10 −0 ...der.Client/Service References/FileReceiver/Uploader.Client.FileReceiver.FinishResponse.datasource
  19. +10 −0 ...der.Client/Service References/FileReceiver/Uploader.Client.FileReceiver.UploadResponse.datasource
  20. +10 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/configuration.svcinfo
  21. +195 −0 UploaderSL/src/Uploader.Client/Service References/FileReceiver/configuration91.svcinfo
  22. +21 −0 UploaderSL/src/Uploader.Client/ServiceReferences.ClientConfig
  23. +207 −0 UploaderSL/src/Uploader.Client/Uploader.Client.csproj
  24. +51 −0 UploaderSL/src/Uploader.Client/Utility.cs
  25. +8 −0 UploaderSL/src/Uploader.ClientHTTP/App.xaml
  26. +66 −0 UploaderSL/src/Uploader.ClientHTTP/App.xaml.cs
  27. +16 −0 UploaderSL/src/Uploader.ClientHTTP/ChunkUploadRequest.cs
  28. +14 −0 UploaderSL/src/Uploader.ClientHTTP/Credentials.cs
  29. +18 −0 UploaderSL/src/Uploader.ClientHTTP/Enums.cs
  30. +39 −0 UploaderSL/src/Uploader.ClientHTTP/Events.cs
  31. +279 −0 UploaderSL/src/Uploader.ClientHTTP/FileSender.cs
  32. +16 −0 UploaderSL/src/Uploader.ClientHTTP/FinishRequest.cs
  33. +12 −0 UploaderSL/src/Uploader.ClientHTTP/FinishResponse.cs
  34. +27 −0 UploaderSL/src/Uploader.ClientHTTP/Items.cs
  35. +11 −0 UploaderSL/src/Uploader.ClientHTTP/ListItem.xaml
  36. +64 −0 UploaderSL/src/Uploader.ClientHTTP/ListItem.xaml.cs
  37. +11 −0 UploaderSL/src/Uploader.ClientHTTP/Page.xaml
  38. +56 −0 UploaderSL/src/Uploader.ClientHTTP/Page.xaml.cs
  39. +6 −0 UploaderSL/src/Uploader.ClientHTTP/Properties/AppManifest.xml
  40. +35 −0 UploaderSL/src/Uploader.ClientHTTP/Properties/AssemblyInfo.cs
  41. +15 −0 UploaderSL/src/Uploader.ClientHTTP/ResponseBase.cs
  42. +12 −0 UploaderSL/src/Uploader.ClientHTTP/UploadResponse.cs
  43. +180 −0 UploaderSL/src/Uploader.ClientHTTP/Uploader.ClientHttp.csproj
  44. +159 −0 UploaderSL/src/Uploader.ClientHTTP/Utility.cs
  45. +37 −0 UploaderSL/src/UploaderSL-vs10.sln
  46. +18 −0 UploaderSL/src/UploaderSL.Web/Config.cs
  47. +58 −0 UploaderSL/src/UploaderSL.Web/Default.aspx
  48. +17 −0 UploaderSL/src/UploaderSL.Web/Default.aspx.cs
  49. +25 −0 UploaderSL/src/UploaderSL.Web/Default.aspx.designer.cs
  50. +60 −0 UploaderSL/src/UploaderSL.Web/HTTPUpload.aspx
  51. +17 −0 UploaderSL/src/UploaderSL.Web/HTTPUpload.aspx.cs
  52. +25 −0 UploaderSL/src/UploaderSL.Web/HTTPUpload.aspx.designer.cs
  53. +35 −0 UploaderSL/src/UploaderSL.Web/Properties/AssemblyInfo.cs
  54. +19 −0 UploaderSL/src/UploaderSL.Web/Services/ChunkUploadRequest.cs
  55. +17 −0 UploaderSL/src/UploaderSL.Web/Services/Credentials.cs
  56. +21 −0 UploaderSL/src/UploaderSL.Web/Services/Enums.cs
  57. +1 −0 UploaderSL/src/UploaderSL.Web/Services/FileReceiver.ashx
  58. +116 −0 UploaderSL/src/UploaderSL.Web/Services/FileReceiver.ashx.cs
  59. +1 −0 UploaderSL/src/UploaderSL.Web/Services/FileReceiver.svc
  60. +98 −0 UploaderSL/src/UploaderSL.Web/Services/FileReceiver.svc.cs
  61. +21 −0 UploaderSL/src/UploaderSL.Web/Services/FinishRequest.cs
  62. +15 −0 UploaderSL/src/UploaderSL.Web/Services/FinishResponse.cs
  63. +21 −0 UploaderSL/src/UploaderSL.Web/Services/IFileReceiver.cs
  64. +18 −0 UploaderSL/src/UploaderSL.Web/Services/ResponseBase.cs
  65. +80 −0 UploaderSL/src/UploaderSL.Web/Services/UploadProcessor.cs
  66. +15 −0 UploaderSL/src/UploaderSL.Web/Services/UploadResponse.cs
  67. +486 −0 UploaderSL/src/UploaderSL.Web/Silverlight.js
  68. +151 −0 UploaderSL/src/UploaderSL.Web/UploaderSL.Web.csproj
  69. +228 −0 UploaderSL/src/UploaderSL.Web/Utility.cs
  70. +128 −0 UploaderSL/src/UploaderSL.Web/Web.config
  71. +37 −0 UploaderSL/src/UploaderSL.sln
View
@@ -0,0 +1,10 @@
+Copyright (c) 2009, Nathan Bridgewater
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of the Integrated Web Systems, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,8 @@
+<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="Uploader.Client.App"
+ >
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+
+namespace Uploader.Client
+{
+ public partial class App : Application
+ {
+
+ public App()
+ {
+ this.Startup += this.Application_Startup;
+ this.Exit += this.Application_Exit;
+ this.UnhandledException += this.Application_UnhandledException;
+
+ InitializeComponent();
+ }
+
+ private void Application_Startup(object sender, StartupEventArgs e)
+ {
+ this.RootVisual = new Page();
+ }
+
+ private void Application_Exit(object sender, EventArgs e)
+ {
+
+ }
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ // If the app is running outside of the debugger then report the exception using
+ // the browser's exception mechanism. On IE this will display it a yellow alert
+ // icon in the status bar and Firefox will display a script error.
+ if (!System.Diagnostics.Debugger.IsAttached)
+ {
+
+ // NOTE: This will allow the application to continue running after an exception has been thrown
+ // but not handled.
+ // For production applications this error handling should be replaced with something that will
+ // report the error to the website and stop the application.
+ e.Handled = true;
+ Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
+ }
+ }
+ private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
+ {
+ try
+ {
+ string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
+ errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
+
+ System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight 2 Application " + errorMsg + "\");");
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+}
@@ -0,0 +1,27 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+
+namespace Uploader.Client
+{
+ public class Items :
+ System.Collections.ObjectModel.ObservableCollection<string>
+ {
+ public Items()
+ {
+ Add("Item 1");
+ Add("Item 2");
+ Add("Item 3");
+ Add("Item 4");
+ Add("Item 5");
+ }
+ }
+
+}
@@ -0,0 +1,11 @@
+<UserControl x:Class="Uploader.Client.ListItem"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Width="390" Height="60">
+ <Grid x:Name="LayoutRoot" Background="White">
+ <Border BorderBrush="Black" BorderThickness="0,0,0,0" Margin="5,5,5,24">
+ <TextBlock x:Name="uxText"></TextBlock>
+ </Border>
+ <ProgressBar Margin="5,5,5,5" Height="15" VerticalAlignment="Bottom" x:Name="uxProgress"/>
+ </Grid>
+</UserControl>
@@ -0,0 +1,223 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.IO;
+
+namespace Uploader.Client
+{
+ public partial class ListItem : UserControl
+ {
+ public ListItem()
+ {
+ InitializeComponent();
+ FilePosition = 0;
+ }
+
+ FileInfo _File;
+ public FileInfo File
+ {
+ get { return _File; }
+ set
+ {
+ _File = value;
+ this.uxText.Text = _File.Name;
+ }
+ }
+ private long FilePosition;
+ private long FileLength;
+ private int CurrentStep = 0;
+ private int Steps = 0;
+
+ public void Send()
+ {
+ try
+ {
+ //send first chunk, start upload.
+
+ FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
+ client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
+ client.BeginUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.BeginUploadCompletedEventArgs>(client_BeginUploadCompleted);
+ FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
+ using (FileStream fs = this.File.OpenRead())
+ {
+ //get full hash first.
+ this.FileLength = fs.Length;
+
+ //setup progress bar.
+ this.Steps = (int)(this.FileLength / (long)Utility.chunkSize);
+ this.uxProgress.Minimum = 0;
+ this.uxProgress.Maximum = this.Steps;
+
+ int read = 0;
+ byte[] buffer = null;
+
+ if (fs.Length <= Utility.chunkSize)
+ buffer = new byte[(int)fs.Length];
+ else
+ buffer = new byte[Utility.chunkSize];
+
+ read = fs.Read(buffer, 0, Utility.chunkSize);
+
+ this.FilePosition += read;
+
+ req.Chunk = buffer;
+ req.ChunkSize = buffer.Length;
+ req.Hash = Utility.GetSHA256Hash(buffer);
+
+ client.BeginUploadAsync(req);
+ }
+ }
+ catch (Exception ex)
+ {
+ //show error.
+ this.uxText.Text = ex.Message;
+ }
+ }
+ void SendNextChunk(Guid token)
+ {
+ try
+ {
+ FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
+ client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
+ client.ContinueUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.ContinueUploadCompletedEventArgs>(client_ContinueUploadCompleted);
+
+ FileReceiver.ChunkUploadRequest req = new Uploader.Client.FileReceiver.ChunkUploadRequest();
+ using (FileStream fs = this.File.OpenRead())
+ {
+ int read = 0;
+ byte[] buffer = null;
+ int readSize = Utility.chunkSize;
+
+ long diff = this.FileLength - this.FilePosition;
+ if (diff < Utility.chunkSize)
+ readSize = (int)diff;
+
+ buffer = new byte[readSize];
+
+ fs.Seek(this.FilePosition, SeekOrigin.Begin);
+ read = fs.Read(buffer, 0, readSize);
+
+ this.FilePosition += read;
+
+ req.ChunkSize = buffer.Length;
+ req.Hash = Utility.GetSHA256Hash(buffer);
+ req.Chunk = buffer;
+ req.Token = token;
+
+ client.ContinueUploadAsync(req);
+ }
+ }
+ catch (Exception ex)
+ {
+ //show error.
+ this.uxText.Text = ex.Message;
+ }
+ }
+
+ void client_ContinueUploadCompleted(object sender, Uploader.Client.FileReceiver.ContinueUploadCompletedEventArgs e)
+ {
+ if (!e.Cancelled && e.Error == null)
+ {
+ if (e.Result.Status == Uploader.Client.FileReceiver.EnumsResponsStatus.Success)
+ {
+ UpdateProgress();
+
+ if (this.FilePosition < this.FileLength)
+ SendNextChunk(e.Result.Token);
+ else
+ {
+ //done..
+ FinishUpload(e.Result.Token);
+ }
+ }
+ }
+ else if (e.Error != null)
+ {
+ this.uxText.Text = e.Error.Message;
+ }
+ else
+ {
+ this.uxText.Text = "Cancelled";
+ }
+ }
+ void client_BeginUploadCompleted(object sender, Uploader.Client.FileReceiver.BeginUploadCompletedEventArgs e)
+ {
+ if (!e.Cancelled && e.Error == null)
+ {
+ if (e.Result.Status == Uploader.Client.FileReceiver.EnumsResponsStatus.Success)
+ {
+ UpdateProgress();
+
+ if (this.FilePosition < this.FileLength)
+ SendNextChunk(e.Result.Token);
+ else
+ {
+ //finish upload.
+ FinishUpload(e.Result.Token);
+ }
+ }
+ else
+ uxText.Text = e.Result.Message;
+ }
+ else if (e.Error != null)
+ {
+ this.uxText.Text = e.Error.Message;
+ }
+ else
+ {
+ this.uxText.Text = "Cancelled";
+ }
+ }
+
+ void FinishUpload(Guid token)
+ {
+ FileReceiver.FileReceiverClient client = new Uploader.Client.FileReceiver.FileReceiverClient();
+ client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Utility.BaseUrl + "Services/FileReceiver.svc");
+ client.FinishUploadCompleted += new EventHandler<Uploader.Client.FileReceiver.FinishUploadCompletedEventArgs>(client_FinishUploadCompleted);
+
+ FileReceiver.FinishRequest req = new Uploader.Client.FileReceiver.FinishRequest();
+ using (FileStream fs = this.File.OpenRead())
+ {
+ req.Extension = this.File.Extension;
+ req.FullHash = Utility.GetSHA256Hash(fs);
+ }
+ req.Token = token;
+
+ client.FinishUploadAsync(req);
+ }
+
+ void UpdateProgress()
+ {
+ this.CurrentStep++;
+ this.uxProgress.Value = this.CurrentStep;
+ }
+
+ void client_FinishUploadCompleted(object sender, Uploader.Client.FileReceiver.FinishUploadCompletedEventArgs e)
+ {
+ if (!e.Cancelled && e.Error == null)
+ {
+ if (e.Result.Status == Uploader.Client.FileReceiver.EnumsResponsStatus.Success)
+ {
+ uxText.Text = "Transferred successfully.";
+ }
+ else
+ uxText.Text = e.Result.Message;
+ }
+ else
+ {
+ if (e.Error != null)
+ uxText.Text = e.Error.Message;
+ else
+ uxText.Text = "Cancelled";
+ }
+ }
+ }
+}
@@ -0,0 +1,11 @@
+<UserControl x:Class="Uploader.Client.Page"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:src="clr-namespace:Uploader.Client"
+ Width="400" Height="600" Loaded="Page_Loaded">
+ <Grid x:Name="LayoutRoot" Background="White">
+ <Button Name="uxSend" Content="Send" Width="50" Height="25" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5,5,5,5" Click="uxSend_Click"/>
+ <Button Name="uxBrowse" Content="Browse..." Width="70" Height="25" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="5,5,70,5" Click="uxBrowse_Click"/>
+ <ListBox Name="uxFiles" Margin="0,35,0,0"/>
+ </Grid>
+</UserControl>
Oops, something went wrong.

0 comments on commit 4a9bd6f

Please sign in to comment.