public static async Task Lesson(DataServiceRestClient client) { await client.CreateParts(new[] { Part, SubPart }); await client.CreateCharacteristics(new[] { Characteristic, Child, SubChild }); //Depth null will result in a recursive search var result = await client.GetCharacteristics(Part.Path, null); Console.WriteLine($"Depth null: {result.Count()} characteristics"); //Depth 0 will return an empty list result = await client.GetCharacteristics(Part.Path, 0); Console.WriteLine($"Depth 0: {result.Count()} characteristics"); //Depth 1 will return the direct child characteristics result = await client.GetCharacteristics(Part.Path, 1); Console.WriteLine($"Depth 1: {result.Count()} characteristics"); //Depth 2 will return the direct children and their children, but not the children of subparts result = await client.GetCharacteristics(Part.Path, 2); Console.WriteLine($"Depth 2: {result.Count()} characteristics"); //Use UpdateParts and UpdateCharacteristics to rename entities, and modify their attributes Part.Path = PathHelper.RoundtripString2PathInformation("P:/PartName2/"); await client.UpdateParts(new[] { Part }); }
public static async Task Lesson(DataServiceRestClient client, RawDataServiceRestClient rawClient) { await client.CreateParts(new[] { Part }); //PiWeb only accepts binary data var data = Encoding.UTF8.GetBytes("Hello RawDataService!"); var target = RawDataTargetEntityDto.CreateForPart(Part.Uuid); //Notes: - see e.g. http://wiki.selfhtml.org/wiki/Referenz:MIME-Typen for a complete list of mime types // - When using Key = -1, the server will generate a new key. The generated key can be read from the result. var createdRawDataInfo = await rawClient.CreateRawData(new RawDataInformationDto { FileName = "Hello.txt", MimeType = "text/plain", Key = -1, Created = DateTime.Now, LastModified = DateTime.Now, MD5 = new Guid(MD5.Create().ComputeHash(data)), Size = data.Length, Target = target }, data); Console.WriteLine($"RawData created with key: {createdRawDataInfo.Key}"); //We can simply update raw data information like filename or MIME-type if (createdRawDataInfo.Key.HasValue) { createdRawDataInfo.FileName = "HelloEdit.txt"; Console.WriteLine($"Renaming raw data file to {createdRawDataInfo.FileName}"); await rawClient.UpdateRawDataInformation(target, createdRawDataInfo.Key.Value, createdRawDataInfo); } var rawDataInformation = await rawClient.ListRawData(new[] { target }); foreach (var information in rawDataInformation) { Console.WriteLine($"Fetching {information.FileName}: {information.Size} bytes"); //Fetch the data by providing the correct RawDataInformation data = await rawClient.GetRawData(information); Console.WriteLine($"Content: {Encoding.UTF8.GetString( data )}"); //We can use the key we found with the ListRawData function to delete a single file await rawClient.DeleteRawDataForPart(Part.Uuid, information.Key); } //Or we simply delete all raw data for a certain entity await rawClient.DeleteRawDataForPart(Part.Uuid); }
public static InspectionPlanPartDto GetOrCreatePart(DataServiceRestClient client, string name) { var parts = client.GetParts(PathInformationDto.Root, null, 1).Result; var existingPart = parts.FirstOrDefault(p => string.Equals(p.Path.Name, name)); if (existingPart == null) { existingPart = new InspectionPlanPartDto { Path = PathHelper.String2PartPathInformation(name), Uuid = Guid.NewGuid() }; client.CreateParts(new[] { existingPart }).Wait(); } return(existingPart); }
public static async Task Lesson(DataServiceRestClient client) { //Create the most commonly used attributes for measurement and measurement value var configuration = await client.GetConfiguration(); if (configuration.GetDefinition(EntityDto.Measurement, MeasurementAttributeDefinition.Key) == null) { await client.CreateAttributeDefinition(EntityDto.Measurement, MeasurementAttributeDefinition); } if (configuration.GetDefinition(EntityDto.Value, ValueAttributeDefinition.Key) == null) { await client.CreateAttributeDefinition(EntityDto.Value, ValueAttributeDefinition); } //Every measurement is attached to a part, and every value is attached to a characteristic await client.CreateParts(new[] { Part }); await client.CreateCharacteristics(new[] { Characteristic }); //The function 'CreateMeasurements' will create measurements without any values. You'll much more likely use the 'CreateMeasurementValues' function await client.CreateMeasurementValues(new[] { Measurement }); Value.Value = new DataValueDto(0.0) //This will result in an unmeasured characteristic, because the attribute array doesn't contain K1 { Attributes = new AttributeDto[] { } }; await client.UpdateMeasurementValues(new[] { Measurement }); Value.Value = new DataValueDto //this will work! { Attributes = new[] { new AttributeDto(ValueAttributeDefinition.Key, 0.5) } }; await client.UpdateMeasurementValues(new[] { Measurement }); var result = await client.GetMeasurementValues( PathInformationDto.Root, // Part where to search measurements new MeasurementValueFilterAttributesDto { AggregationMeasurements = AggregationMeasurementSelectionDto.All, // Decide how to include aggregated measurements in your query CharacteristicsUuidList = null, // Use characteristic uuids to fetch single measurement values Deep = true, // A deep search will find measurements recursively below the start path FromModificationDate = null, // Will only search measurements with a modification date (LastModified) newer than the specified one ToModificationDate = null, // Will only search measurements with a modification date (LastModified) older than the specified one LimitResult = 10, // Will limit the number of returned measurements MeasurementUuids = null, // Use measurement uuids to search for specific measurements OrderBy = new[] // Order the returned measurements by specific attributes { new OrderDto(WellKnownKeys.Measurement.Time, OrderDirectionDto.Asc, EntityDto.Measurement) }, RequestedMeasurementAttributes = null, // Specify, which measurement attributes should be returned (default: all) RequestedValueAttributes = null, // Specify, which value attributes should be returned (default: all) SearchCondition = new GenericSearchAttributeConditionDto // You can create more complex attribute conditions using the GenericSearchAnd, GenericSearchOr and GenericSearchNot class { Attribute = WellKnownKeys.Measurement.Time, //Only measurement attributes are supported Operation = OperationDto.GreaterThan, Value = XmlConvert.ToString(DateTime.UtcNow - TimeSpan.FromDays(2), XmlDateTimeSerializationMode.Utc) } }); foreach (var measurement in result) { Console.WriteLine(measurement.ToString()); } }