Sharepoint 2010 Client Context

Topics: Prism v4 - Silverlight 4
Sep 12, 2012 at 3:07 PM

I have a Silverlight project that I am using as a web part in Sharepoint 2010. When the application starts up I would like to gather the current user logged in to Sharepoint inside of my Appl.xaml.cs file.

The reason being is I want to set up a user object inside the App.xaml.cs, pass that object into my Bootstrapper.cs. Once inside the Bootstrapper.cs, I would like to add that object into my Container so when any of my modules constructors need that user object all they need is to define it as part of the module constructor and have it as needed. I have done this logic with another object. Some code snippets on how I did it follows. I would like to do the same with a Current User object.

App.xaml.cs

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Bootstrapper bootStrapper = new Bootstrapper(this.SetupMapPrincipal());
            bootStrapper.Run();
        }

        private void Application_Exit(object sender, EventArgs e)
        {

        }

        private ReachCalculatorMapPrincipal SetupMapPrincipal()
        {
            ReachCalculatorMapPrincipal principal = new ReachCalculatorMapPrincipal(
                    "http://dg2k8esridev1/ArcGISDevelopment/rest/services/GeographicalforMediaReachTiled/MapServer",
                    "http://dg2k8esridev1/ArcGISDevelopment/rest/services/AirportsforMediaReachTiled/MapServer",
                    "http://dg2k8esridev1/ArcGISDevelopment/rest/services/CountiesforMediaReachTiled/MapServer",
                    "http://dg2k8esridev1/ArcGISDevelopment/rest/services/DMAsforMediaReachTiled/MapServer",
                    "http://dg2k8esridev1/ArcGISDevelopment/rest/services/RoadsforMediaReachTiled/MapServer");
            //ReachCalculatorMapPrincipal principal = new ReachCalculatorMapPrincipal("http://dg2k8esridev1/ArcGISDevelopment/rest/services/BaseMapforIAnalyzeUS/MapServer");
            return principal;
        }
Bootstrapper.cs
    public class Bootstrapper : UnityBootstrapper
    {
        ReachCalculatorMapPrincipal mapPrincipal;

        protected override DependencyObject CreateShell()
        {
            Shell rootShell = new Shell();
            Application.Current.RootVisual = rootShell;
            return rootShell;
        }

        protected override void ConfigureContainer()
        {
            Container.RegisterInstance(typeof(ReachCalculatorMapPrincipal), mapPrincipal, new ContainerControlledLifetimeManager());

            base.ConfigureContainer();
        }

        public Bootstrapper(ReachCalculatorMapPrincipal mPrincipal)
        {
            this.mapPrincipal = mPrincipal;
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            ModuleCatalog modules = new ModuleCatalog();
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.Map.MapModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.Layers.LayersModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.Locations.LocationsModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.AreaSelection.AreaSelectionModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.Demographics.DemographicsModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.ProgressBar.ProgressBarModule));
            modules.AddModule(typeof(Geomentum.ReachCalculator.Modules.Overlays.OverlaysModule));
            return modules;
        }
    }

A module whose constructor needs the Map Principal
            public MapViewModel(IMapView view, IEventAggregator eventAggregator, ReachCalculatorMap map)
        {
            View = view;
            View.Model = this;
            _map = map;

            BaseMapLayerService = CreateMapLayers(map);
            this.eventAggregator = eventAggregator;

            DemographicOverlayList = new ObservableCollection<DemographicCriteriaModel>();
            AreaSelectionList = new ObservableCollection<AreaSelectionsModel>();
            areaDetails = new ObservableCollection<PopulationGeographyDetails>();
            demoDetails = new ObservableCollection<PopulationDemographicsDetails>();

            populationModel = new ObservableCollection<Infrastructure.Models.PopulationModel>();
            mediaReceptivityModel = new ObservableCollection<Infrastructure.Models.MediaReceptivityModel>();

            this.eventAggregator.GetEvent<MapLayersUpdated>().Subscribe(this.updateLayerList);
            this.eventAggregator.GetEvent<LocationOverlaysUpdated>().Subscribe(this.updateLocationLayer);
            this.eventAggregator.GetEvent<LocationOverlaysRemoved>().Subscribe(this.removeLocationLayer);
            this.eventAggregator.GetEvent<MapDemographicsUpdated>().Subscribe(this.updateDemographicOverlays);
            this.eventAggregator.GetEvent<MapDemographicsCleared>().Subscribe(this.clearDemographicOverlays);

            this.eventAggregator.GetEvent<MapMediaTypesCleared>().Subscribe(this.clearMediaTypeOverlays);
            this.eventAggregator.GetEvent<MapMediaTypesUpdated>().Subscribe(this.updateMediaTypeOverlays);

            this.eventAggregator.GetEvent<AreaSelectionUpdate>().Subscribe(this.updateAreaSelections);
        }

Developer
Sep 12, 2012 at 5:34 PM

Hi,

If your problem is how to obtain the currently logged user in Sharepoint 2010 inside your Silverlight application, I believe you could find the following threads interesting:

Also, you might find the following MSDN article useful:

It seems that your problem is more related to how to integrate Sharepoint and Silverlight than to Prism. Therefore, I believe you could find better support regarding this subject in the Sharepoint forums.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Sep 12, 2012 at 8:03 PM

Damian,

I looked at the links you provided before I create this discussion. In each of those it looks like they are getting the ClientContext when the user is already in the silverlight application, most notably in the Shell.xaml or Mainpage.xaml. I put this question in here because I am using Prism and want to get the ClientContext at the application startup instead of in the Shell.xaml, Mainpage.xaml or any modules inside my application.

I will ask the same in Sharepoint forums.

Thanks for your help.

 

Dave