/// <summary> /// Initializes a new instance of the <see cref="GeometryFileReader" /> class. /// </summary> /// <param name="stream">The stream to be read.</param> /// <param name="format">The format of the stream reader.</param> /// <param name="parameters">The parameters of the reader for the specific stream.</param> /// <exception cref="System.ArgumentNullException"> /// The stream is null. /// or /// The format is null. /// or /// The format requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter value does not match the type specified by the format. /// </exception> protected GeometryStreamReader(Stream stream, GeometryStreamFormat format, IDictionary <GeometryStreamParameter, Object> parameters) : this(format, parameters) { if (stream == null) { throw new ArgumentNullException("stream", MessageStreamIsNull); } // store parameters _disposeSourceStream = false; _sourceStream = stream; // apply buffering switch (_bufferingMode) { case BufferingMode.Minimal: _baseStream = new ProxyStream(stream, ProxyStreamOptions.ForceProxy | ProxyStreamOptions.SingleAccess); break; case BufferingMode.Maximal: _baseStream = new MemoryBufferedStream(_sourceStream); break; default: _baseStream = _sourceStream; break; } }
/// <summary> /// Initializes a new instance of the <see cref="GeometryFileReader" /> class. /// </summary> /// <param name="format">The format of the stream reader.</param> /// <param name="parameters">The parameters of the reader.</param> /// <exception cref="System.ArgumentNullException"> /// The format is null. /// or /// The format requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter value does not match the type specified by the format. /// </exception> protected GeometryStreamReader(GeometryStreamFormat format, IDictionary <GeometryStreamParameter, Object> parameters) { if (format == null) { throw new ArgumentNullException("format", MessageFormatIsNull); } if (parameters == null && format.Parameters != null && format.Parameters.Length > 0) { throw new ArgumentNullException("parameters", MessageParametersNull); } if (parameters != null && format.Parameters != null) { foreach (GeometryStreamParameter parameter in format.Parameters) { // check parameter existence if (!parameter.IsOptional && (!parameters.ContainsKey(parameter) || parameters[parameter] == null)) { throw new ArgumentException(String.Format(MessageParameterMissing, parameter.Name), "parameters"); } if (parameters.ContainsKey(parameter)) { // check parameter type if (!(parameter.Type.GetInterfaces().Contains(typeof(IConvertible)) && parameters[parameter] is IConvertible) && !parameter.Type.Equals(parameters[parameter].GetType()) && !parameters[parameter].GetType().IsSubclassOf(parameter.Type) && !parameters[parameter].GetType().GetInterfaces().Contains(parameter.Type)) { throw new ArgumentException(String.Format(MessageParameterTypeError, parameter.Name), "parameters"); } // check parameter value if (!parameter.IsValid(parameters[parameter])) { throw new ArgumentException(String.Format(MessageParameterConditionError, parameter.Name), "parameters"); } } } } // store parameters Format = format; _parameters = parameters; _disposeSourceStream = true; _disposed = false; _bufferingMode = ResolveParameter <BufferingMode>(GeometryStreamParameters.BufferingMode); // resolve factory or factory type if (IsProvidedParameter(GeometryStreamParameters.GeometryFactory)) { _factory = ResolveParameter <IGeometryFactory>(GeometryStreamParameters.GeometryFactory); } else if (IsProvidedParameter(GeometryStreamParameters.GeometryFactoryType)) { _factoryType = ResolveParameter <Type>(GeometryStreamParameters.GeometryFactoryType); } }
/// <summary> /// Initializes a new instance of the <see cref="GeometryFileReader" /> class. /// </summary> /// <param name="path">The file path to be read.</param> /// <param name="format">The format of the stream reader.</param> /// <param name="parameters">The parameters of the reader for the specific stream.</param> /// <exception cref="System.ArgumentNullException"> /// The path is null. /// or /// The format is null. /// or /// The format requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The path is empty, or consists only of whitespace characters. /// or /// The path is in an invalid format. /// or /// The parameters do not contain a required parameter value. /// or /// The type of a parameter value does not match the type specified by the format. /// or /// The parameter value does not satisfy the conditions of the parameter. /// </exception> /// <exception cref="System.IO.IOException">Exception occurred during stream opening.</exception> protected GeometryStreamReader(String path, GeometryStreamFormat format, IDictionary <GeometryStreamParameter, Object> parameters) : this(ResolvePath(path), format, parameters) { }
/// <summary> /// Initializes a new instance of the <see cref="GeometryFileReader" /> class. /// </summary> /// <param name="path">The file path to be read.</param> /// <param name="format">The format of the stream reader.</param> /// <param name="parameters">The parameters of the reader for the specific stream.</param> /// <exception cref="System.ArgumentNullException"> /// The path is null. /// or /// The format is null. /// or /// The format requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter value does not match the type specified by the format. /// </exception> /// <exception cref="System.IO.IOException">Exception occurred during stream opening.</exception> protected GeometryStreamReader(Uri path, GeometryStreamFormat format, IDictionary <GeometryStreamParameter, Object> parameters) : this(ResolveStream(path), format, parameters) { Path = path; _disposeSourceStream = true; }
/// <summary> /// Initializes a new instance of the <see cref="GeometryStreamWriter" /> class. /// </summary> /// <param name="stream">The file path to be written.</param> /// <param name="format">The format.</param> /// <param name="parameters">The parameters.</param> /// <exception cref="System.ArgumentNullException"> /// The stream is null. /// or /// The format is null. /// or /// The format requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter value does not match the type specified by the format. /// </exception> protected GeometryStreamWriter(Stream stream, GeometryStreamFormat format, IDictionary <GeometryStreamParameter, Object> parameters) { if (stream == null) { throw new ArgumentNullException("stream", MessageStreamIsNull); } if (format == null) { throw new ArgumentNullException("format", MessageFormatIsNull); } if (parameters == null && format.Parameters != null && format.Parameters.Length > 0) { throw new ArgumentNullException("parameters", MessageParametersNull); } if (parameters != null && format.Parameters != null) { foreach (GeometryStreamParameter parameter in format.Parameters) { // check parameter existence if (!parameter.IsOptional && (!parameters.ContainsKey(parameter) || parameters[parameter] == null)) { throw new ArgumentException(String.Format(MessageParameterMissing, parameter.Name), "parameters"); } if (parameters.ContainsKey(parameter)) { // check parameter type if (!(parameter.Type.GetInterfaces().Contains(typeof(IConvertible)) && parameters[parameter] is IConvertible) && !parameter.Type.Equals(parameters[parameter].GetType()) && !parameters[parameter].GetType().IsSubclassOf(parameter.Type) && !parameters[parameter].GetType().GetInterfaces().Contains(parameter.Type)) { throw new ArgumentException(String.Format(MessageParameterTypeError, parameter.Name), "parameters"); } // check parameter value if (!parameter.IsValid(parameters[parameter])) { throw new ArgumentException(String.Format(MessageParameterConditionError, parameter.Name), "parameters"); } } } _parameters = new Dictionary <GeometryStreamParameter, Object>(parameters); } Format = format; _bufferingMode = ResolveParameter <BufferingMode>(GeometryStreamParameters.BufferingMode); _disposeSourceStream = false; _disposed = false; _sourceStream = stream; // apply buffering switch (_bufferingMode) { case BufferingMode.Minimal: _baseStream = new ProxyStream(_sourceStream, ProxyStreamOptions.ForceProxy | ProxyStreamOptions.SingleAccess); break; case BufferingMode.Maximal: _baseStream = new MemoryBufferedStream(_sourceStream); break; default: _baseStream = _sourceStream; break; } }