locked
DeploymentCatalog IndexOutOfRangeException problem RRS feed

  • Question

  • Hi,

    I've a problem that I can't solve.
    The part in Bold gives always an "IndexOutOfRangeException".
    Can somebody help???    

     public class MainViewModel : ViewModelBase
        {

            [Import(typeof(IJBAEnvironmentViewModel))]
            public IJBAEnvironmentViewModel JBAEnvir { get; set; }

           [ImportMany(AllowRecomposition = true)]
           public Contracts.IScreen[] Screens { get; set; }

            private string _JBAEnvironment;
            private UserControl _Screen;

            public string JBAEnvironment
            {
                get
                {
                    return _JBAEnvironment;
                }
                set
                {
                    _JBAEnvironment = value;
                    RaisePropertyChanged("JBAEnvironment");
                }
            }

            public UserControl Screen
            {
                get
                {
                    return _Screen;
                }
                set
                {
                    _Screen = value;
                    RaisePropertyChanged("Screen");
                }
            }

     

          

            public MainViewModel()
            {          
                App.aggr.Catalogs.Add(CreateCatalog("JBAEnvir.xap"));
            }

            private DeploymentCatalog CreateCatalog(string uri)
            {
                DeploymentCatalog catalog = new DeploymentCatalog(new Uri(uri, UriKind.Relative));
                CompositionHost.Initialize(catalog);
                catalog.DownloadCompleted += (s, e) =>
                {
                    if (e.Error != null)
                    {
                        string ssss = e.Error.Message;
                    }
                    else
                    {
                        CompositionInitializer.SatisfyImports(this);
                        JBAEnvironment = JBAEnvir.GetJBAEnvironment();
                        //JBAEnvir.Test(JBAEnvironment);
                        //IsUnderMaintenance = JBAEnvir.IsUnderMaintenance;                   
                       
                        string thedate = DateTime.Now.ToString("yyyy-MM-d-HH.mm.ss.000000");
                        MaintenanceSvc.maintenanceServicePortTypeClient ctx = new MaintenanceSvc.maintenanceServicePortTypeClient(new BasicHttpBinding(), new EndpointAddress("http://myLink/maintenance.php"));
                        ctx.setMaintenanceCompleted += (ss, ee) =>
                        {

                            if (ee.Result.Equals("none"))
                            {
                                App.aggr.Catalogs.Add(CreateCatalog2("Start.xap"));                                                              
                            }
                            else
                            {
                                App.aggr.Catalogs.Add(CreateCatalog2("Maintenance.xap"));                                                      
                            }
                        };
                        ctx.setMaintenanceAsync(thedate);                    
                    }
                  
                };
                catalog.DownloadAsync();
                return catalog;
            }

            private DeploymentCatalog CreateCatalog2(string xap)
            {
              
                DeploymentCatalog catalog = new DeploymentCatalog(new Uri(xap, UriKind.Relative));
              
                catalog.DownloadCompleted += (s, e) =>
                {
                    if (e.Error != null)
                    {
                        string ss = e.Error.Message;
                    }
                    else
                    {
                        CompositionInitializer.SatisfyImports(this);                    
                       Screen = Screens[0].getUserControl();                                        
                    }
                };
                catalog.DownloadAsync();
                return catalog;  
            }
        }

    Monday, November 15, 2010 11:24 AM

Answers

  • I think it's not the right way to download an external xap.

    Your method CreateCatalog2(string xap) has to download the extrenal xap and it's ok. Then your class could implement the IPartImportsSatisfiedNotification interface and you could customize the OnImportsSatisfied method. This method is called every time an import is satisfied and is very useful for recomposition as in your case.

    The method CompositionInitializer.SatisfyImports(this) is used to satisfy only the first import.

    [Import(typeof(IJBAEnvironmentViewModel))]
    public IJBAEnvironmentViewModel JBAEnvir { get; set; }

    So avoid to insert it into CreateCatalog2 method.

    Please, read this guide to have a deeper understanding of what I meant. http://mef.codeplex.com/wikipage?title=DeploymentCatalog&referringTitle=Guide

    Regards.


    Tuesday, November 23, 2010 6:06 AM