public virtual string GetResourceString(string baseName, string resourceId) { using (PSTransactionManager.GetEngineProtectionScope()) { if (string.IsNullOrEmpty(baseName)) { throw PSTraceSource.NewArgumentException("baseName"); } if (string.IsNullOrEmpty(resourceId)) { throw PSTraceSource.NewArgumentException("resourceId"); } ResourceManager resourceManager = ResourceManagerCache.GetResourceManager(base.GetType().Assembly, baseName); string str = null; try { str = resourceManager.GetString(resourceId, Thread.CurrentThread.CurrentUICulture); } catch (MissingManifestResourceException) { throw PSTraceSource.NewArgumentException("baseName", "GetErrorText", "ResourceBaseNameFailure", new object[] { baseName }); } if (str == null) { throw PSTraceSource.NewArgumentException("resourceId", "GetErrorText", "ResourceIdFailure", new object[] { resourceId }); } return(str); } }
private bool SetPolicyFromAuthenticodePrompt( string path, PSHost host, ref Exception reason, System.Management.Automation.Signature signature) { bool flag = false; switch (this.AuthenticodePrompt(path, signature, host)) { case PSAuthorizationManager.RunPromptDecision.NeverRun: this.UntrustPublisher(signature); string message1 = ResourceManagerCache.FormatResourceString("Authenticode", "Reason_NeverRun", (object)path); reason = (Exception) new UnauthorizedAccessException(message1); flag = false; break; case PSAuthorizationManager.RunPromptDecision.DoNotRun: flag = false; string message2 = ResourceManagerCache.FormatResourceString("Authenticode", "Reason_DoNotRun", (object)path); reason = (Exception) new UnauthorizedAccessException(message2); break; case PSAuthorizationManager.RunPromptDecision.RunOnce: flag = true; break; case PSAuthorizationManager.RunPromptDecision.AlwaysRun: this.TrustPublisher(signature); flag = true; break; } return(flag); }
private PSAuthorizationManager.RunPromptDecision RemoteFilePrompt( string path, PSHost host) { if (host == null || host.UI == null) { return(PSAuthorizationManager.RunPromptDecision.DoNotRun); } Collection <ChoiceDescription> filePromptChoices = this.GetRemoteFilePromptChoices(); string resourceString = ResourceManagerCache.GetResourceString("Authenticode", "RemoteFilePromptCaption"); string message = ResourceManagerCache.FormatResourceString("Authenticode", "RemoteFilePromptText", (object)path); switch (host.UI.PromptForChoice(resourceString, message, filePromptChoices, 0)) { case 0: return(PSAuthorizationManager.RunPromptDecision.DoNotRun); case 1: return(PSAuthorizationManager.RunPromptDecision.RunOnce); case 2: return(PSAuthorizationManager.RunPromptDecision.Suspend); default: return(PSAuthorizationManager.RunPromptDecision.DoNotRun); } }
internal ChoiceDescription( string resStringBaseName, string labelResourceId, string helpResourceId) : this(ResourceManagerCache.GetResourceString(resStringBaseName, labelResourceId), ResourceManagerCache.GetResourceString(resStringBaseName, helpResourceId)) { }
protected override void SetItem(string name, object value) { using (SessionStateProviderBase.tracer.TraceMethod(name, new object[0])) { if (string.IsNullOrEmpty(name)) { this.WriteError(new ErrorRecord((Exception)SessionStateProviderBase.tracer.NewArgumentNullException(nameof(name)), "SetItemNullName", ErrorCategory.InvalidArgument, (object)name)); } else { try { string resourceString = ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "SetItemAction"); if (!this.ShouldProcess(string.Format((IFormatProvider)this.Host.CurrentCulture, ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "SetItemResourceTemplate"), (object)name, value), resourceString)) { return; } this.SetSessionStateItem(name, value, true); } catch (SessionStateException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } catch (PSArgumentException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } } } }
private static string GetAndCheckFullFileName( string psSnapinName, Hashtable fullFileNameHash, RunspaceConfiguration runspaceConfiguration, string baseFolder, string baseFileName, Collection <string> independentErrors) { string path = !Path.IsPathRooted(baseFileName) ? Path.Combine(baseFolder, baseFileName) : baseFileName; if (!File.Exists(path)) { string str = ResourceManagerCache.FormatResourceString("TypesXml", "FileNotFound", (object)psSnapinName, (object)path); independentErrors.Add(str); return((string)null); } string str1 = (string)fullFileNameHash[(object)path]; if (str1 != null) { string str2 = ResourceManagerCache.FormatResourceString("TypesXml", "DuplicateFile", (object)psSnapinName, (object)path, (object)str1); independentErrors.Add(str2); return((string)null); } if (!path.EndsWith(".ps1xml", StringComparison.OrdinalIgnoreCase)) { string str2 = ResourceManagerCache.FormatResourceString("TypesXml", "EntryShouldBeMshXml", (object)psSnapinName, (object)path); independentErrors.Add(str2); return((string)null); } fullFileNameHash.Add((object)path, (object)psSnapinName); return(path); }
protected override void NewItem(string path, string type, object newItem) { using (SessionStateProviderBase.tracer.TraceMethod(path, new object[0])) { if (string.IsNullOrEmpty(path)) { this.WriteError(new ErrorRecord((Exception)SessionStateProviderBase.tracer.NewArgumentException(nameof(path)), "NewItemNullPath", ErrorCategory.InvalidArgument, (object)path)); } else if (newItem == null) { this.WriteError(new ErrorRecord((Exception)SessionStateProviderBase.tracer.NewArgumentNullException("value"), "NewItemValueNotSpecified", ErrorCategory.InvalidArgument, (object)path)); } else if (this.ItemExists(path) && !(bool)this.Force) { PSArgumentException argumentException = SessionStateProviderBase.tracer.NewArgumentException(nameof(path), "SessionStateStrings", "NewItemAlreadyExists", (object)path); this.WriteError(new ErrorRecord(argumentException.ErrorRecord, (Exception)argumentException)); } else { string resourceString = ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "NewItemAction"); if (!this.ShouldProcess(string.Format((IFormatProvider)this.Host.CurrentCulture, ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "NewItemResourceTemplate"), (object)path, (object)type, newItem), resourceString)) { return; } this.SetItem(path, newItem); } } }
protected override void RemoveItem(string path, bool recurse) { using (SessionStateProviderBase.tracer.TraceMethod(path, new object[0])) { if (string.IsNullOrEmpty(path)) { this.WriteError(new ErrorRecord((Exception)SessionStateProviderBase.tracer.NewArgumentException(nameof(path)), "RemoveItemNullPath", ErrorCategory.InvalidArgument, (object)path)); } else { string resourceString = ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "RemoveItemAction"); if (!this.ShouldProcess(string.Format((IFormatProvider)this.Host.CurrentCulture, ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "RemoveItemResourceTemplate"), (object)path), resourceString)) { return; } try { this.RemoveSessionStateItem(path); } catch (SessionStateException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } catch (SecurityException ex) { this.WriteError(new ErrorRecord((Exception)ex, "RemoveItemSecurityException", ErrorCategory.PermissionDenied, (object)path)); } catch (PSArgumentException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } } } }
public virtual string GetResourceString(string baseName, string resourceId) { using (PSTransactionManager.GetEngineProtectionScope()) { if (string.IsNullOrEmpty(baseName)) { throw CmdletProvider.providerBaseTracer.NewArgumentException(nameof(baseName)); } if (string.IsNullOrEmpty(resourceId)) { throw CmdletProvider.providerBaseTracer.NewArgumentException(nameof(resourceId)); } ResourceManager resourceManager = ResourceManagerCache.GetResourceManager(this.GetType().Assembly, baseName); string str; try { str = resourceManager.GetString(resourceId, Thread.CurrentThread.CurrentUICulture); } catch (MissingManifestResourceException ex) { throw CmdletProvider.providerBaseTracer.NewArgumentException(nameof(baseName), "GetErrorText", "ResourceBaseNameFailure", (object)baseName); } return(str != null ? str : throw CmdletProvider.providerBaseTracer.NewArgumentException(nameof(resourceId), "GetErrorText", "ResourceIdFailure", (object)resourceId)); } }
internal static void ThrowIfNotAdministrator() { if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { throw new InvalidOperationException(ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", "EDcsRequiresElevation")); } }
private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus) { result = LoadingResult.AssemblyNotFound; bindingStatus = AssemblyBindingStatus.NotFound; AssemblyLoadResult result2 = null; if (this._resourceReferenceToAssemblyCache.Contains(resourceReference)) { result2 = this._resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult; bindingStatus = result2.status; } else { bool flag; result2 = new AssemblyLoadResult { a = this.LoadAssemblyFromResourceReference(resourceReference, out flag) }; if (result2.a == null) { result2.status = AssemblyBindingStatus.NotFound; } else { result2.status = flag ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath; } this._resourceReferenceToAssemblyCache.Add(resourceReference, result2); } bindingStatus = result2.status; if (result2.a == null) { result = LoadingResult.AssemblyNotFound; return(null); } try { string str = ResourceManagerCache.GetResourceString(result2.a, resourceReference.baseName, resourceReference.resourceId); if (str == null) { result = LoadingResult.StringNotFound; return(null); } result = LoadingResult.NoError; return(str); } catch (InvalidOperationException) { result = LoadingResult.ResourceNotFound; } catch (MissingManifestResourceException) { result = LoadingResult.ResourceNotFound; } catch (Exception) { throw; } return(null); }
internal RunspaceOpenModuleLoadException( string moduleName, PSDataCollection <ErrorRecord> errors) : base(ResourceManagerCache.FormatResourceString("runspace", "ErrorLoadingModulesOnRunspaceOpen", (object)moduleName, errors == null || errors.Count <= 0 || errors[0] == null ? (object) string.Empty : (object)errors[0].ToString()), (Exception)null) { this._errors = errors; this.SetErrorId("ErrorLoadingModulesOnRunspaceOpen"); this.SetErrorCategory(ErrorCategory.OpenError); }
protected override Collection <PSDriveInfo> InitializeDefaultDrives() { string resourceString = ResourceManagerCache.GetResourceString("SessionStateStrings", "FunctionDriveDescription"); return(new Collection <PSDriveInfo>() { new PSDriveInfo("Function", this.ProviderInfo, string.Empty, resourceString, (PSCredential)null) }); }
private Collection <PSSnapInInfo> Load( string path, out PSConsoleLoadException cle) { using (MshConsoleInfo.tracer.TraceMethod()) { cle = (PSConsoleLoadException)null; MshConsoleInfo._mshsnapinTracer.WriteLine("Load mshsnapins from console file {0}", (object)path); if (string.IsNullOrEmpty(path)) { throw MshConsoleInfo.tracer.NewArgumentNullException(nameof(path)); } if (!Path.IsPathRooted(path)) { MshConsoleInfo._mshsnapinTracer.TraceError("Console file {0} needs to be a absolute path.", (object)path); throw MshConsoleInfo.tracer.NewArgumentException(nameof(path), "ConsoleInfoErrorStrings", "PathNotAbsolute", (object)path); } if (!path.EndsWith(".psc1", StringComparison.OrdinalIgnoreCase)) { MshConsoleInfo._mshsnapinTracer.TraceError("Console file {0} needs to have {1} extension.", (object)path, (object)".psc1"); throw MshConsoleInfo.tracer.NewArgumentException(nameof(path), "ConsoleInfoErrorStrings", "BadConsoleExtension", (object)""); } PSConsoleFileElement fromFile = PSConsoleFileElement.CreateFromFile(path); if (!Utils.IsVersionSupported(fromFile.MonadVersion)) { MshConsoleInfo._mshsnapinTracer.TraceError("Console version {0} is not supported in current monad session.", (object)fromFile.MonadVersion); throw MshConsoleInfo.tracer.NewArgumentException("PSVersion", "ConsoleInfoErrorStrings", "BadMonadVersion", (object)fromFile.MonadVersion, (object)this.psVersion.ToString()); } Collection <PSSnapInException> exceptions = new Collection <PSSnapInException>(); foreach (string psSnapIn in fromFile.PSSnapIns) { try { this.AddPSSnapIn(psSnapIn); } catch (PSArgumentException ex) { PSSnapInException psSnapInException = new PSSnapInException(psSnapIn, ex.Message, (Exception)ex); MshConsoleInfo._mshsnapinTracer.TraceException((Exception)psSnapInException); exceptions.Add(psSnapInException); } catch (SecurityException ex) { string message = ResourceManagerCache.FormatResourceString("ConsoleInfoErrorStrings", "PSSnapInReadError"); PSSnapInException psSnapInException = new PSSnapInException(psSnapIn, message, (Exception)ex); MshConsoleInfo._mshsnapinTracer.TraceException((Exception)psSnapInException); exceptions.Add(psSnapInException); } } if (exceptions.Count > 0) { cle = new PSConsoleLoadException(this, exceptions); } this.isDirty = false; return(this.externalPSSnapIns); } }
private string ModifyCaption(string caption) { string resourceString = ResourceManagerCache.GetResourceString("CredUI", "PromptForCredential_DefaultCaption"); if (caption.Equals(resourceString, StringComparison.OrdinalIgnoreCase)) { return(caption); } return(PSRemotingErrorInvariants.FormatResourceString(PSRemotingErrorId.RemoteHostPromptForCredentialModifiedCaption, (object)caption)); }
internal static string GetMessage(int errorCode) { StringBuilder lpBuffer = new StringBuilder(512); if (Win32Native.FormatMessage(12800, Win32Native.NULL, errorCode, 0, lpBuffer, lpBuffer.Capacity, Win32Native.NULL) != 0) { return(lpBuffer.ToString()); } return(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ResourceManagerCache.GetResourceString("RegistryProviderStrings", "UnknownError_Num"), (object)errorCode.ToString((IFormatProvider)CultureInfo.InvariantCulture))); }
internal void AddError( string typeName, int errorLineNumber, string resourceId, params object[] formatArguments) { string str = ResourceManagerCache.FormatResourceString("TypesXml", resourceId, formatArguments); this.errors.Add(ResourceManagerCache.FormatResourceString("TypesXml", "FileLineTypeError", (object)this.PSSnapinName, (object)this.fileName, (object)errorLineNumber, (object)typeName, (object)str)); }
protected override Collection <PSDriveInfo> InitializeDefaultDrives() { using (EnvironmentProvider.tracer.TraceMethod()) { string resourceString = ResourceManagerCache.GetResourceString("SessionStateStrings", "EnvironmentDriveDescription"); return(new Collection <PSDriveInfo>() { new PSDriveInfo("Env", this.ProviderInfo, string.Empty, resourceString, (PSCredential)null) }); } }
protected override void CopyItem(string path, string copyPath, bool recurse) { using (SessionStateProviderBase.tracer.TraceMethod(path, new object[0])) { if (string.IsNullOrEmpty(path)) { this.WriteError(new ErrorRecord((Exception)SessionStateProviderBase.tracer.NewArgumentException(nameof(path)), "CopyItemNullPath", ErrorCategory.InvalidArgument, (object)path)); } else if (string.IsNullOrEmpty(copyPath)) { this.GetItem(path); } else { object sessionStateItem; try { sessionStateItem = this.GetSessionStateItem(path); } catch (SecurityException ex) { this.WriteError(new ErrorRecord((Exception)ex, "CopyItemSecurityException", ErrorCategory.ReadError, (object)path)); return; } if (sessionStateItem != null) { string resourceString = ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "CopyItemAction"); if (!this.ShouldProcess(string.Format((IFormatProvider)this.Host.CurrentCulture, ResourceManagerCache.GetResourceString("SessionStateProviderBaseStrings", "CopyItemResourceTemplate"), (object)path, (object)copyPath), resourceString)) { return; } try { this.SetSessionStateItem(copyPath, this.GetValueOfItem(sessionStateItem), true); } catch (SessionStateException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } catch (PSArgumentException ex) { this.WriteError(new ErrorRecord(ex.ErrorRecord, (Exception)ex)); } } else { PSArgumentException argumentException = SessionStateProviderBase.tracer.NewArgumentException(nameof(path), "SessionStateStrings", "CopyItemDoesntExist", (object)path); this.WriteError(new ErrorRecord(argumentException.ErrorRecord, (Exception)argumentException)); } } } }
private string PromptUserForFile() { if (!this.ShouldContinue(ResourceManagerCache.FormatResourceString("ConsoleInfoErrorStrings", "PromptForExportConsole"), (string)null)) { return(string.Empty); } Dictionary <string, PSObject> dictionary = this.PSHostInternal.UI.Prompt(ResourceManagerCache.FormatResourceString("ConsoleInfoErrorStrings", "FileNameCaptionForExportConsole", (object)"export-console"), ResourceManagerCache.FormatResourceString("ConsoleInfoErrorStrings", "FileNamePromptMessage"), new Collection <FieldDescription>() { new FieldDescription("Name") }); return(dictionary != null && dictionary["Name"] != null ? dictionary["Name"].BaseObject as string : string.Empty); }
private Collection <ChoiceDescription> GetRemoteFilePromptChoices() { Collection <ChoiceDescription> collection = new Collection <ChoiceDescription>(); string resourceString1 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_DoNotRun"); string resourceString2 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_DoNotRun_Help"); string resourceString3 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_RunOnce"); string resourceString4 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_RunOnce_Help"); string resourceString5 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_Suspend"); string resourceString6 = ResourceManagerCache.GetResourceString("Authenticode", "Choice_Suspend_Help"); collection.Add(new ChoiceDescription(resourceString1, resourceString2)); collection.Add(new ChoiceDescription(resourceString3, resourceString4)); collection.Add(new ChoiceDescription(resourceString5, resourceString6)); return(collection); }
private void ClearHistoryByID() { using (ClearHistoryCommand._trace.TraceMethod()) { if (this._countParamterSpecified && this.Count < 0) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "InvalidCountValue")), "ClearHistoryInvalidCountValue", ErrorCategory.InvalidArgument, (object)this._count)); } if (this._id != null) { if (!this._countParamterSpecified) { foreach (long id in this._id) { HistoryInfo entry = this.history.GetEntry(id); if (entry != null && entry.Id == id) { this.history.ClearEntry(entry.Id); } else { this.WriteError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoHistoryForId", (object)id)), "GetHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, (object)id)); } } } else if (this._id.Length > 1) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoCountWithMultipleIds")), "GetHistoryNoCountWithMultipleIds", ErrorCategory.InvalidArgument, (object)this._count)); } else { this.ClearHistoryEntries((long)this._id[0], this._count, (string)null, this._newest); } } else if (!this._countParamterSpecified) { if (!this.ShouldProcess(ResourceManagerCache.FormatResourceString("History", "ClearHistoryWarning", (object)"Warning"))) { return; } this.ClearHistoryEntries(0L, -1, (string)null, this._newest); } else { this.ClearHistoryEntries(0L, this._count, (string)null, this._newest); } } }
internal History(System.Management.Automation.ExecutionContext context) { using (History._trace.TraceConstructor((object)this)) { this._context = context; context.EngineSessionState.SetVariable(new PSVariable("MaximumHistoryCount", (object)64, ScopedItemOptions.None, new Collection <Attribute>() { (Attribute) new ValidateRangeAttribute((object)1, (object)(int)short.MaxValue) }) { Description = ResourceManagerCache.GetResourceString("SessionStateStrings", "MaxHistoryCountDescription") }, false, CommandOrigin.Internal); this._capacity = 64; this._buffer = new HistoryInfo[this._capacity]; } }
public ModuleSpecification(Hashtable moduleSpecification) { if (moduleSpecification == null) { throw new ArgumentNullException(nameof(moduleSpecification)); } StringBuilder stringBuilder = new StringBuilder(); foreach (DictionaryEntry dictionaryEntry in moduleSpecification) { if (dictionaryEntry.Key.ToString().Equals("ModuleName", StringComparison.OrdinalIgnoreCase)) { this.name = (string)LanguagePrimitives.ConvertTo(dictionaryEntry.Value, typeof(string), (IFormatProvider)CultureInfo.InvariantCulture); } else if (dictionaryEntry.Key.ToString().Equals("ModuleVersion", StringComparison.OrdinalIgnoreCase)) { this.version = (Version)LanguagePrimitives.ConvertTo(dictionaryEntry.Value, typeof(Version), (IFormatProvider)CultureInfo.InvariantCulture); } else if (dictionaryEntry.Key.ToString().Equals("GUID", StringComparison.OrdinalIgnoreCase)) { this.guid = (System.Guid?)LanguagePrimitives.ConvertTo(dictionaryEntry.Value, typeof(System.Guid?), (IFormatProvider)CultureInfo.InvariantCulture); } else { if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append("'"); stringBuilder.Append(dictionaryEntry.Key.ToString()); stringBuilder.Append("'"); } } if (stringBuilder.Length != 0) { throw new ArgumentException(ResourceManagerCache.FormatResourceString("Modules", "InvalidModuleSpecificationMember", (object)"ModuleName, ModuleVersion, GUID", (object)stringBuilder)); } if (string.IsNullOrEmpty(this.name)) { throw new MissingMemberException(ResourceManagerCache.FormatResourceString("Modules", "RequiredModuleMissingModuleName")); } if (this.version == (Version)null) { throw new MissingMemberException(ResourceManagerCache.FormatResourceString("Modules", "RequiredModuleMissingModuleVersion")); } }
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) { using (CredentialAttribute.credTracer.TraceMethod()) { PSCredential psCredential = (PSCredential)null; string userName = (string)null; bool flag = false; if (engineIntrinsics == null || engineIntrinsics.Host == null || engineIntrinsics.Host.UI == null) { throw CredentialAttribute.credTracer.NewArgumentNullException(nameof(engineIntrinsics)); } if (inputData == null) { flag = true; } else { psCredential = LanguagePrimitives.FromObjectAs <PSCredential>(inputData); if (psCredential == null) { flag = true; userName = LanguagePrimitives.FromObjectAs <string>(inputData); if (userName == null) { throw new PSArgumentException("userName"); } } } if (flag) { try { string resourceString1 = ResourceManagerCache.GetResourceString(nameof(CredentialAttribute), "CredentialAttribute_Prompt_Caption"); string resourceString2 = ResourceManagerCache.GetResourceString(nameof(CredentialAttribute), "CredentialAttribute_Prompt"); psCredential = engineIntrinsics.Host.UI.PromptForCredential(resourceString1, resourceString2, userName, ""); } catch (ArgumentTransformationMetadataException ex) { CredentialAttribute.credTracer.TraceException((Exception)ex); throw; } } return((object)psCredential); } }
private bool DebugShouldContinue(string message, ref ActionPreference actionPreference) { using (InternalHostUserInterface.tracer.TraceMethod(message, new object[0])) { InternalHostUserInterface.tracer.WriteLine((object)actionPreference); bool flag1 = false; Collection <ChoiceDescription> choices = new Collection <ChoiceDescription>(); choices.Add(new ChoiceDescription("InternalHostUserInterfaceStrings", "ShouldContinueYesLabel", "ShouldContinueYesHelp")); choices.Add(new ChoiceDescription("InternalHostUserInterfaceStrings", "ShouldContinueYesToAllLabel", "ShouldContinueYesToAllHelp")); choices.Add(new ChoiceDescription("InternalHostUserInterfaceStrings", "ShouldContinueNoLabel", "ShouldContinueNoHelp")); choices.Add(new ChoiceDescription("InternalHostUserInterfaceStrings", "ShouldContinueNoToAllLabel", "ShouldContinueNoToAllHelp")); choices.Add(new ChoiceDescription("InternalHostUserInterfaceStrings", "ShouldContinueSuspendLabel", "ShouldContinueSuspendHelp")); bool flag2; do { flag2 = true; switch (this.PromptForChoice(ResourceManagerCache.GetResourceString("InternalHostUserInterfaceStrings", "ShouldContinuePromptMessage"), message, choices, 0)) { case 0: flag1 = true; break; case 1: actionPreference = ActionPreference.Continue; flag1 = true; break; case 2: flag1 = false; break; case 3: actionPreference = ActionPreference.Stop; flag1 = false; break; case 4: this.parent.EnterNestedPrompt(); flag2 = false; break; } }while (!flag2); return(flag1); } }
private PSAuthorizationManager.RunPromptDecision AuthenticodePrompt( string path, System.Management.Automation.Signature signature, PSHost host) { if (host == null || host.UI == null) { return(PSAuthorizationManager.RunPromptDecision.DoNotRun); } PSAuthorizationManager.RunPromptDecision runPromptDecision1 = PSAuthorizationManager.RunPromptDecision.DoNotRun; if (signature == null) { return(runPromptDecision1); } PSAuthorizationManager.RunPromptDecision runPromptDecision2; switch (signature.Status) { case SignatureStatus.Valid: Collection <ChoiceDescription> authenticodePromptChoices = this.GetAuthenticodePromptChoices(); string resourceString = ResourceManagerCache.GetResourceString("Authenticode", "AuthenticodePromptCaption"); string message; if (signature.SignerCertificate == null) { message = ResourceManagerCache.FormatResourceString("Authenticode", "AuthenticodePromptText_UnknownPublisher", (object)path); } else { message = ResourceManagerCache.FormatResourceString("Authenticode", "AuthenticodePromptText", (object)path, (object)signature.SignerCertificate.SubjectName.Name); } runPromptDecision2 = (PSAuthorizationManager.RunPromptDecision)host.UI.PromptForChoice(resourceString, message, authenticodePromptChoices, 1); break; case SignatureStatus.UnknownError: case SignatureStatus.NotSigned: case SignatureStatus.HashMismatch: case SignatureStatus.NotSupportedFileFormat: runPromptDecision2 = PSAuthorizationManager.RunPromptDecision.DoNotRun; break; default: runPromptDecision2 = PSAuthorizationManager.RunPromptDecision.DoNotRun; break; } return(runPromptDecision2); }
internal virtual int GetAvailableRunspaces() { using (RunspacePoolInternal.tracer.TraceMethod()) { lock (this.syncObject) { if (this.stateInfo.State == RunspacePoolState.Opened) { return(this.pool.Count + (this.maxPoolSz - this.totalRunspaces)); } if (this.stateInfo.State != RunspacePoolState.BeforeOpen && this.stateInfo.State != RunspacePoolState.Opening) { throw new InvalidOperationException(ResourceManagerCache.GetResourceString("HostInterfaceExceptionsStrings", "RunspacePoolNotOpened")); } return(this.maxPoolSz); } } }
internal static void ThrowExceptionOnError( string errorId, Collection <string> independentErrors, Collection <PSSnapInTypeAndFormatErrors> PSSnapinFilesCollection, RunspaceConfigurationCategory category) { Collection <string> collection = new Collection <string>(); foreach (string independentError in independentErrors) { collection.Add(independentError); } foreach (PSSnapInTypeAndFormatErrors psSnapinFiles in PSSnapinFilesCollection) { foreach (string error in psSnapinFiles.Errors) { collection.Add(error); } } if (collection.Count != 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append('\n'); foreach (string str in collection) { stringBuilder.Append(str); stringBuilder.Append('\n'); } string message = ""; switch (category) { case RunspaceConfigurationCategory.Types: message = ResourceManagerCache.FormatResourceString("ExtendedTypeSystem", "TypesXmlError", (object)stringBuilder.ToString()); break; case RunspaceConfigurationCategory.Formats: message = XmlLoadingResourceManager.FormatString("FormatLoadingErrors", (object)stringBuilder.ToString()); break; } RuntimeException runtimeException = new RuntimeException(message); runtimeException.SetErrorId(errorId); throw runtimeException; } }
private PipelineProcessor CreatePipelineProcessor() { CommandCollection commands = this.Commands; if (commands == null || commands.Count == 0) { throw LocalPipeline._trace.NewInvalidOperationException("Runspace", "NoCommandInPipeline"); } PipelineProcessor pipelineProcessor = new PipelineProcessor(); pipelineProcessor.TopLevel = true; bool flag = false; try { foreach (Command command in (Collection <Command>)commands) { CommandProcessorBase commandProcessor = command.CreateCommandProcessor(this.LocalRunspace.ExecutionContext, this.LocalRunspace.CommandFactory, this.AddToHistory); commandProcessor.RedirectShellErrorOutputPipe = this.RedirectShellErrorOutputPipe; pipelineProcessor.Add(commandProcessor); } return(pipelineProcessor); } catch (RuntimeException ex) { flag = true; throw; } catch (Exception ex) { flag = true; CommandProcessorBase.CheckForSevereException(ex); throw new RuntimeException(ResourceManagerCache.GetResourceString("Pipeline", "CannotCreatePipeline"), ex); } finally { if (flag) { pipelineProcessor.Dispose(); } } }