Esempio n. 1
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();
            }            
		}
Esempio n. 2
0
        public void Execute(ActionExecutionContext 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();
            }
        }
Esempio n. 3
0
 private DeploymentCatalog CreateCatalog(string url)
 {
     var catalog = new DeploymentCatalog(url);
     catalog.DownloadCompleted += (catalog_DownloadCompleted);
     catalog.DownloadAsync();
     return catalog;
 }
 public void LoadDeploymentCatalog(string path)
 {
     DeploymentCatalog catalog = new DeploymentCatalog(path);
     catalog.DownloadCompleted += CatalogDownloadCompleted;
     catalog.DownloadProgressChanged += CatalogDownloadProgressChanged;
     catalog.DownloadAsync();
     Catalog.Catalogs.Add(catalog);
 }
Esempio n. 5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var xapCatalog = new DeploymentCatalog("/ClientBin/ContosoAutomotive.Woodgrove.SL.xap");
            xapCatalog.DownloadCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(xapCatalog_DownloadCompleted);
            xapCatalog.DownloadAsync();
            var catalog = new AggregateCatalog(new DeploymentCatalog(), xapCatalog);
            var container = new CompositionContainer(catalog);

            this.RootVisual = container.GetExportedValue<CashMaker>();
        }
 public void AddXap(string uri)
 {
     DeploymentCatalog catalog;
     if (!_catalogs.TryGetValue(uri, out catalog))
     {
         catalog = new DeploymentCatalog(uri);
         catalog.DownloadAsync();
         _catalogs[uri] = catalog;
     }
     _aggregateCatalog.Catalogs.Add(catalog);
 }
        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 += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(catalog_DownloadCompleted);

                catalog.DownloadAsync();
                _catalogs[uri] = catalog;
                _aggregateCatalog.Catalogs.Add(catalog);
            }
        }
        /// <summary>Starts the downloading of a XAP package.</summary>
        /// <param name="packageUri">The URI of the XAP file to download.</param>
        /// <param name="callback">The callback to invoke when the operation is complete.</param>
        public void DownloadAsync(Uri packageUri, CallbackAction<IPackage> callback)
        {
            // Setup initial conditions.
            if (packageUri == null) throw new ArgumentNullException("packageUri");

            // Start the download.
            var downloader = new DeploymentCatalog(packageUri);
            downloader.DownloadCompleted += (s, args) =>
                                                {
                                                    if (callback == null) return;
                                                    var callbackPayload = new Callback<IPackage>
                                                                        {
                                                                            Cancelled = args.Cancelled,
                                                                            Error = args.Error,
                                                                        };
                                                    if (!callbackPayload.HasError) callbackPayload.Result = new PackageWrapper(downloader);
                                                    callback(callbackPayload);
                                                };
            downloader.DownloadAsync();
        }
        public void Load(Panel element, string uri, Action<Panel, string> action, Action<Panel, string> undoAction)
        {
            if (!string.IsNullOrEmpty(uri))
            {
                if (action != null)
                {
                    _actions[uri] = action;
                }
                if (undoAction != null)
                {
                    _undoActions[uri] = undoAction;
                }
                if (element != null)
                {
                    _panels[uri] = element;
                }
                if (_catalogs.ContainsKey(uri))
                {
                    _actions[uri](_panels[uri], uri);
                    return;
                }

                var catalog = new DeploymentCatalog(uri);
                catalog.DownloadCompleted += (s, e) =>
                {
                    if (e.Error != null)
                    {
                        throw e.Error;
                    }
                    _actions[uri](_panels[uri], uri);
                };
                catalog.DownloadAsync();
                _catalogs[uri] = catalog;
                _aggregateCatalog.Catalogs.Add(catalog);
            }
        }
Esempio n. 10
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;
        }
Esempio n. 11
0
        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);
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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;
            }
        }
