private Task UploadRawData(RawDataInformation info, Stream data, HttpMethod method, CancellationToken cancellationToken)
        {
            if (info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair(info.Target.Uuid))
            {
                throw new ArgumentOutOfRangeException("info", "The uuid string for uploading raw data for measurement value needs 2 uuids in the format: {measurementUuid}|{characteristicUuid}");
            }

            if (String.IsNullOrEmpty(info.FileName))
            {
                throw new ArgumentException("FileName needs to be set.", "info");
            }

            var requestString = info.Key >= 0
                                ? string.Format("rawData/{0}/{1}/{2}", info.Target.Entity, info.Target.Uuid, info.Key)
                                : string.Format("rawData/{0}/{1}", info.Target.Entity, info.Target.Uuid);

            if (method.Equals(HttpMethod.Post))
            {
                return(Post(requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName));
            }

            if (method.Equals(HttpMethod.Put))
            {
                return(Put(requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName));
            }

            throw new ArgumentOutOfRangeException("method");
        }
 /// <summary>
 /// Updates the raw data object <paramref name="data"/> for the element identified by <paramref name="info"/>.
 /// </summary>
 /// <param name="data">The raw data to upload.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be updated.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task UpdateRawData(RawDataInformation info, byte[] data, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (info.Key < 0)
     {
         throw new InvalidOperationException("Unable to update raw data object: A key must be specified.");
     }
     return(UploadRawData(info, new MemoryStream(data, 0, data.Length, false, true), HttpMethod.Put, cancellationToken));
 }
 /// <summary>
 /// Updates the raw data object <paramref name="data"/> for the element identified in <paramref name="info"/>.
 /// </summary>
 /// <param name="data">The raw data to be uploaded.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be updated.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task UpdateRawData(RawDataInformation info, Stream data, CancellationToken cancellationToken = default(CancellationToken))
 {
     if (info.Key < 0)
     {
         throw new InvalidOperationException("Unable to update raw data object: A key must be specified.");
     }
     return(UploadRawData(info, data, HttpMethod.Put, cancellationToken));
 }
        /// <summary>
        /// Copy-Constructor.
        /// </summary>
        /// <param name="data">The raw data information object that should be copied.</param>
        public RawDataInformation( RawDataInformation data )
        {
            if( data == null ) throw new ArgumentNullException( "data" );

            Target = data.Target;
            Key = data.Key;
            FileName = data.FileName;
            MimeType = data.MimeType;
            LastModified = data.LastModified;
            Size = data.Size;
            MD5 = data.MD5;
        }
        /// <summary>
        /// Deletes raw data for the element identified by <paramref name="info"/>.
        /// </summary>
        /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be deleted.</param>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public Task DeleteRawData(RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair(info.Target.Uuid))
            {
                throw new ArgumentOutOfRangeException("info", "The uuid string for uploading raw data for measurement value needs two uuids in the format: {measurementUuid}|{characteristicUuid}");
            }

            var url = info.Key >= 0
                                ? string.Format("rawData/{0}/{{{1}}}/{2}", info.Target.Entity, info.Target.Uuid, info.Key)
                                : string.Format("rawData/{0}/{{{1}}}", info.Target.Entity, info.Target.Uuid);

            return(Delete(url, cancellationToken));
        }
Example #6
0
        /// <summary>
        /// Copy-Constructor.
        /// </summary>
        /// <param name="data">The raw data information object that should be copied.</param>
        public RawDataInformation(RawDataInformation data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Target       = data.Target;
            Key          = data.Key;
            FileName     = data.FileName;
            MimeType     = data.MimeType;
            LastModified = data.LastModified;
            Size         = data.Size;
            MD5          = data.MD5;
        }
 /// <summary>
 /// Fetches a preview image for the specified <code>info</code>.
 /// </summary>
 /// <param name="info">The <see cref="RawDataInformation"/> that identifies the raw data object to fetch the preview image for.</param>
 /// <returns>The preview image as stream.</returns>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public async Task <Stream> GetRawDataThumbnailStream(RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken))
 {
     try
     {
         return(await GetStream(string.Format("rawData/{0}/{1}/{2}/thumbnail", info.Target.Entity, info.Target.Uuid, info.Key),
                                cancellationToken).ConfigureAwait(false));
     }
     catch (WrappedServerErrorException ex)
     {
         if (ex.StatusCode != HttpStatusCode.NotFound)
         {
             throw;
         }
     }
     return(null);
 }
