Beispiel #1
0
        /// <summary>
        /// Creates a new instance relative to the given parent
        /// </summary>
        /// <param name="parent">The parent storage</param>
        /// <param name="streamName">Path to stream under parent storage</param>
        /// <param name="compressionOption">CompressionOption</param>
        /// <param name="encryptionOption">EncryptionOption</param>
        internal StreamInfo(StorageInfo parent, string streamName, CompressionOption compressionOption,
                            EncryptionOption encryptionOption)
        {
            // Parameter validation
            CU.CheckAgainstNull(parent, "parent");
            CU.CheckStringAgainstNullAndEmpty(streamName, "streamName");

            // Parse path relative to given parent.
            BuildStreamInfoRelativeToStorage(parent,
                                             streamName);

            _compressionOption = compressionOption;
            _encryptionOption  = encryptionOption;
            _streamReference   = new CompoundFileStreamReference(this.parentStorage.FullNameInternal, this.core.streamName);
        }
        /// <summary>
        /// Full featured constructor
        /// </summary>
        /// <param name="storageName">optional string describing the storage name - may be null if stream exists in the root storage</param>
        /// <param name="streamName">stream name</param>
        /// <exception cref="ArgumentException">streamName cannot be null or empty</exception>
        public CompoundFileStreamReference(string storageName, string streamName)
        {
            ContainerUtilities.CheckStringAgainstNullAndEmpty(streamName, "streamName");

            if ((storageName == null) || (storageName.Length == 0))
            {
                _fullName = streamName;
            }
            else
            {
                // preallocate space for the stream we are building
                StringBuilder sb = new StringBuilder(storageName, storageName.Length + 1 + streamName.Length);
                sb.Append(ContainerUtilities.PathSeparator);
                sb.Append(streamName);
                _fullName = sb.ToString();
            }
        }
        //------------------------------------------------------
        //
        //   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");
            }
        }