コード例 #1
0
        public void Execute(CoroutineExecutionContext context)
        {
            DeploymentCatalog catalog;

            if (Catalogs.TryGetValue(uri, out catalog))
            {
                Completed(this, new ResultCompletionEventArgs());
            }
            else
            {
                catalog = new DeploymentCatalog(new Uri("/ClientBin/" + uri, UriKind.RelativeOrAbsolute));
                catalog.DownloadCompleted += (s, e) => {
                    if (e.Error == null)
                    {
                        Catalogs[uri] = catalog;
                        Catalog.Catalogs.Add(catalog);
                        catalog.Parts
                        .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                        .Where(assembly => !AssemblySource.Instance.Contains(assembly))
                        .Apply(x => AssemblySource.Instance.Add(x));
                    }
                    else
                    {
                        Loader.Hide().Execute(context);
                    }

                    Completed(this, new ResultCompletionEventArgs {
                        Error        = e.Error,
                        WasCancelled = false
                    });
                };

                catalog.DownloadAsync();
            }
        }
コード例 #2
0
ファイル: MefXapModuleTypeLoader.cs プロジェクト: zalid/Prism
        private void DownloadModuleFromUri(ModuleInfo moduleInfo, Uri uri)
        {
            DeploymentCatalog deploymentCatalog = new DeploymentCatalog(uri);

            try
            {
                // If this module has already been downloaded, fire the completed event.
                if (this.IsSuccessfullyDownloaded(deploymentCatalog.Uri))
                {
                    this.RaiseLoadModuleCompleted(moduleInfo, null);
                }
                else
                {
                    bool needToStartDownload = !this.IsDownloading(uri);

                    // I record downloading for the moduleInfo even if I don't need to start a new download
                    this.RecordDownloading(uri, moduleInfo);

                    if (needToStartDownload)
                    {
                        deploymentCatalog.DownloadProgressChanged += this.DeploymentCatalog_DownloadProgressChanged;
                        deploymentCatalog.DownloadCompleted       += this.DeploymentCatalog_DownloadCompleted;
                        deploymentCatalog.DownloadAsync();
                    }
                }
            }
            catch (Exception)
            {
                // if there is an exception between creating the deployment catalog and calling DownloadAsync,
                // the deployment catalog needs to be disposed.
                // otherwise, it is added to the compositioncontainer which should handle this.
                deploymentCatalog.Dispose();
                throw;
            }
        }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: cyrsis/MEF
        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var deploymentCatalog = new DeploymentCatalog("MefRecipes.Plugin.xap");

            Host.AddCatalog(deploymentCatalog);
            deploymentCatalog.DownloadAsync();
        }
コード例 #4
0
ファイル: MefXapModuleTypeLoader.cs プロジェクト: zalid/Prism
        private void HandleDownloadCompleted(DeploymentCatalog deploymentCatalog, AsyncCompletedEventArgs e)
        {
            List <ModuleInfo> moduleInfos = this.GetDownloadingModules(deploymentCatalog.Uri);

            Exception error = e.Error;

            if (error == null)
            {
                try
                {
                    this.RecordDownloadComplete(deploymentCatalog.Uri);

                    foreach (ModuleInfo moduleInfo in moduleInfos)
                    {
                        this.downloadedPartCatalogs.Add(moduleInfo, deploymentCatalog);
                    }

                    this.RecordDownloadSuccess(deploymentCatalog.Uri);
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            }

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseLoadModuleCompleted(moduleInfo, error);
            }
        }
コード例 #5
0
        private void OnAppStartup(object sender, StartupEventArgs e)
        {
            if (!String.IsNullOrEmpty(ApplicationStartupParameters.Current.Language) &&
                !ApplicationStartupParameters.Current.Language.StartsWith("EN", StringComparison.InvariantCultureIgnoreCase))
            {
                var culture = new CultureInfo(ApplicationStartupParameters.Current.Language);

                var catalog = new DeploymentCatalog(
                    new Uri(String.Format("{0}.{1}.xap", "Silverlight", culture.TwoLetterISOLanguageName), UriKind.Relative));

                CompositionHost.Initialize(catalog);

                catalog.DownloadCompleted += (s, args) =>
                {
                    if (null == args.Error)
                    {
                        Thread.CurrentThread.CurrentCulture   = culture;
                        Thread.CurrentThread.CurrentUICulture = culture;
                        Start();
                    }
                    else
                    {
                        // cannot download resources for specific language, continue with default language
                        Start();
                    }
                };

                catalog.DownloadAsync();
            }
            else
            {
                Start();
            }
        }
