private static Encoding ToTextEncoding(FileSystemCmdletProviderEncoding providerEncoding) { switch (providerEncoding) { case FileSystemCmdletProviderEncoding.Unknown: case FileSystemCmdletProviderEncoding.Default: return(Encoding.Default); case FileSystemCmdletProviderEncoding.Ascii: return(Encoding.ASCII); case FileSystemCmdletProviderEncoding.BigEndianUnicode: return(Encoding.BigEndianUnicode); case FileSystemCmdletProviderEncoding.Byte: return(null); case FileSystemCmdletProviderEncoding.String: case FileSystemCmdletProviderEncoding.Unicode: return(Encoding.Unicode); case FileSystemCmdletProviderEncoding.UTF32: return(Encoding.UTF32); case FileSystemCmdletProviderEncoding.UTF7: return(Encoding.UTF7); case FileSystemCmdletProviderEncoding.UTF8: return(Encoding.UTF8); default: throw new ArgumentOutOfRangeException(string.Format(CultureInfo.CurrentCulture, Resources.UnsupportedEncoding, providerEncoding)); } }
private static System.Text.Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding type) { System.Text.Encoding unicode = System.Text.Encoding.Unicode; switch (type) { case FileSystemCmdletProviderEncoding.String: return(System.Text.Encoding.Unicode); case FileSystemCmdletProviderEncoding.Unicode: return(System.Text.Encoding.Unicode); case FileSystemCmdletProviderEncoding.BigEndianUnicode: return(System.Text.Encoding.BigEndianUnicode); case FileSystemCmdletProviderEncoding.UTF8: return(System.Text.Encoding.UTF8); case FileSystemCmdletProviderEncoding.UTF7: return(System.Text.Encoding.UTF7); case FileSystemCmdletProviderEncoding.UTF32: return(System.Text.Encoding.UTF32); case FileSystemCmdletProviderEncoding.Ascii: return(System.Text.Encoding.ASCII); case FileSystemCmdletProviderEncoding.Default: return(System.Text.Encoding.Default); case FileSystemCmdletProviderEncoding.Oem: return(System.Text.Encoding.GetEncoding((int)NativeMethods.GetOEMCP())); } return(System.Text.Encoding.Unicode); }
/// <summary> /// Converts the stream type string into an Encoding /// </summary> /// <param name="content">The content.</param> /// <param name="type"> /// This is a string representation of the encoding. It can be /// "string", "unicode", "bigendianunicode", "ascii", "utf7", or "utf8" /// Note, a ToLowerInvariant is done to the type before comparison is made. /// </param> /// <returns> /// The encoding that was represented by the string /// </returns> /// <throws> /// ArgumentException if type is null, empty, or does not represent one /// of the known encoding types. /// </throws> private static byte[] GetBytes(string content, FileSystemCmdletProviderEncoding type) { switch (type) { case FileSystemCmdletProviderEncoding.String: return Encoding.UTF8.GetBytes(content); case FileSystemCmdletProviderEncoding.Unicode: return Encoding.Unicode.GetBytes(content); case FileSystemCmdletProviderEncoding.BigEndianUnicode: return Encoding.BigEndianUnicode.GetBytes(content); case FileSystemCmdletProviderEncoding.UTF8: return Encoding.UTF8.GetBytes(content); case FileSystemCmdletProviderEncoding.UTF7: return Encoding.UTF7.GetBytes(content); case FileSystemCmdletProviderEncoding.UTF32: return Encoding.UTF32.GetBytes(content); case FileSystemCmdletProviderEncoding.Ascii: return Encoding.ASCII.GetBytes(content); case FileSystemCmdletProviderEncoding.Default: return Encoding.UTF8.GetBytes(content); case FileSystemCmdletProviderEncoding.Oem: { var oemCP = NativeMethods.GetOEMCP(); return Encoding.GetEncoding((int) oemCP).GetBytes(content); } default: // Default to unicode encoding return Encoding.UTF8.GetBytes(content); } }
private static System.Text.Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding type) { System.Text.Encoding unicode = System.Text.Encoding.Unicode; switch (type) { case FileSystemCmdletProviderEncoding.String: return System.Text.Encoding.Unicode; case FileSystemCmdletProviderEncoding.Unicode: return System.Text.Encoding.Unicode; case FileSystemCmdletProviderEncoding.BigEndianUnicode: return System.Text.Encoding.BigEndianUnicode; case FileSystemCmdletProviderEncoding.UTF8: return System.Text.Encoding.UTF8; case FileSystemCmdletProviderEncoding.UTF7: return System.Text.Encoding.UTF7; case FileSystemCmdletProviderEncoding.UTF32: return System.Text.Encoding.UTF32; case FileSystemCmdletProviderEncoding.Ascii: return System.Text.Encoding.ASCII; case FileSystemCmdletProviderEncoding.Default: return System.Text.Encoding.Default; case FileSystemCmdletProviderEncoding.Oem: return System.Text.Encoding.GetEncoding((int) NativeMethods.GetOEMCP()); } return System.Text.Encoding.Unicode; }
private static Encoding ToTextEncoding(FileSystemCmdletProviderEncoding providerEncoding) { switch (providerEncoding) { case FileSystemCmdletProviderEncoding.Unknown: case FileSystemCmdletProviderEncoding.Default: return Encoding.Default; case FileSystemCmdletProviderEncoding.Ascii: return Encoding.ASCII; case FileSystemCmdletProviderEncoding.BigEndianUnicode: return Encoding.BigEndianUnicode; case FileSystemCmdletProviderEncoding.Byte: return null; case FileSystemCmdletProviderEncoding.String: case FileSystemCmdletProviderEncoding.Unicode: return Encoding.Unicode; case FileSystemCmdletProviderEncoding.UTF32: return Encoding.UTF32; case FileSystemCmdletProviderEncoding.UTF7: return Encoding.UTF7; case FileSystemCmdletProviderEncoding.UTF8: return Encoding.UTF8; default: throw new ArgumentOutOfRangeException(string.Format(CultureInfo.CurrentCulture, Resources.UnsupportedEncoding, providerEncoding)); } }
public ItemContentReader(CmdletProvider provider, Item item, FileSystemCmdletProviderEncoding encoding, bool raw) : base(provider, item, encoding, raw) { if (Encoding != null && !Raw) { decoder = Encoding.GetDecoder(); } }
protected ItemContentReaderWriterBase(CmdletProvider provider, Item item, FileSystemCmdletProviderEncoding encoding, bool raw) { Item = item; Provider = provider; Raw = raw; if (encoding == FileSystemCmdletProviderEncoding.Unknown) { encoding = FileSystemCmdletProviderEncoding.Byte; } Encoding = new FileSystemContentWriterDynamicParameters() {Encoding = encoding}.EncodingType; }
private static Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding type) { Encoding result = System.Text.Encoding.Unicode; switch (type) { case FileSystemCmdletProviderEncoding.String: result = System.Text.Encoding.Unicode; return(result); case FileSystemCmdletProviderEncoding.Unicode: result = System.Text.Encoding.Unicode; return(result); case FileSystemCmdletProviderEncoding.BigEndianUnicode: result = System.Text.Encoding.BigEndianUnicode; return(result); case FileSystemCmdletProviderEncoding.UTF8: result = System.Text.Encoding.UTF8; return(result); case FileSystemCmdletProviderEncoding.UTF7: result = System.Text.Encoding.UTF7; return(result); case FileSystemCmdletProviderEncoding.UTF32: result = System.Text.Encoding.UTF32; return(result); case FileSystemCmdletProviderEncoding.Ascii: result = System.Text.Encoding.ASCII; return(result); case FileSystemCmdletProviderEncoding.Default: result = System.Text.Encoding.Default; return(result); case FileSystemCmdletProviderEncoding.Oem: { uint oEMCP = NativeMethods.GetOEMCP(); result = System.Text.Encoding.GetEncoding((int)oEMCP); return(result); } } result = System.Text.Encoding.Unicode; return(result); }
protected ItemContentReaderWriterBase(CmdletProvider provider, Item item, FileSystemCmdletProviderEncoding encoding, bool raw) { Item = item; Provider = provider; Raw = raw; if (encoding == FileSystemCmdletProviderEncoding.Unknown) { encoding = FileSystemCmdletProviderEncoding.Byte; } Encoding = new FileSystemContentWriterDynamicParameters() { Encoding = encoding }.EncodingType; }
public ItemContentWriter(CmdletProvider provider, Item item, string path, FileSystemCmdletProviderEncoding encoding, string extension, bool raw, bool fileBased, bool versioned, string language) : base(provider, item, encoding, raw) { if (Encoding != null && !Raw) { encoder = Encoding.GetEncoder(); } if (!string.IsNullOrEmpty(extension)) { this.extension = extension.StartsWith(".") ? extension : "." + extension; } this.fileBased = fileBased; this.path = path; this.versioned = versioned; this.language = language ?? Item?.Language?.Name; database = Item?.Database?.Name ?? PathUtilities.GetDrive(path, "master"); }
public ItemContentWriter(CmdletProvider provider, Item item, string path, FileSystemCmdletProviderEncoding encoding, string extension, bool raw, bool fileBased, bool versioned, string language) : base(provider, item, encoding, raw) { if (Encoding != null && !Raw) { encoder = Encoding.GetEncoder(); } if (!string.IsNullOrEmpty(extension)) { this.extension = extension.StartsWith(".") ? extension : "." + extension; } this.fileBased = fileBased; this.path = path; this.versioned = versioned; this.language = language ?? Item?.Language?.Name; database = Item?.Database?.Name ?? PathUtilities.GetDrive(path, "master"); }
} // UsingByteEncoding internal static byte[] GetBytes(object content, FileSystemCmdletProviderEncoding encoding) { if (UsingByteEncoding(encoding)) { // first attempt to convert it directly into a byte array var byteArray = content as byte[]; if (byteArray != null) { return(byteArray); } // attempt to convert the object into an object array var contentArray = content as object[]; if (contentArray == null) { throw new CloudException(Resources.InvalidEncoding); } // now, for each element in the content array, ensure it is of type byte var byteList = new List <byte>(); foreach (var entry in contentArray) { if (!(entry is byte)) { throw new CloudException(Resources.InvalidEncoding); } byteList.Add((byte)entry); } return(byteList.ToArray()); } var contentString = content as string; if (contentString == null) { throw new CloudException(Resources.InvalidContent); } return(GetBytes(contentString, encoding)); }
/// <summary> /// Converts the stream type string into an Encoding /// </summary> /// <param name="content">The content.</param> /// <param name="type"> /// This is a string representation of the encoding. It can be /// "string", "unicode", "bigendianunicode", "ascii", "utf7", or "utf8" /// Note, a ToLowerInvariant is done to the type before comparison is made. /// </param> /// <returns> /// The encoding that was represented by the string /// </returns> /// <throws> /// ArgumentException if type is null, empty, or does not represent one /// of the known encoding types. /// </throws> private static byte[] GetBytes(string content, FileSystemCmdletProviderEncoding type) { switch (type) { case FileSystemCmdletProviderEncoding.String: return(Encoding.UTF8.GetBytes(content)); case FileSystemCmdletProviderEncoding.Unicode: return(Encoding.Unicode.GetBytes(content)); case FileSystemCmdletProviderEncoding.BigEndianUnicode: return(Encoding.BigEndianUnicode.GetBytes(content)); case FileSystemCmdletProviderEncoding.UTF8: return(Encoding.UTF8.GetBytes(content)); case FileSystemCmdletProviderEncoding.UTF7: return(Encoding.UTF7.GetBytes(content)); case FileSystemCmdletProviderEncoding.UTF32: return(Encoding.UTF32.GetBytes(content)); case FileSystemCmdletProviderEncoding.Ascii: return(Encoding.ASCII.GetBytes(content)); case FileSystemCmdletProviderEncoding.Default: return(Encoding.UTF8.GetBytes(content)); case FileSystemCmdletProviderEncoding.Oem: { var oemCP = NativeMethods.GetOEMCP(); return(Encoding.GetEncoding((int)oemCP).GetBytes(content)); } default: // Default to unicode encoding return(Encoding.UTF8.GetBytes(content)); } }
internal static Encoding GetEncoding(FileSystemCmdletProviderEncoding type) { switch (type) { case FileSystemCmdletProviderEncoding.String: return(Encoding.UTF8); case FileSystemCmdletProviderEncoding.Unicode: return(Encoding.Unicode); case FileSystemCmdletProviderEncoding.BigEndianUnicode: return(Encoding.BigEndianUnicode); case FileSystemCmdletProviderEncoding.UTF8: return(Encoding.UTF8); case FileSystemCmdletProviderEncoding.UTF7: return(Encoding.UTF7); case FileSystemCmdletProviderEncoding.UTF32: return(Encoding.UTF32); case FileSystemCmdletProviderEncoding.Ascii: return(Encoding.ASCII); case FileSystemCmdletProviderEncoding.Default: return(Encoding.UTF8); case FileSystemCmdletProviderEncoding.Oem: { var oemCP = NativeMethods.GetOEMCP(); return(Encoding.GetEncoding((int)oemCP)); } default: // Default to unicode encoding return(Encoding.UTF8); } }
private static System.Text.Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding type) { System.Text.Encoding unicode = System.Text.Encoding.Unicode; System.Text.Encoding encoding; switch (type) { case FileSystemCmdletProviderEncoding.String: encoding = System.Text.Encoding.Unicode; break; case FileSystemCmdletProviderEncoding.Unicode: encoding = System.Text.Encoding.Unicode; break; case FileSystemCmdletProviderEncoding.BigEndianUnicode: encoding = System.Text.Encoding.BigEndianUnicode; break; case FileSystemCmdletProviderEncoding.UTF8: encoding = System.Text.Encoding.UTF8; break; case FileSystemCmdletProviderEncoding.UTF7: encoding = System.Text.Encoding.UTF7; break; case FileSystemCmdletProviderEncoding.Ascii: encoding = System.Text.Encoding.ASCII; break; default: encoding = System.Text.Encoding.Unicode; break; } return(encoding); }
} // EncodingType /// <summary> /// Converts the stream type string into an Encoding /// </summary> /// /// <param name="type"> /// This is a string representation of the encoding. It can be /// "string", "unicode", "bigendianunicode", "ascii", "utf7", or "utf8" /// /// Note, a ToLowerInvariant is done to the type before comparison is made. /// </param> /// /// <returns> /// The encoding that was represented by the string /// </returns> /// /// <throws> /// ArgumentException if type is null, empty, or does not represent one /// of the known encoding types. /// </throws> private static Encoding GetEncodingFromEnum(FileSystemCmdletProviderEncoding type) { System.Text.Encoding encoding; switch (type) { case FileSystemCmdletProviderEncoding.String: encoding = System.Text.Encoding.Unicode; break; case FileSystemCmdletProviderEncoding.Unicode: encoding = System.Text.Encoding.Unicode; break; case FileSystemCmdletProviderEncoding.BigEndianUnicode: encoding = System.Text.Encoding.BigEndianUnicode; break; case FileSystemCmdletProviderEncoding.UTF8: encoding = System.Text.Encoding.UTF8; break; case FileSystemCmdletProviderEncoding.UTF7: encoding = System.Text.Encoding.UTF7; break; case FileSystemCmdletProviderEncoding.UTF32: encoding = System.Text.Encoding.UTF32; break; case FileSystemCmdletProviderEncoding.BigEndianUTF32: encoding = System.Text.Encoding.GetEncoding("utf-32BE"); break; case FileSystemCmdletProviderEncoding.Ascii: encoding = System.Text.Encoding.ASCII; break; case FileSystemCmdletProviderEncoding.Default: encoding = ClrFacade.GetDefaultEncoding(); break; case FileSystemCmdletProviderEncoding.Oem: { uint oemCP = NativeMethods.GetOEMCP(); encoding = System.Text.Encoding.GetEncoding((int)oemCP); } break; default: // Default to unicode encoding encoding = System.Text.Encoding.Unicode; break; } return encoding; } // GetEncodingFromEnum
/// <summary> /// Gets the Byte Encoding status of the StreamType parameter. Returns true /// if the stream was opened with "Byte" encoding, false otherwise. /// </summary> internal static bool UsingByteEncoding(FileSystemCmdletProviderEncoding encoding) { return(encoding == FileSystemCmdletProviderEncoding.Byte); } // UsingByteEncoding
public ZipFileContentDynamicParameters(FileSystemCmdletProviderEncoding streamType, System.IO.FileMode fileMode, System.IO.FileAccess fileAccess) { this.streamType = streamType; this.fileMode = fileMode; this.fileAccess = fileAccess; }
} // UsingByteEncoding internal static byte[] GetBytes(object content, FileSystemCmdletProviderEncoding encoding) { if (UsingByteEncoding(encoding)) { // first attempt to convert it directly into a byte array var byteArray = content as byte[]; if (byteArray != null) { return byteArray; } // attempt to convert the object into an object array var contentArray = content as object[]; if (contentArray == null) { throw new CloudException(Resources.InvalidEncoding); } // now, for each element in the content array, ensure it is of type byte var byteList = new List<byte>(); foreach (var entry in contentArray) { if (!(entry is byte)) { throw new CloudException(Resources.InvalidEncoding); } byteList.Add((byte) entry); } return byteList.ToArray(); } var contentString = content as string; if (contentString == null) { throw new CloudException(Resources.InvalidContent); } return GetBytes(contentString, encoding); }
/// <summary> /// Gets the Byte Encoding status of the StreamType parameter. Returns true /// if the stream was opened with "Byte" encoding, false otherwise. /// </summary> internal static bool UsingByteEncoding(FileSystemCmdletProviderEncoding encoding) { return encoding == FileSystemCmdletProviderEncoding.Byte; } // UsingByteEncoding
internal static string BytesToString(byte[] content, FileSystemCmdletProviderEncoding type) { return(GetEncoding(type).GetString(content)); }