int EnumMappings(out string output) { System.Text.StringBuilder builder = new System.Text.StringBuilder(); foreach (SlkSPSiteMapping mapping in SlkSPSiteMapping.GetMappings()) { string siteLabel = null; try { using (SPSite spSite = new SPSite(mapping.SPSiteGuid)) { siteLabel = spSite.Url; } } catch (System.IO.FileNotFoundException) { SPFarm farm = SPFarm.Local; SPWebApplication webApp = farm.GetObject(mapping.SPSiteGuid) as SPWebApplication; siteLabel = webApp.Name; } builder.AppendFormat(culture.Resources.StsEnumMappingLine, siteLabel, mapping.SPSiteGuid, mapping.DatabaseServer, mapping.DatabaseName); builder.AppendLine(); } output = builder.ToString(); return(0); }
public void GetSiteCacheInterval_WithoutConfiguredFarmValue_ReturnsNegativeOne() { //Arrange int expected = -1; string expectedKey = "Microsoft.Practices.SharePoint.Common.SiteLocatorCacheInterval"; var bag = new BIPropertyBag(); SPFarm farm = BSPFarm.SetLocal(); var context = new SIApplicationContextProvider(); context.GetCurrentAppDomainFriendlyName = () => "FullTrust"; context.GetSPFarmLocal = () => farm; SharePointEnvironment.ApplicationContextProvider = context; var configMgr = new SIConfigManager(); configMgr.ContainsKeyInPropertyBagStringIPropertyBag = (key, propertyBag) => { if (key == expectedKey) { return(false); } return(true); }; configMgr.GetPropertyBagConfigLevel = (cfgLevel) => bag; var config = new ServiceLocatorConfig(configMgr); //Act int target = config.GetSiteCacheInterval(); //Assert Assert.AreEqual(expected, target); }
public void BackupFarm(SPFarm farm, bool prepare) { if (prepare) { PrepareSystem(); } if (_includeIis) { // Export the IIS settings. string iisBakPath = Path.Combine(_path, "iis_full.bak"); if (_overwrite && File.Exists(iisBakPath)) { File.Delete(iisBakPath); } if (!_overwrite && File.Exists(iisBakPath)) { throw new SPException( string.Format("The IIS backup file '{0}' already exists - specify '-overwrite' to replace the file.", iisBakPath)); } //Utilities.RunCommand("cscript", string.Format("{0}\\iiscnfg.vbs /export /f \"{1}\" /inherited /children /sp /lm", Environment.SystemDirectory, iisBakPath), false); using (DirectoryEntry de = new DirectoryEntry("IIS://localhost")) { Logger.Write("Exporting full IIS settings...."); string decryptionPwd = string.Empty; de.Invoke("Export", new object[] { decryptionPwd, iisBakPath, "/lm", FLAG_EXPORT_INHERITED_SETTINGS }); } } SPEnumerator enumerator = new SPEnumerator(farm); InitiateEnumerator(enumerator); }
private void DeployDefinition(object modelHost, SPFarm spFarm, DiagnosticsServiceBaseDefinition definition) { var currentObject = GetCurrentObject(spFarm, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentObject, ObjectType = typeof(SPDiagnosticsServiceBase), ObjectDefinition = definition, ModelHost = modelHost }); if (currentObject == null) currentObject = CreateObject(spFarm, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentObject, ObjectType = typeof(SPDiagnosticsServiceBase), ObjectDefinition = definition, ModelHost = modelHost }); }
public void SetInPropertyBag(string key, object value, SPFarm propertyBag) { if (key == Constants.AreasConfigKey) { SaveCount++; } }
private void ValidateDefinition(FarmModelHost farmModelHost, SPFarm farm, DeveloperDashboardSettingsDefinition definition) { var spObject = GetCurrentSettings(); var assert = ServiceFactory.AssertService.NewAssert(definition, spObject); assert .ShouldNotBeNull(spObject); if (!string.IsNullOrEmpty(definition.DisplayLevel)) { assert.ShouldBeEqual((p, s, d) => { var srcProp = s.GetExpressionValue(def => def.DisplayLevel); var dstProp = d.GetExpressionValue(ct => ct.DisplayLevel); return(new PropertyValidationResult { Tag = p.Tag, Src = srcProp, Dst = dstProp, IsValid = dstProp.Value.ToString().ToUpper() == (srcProp.Value.ToString().ToUpper()) }); }); } else { assert.SkipProperty(m => m.DisplayLevel); } }
protected override void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); int code = 1; string error = ""; try { SPSecurity.RunWithElevatedPrivileges(delegate() { SPFarm farm = SPFarm.Local; code = int.Parse(farm.Properties["SPA_CLASSIFICATION_CODE"].ToString()); }); } catch (Exception ex) { error = ex.Message.ToString(); } switch (code) { case 1: lblClassificationBanner.Text = "U N C L A S S I F I E D"; break; case 2: lblClassificationBanner.Text = "S E C R E T"; pnlClassificationBanner.CssClass = "bannerClassificationRed"; break; default: lblClassificationBanner.Text = ""; break; } }
void InstallMenuItem_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; Explorer.Update(); // Feature is not installed. string path = this.Tag as string; DirectoryInfo info = new DirectoryInfo(path); string featureName = info.Name + @"\feature.xml"; SPFarm spFarm = Explorer.CurrentFarm; SPFeatureDefinition definition = spFarm.FeatureDefinitions.Add(featureName, Guid.Empty, true); SPFeatureDefinition dd = new SPFeatureDefinition(); this.Text = definition.DisplayName; this.Name = definition.Id.ToString(); this.Tag = definition; FeatureCollectionDefinitionNode nodeCollection = (FeatureCollectionDefinitionNode)this.Parent; this.ImageIndex = nodeCollection.InstalledIndex; this.SelectedImageIndex = nodeCollection.InstalledIndex; IsInstalled = true; Explorer.EndUpdate(); Explorer.Refresh(); //Program.Window.propertyGrid.SelectedObject = this.Tag; Cursor.Current = Cursors.Default; }
private void DeployDefinition(object modelHost, SPFarm spFarm, SecureStoreApplicationDefinition definition) { var currentObject = GetCurrentSecureStoreApplication(spFarm, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentObject, ObjectType = typeof(ISecureStore), ObjectDefinition = definition, ModelHost = modelHost }); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentObject, ObjectType = typeof(ISecureStore), ObjectDefinition = definition, ModelHost = modelHost }); }
protected void btnSave_Click(object sender, EventArgs e) { string servers = ""; foreach (GridViewRow gvRow in GvItems.Rows) { CheckBox cb = (CheckBox)gvRow.Cells[0].Controls[1]; if (cb.Checked) { Label lbl = (Label)gvRow.Cells[1].Controls[0]; servers += "," + lbl.Text.ToLower(); } } if (servers.Length > 1) { servers = servers.Substring(1); } SPSecurity.RunWithElevatedPrivileges(delegate() { SPWeb web = SPContext.Current.Web; { web.AllowUnsafeUpdates = true; SPSite site = web.Site; site.AllowUnsafeUpdates = true; SPFarm farm = site.WebApplication.Farm; farm.Properties["EPMLiveServers"] = servers; farm.Update(); } }); Response.Redirect("/generalapplicationsettings.aspx"); }
public void RetractSolution(Guid ID) { farm = SPFarm.Local; SPSolution sol = farm.Solutions[ID]; sol.Retract(DateTime.Now); }
public void BackupFarm(SPFarm farm, bool prepare) { if (prepare) PrepareSystem(); if (_includeIis) { // Export the IIS settings. string iisBakPath = Path.Combine(_path, "iis_full.bak"); if (_overwrite && File.Exists(iisBakPath)) File.Delete(iisBakPath); if (!_overwrite && File.Exists(iisBakPath)) throw new SPException( string.Format("The IIS backup file '{0}' already exists - specify '-overwrite' to replace the file.", iisBakPath)); //Utilities.RunCommand("cscript", string.Format("{0}\\iiscnfg.vbs /export /f \"{1}\" /inherited /children /sp /lm", Environment.SystemDirectory, iisBakPath), false); using (DirectoryEntry de = new DirectoryEntry("IIS://localhost")) { Logger.Write("Exporting full IIS settings...."); string decryptionPwd = string.Empty; de.Invoke("Export", new object[] { decryptionPwd, iisBakPath, "/lm", FLAG_EXPORT_INHERITED_SETTINGS }); } } SPEnumerator enumerator = new SPEnumerator(farm); InitiateEnumerator(enumerator); }
public void FeatureActivatedTest() { SPFeatureReceiverProperties properties = Isolate.Fake.Instance <SPFeatureReceiverProperties>(Members.ReturnRecursiveFakes); SPFarm fakeSPFarm = Isolate.Fake.Instance <SPFarm>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => SPFarm.Local).WillReturn(fakeSPFarm); Hashtable farmProperties = new Hashtable(); Isolate.WhenCalled(() => fakeSPFarm.Properties).WillReturn(farmProperties); MockConfigManager.ReturnValue = "http://localhost"; SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IConfigManager, MockConfigManager>() .RegisterTypeMapping <ILogger, MockLogger>()); SPWeb fakeSPWeb = Isolate.Fake.Instance <SPWeb>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => properties.Feature.Parent).WillReturn(fakeSPWeb); SPWorkflowAssociation fakeAssociation = Isolate.Fake.Instance <SPWorkflowAssociation>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => SPWorkflowAssociation.CreateListAssociation(null, "", null, null)).WillReturn(fakeAssociation); FeatureReceiver target = new FeatureReceiver(); target.FeatureActivated(properties); Isolate.Verify.WasCalledWithAnyArguments(() => fakeSPWeb.Lists["Sub Site Creation Requests"].Update()); }
public static bool IsJobRunning(SPFarm farm, Guid jobId) { SPServiceCollection services = farm.Services; return (services.SelectMany(service => service.RunningJobs.Cast <SPRunningJob>()).Any( job => job.JobDefinitionId.Equals(jobId))); }
public static unsafe void RegisterTraceProvider() { SPFarm farm = SPFarm.Local; Guid traceGuid = farm.TraceSessionGuid; uint result = NativeMethods.RegisterTraceGuids(ControlCallback, null, ref traceGuid, 0, IntPtr.Zero, null, null, out hTraceReg); System.Diagnostics.Debug.Assert(result == NativeMethods.ERROR_SUCCESS); }
public static bool ExistProperty(this SPFarm farm, string key) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } return(farm.Properties.ContainsKey(key)); }
public SPFarmPropertyBag() { if (SPFarm.Local == null) { throw new NoSharePointContextException("SPFarm was not found."); } this.farm = SPFarm.Local; }
public bool ContainsKeyInPropertyBag(string key, SPFarm propertyBag) { if (key == Constants.AreasConfigKey && Areas != null) { return(true); } return(false); }
internal SPFarmPropertyBag(SPFarm farm) { if (farm == null) { throw new ArgumentNullException("farm"); } this.farm = farm; }
/// <summary> /// Determines whether the specified timer job is currently running (or /// scheduled to run). /// </summary> /// <param name="farm">The farm to check if the job is running on.</param> /// <param name="jobTitle">The title of the timer job.</param> /// <returns><c>true</c> if the specified timer job is currently running /// (or scheduled to run); otherwise <c>false</c>.</returns> public static bool IsJobRunning(SPFarm farm, string jobTitle) { SPServiceCollection services = farm.Services; return (services.SelectMany(service => service.RunningJobs.Cast <SPRunningJob>()).Any( job => string.Compare(job.JobDefinitionTitle, jobTitle, StringComparison.OrdinalIgnoreCase) == 0)); }
/// <summary> /// Get a <see cref="IPropertyBag"/> for the specified SharePoint object /// </summary> /// <param name="propertyBag">The SharePoint object to get the property bag for</param> /// <returns>The IPropertyBag</returns> protected virtual IPropertyBag GetIPropertyBag(SPFarm propertyBag) { if (propertyBag == null) { throw new ArgumentNullException("propertyBag"); } return(new SPFarmPropertyBag(propertyBag)); }
public ParagoServiceProxy(string name, SPFarm farm) : base(farm) { // NOTE: This constructor is required if this service proxy is installed by the // command psconfig -cmd services -install. Name = name; }
public SPNodeProvider(SPFarm farm, IEnumerable <IRule <ISPNode> > rules, IContainerAdapter container) { ViewLevel = 100; Farm = farm; IoCContainer = container; _ruleEngine = new FirstAcceptRuleEngine <ISPNode>(rules); }
public SPNodeProvider(SPFarm farm, IEnumerable<IRule<ISPNode>> rules, IContainerAdapter container) { ViewLevel = 100; Farm = farm; IoCContainer = container; _ruleEngine = new FirstAcceptRuleEngine<ISPNode>(rules); }
public static bool IsJobDefined(SPFarm farm, string jobName) { SPServiceCollection services = farm.Services; return (services.SelectMany(service => service.JobDefinitions).Any( job => string.Compare(job.Title, jobName, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(job.Name, jobName, StringComparison.InvariantCulture) == 0)); }
public void AddSolution(byte[] WSP, string WSPName, Guid SolutionsGUID) { farm = SPFarm.Local; if (CheckSolution(SolutionsGUID) == false) { UploadWSP(WSP, WSPName); farm.Solutions.Add(uploadPath + WSPName); } }
public SiteSubscriptionCollectionNode(SPFarm farm) : this() { this.Text = SPMLocalization.GetString("SiteSubscriptionCollection_Text"); this.ToolTipText = SPMLocalization.GetString("SiteSubscriptionCollection_ToolTip"); this.Name = "SiteSubscriptionCollection"; this.Tag = farm.SiteSubscriptions; this.SPParent = farm; }
public FarmNode(SPFarm farm) { this.Tag = farm; this.DefaultExpand = true; this.Setup(); this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
public TValue GetFromPropertyBag <TValue>(string key, SPFarm propertyBag) { if (typeof(TValue) == typeof(DiagnosticsAreaCollection)) { LoadedCount++; return((TValue)(object)Areas); } return(default(TValue)); }
public SPInstance(ScriptEngine engine, SPBaristaContext context, SPFarm farmContext, SPServer serverContext) : base(engine) { m_context = new SPContextInstance(Engine, context); m_farm = new SPFarmInstance(Engine.Object.InstancePrototype, farmContext); m_server = new SPServerInstance(Engine.Object.InstancePrototype, serverContext); m_secureStore = new SPSecureStoreInstance(Engine.Object.InstancePrototype); PopulateFunctions(); }
/// <summary> /// Removes the setting store. Warning, all settings will be lost when removed. /// </summary> /// <param name="farm">The farm to clear the settings for</param> public static void DeleteStore(SPFarm farm) { var settingStore = farm.GetChild <FarmSettingStore>(FarmSettingStore.StoreName); if (settingStore != null) { settingStore.Delete(); } }
public HarshServerProvisionerContext(SPFarm farm) { if (farm == null) { throw Logger.Fatal.ArgumentNull("farm"); } Farm = farm; }
private static void DeleteQuotaTemplate(string name) { SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates; quotaColl.Delete(name); }
/// <summary> /// Initializes a new instance of the <see cref="SPWebAppPropertyBag"/> class. /// </summary> /// <param name="farm">The Farm.</param> public SPFarmPropertyBag(SPFarm farm) { if (farm == null) { throw new NoSharePointContextException(Resources.SPFarmNotFound); } this.farm = farm; }
private void DeployManagedAccount(object modelHost, SPFarm farm, ManagedAccountDefinition managedAccountDefinition) { var currentAccount = GetManagedAccount(farm, managedAccountDefinition); var loginName = managedAccountDefinition.LoginName; var accounts = new SPFarmManagedAccountCollection(farm); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentAccount, ObjectType = typeof(SPManagedAccount), ObjectDefinition = managedAccountDefinition, ModelHost = modelHost }); if (currentAccount == null) { TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new managed account"); currentAccount = accounts.FindOrCreateAccount(loginName); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentAccount, ObjectType = typeof(SPManagedAccount), ObjectDefinition = managedAccountDefinition, ModelHost = modelHost }); currentAccount.Update(); } else { TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing managed account"); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentAccount, ObjectType = typeof(SPManagedAccount), ObjectDefinition = managedAccountDefinition, ModelHost = modelHost }); currentAccount.Update(); } }
private SPDiagnosticsServiceBase CreateObject(SPFarm spFarm, DiagnosticsServiceBaseDefinition definition) { var serviceType = Type.GetType(definition.AssemblyQualifiedName); var serviceInstance = Activator.CreateInstance(serviceType) as SPDiagnosticsServiceBase; spFarm.Services.Add(serviceInstance); spFarm.Update(); return GetCurrentObject(spFarm, definition); }
public SolutionCollectionNode(SPFarm farm) { this.CurrentFarm = farm; this.Text = SPMLocalization.GetString("Solutions_Text"); this.ToolTipText = SPMLocalization.GetString("Solutions_ToolTip"); this.Name = "Solutions"; this.Tag = farm.Solutions; this.SPParent = CurrentFarm; this.Nodes.Add("Dummy"); }
protected SPDocumentParser GetCurrentObject(SPFarm farm, DocumentParserDefinition definition) { var currentExtension = definition.FileExtension; var service = SPWebService.ContentService; var parsers = service.PluggableParsers; if (parsers.ContainsKey(currentExtension)) return parsers[currentExtension]; return null; }
protected ISecureStore GetCurrentSecureStoreApplication(SPFarm spFarm, SecureStoreApplicationDefinition definition) { if (definition.UseDefault) { var context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default); var ssp = new SecureStoreServiceProxy(); return ssp.GetSecureStore(context); } else { throw new SPMeta2NotImplementedException("Secure Store resolution by Name/Id is not supported yet. Please use 'UseDefault' property set 'true' instead."); } }
public ServerCollectionNode(SPFarm farm) { this.CurrentFarm = farm; this.Text = SPMLocalization.GetString("Servers_Text"); this.ToolTipText = SPMLocalization.GetString("Servers_ToolTip"); this.Name = "Servers"; this.Tag = farm.Servers; this.SPParent = CurrentFarm; this.ImageIndex = 1; this.SelectedImageIndex = 1; this.Nodes.Add("Dummy"); }
public ServiceProxyCollectionNode(SPFarm farm) { this.Text = SPMLocalization.GetString("ServiceProxies_Text"); this.ToolTipText = SPMLocalization.GetString("ServiceProxies_ToolTip"); this.Name = "ServiceProxies"; this.Tag = farm.ServiceProxies; this.ServiceProxies = farm.ServiceProxies; this.SPParent = farm; int index = Program.Window.Explorer.AddImage(this.ImageUrl()); this.ImageIndex = index; this.SelectedImageIndex = index; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
protected SPManagedAccount GetManagedAccount(SPFarm farm, ManagedAccountDefinition managedAccountDefinition) { var loginName = managedAccountDefinition.LoginName; var accounts = new SPFarmManagedAccountCollection(farm); SPManagedAccount currentAccount = null; try { currentAccount = accounts[loginName]; } catch (Exception) { } return currentAccount; }
private void DeployWebApplication(FarmModelHost farmModelHost, SPFarm farm, WebApplicationDefinition webApplicationDefinition) { var webApps = SPWebService.ContentService.WebApplications; var webAppBuilder = new SPWebApplicationBuilder(farm); webAppBuilder.Port = webApplicationDefinition.Port; webAppBuilder.ApplicationPoolId = webApplicationDefinition.ApplicationPoolId; if (!string.IsNullOrEmpty(webApplicationDefinition.ManagedAccount)) { webAppBuilder.IdentityType = IdentityType.SpecificUser; var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local); var maccount = managedAccounts.FindOrCreateAccount(webApplicationDefinition.ManagedAccount); webAppBuilder.ManagedAccount = maccount; } else { webAppBuilder.ApplicationPoolUsername = webApplicationDefinition.ApplicationPoolUsername; var password = new SecureString(); foreach (char c in webApplicationDefinition.ApplicationPoolPassword.ToCharArray()) password.AppendChar(c); webAppBuilder.ApplicationPoolPassword = password; } webAppBuilder.CreateNewDatabase = webApplicationDefinition.CreateNewDatabase; webAppBuilder.DatabaseName = webApplicationDefinition.DatabaseName; webAppBuilder.DatabaseServer = webApplicationDefinition.DatabaseServer; webAppBuilder.UseNTLMExclusively = webApplicationDefinition.UseNTLMExclusively; webAppBuilder.HostHeader = webApplicationDefinition.HostHeader; webAppBuilder.AllowAnonymousAccess = webApplicationDefinition.AllowAnonymousAccess; webAppBuilder.UseSecureSocketsLayer = webApplicationDefinition.UseSecureSocketsLayer; var webApp = webAppBuilder.Create(); webApp.Provision(); }
private void DeployDefinition(object modelHost, SPFarm farm, DocumentParserDefinition definition) { var service = SPWebService.ContentService; var parsers = service.PluggableParsers; var currentExtension = definition.FileExtension; var currentParser = GetCurrentObject(farm, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = currentParser, ObjectType = typeof(SPDocumentParser), ObjectDefinition = definition, ModelHost = modelHost }); if (currentParser != null) { parsers.Remove(currentExtension); service.Update(); } currentParser = new SPDocumentParser(definition.ProgId, currentExtension); service.PluggableParsers.Add(currentExtension, currentParser); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = currentParser, ObjectType = typeof(SPDocumentParser), ObjectDefinition = definition, ModelHost = modelHost }); service.Update(); }
/// <summary> /// Activates the feature. It imports the model file, resource model file and the assemblies. /// </summary> /// <param name="properties">Feature properties.</param> public override void FeatureActivated(SPFeatureReceiverProperties properties) { if (properties == null) { throw new ArgumentNullException("properties"); } if (properties.Definition == null || properties.Definition.Properties == null) { throw new ArgumentException( "Feature definition is null or feature properties are null."); } if (properties.Definition.Scope != SPFeatureScope.Farm) { throw new ArgumentException( "BDC import model feature receiver expects feature be 'Farm' scoped."); } this.featureName = properties.Definition.DisplayName; parentFarm = properties.Definition.Farm; var featureFolder = GetFeatureFolder(properties.Definition); var modelFilePath = GetModelFilePath(properties.Definition.Properties["ModelFileName"], featureFolder); var resourceFilePaths = GetResourceModelFilesPaths(properties.Definition.Properties["ResourceFiles"], featureFolder); modelDocument.Load(modelFilePath); var lobSystemAssemblies = GetLobSystemAssemblies(properties.Definition.Properties, featureFolder); bool incremental = GetIncrementalUpdate(properties.Definition.Properties["IncrementalUpdate"]); CreateAdministrationMetadataCatalog(properties.Definition.Properties["SiteUrl"]); ImportBdcArtifacts(featureFolder, modelFilePath, resourceFilePaths, lobSystemAssemblies, incremental); }
/// <summary> /// Initializes a new instance of the <see cref="RepoServiceProxy"/> class. Use this constructor to install the service proxy on servers in the farm. /// </summary> /// <param name="farm">The <see cref="Microsoft.SharePoint.Administration.SPFarm" /> to install the Service Proxy to.</param> internal RepoServiceProxy(SPFarm farm) : base(farm) { }
public DiagnosticsService(string name, SPFarm farm) : base(name, farm) { }
public NodeService(SPFarm farm) : base(farm) { }
public static bool IsFeatureActivatedOnFarm(SPFarm farm, Guid featureId) { return isFeatureActivated(SPWebService.AdministrationService.Features, featureId); }
/// <summary> /// <para> /// Creates a new child lifetime scope under the root application container (objects /// registered as InstancePerSite, InstancePerWeb or InstancePerRequest will be /// inaccessible). /// </para> /// <para> /// If more than 1 assembly matches the *.ServiceLocator.DLL pattern in the GAC, /// store your preferred ServiceLocator assembly name (with key: 'ServiceLocatorAssemblyName') /// in the SPFarm property bag to indicate which ServiceLocator should be used in your context. /// If the discriminator setting cannot be found in any of the property bags in the /// hierarchy, an error will be logged to ULS and the FallbackServiceLocator will be used /// (preventing your AddOn registration modules from being loaded). /// </para> /// <para> /// Please dispose this lifetime scope when done (E.G. call this method from /// a using block). /// </para> /// </summary> /// <param name="farm">The current context's farm</param> /// <returns>A new child lifetime scope which should be disposed by the caller.</returns> public ILifetimeScope BeginLifetimeScope(SPFarm farm) { this.EnsureServiceLocatorAccessorForCurrentContext(farm); return this.GetLocatorAccessor(null, null, null, farm).ServiceLocatorInstance.BeginLifetimeScope(farm); }
private static Guid? GetMostSpecificIdentifier(SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm) { // Check the SPWeb if (web != null) { return web.ID; } // Check the SPSite if (site != null) { return site.ID; } // Check the SPWebApplication if (webApplication != null) { return webApplication.Id; } // Check the SPFarm if (farm != null) { return farm.Id; } // All parameters were null. return null; }
/// <summary> /// Inspects the property bags of all SPPersistedObjects in the /// context, from SPWeb to SPSite to SPWebApplication to SPFarm. /// </summary> /// <param name="web">The context's SPWeb. Keep null if none available.</param> /// <param name="site">The context's SPSite. Keep null if none available.</param> /// <param name="webApplication">The context's SPWebApplication. Keep null if none available.</param> /// <param name="farm">The context's SPFarm. Keep null if none available.</param> /// <param name="locationWhereDiscriminatorWasFound">An out parameter string that returns the identity of the SPPersistedObject where the discriminator setting was found</param> /// <returns>The ServiceLocatorAssemblyName discriminator settings, if found in one of the context objects' property bags</returns> private static string FindServiceLocatorAccessorTypeNameFromMostSpecificPropertyBag(SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm, out string locationWhereDiscriminatorWasFound) { if (web != null && web.AllProperties.ContainsKey(KeyServiceLocatorAssemblyName)) { locationWhereDiscriminatorWasFound = "SPWeb @ " + web.Url; return web.GetProperty(KeyServiceLocatorAssemblyName).ToString(); } else if (site != null && site.RootWeb.AllProperties.ContainsKey(KeyServiceLocatorAssemblyName)) { locationWhereDiscriminatorWasFound = "SPSite.RootWeb @ " + site.RootWeb.Url; return site.RootWeb.GetProperty(KeyServiceLocatorAssemblyName).ToString(); } else if (webApplication != null && webApplication.Properties.ContainsKey(KeyServiceLocatorAssemblyName)) { locationWhereDiscriminatorWasFound = "SPWebApplication @ " + webApplication.DisplayName; return (string)webApplication.Properties[KeyServiceLocatorAssemblyName]; } else if (farm != null && farm.Properties.ContainsKey(KeyServiceLocatorAssemblyName)) { locationWhereDiscriminatorWasFound = "SPFarm @ " + farm.DisplayName; return (string)farm.Properties[KeyServiceLocatorAssemblyName]; } else { locationWhereDiscriminatorWasFound = "Not found!!!"; return string.Empty; } }
/// <summary> /// Triggers ServiceLocator bootstrapping (scans the GAC for assemblies with a name /// that matches *.ServiceLocator.DLL, by convention). /// </summary> /// <param name="web">The context's SPWeb. Keep null if none available.</param> /// <param name="site">The context's SPSite. Keep null if none available.</param> /// <param name="webApplication">The context's SPWebApplication. Keep null if none available.</param> /// <param name="farm">The context's SPFarm. Keep null if none available.</param> private void EnsureServiceLocatorAccessor(SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm) { if (this.GetLocatorAccessor(web, site, webApplication, farm) == null) { lock (this.lockObject) { if (this.GetLocatorAccessor(web, site, webApplication, farm) == null) { try { // 1) Scan the GAC for any DLL matching the *.ServiceLocator.DLL pattern var matchingAssemblies = GacAssemblyLocator.GetAssemblies(new List<string>() { "GAC_MSIL" }, assemblyFileName => assemblyFileName.Contains(".ServiceLocator")); Assembly serviceLocatorAssembly = null; Type accessorType = null; if (matchingAssemblies.Any()) { if (matchingAssemblies.Count > 1) { // 2) If more than one service locator is found, we must disambiguate. We have to use the // contextual SPWeb, SPSite, SPWebApp or SPFarm objects and extract the preferred service // locator assembly name setting from their property bag. // The SPWeb's property bag is inspected first, if available, then the SPSite's RootWeb property // bag, then the SPWebApp's, then the SPFarm's property bag as a last resort. string contextObjectWhereDiscriminatorWasFound; string serviceLocatorAssemblyNameDiscriminator = FindServiceLocatorAccessorTypeNameFromMostSpecificPropertyBag(web, site, webApplication, farm, out contextObjectWhereDiscriminatorWasFound); string allServiceLocatorAssemblyNames = string.Join(";", matchingAssemblies.Select(locatorAssembly => locatorAssembly.FullName).ToArray()); string basicDisambiguationErrorMessage = string.Format( CultureInfo.InvariantCulture, "Failed to disambiguate between all DLLs in the GAC that match the *.ServiceLocator.DLL filename pattern. All matching assemblies in GAC: {0}.", allServiceLocatorAssemblyNames); if (!string.IsNullOrEmpty(serviceLocatorAssemblyNameDiscriminator)) { // We found a ServiceLocator assembly name in one of the context's Property Bags. serviceLocatorAssembly = matchingAssemblies.FirstOrDefault(assembly => assembly.FullName.Contains(serviceLocatorAssemblyNameDiscriminator)); if (serviceLocatorAssembly == null) { throw new InvalidOperationException(basicDisambiguationErrorMessage + " The discriminator found in one of the context's Property Bags (value=" + serviceLocatorAssemblyNameDiscriminator + ", property bag location=" + contextObjectWhereDiscriminatorWasFound + ") did not match either of the " + matchingAssemblies.Count + " ServiceLocator DLLs available in GAC. The discriminator value should match one of the DLLs so that we can determine which to use."); } } else { // We failed to find a discriminator setting in all of the context's Property Bags throw new InvalidOperationException(basicDisambiguationErrorMessage + " You cannot begin injection from the root application container if more that one ServiceLocator assembly exists in the GAC." + " You must begin injection with one of the following methods on your ISharePointServiceLocator: BeginLifetimeScope(SPFeature) or" + " BeginLifetimeScope(SPWeb) or BeginLifetimeScope(SPSite) or BeginLifetimeScope(SPWebApplication) or BeginLifetimeScope(SPFarm)," + " depending on your context. IMPORTANT: The property bags on the context' SPWeb, SPSite, SPWebApplication and SPFarm will be inspected" + " (in that order) to find a value for the key '" + KeyServiceLocatorAssemblyName + "'. This discriminator value will indicate to Dynamite's" + " AddOnProvidedServiceLocator which concrete add-on's ServiceLocator DLL to use in the current context."); } } if (serviceLocatorAssembly != null) { // Only one matching assembly, find its accessor class accessorType = FindServiceLocatorAccessorType(serviceLocatorAssembly); } else { // Only one ServiceLocator DLL found in GAC. There is no ambiguity: use this locator. serviceLocatorAssembly = matchingAssemblies[0]; } if (serviceLocatorAssembly != null) { // At this point we figured out the right matching assembly: find its accessor class within its types accessorType = FindServiceLocatorAccessorType(serviceLocatorAssembly); } } else { // Not even one DLL in GAC matches the *.ServiceLocator.DLL pattern throw new InvalidOperationException("Failed to find any assembly in the GAC that matches the *.ServiceLocator.DLL pattern."); } if (accessorType != null) { // 3) Create the accessor instance this.AddLocatorAccessor(web, site, webApplication, farm, (ISharePointServiceLocatorAccessor)Activator.CreateInstance(accessorType)); } else { throw new InvalidOperationException("Failed to find implementation of ISharePointServiceLocatorAccessor for AddOnProvidedServiceLocator. Your ServiceLocator assembly (" + serviceLocatorAssembly.FullName + ") should expose its static container through that interface."); } } catch (InvalidOperationException exception) { var logger = new TraceLogger("GSoft.Dynamite", "GSoft.Dynamite", false); logger.Error( "AddOnProvidedServiceLocator Initialization Error - An error occured while trying to find a DLL matching the pattern *ServiceLocator.dll in the GAC. The FallbackServiceLocator will be used instead as a last resort (no AddOn registration module will be registered). Exception: {0}", exception.ToString()); // Either no assembly in the GAC matches the pattern *.ServiceLocator.DLL pattern, // or in the matching assembly that was found, no class implements ISharePointServiceLocatorAccessor. // In this case, use our default all-available-Dynamite-modules-only service locator this.AddLocatorAccessor(web, site, webApplication, farm, new FallbackServiceLocator()); } } } } }
private void EnsureServiceLocatorAccessorForCurrentContext(SPFarm farm) { this.EnsureServiceLocatorAccessor(null, null, null, farm); }
/// <summary> /// Gets the SharePoint Service Locator Accessor for the context. /// Null is returned if no accessor is found for any context. /// </summary> /// <param name="web">The context's SPWeb. Keep null if none available.</param> /// <param name="site">The context's SPSite. Keep null if none available.</param> /// <param name="webApplication">The context's SPWebApplication. Keep null if none available.</param> /// <param name="farm">The context's SPFarm. Keep null if none available.</param> /// <returns>The SharePoint Service Locator Accessor.</returns> private ISharePointServiceLocatorAccessor GetLocatorAccessor(SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm) { // Get the identifier that represents the most specific context. Guid? mostSpecificIdentifier = GetMostSpecificIdentifier(web, site, webApplication, farm); if (mostSpecificIdentifier.HasValue) { // If we already have an accessor specified for that context, lets use that one. if (this.locatorAccessors.ContainsKey(mostSpecificIdentifier.Value)) { return this.locatorAccessors[mostSpecificIdentifier.Value]; } } // In case no accessor was found. return null; }
/// <summary> /// Initializes a new instance of the <see cref="SPWebAppPropertyBag"/> class. /// </summary> /// <param name="farm">The Farm.</param> public SPFarmPropertyBag(SPFarm farm) { if (farm == null) { throw new NoSharePointContextException(Properties.Resources.SPFarmNotFound); } this.farm = farm; }
public static void DeployFarmModel(this SSOMProvisionService modelHost, SPFarm farm, ModelNode model) { modelHost.DeployModel(FarmModelHost.FromFarm(farm), model); }
/// <summary> /// Adds the locator accessor to the available accessors. /// If all parameters are null or an accessor already exists with that context, an exception is thrown. /// </summary> /// <param name="web">The context's SPWeb. Keep null if none available.</param> /// <param name="site">The context's SPSite. Keep null if none available.</param> /// <param name="webApplication">The context's SPWebApplication. Keep null if none available.</param> /// <param name="farm">The context's SPFarm. Keep null if none available.</param> /// <param name="locatorAccessor">The SharePoint locator accessor we want to add.</param> private void AddLocatorAccessor(SPWeb web, SPSite site, SPWebApplication webApplication, SPFarm farm, ISharePointServiceLocatorAccessor locatorAccessor) { // Get the identifier that represents the most specific context. Guid? mostSpecificIdentifier = GetMostSpecificIdentifier(web, site, webApplication, farm); if (!mostSpecificIdentifier.HasValue) { throw new NotSupportedException("Unable to get the most specific identifier for the context. Make sure at lest one parameter is not null."); } if (this.GetLocatorAccessor(web, site, webApplication, farm) != null) { throw new NotSupportedException("Trying to add a SharePoint Locator Accessor for a context that is already added."); } // Add the accessor to the dictionary. this.locatorAccessors.Add(mostSpecificIdentifier.Value, locatorAccessor); }