コード例 #6
0
        /// <summary>
        /// Attempts to load the plug-ins at the specified location.
        /// </summary>
        /// <param name="xapLocation"></param>
        public void BeginAddExternalPackage(Uri xapLocation)
        {
            var catalog = new DeploymentCatalog(xapLocation);

            catalog.DownloadCompleted       += new EventHandler <AsyncCompletedEventArgs>(Catalog_DownloadCompleted);
            catalog.DownloadProgressChanged += new EventHandler <DownloadProgressChangedEventArgs>(Catalog_DownloadProgressChanged);
            catalog.DownloadAsync();
        }
コード例 #7
0
        private DeploymentCatalog CreateCatalog(string url)
        {
            var catalog = new DeploymentCatalog(url);

            catalog.DownloadCompleted += (catalog_DownloadCompleted);
            catalog.DownloadAsync();
            return(catalog);
        }
コード例 #8
0
ファイル: MefXapModuleTypeLoader.cs プロジェクト: zalid/Prism
        private void HandleDownloadProgressChanged(DeploymentCatalog deploymentCatalog, DownloadProgressChangedEventArgs e)
        {
            List <ModuleInfo> moduleInfos = this.GetDownloadingModules(deploymentCatalog.Uri);

            foreach (ModuleInfo moduleInfo in moduleInfos)
            {
                this.RaiseModuleDownloadProgressChanged(moduleInfo, e.BytesReceived, e.TotalBytesToReceive);
            }
        }
コード例 #9
0
ファイル: App.xaml.cs プロジェクト: cyrsis/MEF
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var catalog = new AggregateCatalog(new DeploymentCatalog());

            _extension = new DeploymentCatalog("SilverlightMEF.Extensions.xap");
            catalog.Catalogs.Add(_extension);
            var container = new CompositionContainer(catalog);

            CompositionHost.Initialize(container);
            container.ComposeExportedValue <ILaunchInterface>(this);
            CompositionInitializer.SatisfyImports(this);
        }
コード例 #10
0
ファイル: MefXapModuleTypeLoader.cs プロジェクト: zalid/Prism
        private void DeploymentCatalog_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            DeploymentCatalog deploymentCatalog = (DeploymentCatalog)sender;

            // I ensure the download progress changed is raised is on the UI thread.
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(new Action <DeploymentCatalog, DownloadProgressChangedEventArgs>(this.HandleDownloadProgressChanged), deploymentCatalog, e);
            }
            else
            {
                this.HandleDownloadProgressChanged(deploymentCatalog, e);
            }
        }
コード例 #11
0
        /// <summary>
        /// Creates a DeploymentCatalog that targets the specified path.  This
        /// method asynchronously downloads the XAP files in the target folder
        /// and will update the catalog as it completes.
        /// </summary>
        /// <param name="path">The path to download XAP files from</param>
        /// <returns>the DeploymentCatalog that was created</returns>
        private static DeploymentCatalog GetDeploymentCatalog(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "The provided path was empty");
            }

            DeploymentCatalog catalog = new DeploymentCatalog(path);

            catalog.DownloadCompleted += (s, e) => DownloadCompleted(s, e);
            catalog.DownloadAsync();


            return(catalog);
        }
コード例 #12
0
        /// <summary>
        /// Can optionally be called ahead of time to preload all the plugins and speed up the loading of video
        /// </summary>
        private static void InitializeCompositionContainer()
        {
            lock (SyncObject)
            {
                if (PluginsCatalog == null || PluginsContainer == null)
                {
#if WINDOWS_PHONE
                    var currentAssembliesCatalog = new DeploymentCatalog(a => !AssembliesToExclude.Any(n => a.FullName.StartsWith(n)));
#else
                    var currentAssembliesCatalog = new DeploymentCatalog();
#endif
                    PluginsCatalog   = new AggregateCatalog(currentAssembliesCatalog);
                    PluginsContainer = new CompositionContainer(PluginsCatalog);
                }
            }
        }
コード例 #13
0
ファイル: MefXapModuleTypeLoader.cs プロジェクト: zalid/Prism
        private void DeploymentCatalog_DownloadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            DeploymentCatalog deploymentCatalog = (DeploymentCatalog)sender;

            deploymentCatalog.DownloadProgressChanged -= DeploymentCatalog_DownloadProgressChanged;
            deploymentCatalog.DownloadCompleted       -= DeploymentCatalog_DownloadCompleted;

            // I ensure the download completed is on the UI thread so that types can be loaded into the application domain.
            if (!Deployment.Current.Dispatcher.CheckAccess())
            {
                Deployment.Current.Dispatcher.BeginInvoke(new Action <DeploymentCatalog, AsyncCompletedEventArgs>(this.HandleDownloadCompleted), deploymentCatalog, e);
            }
            else
            {
                this.HandleDownloadCompleted(deploymentCatalog, e);
            }
        }
