private static void ExtendWebApplication(SPWebApplication webapp, string name, int port, SPUrlZone zone, bool secure, bool useWindowsAuth, bool allowAnonymous, bool useClaims)
{
if (webapp == null)
{
throw (new ArgumentNullException("webapp"));
}
SPServerBinding serverBinding = null;
SPSecureBinding secureBinding = null;
if (secure)
{
secureBinding = new SPSecureBinding();
secureBinding.Port = port;
}
else
{
serverBinding = new SPServerBinding();
serverBinding.Port = port;
}
string extendedAppPath = webapp.IisSettings[SPUrlZone.Default].Path.ToString().Substring(0, webapp.IisSettings[SPUrlZone.Default].Path.ToString().LastIndexOf(@"\") + 1) + port.ToString();
SPIisSettings iisSettings = new SPIisSettings(
string.Format(CultureInfo.InvariantCulture, "{0} - {1}", name, port),
false,
true,
serverBinding,
secureBinding,
new DirectoryInfo(extendedAppPath));
iisSettings.DisableKerberos = !useWindowsAuth;
iisSettings.UseWindowsIntegratedAuthentication = useWindowsAuth;
iisSettings.AllowAnonymous = allowAnonymous;
webapp.IisSettings.Add(zone, iisSettings);
webapp.AlternateUrls.SetResponseUrl(new SPAlternateUrl(GetAlternateUrl(port, secure), zone));
webapp.AlternateUrls.Update();
webapp.UseClaimsAuthentication = useClaims;
webapp.Update();
webapp.ProvisionGlobally();
}
Friday, June 5, 2009
SharePoint: Code for extending a web app
This doesn't claim to be the code to extend a web app, but more like a boilerplate that you can adapt to your own needs. I tried it with a generous matrix of parameters and works correctly, but I have no doubt that some combinations may cause issues.
Tuesday, June 2, 2009
C#: Running PowerShell from C#
This is a class that allows to execute PowerShell scripts from C#
using System.Management.Automation;
using System.Management.Automation.Runspaces;
/// <summary>
/// PowerShellExecutor
/// </summary>
public class PowerShellExecutor
{
Runspace _runspace = null;
Pipeline _pipeline = null;
/// <summary>
/// .ctor
/// </summary>
public PowerShellExecutor()
{
_runspace = RunspaceFactory.CreateRunspace();
_runspace = RegisterCmdlets(_runspace, _runspace.CreatePipeline());
_pipeline = _runspace.CreatePipeline();
}
public void ClearErrors()
{
_pipeline = _runspace.CreatePipeline("$error.Clear()");
_pipeline.Invoke();
}
/// <summary>
/// ExecuteCmdlet
/// </summary>
/// <param name="command"></param>
/// <param name="rs"></param>
/// <param name="pipe"></param>
/// <returns></returns>
/// <example>
/// PowerShellExecutor p = new PowerShellExecutor();
/// Collection<PSObject> c = p.ExecuteCmdlet("$w = Get-Web 'MySite - 80'", null);
/// c = p.ExecuteCmdlet("[System.Console]::WriteLine($w)", null);
/// </example>
public Collection<PSObject> ExecuteCmdlet(string command)
{
// create pipeline
_pipeline = _runspace.CreatePipeline();
// add script to execute
_pipeline.Commands.AddScript(command);
// execute
Collection<PSObject> results = _pipeline.Invoke();
StringBuilder result = new StringBuilder();
// check results
if (results.Count == 0)
{
result = new StringBuilder();
result.Append("$error");
_pipeline = _runspace.CreatePipeline(result.ToString());
results = _pipeline.Invoke();
}
// return
return results;
}
/// <summary>
/// RegisterCmdlets
/// </summary>
/// <param name="runspace"></param>
/// <param name="pipeline"></param>
/// <returns></returns>
private Runspace RegisterCmdlets(Runspace runspace, Pipeline pipeline)
{
Collection<PSObject> results;
StringBuilder command = new StringBuilder();
runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
command.Append("Set-Alias powershell $env:windir\\System32\\WindowsPowerShell\\v1.0\\powershell.exe");
pipeline = runspace.CreatePipeline(command.ToString());
results = pipeline.Invoke();
command = new StringBuilder();
command.Append("Add-pssnapin Microsoft.SharePoint.PowerShell");
pipeline = runspace.CreatePipeline(command.ToString());
results = pipeline.Invoke();
return runspace;
}
}
Monday, June 1, 2009
Architectural Concerns
Cheat-sheet on things to have in mind when looking at a system from an architectural perspective:
Simplicity
Testability
Usability
Deployment
Ecosystem
Modularity
Diagnosibility
Performance
Manageability
Compatibility
Layering
Reliability
Accessibility
Serviceability
Extensibility
Dependencies
Security
Globalizability
Supportability
Programmability
Maintenance
Simplicity
Testability
Usability
Deployment
Ecosystem
Modularity
Diagnosibility
Performance
Manageability
Compatibility
Layering
Reliability
Accessibility
Serviceability
Extensibility
Dependencies
Security
Globalizability
Supportability
Programmability
Maintenance
Subscribe to:
Posts (Atom)