Esempio n. 14
0
            public override void Load(Uri targetUri, Uri currentUri)
            {
                try
                {
                    if (!parent._initialized)
                        parent.Initialize();
                   
                    var saveTargetUri = targetUri;
                    if (!targetUri.IsAbsoluteUri)
                        targetUri = new Uri("MEF:///" + targetUri.OriginalString);

                    string xap = null;

                    if (_uriMap.TryGetValue(saveTargetUri, out xap) && xap != null && !_loadedXaps.Contains(xap))
                    {
                        var dc = new DeploymentCatalog(xap);
                        dc.DownloadCompleted += (s, e) =>
                        {
                            if (e.Error != null)
                            {
                                this.Error(e.Error);
                                return;
                            }
                            _catalog.Catalogs.Add(dc);
                            _loadedXaps.Add(xap);
                            NavigateToPage(targetUri);
                        };
                        dc.DownloadAsync();
                    }
                    else
                        NavigateToPage(targetUri);
                }
                catch (Exception e)
                {
                    Error(e);
                }
            }
Esempio n. 15
0
 private void DownloadCatalogAsync(Uri uri)
 {
     var catalog = new DeploymentCatalog(uri);
     catalog.DownloadCompleted += catalog_DownloadCompleted;
     catalog.DownloadAsync();
     mainCatalog.Catalogs.Add(catalog);
 }
Esempio n. 16
0
        /// <summary />
        private void InitializeCatalogs()
        {
            // load remote catalogs
            IDictionary<string, string> args = Application.Current.Host.InitParams;
            if (args != null && args.ContainsKey("xap"))
            {
                string value = args["xap"];

                string[] collection = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string xap in collection)
                {
                    bool absoluteUri = xap.IndexOf("://", StringComparison.OrdinalIgnoreCase) >= 0;
                    Uri uri = new Uri(xap, absoluteUri ? UriKind.Absolute : UriKind.Relative);

                    DeploymentCatalog dc = new DeploymentCatalog(uri);
                    dc.DownloadCompleted += this.DownloadCompleted;
                    this.pendingDeployments.Add(dc);
                    this.catalogCollection.Catalogs.Add(dc);

                    dc.DownloadAsync();
                }
            }
        }
        /// <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);
                }
            }
        }
        private void HandleDownloadCompleted(DeploymentCatalog deploymentCatalog, AsyncCompletedEventArgs e)
        {
            ModuleInfo moduleInfo = GetDownloadingModule(deploymentCatalog.Uri);
            Exception error = e.Error;
            if (error == null)
            {
                try
                {
                    this.RecordDownloadComplete(deploymentCatalog.Uri);
                                        
                    this.AggregateCatalog.Catalogs.Add(deploymentCatalog);

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

            this.RaiseLoadModuleCompleted(moduleInfo, error);
        }      
 public PackageWrapper(DeploymentCatalog downloader)
 {
     Uri = downloader.Uri;
     Parts = downloader.Parts;
 }
 /// <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();
 }
Esempio n. 21
0
        private void addAndDownloadDeploymentCatalogs(IEnumerable<string> xapsDeployedOnServer)
        {
            numberOfXapsDeployedOnServer = xapsDeployedOnServer.Count();

            deploymentCatalogs.Clear();

            foreach (var deployedXap in xapsDeployedOnServer)
            {
                //string url = GetBaseUrl() + "ClientBin/" + deployedXap;
                var xapUri = new Uri(deployedXap, UriKind.Relative);
                Debug.WriteLine("Dwnloading: " + xapUri);
                var deploymentCatalog = new DeploymentCatalog(xapUri);
                deploymentCatalogs.Add(deploymentCatalog);
                deploymentCatalog.Changed += (o, ee) => OnChanged(ee);
                deploymentCatalog.Changing += (o, ee) => OnChanging(ee);
                deploymentCatalog.DownloadCompleted += (o, ee) => OnDownloadCompleted(ee);

                deploymentCatalog.DownloadAsync();
            }
        }
Esempio n. 22
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);
                }
            }
        }
 private void HandleDownloadProgressChanged(DeploymentCatalog deploymentCatalog, DownloadProgressChangedEventArgs e)
 {
     ModuleInfo moduleInfo = this.GetDownloadingModule(deploymentCatalog.Uri);
     this.RaiseModuleDownloadProgressChanged(moduleInfo, e.BytesReceived, e.TotalBytesToReceive);
 }