Example #8
0
		/// <summary>
		/// This method fetches additional data for the selected part. For demonstration purposes only the additional data for parts are fetched.
		/// However, additional data can be stored for parts, characteristics, measurements and also for values.
		/// When presenting a list of raw data entries please consider to fetch a thumbnail picture for each entry using the method 
		/// <see cref="RawDataServiceRestClient.GetRawDataThumbnail"/>.
		/// </summary>
		private async Task<RawDataInformation[]> FetchAdditionalDataListForPart( Guid partUuid )
		{
			_RawDataListView.Items.Clear();
			var rawDataInformation = new RawDataInformation[0];
			try
			{
				LogMessage( "Fetching additional data for part with uuid '{0}' from raw data service.", partUuid );

				var sw = System.Diagnostics.Stopwatch.StartNew();
				rawDataInformation = await _RestRawDataServiceClient.ListRawDataForParts( new[] { partUuid } );
				
				sw.Stop();

				LogMessage( "Successfully fetched {1} additional data from data service in {0} ms.\r\n", sw.ElapsedMilliseconds, rawDataInformation.Length );
			}
			catch( Exception ex )
			{
				LogMessage( "Error fetching additional data for part with uuid '{0}' from data service: '{1}'.\r\n", partUuid, ex.Message );
			}

			_RawDataListView.BeginUpdate();
			foreach( var rawDataInfo in rawDataInformation.OrderBy( p => p.FileName.ToString() ) )
			{
				_RawDataListView.Items.Add( CreateListViewItem( rawDataInfo ) );
			}
			_RawDataListView.EndUpdate();
			return rawDataInformation;
		}
