//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ /// <summary> /// Assign the fullName /// </summary> /// <param name="fullName">name</param> /// <remarks>cache a duplicate copy of the storage name to save having to do this for /// every call to get_Name</remarks> /// <exception cref="ArgumentException">if leading or trailing path delimiter</exception> private void SetFullName(string fullName) { if (fullName == null || fullName.Length == 0) { _fullName = String.Empty; } else { // fail on leading path separator to match functionality across the board // Although we need to do ToUpperInvariant before we do string comparison, in this case // it is not necessary since PathSeparatorAsString is a path symbol if (fullName.StartsWith(ContainerUtilities.PathSeparatorAsString, StringComparison.Ordinal)) { throw new ArgumentException( SR.Get(SRID.DelimiterLeading), "fullName"); } _fullName = fullName; // ensure that the string is a legal whack-path string[] strings = ContainerUtilities.ConvertBackSlashPathToStringArrayPath(_fullName); if (strings.Length == 0) { throw new ArgumentException( SR.Get(SRID.CompoundFilePathNullEmpty), "fullName"); } } }
/// <summary>Save to a stream</summary> /// <param name="reference">reference to save</param> /// <param name="writer">The BinaryWriter to persist this object to. /// This method will alter the stream pointer of the underlying stream as a side effect. /// Passing null simply calculates how many bytes would be written.</param> /// <returns>number of bytes written including any padding</returns> static internal int Save(CompoundFileReference reference, BinaryWriter writer) { int bytes = 0; // NOTE: Our RefComponentType must be written by our caller bool calcOnly = (writer == null); // what are we dealing with here? CompoundFileStreamReference streamReference = reference as CompoundFileStreamReference; if ((streamReference == null) && (!(reference is CompoundFileStorageReference))) { throw new ArgumentException(SR.Get(SRID.UnknownReferenceSerialize), "reference"); } // first parse the path into strings string[] segments = ContainerUtilities.ConvertBackSlashPathToStringArrayPath(reference.FullName); int entries = segments.Length; // write the count if (!calcOnly) { writer.Write(entries); } bytes += ContainerUtilities.Int32Size; // write the segments - if we are dealing with a stream entry, don't write the last "segment" // because it is in fact a stream name for (int i = 0; i < segments.Length - (streamReference == null ? 0 : 1); i++) { if (!calcOnly) { writer.Write((Int32)RefComponentType.Storage); } bytes += ContainerUtilities.Int32Size; bytes += ContainerUtilities.WriteByteLengthPrefixedDWordPaddedUnicodeString(writer, segments[i]); } if (streamReference != null) { // we are responsible for the prefix if (!calcOnly) { writer.Write((Int32)RefComponentType.Stream); } bytes += ContainerUtilities.Int32Size; // write the stream name bytes += ContainerUtilities.WriteByteLengthPrefixedDWordPaddedUnicodeString(writer, segments[segments.Length - 1]); } return(bytes); }
//------------------------------------------------------ // // Private Methods // //------------------------------------------------------ /// <summary> /// Initialize _fullName /// </summary> /// <remarks>this should only be called from constructors as references are immutable</remarks> /// <param name="fullName">string to parse</param> /// <exception cref="ArgumentException">if leading or trailing path delimiter</exception> private void SetFullName(string fullName) { ContainerUtilities.CheckStringAgainstNullAndEmpty(fullName, "fullName"); // fail on leading path separator to match functionality across the board // Although we need to do ToUpperInvariant before we do string comparison, in this case // it is not necessary since PathSeparatorAsString is a path symbol if (fullName.StartsWith(ContainerUtilities.PathSeparatorAsString, StringComparison.Ordinal)) { throw new ArgumentException( SR.DelimiterLeading, "fullName"); } _fullName = fullName; string[] strings = ContainerUtilities.ConvertBackSlashPathToStringArrayPath(fullName); if (strings.Length == 0) { throw new ArgumentException( SR.CompoundFilePathNullEmpty, "fullName"); } }