Beispiel #1
0
        /// <summary>
        /// Reads service properties from a stream.
        /// </summary>
        /// <param name="inputStream">The stream from which to read the service properties.</param>
        /// <returns>The service properties stored in the stream.</returns>
        public static FileServiceProperties ReadServiceProperties(Stream inputStream)
        {
            using (XmlReader reader = XmlReader.Create(inputStream))
            {
                XDocument servicePropertyDocument = XDocument.Load(reader);

                return(FileServiceProperties.FromServiceXml(servicePropertyDocument));
            }
        }
        public void MyTestInitialize()
        {
            props = DefaultServiceProperties();

            if (TestBase.FileBufferManager != null)
            {
                TestBase.FileBufferManager.OutstandingBufferCount = 0;
            }
        }
        /// <summary>
        /// Constructs a <c>ServiceProperties</c> object from an XML document received from the service.
        /// </summary>
        /// <param name="servicePropertiesDocument">The XML document.</param>
        /// <returns>A <c>ServiceProperties</c> object containing the properties in the XML document.</returns>
        internal static FileServiceProperties FromServiceXml(XDocument servicePropertiesDocument)
        {
            XElement servicePropertiesElement = servicePropertiesDocument.Element(ServiceProperties.StorageServicePropertiesName);

            FileServiceProperties properties = new FileServiceProperties
            {
                Cors = ServiceProperties.ReadCorsPropertiesFromXml(servicePropertiesElement.Element(ServiceProperties.CorsName))
            };

            return(properties);
        }
        /// <summary>
        /// Constructs a <c>ServiceProperties</c> object from an XML document received from the service.
        /// </summary>
        /// <param name="servicePropertiesDocument">The XML document.</param>
        /// <returns>A <c>ServiceProperties</c> object containing the properties in the XML document.</returns>
        internal static FileServiceProperties FromServiceXml(XDocument servicePropertiesDocument)
        {
            XElement servicePropertiesElement = servicePropertiesDocument.Element(ServiceProperties.StorageServicePropertiesName);

            FileServiceProperties properties = new FileServiceProperties
            {
                Cors = ServiceProperties.ReadCorsPropertiesFromXml(servicePropertiesElement.Element(ServiceProperties.CorsName))
            };

            return properties;
        }
Beispiel #5
0
        /// <summary>
        /// Reads service properties from a stream.
        /// </summary>
        /// <param name="inputStream">The stream from which to read the service properties.</param>
        /// <returns>The service properties stored in the stream.</returns>
        public static Task <FileServiceProperties> ReadServicePropertiesAsync(Stream inputStream, CancellationToken token)
        {
            return(Task.Run(
                       () =>
            {
                using (XmlReader reader = XmlReader.Create(inputStream))
                {
                    XDocument servicePropertyDocument = XDocument.Load(reader);

                    return FileServiceProperties.FromServiceXml(servicePropertyDocument);
                }
            },
                       token
                       ));
        }
 public virtual ICancellableAsyncResult BeginSetServiceProperties(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state)
 {
     requestOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return Executor.BeginExecuteAsync(
         this.SetServicePropertiesImpl(properties, requestOptions),
         requestOptions.RetryPolicy,
         operationContext,
         callback,
         state);
 }
 public virtual ICancellableAsyncResult BeginSetServiceProperties(FileServiceProperties properties, AsyncCallback callback, object state)
 {
     return this.BeginSetServiceProperties(properties, null /* requestOptions */, null /* operationContext */, callback, state);
 }
        public IAsyncAction SetServicePropertiesAsync(FileServiceProperties properties)
