Пример #1
0
        public DscIOStream(string streamName, FileAccess access, DscCompressionScheme compressionScheme)
        {
            if (String.IsNullOrEmpty(streamName))
            {
                throw new ArgumentNullException("streamName");
            }

            Uri streamUri = new Uri(streamName);

            this.m_dscClient         = new DscService(streamUri.Host);
            this.m_fileSetName       = streamUri.LocalPath;
            this.m_mode              = access;
            this.m_fstream           = null;
            this.m_atEOF             = false;
            this.m_compressionScheme = compressionScheme;

            if (access == FileAccess.Read)
            {
                this.m_dscFileSet        = this.m_dscClient.GetFileSet(streamName);
                this.m_dscFileEnumerator = this.m_dscFileSet.GetFiles().GetEnumerator();
            }
            else if (access == FileAccess.Write)
            {
                this.m_dscFileSet = this.m_dscClient.CreateFileSet(streamName, compressionScheme);
            }
            else
            {
                throw new ArgumentException(SR.ReadWriteNotSupported, "access");
            }
        }
Пример #2
0
        public DscIOStream(string streamName, FileAccess access, FileMode createMode, DscCompressionScheme compressionScheme)
        {
            if (String.IsNullOrEmpty(streamName))
            {
                throw new ArgumentNullException("streamName");
            }

            Uri streamUri = new Uri(streamName);

            this.m_dscClient         = new DscService(streamUri.Host);
            this.m_fileSetName       = streamUri.LocalPath.TrimStart('/');
            this.m_mode              = access;
            this.m_compressionScheme = compressionScheme;

            bool streamExists = this.m_dscClient.FileSetExists(this.m_fileSetName);

            if (access == FileAccess.Read)
            {
                switch (createMode)
                {
                case FileMode.Open:
                case FileMode.OpenOrCreate:
                    if (!streamExists)
                    {
                        throw new FileNotFoundException(String.Format(SR.StreamDoesNotExist, streamName));
                    }
                    break;

                case FileMode.Append:
                case FileMode.Create:
                case FileMode.CreateNew:
                case FileMode.Truncate:
                    throw new NotSupportedException();
                }

                this.m_dscFileSet        = this.m_dscClient.GetFileSet(streamName);
                this.m_dscFileEnumerator = this.m_dscFileSet.GetFiles().GetEnumerator();
            }
            else if (access == FileAccess.Write)
            {
                switch (createMode)
                {
                case FileMode.Append:
                    if (!streamExists)
                    {
                        this.m_dscFileSet = this.m_dscClient.CreateFileSet(this.m_fileSetName, this.m_compressionScheme);
                    }
                    break;

                case FileMode.Create:
                    if (streamExists)
                    {
                        this.m_dscClient.DeleteFileSet(this.m_fileSetName);
                    }
                    this.m_dscFileSet = this.m_dscClient.CreateFileSet(this.m_fileSetName, this.m_compressionScheme);
                    break;

                case FileMode.CreateNew:
                    if (streamExists)
                    {
                        throw new IOException(String.Format(SR.StreamAlreadyExists, streamName));
                    }
                    break;

                case FileMode.Truncate:
                    if (streamExists)
                    {
                        this.m_dscClient.DeleteFileSet(this.m_fileSetName);
                    }
                    this.m_dscFileSet = this.m_dscClient.CreateFileSet(this.m_fileSetName, this.m_compressionScheme);
                    break;

                case FileMode.Open:
                case FileMode.OpenOrCreate:     // TODO: this should be dealt with correctly,
                                                // although it's not obvious what open should do
                    throw new NotSupportedException();
                }
            }
            else
            {
                throw new ArgumentException(SR.ReadWriteNotSupported, "access");
            }

            this.m_fstream = null;
            this.m_atEOF   = false;
        }