Beispiel #1
0
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>();
            typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>();
        }
Beispiel #2
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            IConfigManager hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IConfigManager>();

            hierarchicalConfig.SetInPropertyBag(Constants.SubSiteCreationConfigSiteKey, web.Url, SPFarm.Local);

            SPList taskList    = web.Lists[taskListName];
            SPList historyList = web.Lists[workflowHistoryName];
            SPList subSiteCreationRequestList = web.Lists[subSiteRequestsListName];

            var existingAssociation = subSiteCreationRequestList.WorkflowAssociations.GetAssociationByName(workflowTemplateName, CultureInfo.CurrentCulture);

            if (existingAssociation == null)
            {
                SPWorkflowManager            workflowManager = web.Site.WorkflowManager;
                SPWorkflowTemplateCollection templates       = workflowManager.GetWorkflowTemplatesByCategory(web, null);
                SPWorkflowTemplate           template        = templates.GetTemplateByBaseID(workflowTemplateId);
                SPWorkflowAssociation        association     = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList);
                association.AllowManual     = true;
                association.AutoStartCreate = true;
                subSiteCreationRequestList.AddWorkflowAssociation(association);
                subSiteCreationRequestList.Update();
                association.Enabled = true;
            }

            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>();
            typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>();
        }
Beispiel #3
0
        public void RegisterTypeMapping_SetANewMappingForExistingMapping()
        {
            //Arrange
            List <TypeMapping> mappings = null;
            var propertyBag             = new BIPropertyBag();

            BSPFarm.SetLocal();

            var configMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (stringValue, farm) => false,
                SetInPropertyBagStringObjectIPropertyBag   = (strValue, obj, farm) => mappings = obj as List <TypeMapping>,
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => propertyBag
            };

            configMgr.BehaveAsDefaultValue();

            //Act
            var target = new ServiceLocatorConfig(configMgr);

            target.RegisterTypeMapping <ISomething, Something>();
            target.RegisterTypeMapping <ISomething, SomethingElse>();
            TypeMapping mapping = mappings.First();

            //Assert
            Assert.IsTrue(mapping.ToType.Contains("SomethingElse"));
        }
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IIncidentManagementRepository, IncidentManagementRepository>();
            typeMappings.RegisterTypeMapping <IPricingRepository, PricingRepository>();
            typeMappings.RegisterTypeMapping <IProductCatalogRepository, CachedBdcProductCatalogRepository>();
        }
Beispiel #5
0
        public void SerLocConfigRemoveTypeMappingKey()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IConfig, ConfigTest>();
            target.RegisterTypeMapping <IConfig, ConfigTest>("key");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));

            actual = new List <TypeMapping>(target.GetTypeMappings());

            target.RemoveTypeMapping <IConfig>("key");
            Assert.AreEqual(actual.Count - 1, target.GetTypeMappings().Count());
        }
        public void RegisteringTypeMappingTwiceOverwritesLastOne()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>();
            target.RegisterTypeMapping <ISomething, SomethingElse>();

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping = typeMappings.First();

            Assert.IsTrue(mapping.ToType.Contains("SomethingElse"));
        }
Beispiel #7
0
        public void SetServiceLocatorTest()
        {
            SharePointServiceLocator.ReplaceCurrentServiceLocator(SharePointServiceLocator.Current);

            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IFirstType, FirstTest1>();
            target.RegisterTypeMapping <IFirstType, FirstTest1>("First");
            target.RegisterTypeMapping <IFirstType, FirstTest2>("Second");
            SharePointServiceLocator.Reset();


            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>(), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("First"), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("Second"), typeof(FirstTest2));
        }
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig();
            serviceLocatorConfig.RegisterTypeMapping<IIssueManagementRepository, IssueManagementRepository>();


        }
Beispiel #9
0
        public void RegisterTypeMapping_SaveNewMappingWithNoContext_ThrowsInvalidOperationException()
        {
            // Arrange
            object value      = null;
            var    rootConfig = new BIPropertyBag();
            bool   expectedExceptionThrown = false;

            var mgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (stringValue, propertyBag) => false,
                SetInPropertyBagStringObjectIPropertyBag   = (strValue, obj, propertyBag) => value = obj as List <TypeMapping>,
                GetPropertyBagConfigLevel = (level) => rootConfig,
                CanAccessFarmConfigGet    = () => false
            };

            mgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, bag) => null);

            //Act
            var target = new ServiceLocatorConfig(mgr);

            try
            {
                target.RegisterTypeMapping <ISomething, Something>();
            }
            catch (InvalidOperationException)
            {
                expectedExceptionThrown = true;
            }

            Assert.IsTrue(expectedExceptionThrown);
        }