#endif
        {
            return this.SetServicePropertiesAsync(properties, null /* options */, null /* operationContext */);
        }
 public static void MyClassInitialize(TestContext testContext)
 {
     client = GenerateCloudFileClient();
     startProperties = client.GetServiceProperties();
 }
 public virtual void SetServiceProperties(FileServiceProperties properties, FileRequestOptions requestOptions = null, OperationContext operationContext = null)
 {
     requestOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     Executor.ExecuteSync(
         this.SetServicePropertiesImpl(properties, requestOptions),
         requestOptions.RetryPolicy,
         operationContext);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext)
 {
     return this.SetServicePropertiesAsync(properties, requestOptions, operationContext, CancellationToken.None);
 }
        /// <summary>
        /// Writes File service properties to a stream, formatted in XML.
        /// </summary>
        /// <param name="properties">A <see cref="FileServiceProperties"/> object.</param>
        /// <param name="outputStream">The <see cref="System.IO.Stream"/> object to which the formatted properties are to be written.</param>
        public static void WriteServiceProperties(FileServiceProperties properties, Stream outputStream)
        {
            CommonUtility.AssertNotNull("properties", properties);

            properties.WriteServiceProperties(outputStream);
        }
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties();

            props.Cors.CorsRules = new List<CorsRule>();

            return props;
        }
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties();

            props.HourMetrics.MetricsLevel = MetricsLevel.None;
            props.HourMetrics.RetentionDays = null;
            props.HourMetrics.Version = "1.0";

            props.MinuteMetrics.MetricsLevel = MetricsLevel.None;
            props.MinuteMetrics.RetentionDays = null;
            props.MinuteMetrics.Version = "1.0";

            props.Cors.CorsRules = new List<CorsRule>();

            return props;
        }
 public IAsyncAction SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext)
 {
     FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return AsyncInfo.Run(async (token) => await Executor.ExecuteAsyncNullReturn(
          this.SetServicePropertiesImpl(properties, modifiedOptions),
         modifiedOptions.RetryPolicy,
         operationContext,
         token));
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties)
 {
     return this.SetServicePropertiesAsync(properties, CancellationToken.None);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, CancellationToken cancellationToken)
 {
     return AsyncExtensions.TaskFromVoidApm(this.BeginSetServiceProperties, this.EndSetServiceProperties, properties, cancellationToken);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties)
 {
     return this.SetServicePropertiesAsync(properties, null /* options */, null /* operationContext */);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
 {
     return AsyncExtensions.TaskFromVoidApm(this.BeginSetServiceProperties, this.EndSetServiceProperties, properties, requestOptions, operationContext, cancellationToken);
 }
 public virtual Task SetServicePropertiesAsync(FileServiceProperties properties, FileRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
 {
     FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(requestOptions, this);
     operationContext = operationContext ?? new OperationContext();
     return Task.Run(async () => await Executor.ExecuteAsyncNullReturn(
          this.SetServicePropertiesImpl(properties, modifiedOptions),
         modifiedOptions.RetryPolicy,
         operationContext,
         cancellationToken), cancellationToken);
 }
        private RESTCommand<NullType> SetServicePropertiesImpl(FileServiceProperties properties, FileRequestOptions requestOptions)
        {
            MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
            try
            {
                properties.WriteServiceProperties(str);
            }
            catch (InvalidOperationException invalidOpException)
            {
                str.Dispose();
                throw new ArgumentException(invalidOpException.Message, "properties");
            }

            str.Seek(0, SeekOrigin.Begin);

            RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.StorageUri);
            retCmd.SendStream = str;
            retCmd.StreamToDispose = str;
            retCmd.BuildRequestDelegate = FileHttpWebRequestFactory.SetServiceProperties;
            retCmd.RecoveryAction = RecoveryActions.RewindStream;
            retCmd.SignRequest = this.AuthenticationHandler.SignRequest;
            retCmd.PreProcessResponse =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex);
            requestOptions.ApplyToStorageCommand(retCmd);
            return retCmd;
        }
        private RESTCommand<NullType> SetServicePropertiesImpl(FileServiceProperties properties, FileRequestOptions requestOptions)
        {
            MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
            try
            {
                properties.WriteServiceProperties(memoryStream);
            }
            catch (InvalidOperationException invalidOpException)
            {
                throw new ArgumentException(invalidOpException.Message, "properties");
            }

            RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.StorageUri);
            requestOptions.ApplyToStorageCommand(retCmd);
            retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => FileHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx, this.GetCanonicalizer(), this.Credentials);
            retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx);
            retCmd.StreamToDispose = memoryStream;
            retCmd.RetrieveResponseStream = true;
            retCmd.PreProcessResponse =
                (cmd, resp, ex, ctx) =>
                HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex);
            requestOptions.ApplyToStorageCommand(retCmd);
            return retCmd;
        }
        private static FileServiceProperties DefaultServiceProperties()
        {
            FileServiceProperties props = new FileServiceProperties();
            props.MinuteMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1;
            props.HourMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1;

            props.Cors.CorsRules = new List<CorsRule>();

            return props;
        }
        /// <summary>
        /// Set service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="properties">Service properties</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext)
        {
            CloudStorageAccount account = StorageContext.StorageAccount;
            switch (type)
            {
                case StorageServiceType.Blob:
                    account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext);
                    break;
                case StorageServiceType.Queue:
                    account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext);
                    break;
                case StorageServiceType.Table:
                    account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext);
                    break;
                case StorageServiceType.File:
                    if (null != properties.Logging)
                    {
                        throw new InvalidOperationException(Resources.FileNotSupportLogging);
                    }

                    if (null != properties.HourMetrics || null != properties.MinuteMetrics)
                    {
                        throw new InvalidOperationException(Resources.FileNotSupportMetrics);
                    }

                    FileServiceProperties fileServiceProperties = new FileServiceProperties();
                    fileServiceProperties.Cors = properties.Cors;
                    account.CreateCloudFileClient().SetServiceProperties(fileServiceProperties, (FileRequestOptions)options, operationContext);
                    break;
                default:
                    throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
            }
        }
        /// <summary>
        /// Writes File service properties to a stream, formatted in XML.
        /// </summary>
        /// <param name="properties">A <see cref="FileServiceProperties"/> object.</param>
        /// <param name="outputStream">The <see cref="System.IO.Stream"/> object to which the formatted properties are to be written.</param>
        public static void WriteServiceProperties(FileServiceProperties properties, Stream outputStream)
        {
            CommonUtility.AssertNotNull("properties", properties);

            properties.WriteServiceProperties(outputStream);
        }
 public Task SetServicePropertiesAsync(FileServiceProperties properties)