Ejemplo n.º 1
0
        private void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            var task = e.UserState as OfflineTask;

            if (task != null)
            {
                if (e.Error == null)
                {
                    try
                    {
                        if (e.Result.Length > 0)
                        {
                            var filename = task.ResourceLocation.ComputeOfflineFilename();
                            _offlineStorageManager.StoreResource(e.Result, filename);
                        }
                        else
                        {
                            string message = string.Format(SilverlightMediaFrameworkResources.OfflineDownloadFailedErrorMessage,
                                                           task.ResourceLocation.AbsolutePath, e.Result.Length);
                            throw new OfflineException(message);
                        }
                    }
                    catch (Exception err)
                    {
                        ErrorOccurred.IfNotNull(i => i(this, err));
                    }
                    finally
                    {
                        e.Result.Close();
                    }
                }
                else if (!e.Cancelled)
                {
                    ErrorOccurred.IfNotNull(i => i(this, e.Error));
                }

                DequeueOfflineTask(task);
            }
        }