Beispiel #10
0
        public void SerLocConfigRegisterTypeMappingOverwritekey()
        {
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();
            int beforeCount;

            target.RegisterTypeMapping <IConfig, ConfigTest>("key");
            actual = new List <TypeMapping>(target.GetTypeMappings());

            beforeCount = actual.Count;
            target.RegisterTypeMapping <IConfig, ConfigTest1>("key");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>("key"), typeof(ConfigTest1));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            Assert.AreEqual(beforeCount, actual.Count);
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            featureDefinition = properties.Feature.Definition;

            SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

            webApp.WebConfigModifications.Add(GetModification());

            webApp.Update();
            webApp.WebService.ApplyWebConfigModifications();

            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IIncidentManagementRepository, IncidentManagementRepository>();
            typeMappings.RegisterTypeMapping <IPricingRepository, PricingRepository>();
            typeMappings.RegisterTypeMapping <IProductCatalogRepository, CachedBdcProductCatalogRepository>();
        }
        public void CanRegisterTypeMappingWithKey()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>("key1");
            target.RegisterTypeMapping <ISomething, Something>("key2");

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping1 = typeMappings.First();
            TypeMapping mapping2 = typeMappings.Skip(1).First();

            Assert.AreEqual("key1", mapping1.Key);
            Assert.AreEqual("key2", mapping2.Key);
        }
Beispiel #13
0
        public void RegisterTypeMapping_SaveNewMappingWithSite()
        {
            var    mappings   = new List <TypeMapping>();
            string savedkey   = null;
            object savedValue = null;
            var    configData = new ServiceLocationConfigData(mappings);

            BSPFarm.SetLocal();
            const string expectedKey = "Microsoft.Practices.SharePoint.Common.TypeMappings";
            var          web         = new MSPWeb();
            var          propBag     = new BIPropertyBag();

            var mgr = new SIConfigManager()
            {
                SetInPropertyBagStringObjectIPropertyBag = (key, value, bag) =>
                {
                    savedkey   = key;
                    savedValue = value;
                },

                ContainsKeyInPropertyBagStringIPropertyBag = (key, bag) =>
                {
                    if (key == expectedKey)
                    {
                        return(true);
                    }
                    return(false);
                },
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (level) => propBag,
                SetWebSPWeb = (w) => { },
            };

            mgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, bag) =>
            {
                if (key == expectedKey)
                {
                    return(configData);
                }
                return(null);
            });

            var configSite = new MSPSite()
            {
                RootWebGet = () => web
            };

            var target = new ServiceLocatorConfig(mgr);

            target.Site = configSite;

            //act
            target.RegisterTypeMapping <ISomething, Something>();

            //assert
            Assert.IsNotNull(savedValue);
            Assert.AreEqual(expectedKey, savedkey);
        }
Beispiel #14
0
        public void SetServiceLocatorTest2()
        {
            SharePointServiceLocator.ReplaceCurrentServiceLocator(SharePointServiceLocator.Current);

            ServiceLocatorConfig target = new ServiceLocatorConfig();

            target.RegisterTypeMapping <IFirstType, FirstTest1>();
            target.RegisterTypeMapping <IFirstType, FirstTest1>("First");
            target.RegisterTypeMapping <IFirstType, FirstTest2>("Second");
            SharePointServiceLocator.Reset();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>(), typeof(FirstTest1));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IFirstType>("First"), typeof(FirstTest1));

            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <ILogger>(), typeof(SharePointLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <ITraceLogger>(), typeof(TraceLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IEventLogLogger>(), typeof(EventLogLogger));
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfigManager>(), typeof(HierarchicalConfig));
        }
Beispiel #15
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb  incidentsWeb = properties.Feature.Parent as SPWeb;
            SPFile file         = incidentsWeb.Files[IncidentDashboardFileName];

            file.MoveTo(DefaultFileName, true);

            ServiceLocatorConfig config = new ServiceLocatorConfig();

            config.RegisterTypeMapping <IIncidentTaskRepository, FullTextSearchIncidentTaskRepository>();
        }
Beispiel #16
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            if (site != null)
            {
                ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig();
                serviceLocatorConfig.Site = site;
                serviceLocatorConfig.RegisterTypeMapping <IPartManagementRepository, PartManagementRepository>();
            }
        }
Beispiel #17
0
        public void SerLocConfigRegisterTypeMappingTestHelper()
        {
            int beforeCount;
            List <TypeMapping>   actual;
            ServiceLocatorConfig target = new ServiceLocatorConfig();

            actual      = new List <TypeMapping>(target.GetTypeMappings());
            beforeCount = actual.Count;
            target.RegisterTypeMapping <IConfig, ConfigTest>();
            Assert.IsInstanceOfType(SharePointServiceLocator.Current.GetInstance <IConfig>(), typeof(ConfigTest));
            actual = new List <TypeMapping>(target.GetTypeMappings());

            Assert.AreEqual(beforeCount + 1, actual.Count);
        }