Example #9
0
		private ListViewItem CreateListViewItem( RawDataInformation info )
		{
			var subItems = new[]
			{
				info.FileName,
				info.MimeType,
				info.Created.ToLocalTime().ToString( CultureInfo.CurrentCulture ),
				info.Size.ToString( "N0" )
			};

			return new ListViewItem( subItems ) { Tag = info };
		}
		/// <summary> 
		/// Creates a new raw data object <paramref name="data"/> for the element specified by <paramref name="info"/>. 
		/// </summary>
		/// <param name="data">The raw data to upload.</param>
		/// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be uploaded.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		/// <remarks>
		/// If key speciefied by <see cref="RawDataInformation.Key"/> is -1, a new key will be chosen by the server automatically. This is the preferred way.
		/// </remarks>
		public Task CreateRawData( RawDataInformation info, byte[] data, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			return UploadRawData( info, new MemoryStream( data, 0, data.Length, false, true ), HttpMethod.Post, cancellationToken );
		}
		/// <summary> 
		/// Creates a new raw data object <paramref name="data"/> for the element identified by <paramref name="info"/>. 
		/// </summary>
		/// <param name="data">The raw data to upload.</param>
		/// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be uploaded.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		/// <remarks>
		/// If key speciefied by <see cref="RawDataInformation.Key"/> is -1, a new key will be chosen by the server automatically. This is the preferred way.
		/// </remarks>
		public Task CreateRawData( RawDataInformation info, Stream data, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			return UploadRawData( info, data, HttpMethod.Post, cancellationToken );
		}
		/// <summary>
		/// Updates the raw data object <paramref name="data"/> for the element identified in <paramref name="info"/>.
		/// </summary>
		/// <param name="data">The raw data to be uploaded.</param>
		/// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be updated.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task UpdateRawData( RawDataInformation info, Stream data, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			if( info.Key < 0 )
				throw new InvalidOperationException( "Unable to update raw data object: A key must be specified." );
			return UploadRawData( info, data, HttpMethod.Put, cancellationToken );
		}
		/// <summary> 
		/// Updates the raw data object <paramref name="data"/> for the element identified by <paramref name="info"/>. 
		/// </summary>
		/// <param name="data">The raw data to upload.</param>
		/// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be updated.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task UpdateRawData( RawDataInformation info, byte[] data, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			if( info.Key < 0 )
				throw new InvalidOperationException( "Unable to update raw data object: A key must be specified." );
			return UploadRawData( info, new MemoryStream( data, 0, data.Length, false, true ), HttpMethod.Put, cancellationToken );
		}
 /// <summary>
 /// Creates a new raw data object <paramref name="data"/> for the element specified by <paramref name="info"/>.
 /// </summary>
 /// <param name="data">The raw data to upload.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be uploaded.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 /// <remarks>
 /// If key speciefied by <see cref="RawDataInformation.Key"/> is -1, a new key will be chosen by the server automatically. This is the preferred way.
 /// </remarks>
 public Task CreateRawData(RawDataInformation info, byte[] data, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UploadRawData(info, new MemoryStream(data, 0, data.Length, false, true), HttpMethod.Post, cancellationToken));
 }
		/// <summary> 
		/// Fetches a preview image for the specified <code>info</code>. 
		/// </summary>
		/// <param name="info">The <see cref="RawDataInformation"/> that identifies the raw data object to fetch the preview image for.</param>
		/// <returns>The preview image as stream.</returns>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public async Task<Stream> GetRawDataThumbnailStream( RawDataInformation info, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			try
			{
				return await GetStream( string.Format( "rawData/{0}/{1}/{2}/thumbnail", info.Target.Entity, info.Target.Uuid, info.Key ),
					cancellationToken ).ConfigureAwait( false );
			}
			catch( WrappedServerErrorException ex )
			{
				if( ex.StatusCode != HttpStatusCode.NotFound )
					throw;
			}
			return null;
		}
		private Task UploadRawData( RawDataInformation info, Stream data, HttpMethod method, CancellationToken cancellationToken )
		{
			if( info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair( info.Target.Uuid ) )
				throw new ArgumentOutOfRangeException( "info", "The uuid string for uploading raw data for measurement value needs 2 uuids in the format: {measurementUuid}|{characteristicUuid}" );

			if( String.IsNullOrEmpty( info.FileName ) )
				throw new ArgumentException( "FileName needs to be set.", "info" );

			var requestString = info.Key >= 0
				? string.Format( "rawData/{0}/{1}/{2}", info.Target.Entity, info.Target.Uuid, info.Key )
				: string.Format( "rawData/{0}/{1}", info.Target.Entity, info.Target.Uuid );

			if( method.Equals( HttpMethod.Post ) )
				return Post( requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName );

			if( method.Equals( HttpMethod.Put ) )
				return Put( requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName );

			throw new ArgumentOutOfRangeException( "method" );
		}
 /// <summary>
 /// Fetches raw data as a stream for the raw data item identified by <paramref name="info"/>.
 /// </summary>
 /// <param name="info">The <see cref="RawDataInformation"/> that specifies the raw data object that should be fetched.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task <Stream> GetRawDataStream(RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(GetStream(string.Format("rawData/{0}/{1}/{2}", info.Target.Entity, info.Target.Uuid, info.Key),
                      cancellationToken));
 }
		/// <summary>
		/// Deletes raw data for the element identified by <paramref name="info"/>.
		/// </summary>
		/// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be deleted.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task DeleteRawData( RawDataInformation info, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			if( info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair( info.Target.Uuid ) )
				throw new ArgumentOutOfRangeException( "info", "The uuid string for uploading raw data for measurement value needs two uuids in the format: {measurementUuid}|{characteristicUuid}" );

			var url = info.Key >= 0
				? string.Format( "rawData/{0}/{{{1}}}/{2}", info.Target.Entity, info.Target.Uuid, info.Key )
				: string.Format( "rawData/{0}/{{{1}}}", info.Target.Entity, info.Target.Uuid );

			return Delete( url, cancellationToken );
		}
 /// <summary>
 /// Creates a new raw data object <paramref name="data"/> for the element identified by <paramref name="info"/>.
 /// </summary>
 /// <param name="data">The raw data to upload.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be uploaded.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 /// <remarks>
 /// If key speciefied by <see cref="RawDataInformation.Key"/> is -1, a new key will be chosen by the server automatically. This is the preferred way.
 /// </remarks>
 public Task CreateRawData(RawDataInformation info, Stream data, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UploadRawData(info, data, HttpMethod.Post, cancellationToken));
 }
		/// <summary>
		/// Fetches raw data as a stream for the raw data item identified by <paramref name="info"/>. 
		/// </summary>
		/// <param name="info">The <see cref="RawDataInformation"/> that specifies the raw data object that should be fetched.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task<Stream> GetRawDataStream( RawDataInformation info, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			return GetStream( string.Format( "rawData/{0}/{1}/{2}", info.Target.Entity, info.Target.Uuid, info.Key ),
				cancellationToken );
		}