private PostEditorStorageException(IOException ex) : base(StringId.PostEditorStorageExceptionTitle2, StringId.PostEditorStorageExceptionMessage2, ex.GetType().Name, ex.Message) { }
static int GetHResult(IOException exception, int defaultValue) { if (exception == null) throw new ArgumentNullException("exception"); var field = exception.GetType().GetField("_HResult", BindingFlags.NonPublic | BindingFlags.Instance); if (field != null) return Convert.ToInt32(field.GetValue(exception)); return defaultValue; }
static bool IsSharingViolation( IOException ioEx) { var field = ioEx .GetType().GetField("_HResult", BindingFlags.NonPublic | BindingFlags.Instance); if (field == null) return false; var hres = (int) field.GetValue(ioEx); Debug.WriteLine("Error '{0}' {1}", ioEx.Message, hres); return hres == HResultSharingViolation; }
/// <summary> /// Gets the HRESULT of the specified exception. /// </summary> /// <param name="exception">The exception to test. May not be null.</param> /// <param name="defaultValue">The default value in case of an error.</param> /// <returns>The HRESULT value.</returns> private static int GetHResult(IOException exception, int defaultValue) { if (exception == null) throw new ArgumentNullException("exception"); try { return (int)exception.GetType().GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(exception, null); } catch { return defaultValue; } }
static int GetHResult(IOException ioe, int defaultValue) { if (ioe == null) throw new ArgumentNullException("ioe"); try { return (int)ioe.GetType() .GetProperty("HResult", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(ioe, null); } catch { return defaultValue; } }
public static int GetHResult(IOException exception, int defaultValue) { if (exception == null) throw new ArgumentNullException("exception"); try { const string name = "HResult"; PropertyInfo pi = exception.GetType().GetProperty(name, BindingFlags.NonPublic | BindingFlags.Instance); // CLR2 if (pi == null) { pi = exception.GetType().GetProperty(name, BindingFlags.Public | BindingFlags.Instance); // CL4 } if (pi != null) return (int)pi.GetValue(exception, null); } catch { } return defaultValue; }
public BlogClientIOException(FileInfo file, IOException ioException) : base(StringId.BCEFileIOTitle, StringId.BCEFileIOMessage, file.Name, ioException.GetType().Name, ioException.Message) { }
public BlogClientIOException(string context, IOException ioException) : base(StringId.BCENetworkIOTitle, StringId.BCENetworkIOMessage, context, ioException.GetType().Name, ioException.Message) { }
public void NewProperty(string path, string propertyName, string type, object value) { if (path == null) { throw PSTraceSource.NewArgumentNullException("path"); } if (this.CheckOperationNotAllowedOnHiveContainer(path)) { IRegistryWrapper regkeyForPathWriteIfError = this.GetRegkeyForPathWriteIfError(path, true); if (regkeyForPathWriteIfError != null) { string newPropertyAction = RegistryProviderStrings.NewPropertyAction; string newPropertyResourceTemplate = RegistryProviderStrings.NewPropertyResourceTemplate; string target = string.Format(base.Host.CurrentCulture, newPropertyResourceTemplate, new object[] { path, propertyName }); if (base.ShouldProcess(target, newPropertyAction)) { RegistryValueKind kind; if (!this.ParseKind(type, out kind)) { regkeyForPathWriteIfError.Close(); return; } try { if ((base.Force != 0) || (regkeyForPathWriteIfError.GetValue(propertyName) == null)) { this.SetRegistryValue(regkeyForPathWriteIfError, propertyName, value, kind, path); } else { IOException exception = new IOException(RegistryProviderStrings.PropertyAlreadyExists); base.WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.ResourceExists, path)); regkeyForPathWriteIfError.Close(); return; } } catch (ArgumentException exception2) { base.WriteError(new ErrorRecord(exception2, exception2.GetType().FullName, ErrorCategory.WriteError, path)); } catch (InvalidCastException exception3) { base.WriteError(new ErrorRecord(exception3, exception3.GetType().FullName, ErrorCategory.WriteError, path)); } catch (IOException exception4) { base.WriteError(new ErrorRecord(exception4, exception4.GetType().FullName, ErrorCategory.WriteError, path)); } catch (SecurityException exception5) { base.WriteError(new ErrorRecord(exception5, exception5.GetType().FullName, ErrorCategory.PermissionDenied, path)); } catch (UnauthorizedAccessException exception6) { base.WriteError(new ErrorRecord(exception6, exception6.GetType().FullName, ErrorCategory.PermissionDenied, path)); } } regkeyForPathWriteIfError.Close(); } } }
protected override void NewItem(string path, string type, object newItem) { if (string.IsNullOrEmpty(path)) { throw PSTraceSource.NewArgumentException("path"); } string newItemAction = RegistryProviderStrings.NewItemAction; string newItemResourceTemplate = RegistryProviderStrings.NewItemResourceTemplate; string target = string.Format(base.Host.CurrentCulture, newItemResourceTemplate, new object[] { path }); if (base.ShouldProcess(target, newItemAction)) { IRegistryWrapper regkeyForPath = this.GetRegkeyForPath(path, false); if (regkeyForPath != null) { if (base.Force == 0) { Exception exception = new IOException(RegistryProviderStrings.KeyAlreadyExists); base.WriteError(new ErrorRecord(exception, exception.GetType().FullName, ErrorCategory.ResourceExists, regkeyForPath)); regkeyForPath.Close(); return; } regkeyForPath.Close(); this.RemoveItem(path, false); } if ((base.Force == 0) || this.CreateIntermediateKeys(path)) { string parentPath = this.GetParentPath(path, null); string childName = this.GetChildName(path); IRegistryWrapper regkeyForPathWriteIfError = this.GetRegkeyForPathWriteIfError(parentPath, true); if (regkeyForPathWriteIfError != null) { try { IRegistryWrapper key = regkeyForPathWriteIfError.CreateSubKey(childName); regkeyForPathWriteIfError.Close(); try { if (newItem != null) { RegistryValueKind kind; if (!this.ParseKind(type, out kind)) { return; } this.SetRegistryValue(key, string.Empty, newItem, kind, path, false); } } catch (Exception exception2) { if (((!(exception2 is ArgumentException) && !(exception2 is InvalidCastException)) && (!(exception2 is IOException) && !(exception2 is SecurityException))) && (!(exception2 is UnauthorizedAccessException) && !(exception2 is NotSupportedException))) { throw; } ErrorRecord errorRecord = new ErrorRecord(exception2, exception2.GetType().FullName, ErrorCategory.WriteError, key) { ErrorDetails = new ErrorDetails(StringUtil.Format(RegistryProviderStrings.KeyCreatedValueFailed, childName)) }; base.WriteError(errorRecord); } this.WriteRegistryItemObject(key, path); } catch (IOException exception3) { base.WriteError(new ErrorRecord(exception3, exception3.GetType().FullName, ErrorCategory.WriteError, path)); } catch (SecurityException exception4) { base.WriteError(new ErrorRecord(exception4, exception4.GetType().FullName, ErrorCategory.PermissionDenied, path)); } catch (UnauthorizedAccessException exception5) { base.WriteError(new ErrorRecord(exception5, exception5.GetType().FullName, ErrorCategory.PermissionDenied, path)); } catch (ArgumentException exception6) { base.WriteError(new ErrorRecord(exception6, exception6.GetType().FullName, ErrorCategory.InvalidArgument, path)); } catch (NotSupportedException exception7) { base.WriteError(new ErrorRecord(exception7, exception7.GetType().FullName, ErrorCategory.InvalidOperation, path)); } } } } }