Beispiel #18
0
        public void RegisterTypeMapping_RegisterMappingWithAKey()
        {
            //Arrange
            BSPFarm.SetLocal();
            List <TypeMapping> typeMappings = new List <TypeMapping>();
            var configData = new ServiceLocationConfigData();
            var propBag    = new BIPropertyBag();

            int savedCnt  = 0;
            var configMgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (s, propertybag) => typeMappings != null,
                SetInPropertyBagStringObjectIPropertyBag   = (s, obj, propertybag) =>
                {
                    savedCnt++;
                },
                CanAccessFarmConfigGet    = () => true,
                GetPropertyBagConfigLevel = (configlevel) => propBag,
            };

            configMgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, propertybag) => configData);

            //Act
            var target = new ServiceLocatorConfig(configMgr as IConfigManager);

            target.RegisterTypeMapping <ISomething, Something>("key1");
            target.RegisterTypeMapping <ISomething, Something>("key2");

            //Assert
            Assert.IsTrue(configData.Count == 2);
            Assert.IsTrue(savedCnt == 2);
            TypeMapping mapping1 = configData[0];
            TypeMapping mapping2 = configData[1];

            Assert.AreEqual("key1", configData[0].Key);
            Assert.AreEqual("key2", configData[1].Key);
        }
        public void CanRegisterTypeMapping()
        {
            var mockPropertyBag = new MockPropertyBag();
            MockConfigManager hierarchicalConfig = new MockConfigManager();
            var target = new ServiceLocatorConfig(hierarchicalConfig);

            target.RegisterTypeMapping <ISomething, Something>();

            var typeMappings = hierarchicalConfig.Value as List <TypeMapping>;

            TypeMapping mapping = typeMappings.First();

            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromAssembly);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests.ServiceLocation.ISomething, Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromType);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToAssembly);
            Assert.AreEqual("Microsoft.Practices.SPG.Common.Tests.ServiceLocation.Something, Microsoft.Practices.SPG.Common.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToType);
        }
Beispiel #20
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            // The Site Directory used for the Partner Directory requires a new field to store Partner Id.
            // The field is provisioned in the Site Collection scoped feature, but should be added to the exisitng
            // Sites list here.
            SPList sitesList = AddPartnerFieldToSiteDirectory(web);

            // The Site Directory makes available a set of Tabbed pages for things like Top Sites, Site Map and Categories
            // We will add a new Tabbed page to easily see only sites for Partners.
            CreatePartnerTabbedPage(web, sitesList);

            // Also register this site as the Partner Site Directory in config settings
            SetPartnerSiteDirectoryInConfig(web);

            // Register the type mapping for the Partner Site Directory Repository
            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IPartnerSiteDirectory, PartnerSiteDirectory>();
        }
Beispiel #21
0
        public void RegisterTypeMapping_SaveNewMapping()
        {
            // Arrange
            object value      = null;
            var    rootConfig = new BIPropertyBag();

            BSPFarm.SetLocal();

            var mgr = new SIConfigManager
            {
                ContainsKeyInPropertyBagStringIPropertyBag = (stringValue, propertyBag) => false,
                SetInPropertyBagStringObjectIPropertyBag   = (strValue, obj, propertyBag) => value = obj as List <TypeMapping>,
                GetPropertyBagConfigLevel = (level) => rootConfig,
                CanAccessFarmConfigGet    = () => true
            };

            mgr.GetFromPropertyBagStringIPropertyBag <ServiceLocationConfigData>((key, bag) => null);

            //Act
            var target = new ServiceLocatorConfig(mgr);

            target.RegisterTypeMapping <ISomething, Something>();
            var typeMappings = value as List <TypeMapping>;


            //Assert
            Assert.IsNotNull(typeMappings);
            Assert.IsTrue(typeMappings.Count >= 1);
            TypeMapping mapping = typeMappings[0];

            Assert.AreEqual("Microsoft.Practices.SharePoint.Common.Tests, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromAssembly);
            Assert.AreEqual("Microsoft.Practices.SharePoint.Common.Tests.ServiceLocation.ISomething, Microsoft.Practices.SharePoint.Common.Tests, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.FromType);
            Assert.AreEqual("Microsoft.Practices.SharePoint.Common.Tests, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToAssembly);
            Assert.AreEqual("Microsoft.Practices.SharePoint.Common.Tests.ServiceLocation.Something, Microsoft.Practices.SharePoint.Common.Tests, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
                            , mapping.ToType);
        }
Beispiel #22
0
        private static void RegisterPromotionRepositoryTypeMapping()
        {
            ServiceLocatorConfig typeMappings = new ServiceLocatorConfig();

            typeMappings.RegisterTypeMapping <IPartnerPromotionRepository, PartnerPromotionRepository>();
        }
Beispiel #23
0
 // register implementation
 /// <summary>
 /// Registers this instance.
 /// </summary>
 /// <typeparam name="TService">The type of the service.</typeparam>
 /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
 public void Register <TService, TImplementation>()
     where TService : class
     where TImplementation : class, TService
 {
     _registrar.RegisterTypeMapping <TService, TImplementation>(null, GetLifestyle());
 }
Beispiel #24
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig();

            serviceLocatorConfig.RegisterTypeMapping <IPartManagementRepository, PartManagementRepository>();
        }