コード例 #14
0
ファイル: App.xaml.cs プロジェクト: jinibyun/PatternInAction
        /// <summary>
        /// Initialize MEF Container and load specified plugin xap file.
        /// </summary>
        private void InitializeContainer()
        {
            var catalog = new AggregateCatalog();

            // Add this assembly to list of catalogs
            catalog.Catalogs.Add(new DeploymentCatalog());

            // Add charting assembly to list of catalogs
            var uri          = new Uri("SilverlightCharts.xap", UriKind.Relative);
            var chartCatalog = new DeploymentCatalog(uri);

            chartCatalog.DownloadCompleted += catalog_DownloadCompleted;
            catalog.Catalogs.Add(chartCatalog);

            // Perform part composition.
            CompositionHost.Initialize(catalog);

            // Asynchronously download charts imports
            chartCatalog.DownloadAsync();
        }
コード例 #15
0
        public void AddXap(string uri, Action <AsyncCompletedEventArgs> completedAction = null)
        {
            DeploymentCatalog catalog;

            if (!_catalogs.TryGetValue(uri, out catalog))
            {
                catalog = new DeploymentCatalog(uri);
                if (completedAction != null)
                {
                    catalog.DownloadCompleted +=
                        (s, e) => completedAction(e);
                }
                else
                {
                    catalog.DownloadCompleted +=
                        (catalog_DownloadCompleted);
                }

                catalog.DownloadAsync();
                _catalogs[uri] = catalog;
                _aggregateCatalog.Catalogs.Add(catalog);
            }
        }
コード例 #16
0
        /// <summary>
        /// An internal workflow to facilitate downloading the XAP file
        /// </summary>
        /// <param name="xapName">The name of the XAP</param>
        /// <param name="xapLoaded">The action to call once it is loaded</param>
        /// <param name="xapProgress">Action to call to report download progress</param>
        /// <returns>A list of <see cref="IWorkflow"/> items to execute</returns>
        private IEnumerable <IWorkflow> DownloadWorkflow(
            string xapName,
            Action <Exception> xapLoaded,
            Action <long, int, long> xapProgress)
        {
            var xap = xapName.Trim().ToLower();

            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, xapName);

            var uri = new Uri(xap, UriKind.Relative);

            if (_loaded.Contains(uri))
            {
                if (xapLoaded != null)
                {
                    xapLoaded(null);
                }
                yield break;
            }

            var deploymentCatalog = new DeploymentCatalog(uri);

            EventHandler <DownloadProgressChangedEventArgs> eventHandler = null;

            if (xapProgress != null)
            {
                eventHandler = (o, args) => xapProgress(
                    args.BytesReceived,
                    args.ProgressPercentage,
                    args.TotalBytesToReceive);
                deploymentCatalog.DownloadProgressChanged += eventHandler;
            }

            var downloadAction = new WorkflowEvent <AsyncCompletedEventArgs>(deploymentCatalog.DownloadAsync,
                                                                             h => deploymentCatalog.DownloadCompleted += h,
                                                                             h => deploymentCatalog.DownloadCompleted -= h);

            Catalog.Catalogs.Add(deploymentCatalog);

            EventAggregator.Publish(Constants.BEGIN_BUSY);

            yield return(downloadAction);

            if (xapProgress != null)
            {
                deploymentCatalog.DownloadProgressChanged -= eventHandler;
            }

            InitModules();

            EventAggregator.Publish(Constants.END_BUSY);

            Logger.LogFormat(LogSeverity.Verbose, GetType().FullName, "{0}::{1}", MethodBase.GetCurrentMethod().Name, deploymentCatalog.Uri);

            var e = downloadAction.Result;

            if (e.Error != null)
            {
                var exception = new DeploymentCatalogDownloadException(e.Error);

                Logger.Log(LogSeverity.Critical, string.Format("{0}::{1}", GetType().FullName,
                                                               MethodBase.GetCurrentMethod().Name), exception);

                if (xapLoaded == null)
                {
                    throw exception;
                }
            }
            else
            {
                _loaded.Add(deploymentCatalog.Uri);
                Logger.LogFormat(LogSeverity.Verbose, string.Format("{0}::{1}", GetType().FullName,
                                                                    MethodBase.GetCurrentMethod().Name),
                                 Resources.DeploymentService_DeploymentCatalogDownloadCompleted_Finished, deploymentCatalog.Uri);

                if (xapLoaded != null)
                {
                    xapLoaded(null);
                }
            }
        }