public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { try { IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); IServiceLocatorConfig typeMappings = serviceLocator.GetInstance <IServiceLocatorConfig>(); typeMappings.Site = SPContext.Current.Site; typeMappings.RemoveTypeMappings <LicenseRepository>(); typeMappings.RemoveTypeMappings <PageLayoutRepository>(); typeMappings.RemoveTypeMappings <MasterPageRepository>(); } catch (Exception ex) { ex.ToString(); } try { SPUserCodeService userCodeService = SPUserCodeService.Local; RemoveProxyOperation(userCodeService, ContainsKeyDataArgs.OperationAssemblyName, ContainsKeyDataArgs.OperationTypeName); RemoveProxyOperation(userCodeService, ReadConfigArgs.OperationAssemblyName, ReadConfigArgs.OperationTypeName); RemoveProxyOperation(userCodeService, ProxyInstalledArgs.OperationAssemblyName, ProxyInstalledArgs.OperationTypeName); userCodeService.Update(); } catch (Exception ex) { ex.ToString(); } }
public void Remove(string key) { var logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>(); rrLock.EnterWriteLock(); try { //intentionally nested, both cases getting a write lock, is safe and ensures no race. //Force the reload of the persisted object, which minimizes chances of a failure due // to a concurrency failure. Reset(); WebAppSettingStore store = GetWriteSettingStore(); if (store.Settings.ContainsKey(key)) { store.Settings.Remove(key); store.Update(); } } catch (SPUpdatedConcurrencyException) { Reset(); throw; } finally { rrLock.ExitWriteLock(); } }
public ManageMasterPages() { serviceLocator = SharePointServiceLocator.GetCurrent(); serviceMasterPages = serviceLocator.GetInstance <IMasterPageRepository>(); cmurl = SPContext.Current.Site.RootWeb.CustomMasterUrl; murl = SPContext.Current.Site.RootWeb.MasterUrl; }
/// <summary> /// Registers the logger source. /// </summary> /// <param name="LoggingArea">The logging area.</param> /// <param name="categories">The area categories.</param> public static void RegisterLoggerSource(string LoggingArea, string[] categories) { DiagnosticsArea _newArea = new DiagnosticsArea(LoggingArea); foreach (string _cn in categories) { _newArea.DiagnosticsCategories.Add(new DiagnosticsCategory(_cn, EventSeverity.Verbose, TraceSeverity.Verbose)); } IConfigManager configMgr = SharePointServiceLocator.GetCurrent().GetInstance <IConfigManager>(); DiagnosticsAreaCollection _configuredAreas = new DiagnosticsAreaCollection(configMgr); var existingArea = _configuredAreas[_newArea.Name]; if (existingArea == null) { _configuredAreas.Add(_newArea); } else { foreach (DiagnosticsCategory _dc in _newArea.DiagnosticsCategories) { DiagnosticsCategory existingCategory = existingArea.DiagnosticsCategories[_dc.Name]; if (existingCategory == null) { existingArea.DiagnosticsCategories.Add(_dc); } } } _configuredAreas.SaveConfiguration(); }
//public override void FeatureActivated(SPFeatureReceiverProperties properties) //{ //} //public override void FeatureDeactivating(SPFeatureReceiverProperties properties) //{ //} /// <summary> /// Occurs after a Feature is installed. /// </summary> /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties" /> object that represents the properties of the event.</param> public override void FeatureInstalled(SPFeatureReceiverProperties properties) { try { if (!System.Diagnostics.EventLog.SourceExists(SourceName)) { System.Diagnostics.EventLog.CreateEventSource(new System.Diagnostics.EventSourceCreationData(SourceName, "Application")); } WebsiteModelExtensions.RegisterLoggerSource(); WebsiteModelExtensions.TraceEvent (String.Format("CAS.SmartFactory.CW.WebsiteModel FeatureInstalled: {0}", properties.Definition.DisplayName), 54, TraceSeverity.High, WebsiteModelExtensions.LoggingCategories.FeatureActivation); IServiceLocator _serviceLocator = SharePointServiceLocator.GetCurrent(); IServiceLocatorConfig _typeMappings = _serviceLocator.GetInstance <IServiceLocatorConfig>(); _typeMappings.RegisterTypeMapping <ICWAccountFactory, CWAccountData>(); WebsiteModelExtensions.TraceEvent("CAS.SmartFactory.CW.WebsiteModel TypeMapping registered", 59, TraceSeverity.High, WebsiteModelExtensions.LoggingCategories.FeatureActivation); } catch (Exception _ex) { System.Diagnostics.EventLog.WriteEvent(SourceName, new System.Diagnostics.EventInstance(63, 0) { EntryType = System.Diagnostics.EventLogEntryType.Error }, _ex); throw; } }
protected void AreaRadioButton_SelectedIndexChanged(object sender, EventArgs e) { //Clear the Part Results Grid PartResultsGridView.DataSource = null; PartResultsGridView.DataBind(); PartResultUpdatePanel.Update(); //Clear the Machine Results Grid MachineResultsGridView.DataSource = null; MachineResultsGridView.DataBind(); MachineResultsUpdatePanel.Update(); AreaDisplayTypes displayType = (AreaDisplayTypes)System.Enum.Parse(typeof(AreaDisplayTypes), AreaRadioButton.SelectedValue); // AreaResultsGridView.Columns[1].HeaderText = "All " + MakePlural(displayType); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { if (displayType == AreaDisplayTypes.Category) { var categories = partManagementRepository.GetCategories(); var areaDtos = categories.Select(category => new AreaDTO { Title = category.Title, Id = category.Id.HasValue ? category.Id.Value : 0 }); ShowAreaResults(areaDtos); } if (displayType == AreaDisplayTypes.Department) { var departments = partManagementRepository.GetDepartments(); var areaDtos = departments.Select(department => new AreaDTO { Title = department.Title, Id = department.Id.HasValue ? department.Id.Value : 0 }); ShowAreaResults(areaDtos); } if (displayType == AreaDisplayTypes.Manufacturer) { var manufacturers = partManagementRepository.GetManufacturers(); var areaDtos = manufacturers.Select(manufacturer => new AreaDTO { Title = manufacturer.Title, Id = manufacturer.Id. HasValue ? manufacturer.Id. Value : 0 }); ShowAreaResults(areaDtos); } } }
protected void areaResultsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { AreaDisplayTypes displayType = (AreaDisplayTypes)System.Enum.Parse(typeof(AreaDisplayTypes), AreaRadioButton.SelectedValue); int selectedAreaId = int.Parse(AreaResultsGridView.DataKeys[int.Parse(e.CommandArgument.ToString())].Value.ToString()); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <MachineDTO> machines = null; switch (displayType) { case AreaDisplayTypes.Category: machines = partManagementRepository.GetMachinesByCategory(selectedAreaId); break; case AreaDisplayTypes.Manufacturer: machines = partManagementRepository.GetMachinesByManufacturer(selectedAreaId); break; case AreaDisplayTypes.Department: machines = partManagementRepository.GetMachinesByDepartment(selectedAreaId); break; } ShowMachines(machines); } }
public void FindCategoryWithValidCategorySucceeds() { //Arrange var replaceLocator = new ActivatingServiceLocator(); SharePointServiceLocator.ReplaceCurrentServiceLocator(replaceLocator); replaceLocator.RegisterTypeMapping <IHierarchicalConfig, MockHierarchicalConfig>(InstantiationType.AsSingleton); replaceLocator.RegisterTypeMapping <IConfigManager, MockConfigManager>(InstantiationType.AsSingleton); var target = new DiagnosticsService(); var config = SharePointServiceLocator.GetCurrent().GetInstance <IConfigManager>() as MockConfigManager; string category11Name = string.Format("{0}/{1}", MockConfigManager.Area1Name, MockConfigManager.Area1Category1Name); string category21Name = string.Format("{0}/{1}", MockConfigManager.Area2Name, MockConfigManager.Area2Category1Name); string category12Name = string.Format("{0}/{1}", MockConfigManager.Area1Name, MockConfigManager.Area1Category2Name); string category22Name = string.Format("{0}/{1}", MockConfigManager.Area2Name, MockConfigManager.Area2Category2Name); //Act SPDiagnosticsCategory category11 = target.FindCategory(category11Name); SPDiagnosticsCategory category12 = target.FindCategory(category12Name); SPDiagnosticsCategory category21 = target.FindCategory(category21Name); SPDiagnosticsCategory category22 = target.FindCategory(category22Name); // Assert Assert.AreEqual(MockConfigManager.Area1Category1Name, category11.Name); Assert.AreEqual(MockConfigManager.Area1Category2Name, category12.Name); Assert.AreEqual(MockConfigManager.Area2Category1Name, category21.Name); Assert.AreEqual(MockConfigManager.Area2Category2Name, category22.Name); Assert.AreEqual(MockConfigManager.Area1Name, category11.Area.Name); Assert.AreEqual(MockConfigManager.Area1Name, category12.Area.Name); Assert.AreEqual(MockConfigManager.Area2Name, category21.Area.Name); Assert.AreEqual(MockConfigManager.Area2Name, category22.Area.Name); Assert.IsTrue(config.LoadedCount == 1); }
public static void EnsureConfiguredAreasRegistered() { var mgr = SharePointServiceLocator.GetCurrent().GetInstance <IConfigManager>(); var areas = new DiagnosticsAreaCollection(mgr); RegisterAreas(areas); }
/// <summary> /// Calls the service. /// </summary> /// <param name="requestUrl">The request URL.</param> /// <param name="warnningList">The warnning list.</param> public void CallService(string requestUrl, List <Customs.Warnning> warnningList) { IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); ICWAccountFactory _cwFactory = serviceLocator.GetInstance <ICWAccountFactory>(); _cwFactory.ClearThroughCustoms(this, warnningList, requestUrl); }
public UoBMySiteJob() : base() { IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); ILogger logger = serviceLocator.GetInstance <ILogger>(); logger.LogToOperations("Starting UoB Delete Old MySite DocLibs Timer Job", EventSeverity.Information); }
/// <summary> /// Calls the remote service. /// </summary> /// <param name="requestUrl">The The URL of a Windows SharePoint Services "14" Web site.</param> /// <param name="warnningList">The warnning list.</param> public override void CallService(string requestUrl, List <Warnning> warnningList) { IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); ICWAccountFactory _cwFactory = serviceLocator.GetInstance <ICWAccountFactory>(); _cwFactory.CreateCWAccount(this, warnningList, requestUrl); }
public void LogMessageShouldContainContextualInformation() { // arrange var context = BHttpContext.SetCurrent(); MSPContext.CurrentGet = () => null; context.Timestamp = new DateTime(2000, 1, 1); var user = context.SetUser(); var identity = user.SetIdentity(); identity.Name = "TestUser"; var request = context.SetRequest(); request.Url = new Uri("http://localhost/mypage.aspx"); request.UserHostAddress = "1.1.1.1.1"; request.UserAgent = "MyAgent"; var eventLogger = SharePointServiceLocator.GetCurrent().GetInstance <IEventLogLogger>() as MockEventAndTraceLogger; Exception ex = new Exception("message"); // act var target = new SharePointLogger(); target.LogToOperations(ex); var message = eventLogger.Messages[0].Message; Assert.IsTrue(message.Contains(@"Request URL: 'http://localhost/mypage.aspx'")); Assert.IsTrue(message.Contains("Request TimeStamp: '" + context.Timestamp.ToString("o", CultureInfo.CurrentCulture) + "'")); Assert.IsTrue(message.Contains("UserName: '******'")); Assert.IsTrue(message.Contains("Originating IP address: '1.1.1.1.1'")); Assert.IsTrue(message.Contains("User Agent: 'MyAgent'")); }
public void WhenLoggingFailsAClearExceptionIsThrown() { //Arrange var target = new SharePointLogger(); string message = testMessageString; ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent()) .RegisterTypeMapping <IEventLogLogger, FailingEventLogger>(); //Act try { target.LogToOperations(message, 99, EventSeverity.Error, TestsConstants.AreasCategories); Assert.Fail(); } //Assert catch (LoggingException ex) { Assert.IsTrue(ex.Message.Contains(message)); Assert.IsTrue(ex.Message.Contains("EventLog")); } catch (Exception) { Assert.Fail(); } }
public void Setup() { SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator()); ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent()) .RegisterTypeMapping <ITraceLogger, MockEventAndTraceLogger>(InstantiationType.AsSingleton) .RegisterTypeMapping <IEventLogLogger, MockEventAndTraceLogger>(InstantiationType.AsSingleton); }
private void CheckContains() { var cfg = SharePointServiceLocator.GetCurrent().GetInstance <IHierarchicalConfig>(); bool contains = cfg.ContainsKey(key); Literal1.Text = Literal1.Text + "<br/><br/> Contains Key check: " + contains.ToString(); }
private void GoButton_Click(object sender, EventArgs eventArgs) { using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <Machine> machines = partManagementRepository.GetMachinesByPartialModelNumber(MachineSearchTextBox.Text); ShowMachineResults(machines); } }
protected void LoadPartLocations(string partSku) { using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <PartInventoryDTO> partsData = partManagementRepository.GetPartsInventoryView(partSku); ShowParts(partsData); } }
public WordScraper() { settings = new KeywordSettings(); settings = settings.Load(); serviceLocator = SharePointServiceLocator.GetCurrent(); serviceKeywords = serviceLocator.GetInstance <IKeywordRepository>(); }
private void GoButton_Click(object sender, EventArgs eventArgs) { using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <PartInventoryDTO> partsData = partManagementRepository.GetPartsInventoryView(PartSearchTextBox.Text); ShowParts(partsData); } }
public void Init() { SharePointServiceLocator.ReplaceCurrentServiceLocator( new ActivatingServiceLocator() .RegisterTypeMapping <ILogger, MockLogger>(InstantiationType.AsSingleton)); logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>() as MockLogger; }
void ISPServiceBehaviorAccessor.SetContainer(SPSite site) { _container = (site != null ? SharePointServiceLocator.GetCurrent(site) : SharePointServiceLocator.GetCurrent()); _registrar = (_container.GetInstance <IServiceLocatorConfig>() as ServiceLocatorConfig); if (_registrar == null) { throw new NullReferenceException("registrar"); } }
/// <summary> /// Removes the mappings for the configuration manager for list backed configuration. This results /// in the default implementations being picked up for these services. /// </summary> /// <param name="properties">The properties related to the current context</param> public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { var slConfig = SharePointServiceLocator.GetCurrent().GetInstance <IServiceLocatorConfig>(); var site = properties.Feature.Parent as SPSite; slConfig.Site = site; slConfig.RemoveTypeMapping <IConfigManager>(null); slConfig.RemoveTypeMapping <IHierarchicalConfig>(null); SharePointServiceLocator.Reset(); }
protected void CategoryResultsGridView_SelectedIndexChanged(object sender, EventArgs e) { int selectedCategoryId = int.Parse(CategoryResultsGridView.DataKeys[CategoryResultsGridView.SelectedRow.RowIndex].Value.ToString()); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <MachineDTO> machines = partManagementRepository.GetMachinesByCategory(selectedCategoryId); ShowMachines(machines); } }
protected void SupplierResultsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { int partSupplierId = int.Parse(PartSupplierResultsGridView.DataKeys[e.RowIndex].Value.ToString()); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { partManagementRepository.DeletePartSupplier(partSupplierId); string partSku = this.Page.Request.QueryString[Constants.PartSku].ToString(); LoadPartSuppliers(partSku); } }
public void ReplaceCurrentServiceLocator_ChangeServiceLocator() { //Arrange var serviceLocator = new SIServiceLocator(); //Act SharePointServiceLocator.ReplaceCurrentServiceLocator(serviceLocator); //Assert Assert.AreSame(serviceLocator, SharePointServiceLocator.GetCurrent()); }
public void Execute_TracesMessage() { //Arrange var args = new TracingOperationArgs(); Guid createGuid = Guid.Empty; args.Message = TestsConstants.TestGuidName; args.EventId = -99; args.Category = TestsConstants.AreasCategories; args.Severity = (int)SandboxTraceSeverity.High; args.SiteID = TestsConstants.TestGuid; SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator()); ((ActivatingServiceLocator)SharePointServiceLocator.GetCurrent()) .RegisterTypeMapping <ILogger, TestTraceLogger>(InstantiationType.AsSingleton); var operation = new TracingOperation(); BSPFarm.SetLocal(); MSPSite site; BSPWeb bweb = new BSPWeb(); var mweb = new MSPWeb(bweb) { NameGet = () => "foo.bar", }; MSPSite.ConstructorGuid = (instance, g) => { site = new MSPSite(instance) { Dispose = () => { }, IDGet = () => TestsConstants.TestGuid, RootWebGet = () => mweb }; createGuid = g; }; //Act object target = operation.Execute(args); //Assert var logger = SharePointServiceLocator.GetCurrent().GetInstance <ILogger>() as TestTraceLogger; Assert.IsNotInstanceOfType(target, typeof(Exception)); Assert.AreEqual(TestsConstants.TestGuid, createGuid); Assert.IsTrue(logger.Message.Contains(args.Message)); Assert.AreEqual(logger.Category, TestsConstants.AreasCategories); Assert.AreEqual(logger.EventId, args.EventId); Assert.AreEqual(logger.Severity, SandboxTraceSeverity.High); }
private void GoButton_Click(object sender, EventArgs eventArgs) { PartResultsGridView.DataSource = null; PartResultsGridView.DataBind(); PartResultUpdatePanel.Update(); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { IEnumerable <Machine> machines = partManagementRepository.GetMachinesByPartialModelNumber(MachineSearchTextBox.Text); ShowMachineResults(machines); } }
protected void MachineResultsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { var selectedMachineDepartmentId = int.Parse(MachineResultsGridView.DataKeys[e.RowIndex].Value.ToString()); var selectedDepartmentId = int.Parse(DepartmentResultsGridView.DataKeys[DepartmentResultsGridView.SelectedRow.RowIndex].Value.ToString()); using (var partManagementRepository = SharePointServiceLocator.GetCurrent().GetInstance <IPartManagementRepository>()) { partManagementRepository.DeleteMachineDepartment(selectedMachineDepartmentId); } BindMachineParts(selectedDepartmentId); }
/// <summary> /// Unregisters the logger source. /// </summary> /// <param name="loggingArea">The logging area.</param> public static void UnregisterLoggerSource(string loggingArea) { IConfigManager _configMgr = SharePointServiceLocator.GetCurrent().GetInstance <IConfigManager>(); DiagnosticsAreaCollection _configuredAreas = new DiagnosticsAreaCollection(_configMgr); DiagnosticsArea areaToRemove = _configuredAreas[loggingArea]; if (areaToRemove != null) { _configuredAreas.Remove(areaToRemove); } _configuredAreas.SaveConfiguration(); }