本文整理汇总了C#中System.Management.Automation.SessionState类的典型用法代码示例。如果您正苦于以下问题:C# SessionState类的具体用法?C# SessionState怎么用?C# SessionState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SessionState类属于System.Management.Automation命名空间,在下文中一共展示了SessionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsCurrentDriveAD
internal static bool IsCurrentDriveAD(SessionState sessionState)
{
PSDriveInfo current = sessionState.Drive.Current;
ProviderInfo provider = current.Provider;
bool flag = string.Compare(provider.Name, "ActiveDirectory", StringComparison.OrdinalIgnoreCase) == 0;
return flag;
}
示例2: ProcessRecord
//private string _projectCollectionUri;
//[AllowNull]
//[Parameter(ParameterSetName = "ParamByUri")]
//public string ProjectCollectionUri
//{
// get { return _projectCollectionUri; }
// set
// {
// if (Uri.IsWellFormedUriString(value, UriKind.Absolute))
// {
// _projectCollectionUri = value;
// }
// }
//}
protected override void ProcessRecord()
{
PendingChange[] pc;
try
{
//if (_projectCollectionUri != null)
//{
//var uri = new Uri(_projectCollectionUri);
//var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri);
//var vcs = tpc.GetService<VersionControlServer>();
//tpc.ConfigurationServer.Connect(ConnectOptions.IncludeServices);
//tpc.ConfigurationServer.Authenticate();
///builds = buildserver.QueryBuilds(ProjectName);
//}
var x = new SessionState();
var currentDirectory = x.Path.CurrentLocation.Path;
var wk = Core.GetWorkspaceByLocalPath(currentDirectory);
pc = wk.GetPendingChanges();
if (pc == null)
{
throw new Exception("No mapped workspace could be found at this path");
}
WriteObject(pc, true);
}
catch (Exception ex)
{
WriteObject(ex, true);
}
base.ProcessRecord();
}
示例3: GetSessionState
private static InitialSessionState GetSessionState(SessionState sessionState)
{
var initialSessionState = InitialSessionState.CreateDefault2();
CaptureVariables(sessionState, initialSessionState);
CaptureFunctions(sessionState, initialSessionState);
return initialSessionState;
}
示例4: GetCurrentPartitionPath
internal static string GetCurrentPartitionPath(SessionState sessionState)
{
ADRootDSE rootDSE;
string str = null;
ADDriveInfo current = sessionState.Drive.Current as ADDriveInfo;
if (current != null)
{
using (ADObjectSearcher aDObjectSearcher = new ADObjectSearcher(current.SessionInfo))
{
rootDSE = aDObjectSearcher.GetRootDSE();
rootDSE.SessionInfo = current.SessionInfo;
}
string currentDriveLocation = ProviderUtils.GetCurrentDriveLocation(sessionState, current.SessionInfo);
if (currentDriveLocation != string.Empty)
{
try
{
str = ADForestPartitionInfo.ExtractAndValidatePartitionInfo(rootDSE, currentDriveLocation);
}
catch (ArgumentException argumentException1)
{
ArgumentException argumentException = argumentException1;
object[] objArray = new object[1];
objArray[0] = currentDriveLocation;
throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ProviderUtilInvalidDrivePath, objArray), argumentException);
}
}
else
{
return string.Empty;
}
}
return str;
}
示例5: ProcessRecord
protected override void ProcessRecord()
{
IBuildDefinition[] builddefinitions;
try
{
if (_projectCollectionUri != null)
{
var uri = new Uri(_projectCollectionUri);
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri);
var buildserver = tpc.GetService<IBuildServer>();
builddefinitions = buildserver.QueryBuildDefinitions(ProjectName);
}
else
{
var x = new SessionState();
var currentDirectory = x.Path.CurrentLocation.Path;
builddefinitions = Core.GetBuildDefinitionsByLocalPath(currentDirectory);
if (builddefinitions == null)
{
throw new Exception("No mapped workspace could be found at this path");
}
}
WriteObject(builddefinitions, true);
}
catch (Exception ex)
{
WriteObject(ex, true);
}
base.ProcessRecord();
}
示例6: ProviderInfo
internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description, string home, string helpFile, PSSnapInInfo psSnapIn)
{
this.helpFile = "";
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
}
if (implementingType == null)
{
throw PSTraceSource.NewArgumentNullException("implementingType");
}
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
}
if (string.IsNullOrEmpty(name))
{
throw PSTraceSource.NewArgumentException("name");
}
this.sessionState = sessionState;
this.name = name;
this.description = description;
this.home = home;
this.implementingType = implementingType;
this.helpFile = helpFile;
this.pssnapin = psSnapIn;
this.hiddenDrive = new PSDriveInfo(this.FullName, this, "", "", null);
this.hiddenDrive.Hidden = true;
}
示例7: ProviderRuntime
internal ProviderRuntime(SessionState sessionState, bool force, bool avoidWildcardExpansion)
: this()
{
SessionState = sessionState;
AvoidGlobbing = avoidWildcardExpansion;
Force = force;
}
示例8: PathInfo
internal PathInfo(PSDriveInfo drive, ProviderInfo provider, Path path, SessionState sessionState)
{
Drive = drive;
Provider = provider;
_path = path;
_sessionState = sessionState;
}
示例9: AddToSshSessionCollection
public static SshSession AddToSshSessionCollection(SshClient sshclient, SessionState pssession)
{
//Set initial variables
var obj = new SshSession();
var sshSessions = new List<SshSession>();
var index = 0;
// Retrieve existing sessions from the global variable.
var sessionvar = pssession.PSVariable.GetValue("Global:SshSessions") as List<SshSession>;
// If sessions exist we set the proper index number for them.
if (sessionvar != null && sessionvar.Count > 0)
{
sshSessions.AddRange(sessionvar);
// Get the SessionId of the last item and count + 1
SshSession lastSession = sshSessions[sshSessions.Count - 1];
index = lastSession.SessionId + 1;
}
// Create the object that will be saved
obj.SessionId = index;
obj.Host = sshclient.ConnectionInfo.Host;
obj.Session = sshclient;
sshSessions.Add(obj);
// Set the Global Variable for the sessions.
pssession.PSVariable.Set((new PSVariable("Global:SshSessions", sshSessions, ScopedItemOptions.AllScope)));
return obj;
}
示例10: AddToSftpSessionCollection
public static SftpSession AddToSftpSessionCollection(SftpClient sftpclient, SessionState pssession)
{
//Set initial variables
var obj = new SftpSession();
var sftpSessions = new List<SftpSession>();
var index = 0;
// Retrive existing sessions from the globla variable.
var sessionvar = pssession.PSVariable.GetValue("Global:SFTPSessions") as List<SftpSession>;
// If sessions exist we set the proper index number for them.
if (sessionvar != null)
{
sftpSessions.AddRange(sessionvar);
index = sftpSessions.Count;
}
// Create the object that will be saved
obj.SessionId = index;
obj.Host = sftpclient.ConnectionInfo.Host;
obj.Session = sftpclient;
sftpSessions.Add(obj);
// Set the Global Variable for the sessions.
pssession.PSVariable.Set((new PSVariable("Global:SFTPSessions", sftpSessions, ScopedItemOptions.AllScope)));
return obj;
}
示例11: CreatePsPath
public static Stream CreatePsPath(SessionState session, string filePath)
{
string parentPath = session.Path.ParseParent(filePath, null);
string childName = session.Path.ParseChildName(filePath);
var parentItems = session.InvokeProvider.Item.Get(parentPath);
if (parentItems.Count > 1)
{
throw new IOException(string.Format(CultureInfo.InvariantCulture, "PowerShell path {0} is ambiguous", parentPath));
}
else if (parentItems.Count < 1)
{
throw new DirectoryNotFoundException("No such directory");
}
DirectoryInfo parentAsDir = parentItems[0].BaseObject as DirectoryInfo;
if (parentAsDir != null)
{
return File.Create(Path.Combine(parentAsDir.FullName, childName));
}
DiscDirectoryInfo parentAsDiscDir = parentItems[0].BaseObject as DiscDirectoryInfo;
if (parentAsDiscDir != null)
{
return parentAsDiscDir.FileSystem.OpenFile(Path.Combine(parentAsDiscDir.FullName, childName), FileMode.Create, FileAccess.ReadWrite);
}
throw new FileNotFoundException("Path is not a directory", parentPath);
}
示例12: GetPsObject
internal static PSObject GetPsObject(SessionState provider, Notification notification)
{
var psobj = PSObject.AsPSObject(notification);
psobj.Properties.Add(new PSNoteProperty("Type", notification.GetType().Name));
return psobj;
}
示例13: ExecutionContext
public ExecutionContext(PSHost host, RunspaceConfiguration config)
: this()
{
RunspaceConfiguration = config;
LocalHost = host;
SessionStateGlobal = new SessionStateGlobal(this);
SessionState = new SessionState(SessionStateGlobal);
}
示例14: SessionState
internal SessionState(SessionState sessionState)
{
SessionStateGlobal = sessionState.SessionStateGlobal;
Drive = sessionState.Drive;
Path = sessionState.Path;
Provider = sessionState.Provider;
PSVariable = sessionState.PSVariable;
}
示例15: LocationGlobber
internal LocationGlobber(SessionState sessionState)
{
if (sessionState == null)
{
throw PSTraceSource.NewArgumentNullException("sessionState");
}
this.sessionState = sessionState;
}