Exemplo n.º 1
0
 internal ChoiceDescription(
     string resStringBaseName,
     string labelResourceId,
     string helpResourceId)
     : this(ResourceManagerCache.GetResourceString(resStringBaseName, labelResourceId), ResourceManagerCache.GetResourceString(resStringBaseName, helpResourceId))
 {
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 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));
             }
         }
     }
 }
Exemplo n.º 5
0
 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));
             }
         }
     }
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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)
            });
        }
Exemplo n.º 8
0
        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)));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
 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)
         });
     }
 }
Exemplo n.º 11
0
 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));
             }
         }
     }
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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];
     }
 }
Exemplo n.º 14
0
 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);
     }
 }
Exemplo n.º 15
0
        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);
            }
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
 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);
         }
     }
 }
Exemplo n.º 18
0
        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();
                }
            }
        }
Exemplo n.º 19
0
        internal static void RestartWinRMService(
            PSCmdlet cmdlet,
            bool isErrorReported,
            bool force,
            bool noServiceRestart)
        {
            if (isErrorReported || noServiceRestart)
            {
                return;
            }
            string resourceString = ResourceManagerCache.GetResourceString("RemotingErrorIdStrings", "RestartWSManServiceAction");
            string target         = ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", "RestartWSManServiceTarget", (object)"WinRM");

            if (!force && !cmdlet.ShouldProcess(target, resourceString))
            {
                return;
            }
            cmdlet.WriteVerbose(ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", "RestartWSManServiceMessageV"));
            cmdlet.InvokeCommand.NewScriptBlock("restart-service winrm -force -confirm:$false").InvokeUsingCmdlet((Cmdlet)cmdlet, true, true, (object)AutomationNull.Value, (object)new object[0], (object)AutomationNull.Value);
        }
        internal override int GetAvailableRunspaces()
        {
            long callId = 0;

            lock (this.syncObject)
            {
                if (this.stateInfo.State == RunspacePoolState.Opened)
                {
                    callId = this.DispatchTable.CreateNewCallId();
                    this.dataStructureHandler.SendGetAvailableRunspacesToServer(callId);
                }
                else
                {
                    if (this.stateInfo.State != RunspacePoolState.BeforeOpen && this.stateInfo.State != RunspacePoolState.Opening)
                    {
                        throw new InvalidOperationException(ResourceManagerCache.GetResourceString("HostInterfaceExceptionsStrings", "RunspacePoolNotOpened"));
                    }
                    return(this.maxPoolSz);
                }
            }
            return((int)this.dispatchTable.GetResponse(callId, (object)0));
        }
Exemplo n.º 21
0
        private static Exception _HandleErrorCode(
            int errorCode,
            string name,
            SafeHandle handle,
            object context)
        {
            Exception exception = (Exception)null;

            switch (errorCode)
            {
            case 2:
                exception = (Exception) new IOException(ResourceManagerCache.GetResourceString("RegistryProviderStrings", "Arg_RegKeyNotFound"));
                break;

            case 6:
                exception = (Exception) new ArgumentException(ResourceManagerCache.GetResourceString("RegistryProviderStrings", "AccessControl_InvalidHandle"));
                break;

            case 123:
                exception = (Exception) new ArgumentException(ResourceManagerCache.GetResourceString("RegistryProviderStrings", "Arg_RegInvalidKeyName"));
                break;
            }
            return(exception);
        }
Exemplo n.º 22
0
 internal static MshConsoleInfo CreateDefaultConfiguration()
 {
     using (MshConsoleInfo.tracer.TraceMethod())
     {
         MshConsoleInfo mshConsoleInfo = new MshConsoleInfo(PSVersionInfo.PSVersion);
         try
         {
             mshConsoleInfo.defaultPSSnapIns = PSSnapInReader.ReadEnginePSSnapIns();
         }
         catch (PSArgumentException ex)
         {
             string resourceString = ResourceManagerCache.GetResourceString("ConsoleInfoErrorStrings", "CannotLoadDefaults");
             MshConsoleInfo._mshsnapinTracer.TraceError(resourceString);
             throw new PSSnapInException(resourceString, (Exception)ex);
         }
         catch (SecurityException ex)
         {
             string resourceString = ResourceManagerCache.GetResourceString("ConsoleInfoErrorStrings", "CannotLoadDefaults");
             MshConsoleInfo._mshsnapinTracer.TraceError(resourceString);
             throw new PSSnapInException(resourceString, (Exception)ex);
         }
         return(mshConsoleInfo);
     }
 }
Exemplo n.º 23
0
 internal override int Write(object obj, bool enumerateCollection)
 {
     using (ObjectStreamBase._trace.TraceMethod())
     {
         if (obj == AutomationNull.Value)
         {
             return(0);
         }
         if (!this.IsOpen)
         {
             Exception exceptionRecord = (Exception) new PipelineClosedException(ResourceManagerCache.GetResourceString("Pipeline", "WriteToClosedPipeline"));
             ObjectStreamBase._trace.TraceException(exceptionRecord);
             throw exceptionRecord;
         }
         ArrayList   arrayList  = new ArrayList();
         IEnumerable enumerable = (IEnumerable)null;
         if (enumerateCollection)
         {
             enumerable = LanguagePrimitives.GetEnumerable(obj);
         }
         if (enumerable == null)
         {
             arrayList.Add(obj);
         }
         else
         {
             foreach (object obj1 in enumerable)
             {
                 if (AutomationNull.Value != obj1)
                 {
                     arrayList.Add(obj1);
                 }
             }
         }
         int index  = 0;
         int count1 = arrayList.Count;
         while (count1 > 0)
         {
             bool flag = false;
             if (this.WaitWrite())
             {
                 try
                 {
                     lock (this._monitorObject)
                     {
                         if (this.IsOpen)
                         {
                             int num = this._capacity - this._objects.Count;
                             if (0 < num)
                             {
                                 int count2 = count1;
                                 if (count2 > num)
                                 {
                                     count2 = num;
                                 }
                                 try
                                 {
                                     if (count2 == arrayList.Count)
                                     {
                                         this._objects.AddRange((ICollection)arrayList);
                                         index  += count2;
                                         count1 -= count2;
                                     }
                                     else
                                     {
                                         this._objects.AddRange((ICollection)arrayList.GetRange(index, count2));
                                         index  += count2;
                                         count1 -= count2;
                                     }
                                 }
                                 finally
                                 {
                                     flag = true;
                                 }
                             }
                         }
                         else
                         {
                             break;
                         }
                     }
                 }
                 finally
                 {
                     if (flag)
                     {
                         this.RaiseEvents();
                     }
                 }
             }
             else
             {
                 break;
             }
         }
         return(index);
     }
 }
 internal void ThrowNotInteractive() => throw new HostException(ResourceManagerCache.GetResourceString("HostInterfaceExceptionsStrings", "HostFunctionNotImplemented"), (Exception)null, "HostFunctionNotImplemented", ErrorCategory.NotImplemented);
Exemplo n.º 25
0
        internal void WriteDebugLine(string message, ref ActionPreference preference)
        {
            using (InternalHostUserInterface.tracer.TraceMethod(message, new object[0]))
            {
                InternalHostUserInterface.tracer.WriteLine((object)preference);
                switch (preference)
                {
                case ActionPreference.SilentlyContinue:
                    break;

                case ActionPreference.Stop:
                    this.WriteDebugLineHelper(message);
                    ActionPreferenceStopException preferenceStopException1 = new ActionPreferenceStopException(new ErrorRecord((Exception) new ParentContainsErrorRecordException(ResourceManagerCache.GetResourceString("InternalHostUserInterfaceStrings", "WriteDebugLineStoppedError")), "ActionPreferenceStop", ErrorCategory.OperationStopped, (object)null));
                    InternalHostUserInterface.tracer.TraceException((Exception)preferenceStopException1);
                    throw preferenceStopException1;

                case ActionPreference.Continue:
                    this.WriteDebugLineHelper(message);
                    break;

                case ActionPreference.Inquire:
                    if (!this.DebugShouldContinue(message, ref preference))
                    {
                        ActionPreferenceStopException preferenceStopException2 = new ActionPreferenceStopException(new ErrorRecord((Exception) new ParentContainsErrorRecordException(ResourceManagerCache.GetResourceString("InternalHostUserInterfaceStrings", "WriteDebugLineStoppedError")), "UserStopRequest", ErrorCategory.OperationStopped, (object)null));
                        InternalHostUserInterface.tracer.TraceException((Exception)preferenceStopException2);
                        throw preferenceStopException2;
                    }
                    this.WriteDebugLineHelper(message);
                    break;

                default:
                    throw InternalHostUserInterface.tracer.NewArgumentException(nameof(preference), "InternalHostUserInterfaceStrings", "UnsupportedPreferenceError", (object)preference);
                }
            }
        }
 internal override int Write(object obj, bool enumerateCollection)
 {
     using (ObjectStreamBase._trace.TraceMethod())
     {
         if (obj == AutomationNull.Value)
         {
             return(0);
         }
         if (!this.IsOpen)
         {
             Exception exceptionRecord = (Exception) new PipelineClosedException(ResourceManagerCache.GetResourceString("PSDataBufferStrings", "WriteToClosedBuffer"));
             ObjectStreamBase._trace.TraceException(exceptionRecord);
             throw exceptionRecord;
         }
         Collection <T> collection = new Collection <T>();
         IEnumerable    enumerable = (IEnumerable)null;
         if (enumerateCollection)
         {
             enumerable = LanguagePrimitives.GetEnumerable(obj);
         }
         if (enumerable == null)
         {
             collection.Add((T)LanguagePrimitives.ConvertTo(obj, typeof(T), (IFormatProvider)CultureInfo.InvariantCulture));
         }
         else
         {
             foreach (object obj1 in enumerable)
             {
                 if (AutomationNull.Value != obj1)
                 {
                     collection.Add((T)LanguagePrimitives.ConvertTo(obj, typeof(T), (IFormatProvider)CultureInfo.InvariantCulture));
                 }
             }
         }
         this._objects.InternalAddRange(this.psInstanceId, (ICollection)collection);
         return(collection.Count);
     }
 }
Exemplo n.º 27
0
 internal QuestionMarkVariable(ExecutionContext context)
     : base("?", (object)true, ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope, ResourceManagerCache.GetResourceString("RunspaceInit", "DollarHookDescription"))
 {
     using (QuestionMarkVariable.tracer.TraceConstructor((object)this))
         this._context = context;
 }
Exemplo n.º 28
0
        internal void ReportError(int errorCode, string methodName)
        {
            string message = string.Format((IFormatProvider)CultureInfo.InvariantCulture, ResourceManagerCache.GetResourceString("remotingerroridstrings", "GeneralError"), (object)errorCode, (object)methodName);

            ThreadPool.QueueUserWorkItem((WaitCallback)(state => this.RaiseErrorHandler(new TransportErrorOccuredEventArgs(new PSRemotingTransportException(message)
            {
                ErrorCode = errorCode
            }, TransportMethodEnum.Unknown))));
        }
Exemplo n.º 29
0
        private string GetStringHelper(StringResourceReference resourceReference, out LoadingResult result, out AssemblyBindingStatus bindingStatus)
        {
            result        = LoadingResult.AssemblyNotFound;
            bindingStatus = AssemblyBindingStatus.NotFound;

            AssemblyLoadResult loadResult = null;

            // try first to see if we have an assembly reference in the cache
            if (_resourceReferenceToAssemblyCache.Contains(resourceReference))
            {
                loadResult    = _resourceReferenceToAssemblyCache[resourceReference] as AssemblyLoadResult;
                bindingStatus = loadResult.status;
            }
            else
            {
                loadResult = new AssemblyLoadResult();
                // we do not have an assembly, we try to load it
                bool foundInGac;
                loadResult.a = LoadAssemblyFromResourceReference(resourceReference, out foundInGac);
                if (loadResult.a == null)
                {
                    loadResult.status = AssemblyBindingStatus.NotFound;
                }
                else
                {
                    loadResult.status = foundInGac ? AssemblyBindingStatus.FoundInGac : AssemblyBindingStatus.FoundInPath;
                }

                // add to the cache even if null
                _resourceReferenceToAssemblyCache.Add(resourceReference, loadResult);
            }

            bindingStatus = loadResult.status;

            if (loadResult.a == null)
            {
                // we failed the assembly loading
                result = LoadingResult.AssemblyNotFound;
                return(null);
            }
            else
            {
                resourceReference.assemblyLocation = loadResult.a.Location;
            }

            // load now the resource from the resource manager cache
            try
            {
                string val = ResourceManagerCache.GetResourceString(loadResult.a, resourceReference.baseName, resourceReference.resourceId);
                if (val == null)
                {
                    result = LoadingResult.StringNotFound;
                    return(null);
                }
                else
                {
                    result = LoadingResult.NoError;
                    return(val);
                }
            }
            catch (InvalidOperationException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (MissingManifestResourceException)
            {
                result = LoadingResult.ResourceNotFound;
            }
            catch (Exception e) // will rethrow
            {
                Diagnostics.Assert(false, "ResourceManagerCache.GetResourceString unexpected exception " + e.GetType().FullName);
                throw;
            }

            return(null);
        }
Exemplo n.º 30
0
 internal string GetMessage(PSRemotingErrorId errorId, params object[] args) => args == null?ResourceManagerCache.GetResourceString("RemotingErrorIdStrings", errorId.ToString()) : ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", errorId.ToString(), args);