Zipping File before Upload

Nov 29, 2012 at 10:41 AM

Hi, really awesome control!

My goal is to zip the file before uploading.

'cause I'm newbie in this area (Silverlight) the first thing I did is write my own zip code inside of the class  UploadFileViewModel in BeginUpload method.

There are several problems:
1) I created a new state, ie FileStates.Zipping to indicate the time required for compression
2) I changed the properties fileLength for the correct calculation of bytes to be transferred
BUT I have no evidence of what happens in UI of SL control!!

Is there anyone who can help me in writing a simple code (blueprint) and specified where act correctly in the pattern?

I'd like to have the state Zipping in State column files during compression

Thanks in advance

  
Nov 29, 2012 at 3:00 PM

It depends on when/where you want to perform the zipping.

One possible solution (for Interlink v3), off the top of my head...

In the UploadFile.cs modify the method 'Initialize' to call your zip code, setting the state to FileStates.Zipping.
Be sure the zipping is done on a Pooled Thread so you don't lock up the UI.
When the zipping is complete set the state to FileStates.Ready and update the File Length
Modify the method UpdateVisualState, to include support for the new FileState

 

The upload control will not allow the upload to begin until all files are in a ready state.

You'll have to test for side effects of delaying the ready state for a file, but should work.

 Sample modification to the Initialize method

 

protected internal virtual void Initialize(Stream stream, string file, string uploadClientType, string config, string service)
{
	if (null == stream)
		throw new ArgumentNullException("stream");
			
	// Wait until we zip the stream
	//this.uploadStream = stream;

	this.clientType = uploadClientType;
	this.serviceUri = service;
	this.clientConfig = config;

	this.FileLength = stream.Length;
	this.FileName = file;

	this.CancelCommand = new InterlinkCommand(this.CancelAsync, this.CanCancel);
	this.RemoveCommand = new InterlinkCommand(this.Remove, this.CanRemove);
	this.ShowDetailCommand = new InterlinkCommand(this.ShowDetail, this.CanShowDetail);

	//this.State = FileState.Ready;
	// ZIP THE FILE HERE
	this.State = FileState.Zipping;
	Zipper.ZipAsync(stream, (success, newSize, zipStream) =>
	{
		if (success)
		{
			this.uploadStream = zipStream;
			this.FileLength = newSize;
			this.State = FileState.Ready;
		}
		else
			this.State = FileState.Error;
	});
}
Nov 29, 2012 at 4:19 PM

 

>>It depends on when/where you want to perform the zipping.

I was wondering if it's possible zipping the i-th file (from disk to memory) immediately before sending memorystream to upload ....

  >>>In the UploadFile.cs modify

I apologize for the stupid question ...but you mean UploadFileDialog.cs  ??? i don't see UploadFile.cs in the HSS.Interlink project ...ie

bool AddFile(FileInfo file)
{
       string fileName = file.Name;
try
{
#region Validation
#endregion
UploadFileViewModel fileViewModel = new UploadFileViewModel();

you mean HERE? >>>>    fileViewModel.Initialize(this.viewModel, file);

this.viewModel.Files.Add(fileViewModel);
return true;
}
catch
{
}
return false;
}

 

Thank you very much for your help....

 

Nov 30, 2012 at 2:38 PM

I think you're looking at an old version. If you go to the source code tab look at HSS.Interlink 3.0

http://interlink.codeplex.com/SourceControl/changeset/view/79962

Nov 30, 2012 at 2:59 PM

oops...

Thanks.