A version of 'AsyncCompletedEventArgs' that can be used by the TestableWebClient.
Inheritance: System.ComponentModel.AsyncCompletedEventArgs
 protected void OnOpenReadCompleted(TestableOpenReadCompletedEventArgs e)
 {
     if (OpenReadCompleted != null)
     {
         OpenReadCompleted(this, e);
     }
 }
        void Handle_OpenReadCompleted(object sender, TestableOpenReadCompletedEventArgs e)
        {
            // Check for errors.
            Error = CheckForError(e);
            if (Error != null)
            {
                State = LoaderState.LoadError;
                OnLoadFailed();
            }

            // Pass execution to the callback, and alert listeners.
            if (State != LoaderState.LoadError) state = LoaderState.Loaded; // Update the load state prior to executing the callback...
            OnLoadCallback(e);
            if (State != LoaderState.LoadError) OnPropertyChanged(PropLoaderState); // ...but wait for the callback to be executed before firing the property changed event.

            // Calculate the load time.
            LoadTime = DateTime.UtcNow.Subtract(loadStartedAt);

            // Finish up.
            OnLoaded();
            if (loadCallback != null)
            {
                loadCallback.Invoke();
                loadCallback = null;
            }
        }
 public override void OpenReadAsync(Uri address)
 {
     var stream = new MemoryStream();
     var args = new TestableOpenReadCompletedEventArgs(stream, Error, Cancelled, UserState);
     if (Async)
     {
         DelayedAction.Invoke(AsyncDelay, () => OnOpenReadCompleted(args));
     }
     else
     {
         OnOpenReadCompleted(args);
     }
 }
 /// <summary>Called after the load operation has completed.</summary>
 /// <param name="e">The event arguments containing information about the server call.</param>
 /// <remarks>Check the 'LoadError' property to see whether the operation was successful.</remarks>
 protected abstract void OnLoadCallback(TestableOpenReadCompletedEventArgs e);
 private static Exception CheckForError(TestableOpenReadCompletedEventArgs e)
 {
     if (e.Error != null) return e.Error;
     try
     {
         var resultStream = e.Result; // Attempt to retreive the content, will force error if there was a problem.
     }
     catch (TargetInvocationException error) { return error; }
     return null;
 }
 protected override void OnLoadCallback(TestableOpenReadCompletedEventArgs e)
 {
     LoadCallbackInvoked = true;
 }
        protected override void OnLoadCallback(TestableOpenReadCompletedEventArgs e)
        {
            // Setup initial conditions.
            if (State == LoaderState.LoadError) return;
            var resultStream = e.Result;
            var assembliesList = new List<Assembly>();

            // Retrieve the AppManifest.xaml text.
            var info = GetInfo(resultStream, null, AppManifestXaml);
            var appManifest = new StreamReader(info.Stream).ReadToEnd();

            // Extract each of the <AssemblyPart> items from the manifest.
            var xDeploymentRoot = XDocument.Parse(appManifest).Root;
            if (xDeploymentRoot == null) throw new Exception("Failed to read the application manifest.");
            var entryPointAssembly = GetEntryPointAssembly(xDeploymentRoot);

            var ns = xDeploymentRoot.Name.Namespace;
            var deploymentParts = (
                                      from assemblyParts in xDeploymentRoot.Descendants(ns + "AssemblyPart")
                                      select assemblyParts
                                  ).ToList();

            // Load the deployment.
            foreach (var xElement in deploymentParts)
            {
                // Extract the 'Source=' value from the <AssemblyPart>.
                var source = xElement.Attribute(AttrSource).ValueOrNull();
                if (source != null)
                {
                    var streamInfo = GetInfo(resultStream, AppBinary, source);

                    var assemblyPart = new AssemblyPart();
                    if (source == entryPointAssembly)
                    {
                        // The source DLL matches the control being instantiated...load into memory and hold onto a reference of it.
                        RootAssembly = assemblyPart.Load(streamInfo.Stream);
                        assembliesList.Add(RootAssembly);
                    }
                    else
                    {
                        // This is not the DLL containing the control being instantiated, rather it is a dependent DLL.
                        // Load it into memory.
                        var assembly = assemblyPart.Load(streamInfo.Stream);
                        assembliesList.Add(assembly);
                    }
                }
            }

            // Finish up.
            Assemblies = assembliesList;
        }
 protected void OnOpenReadCompleted(OpenReadCompletedEventArgs e)
 {
     var args = new TestableOpenReadCompletedEventArgs(e);
     OnOpenReadCompleted(args);
 }