/// <summary> /// Updates a custom material property. /// </summary> /// <param name="name">The new name to set.</param> /// <returns>Returns the updated prop.</returns> /// <exception cref="CustomPropNotFoundException">Thrown if no matching prop could be found.</exception> public CustomMaterialProp UpdateCustomMaterialProp(Guid id, string name) { CustomMaterialProp prop = GetCustomMaterialPropOrThrowNotFoundException(id); prop.Name = name; PropRepository.UpdateCustomMaterialProp(prop); return(prop); }
/// <summary> /// Attempts to get a material prop from the underlying repository and throws a <see cref="CustomPropNotFoundException"/> if no matching prop could be found. /// </summary> /// <param name="id">ID of the prop to get.</param> /// <exception cref="CustomPropNotFoundException">Thrown if no matching prop could be found.</exception> /// <returns>Returns the prop, if found.</returns> private CustomMaterialProp GetCustomMaterialPropOrThrowNotFoundException(Guid id) { CustomMaterialProp prop = PropRepository.GetCustomMaterialProp(id); // Check for prop existence if (prop == null) { throw new CustomPropNotFoundException(id); } return(prop); }
public void TestCustomMaterialPropValues() { // Create materials Material m1 = Repository.CreateMaterial("m1", "Alpha", "alpha-m1", PC); Material m2 = Repository.CreateMaterial("m2", "Alpha", "alpha-m2", PE); Material m3 = Repository.CreateMaterial("m3", "Beta", "beta-m1", PC); // Create custom props CustomMaterialProp textProp = PropRepository.CreateCustomMaterialProp("test", PropType.Text); CustomMaterialProp fileProp = PropRepository.CreateCustomMaterialProp("file", PropType.Text); // Test getters with no prop values IEnumerable <Material> materials = Repository.GetAllMaterials(); Assert.Equal(3, materials.Count()); Assert.Empty(materials.Where(m => m.CustomProps.Count > 0)); // Set custom prop values PropValueRepository.SetCustomTextMaterialProp(m1.Id, textProp.Id, "Lorem Ipsum"); PropValueRepository.SetCustomFileMaterialProp(m1.Id, fileProp.Id, "Z:/my-files/file.pdf"); PropValueRepository.SetCustomFileMaterialProp(m2.Id, fileProp.Id, "X:/formatc.cmd"); // Test custom prop values materials = Repository.GetAllMaterials(); m1 = materials.Single(m => m.Name == "m1"); m2 = materials.Single(m => m.Name == "m2"); m3 = materials.Single(m => m.Name == "m3"); Assert.Equal(2, m1.CustomProps.Count); Assert.Single(m2.CustomProps); Assert.Empty(m3.CustomProps); Assert.Single(m1.CustomProps.Where(p => p.PropId == textProp.Id && (string)p.Value == "Lorem Ipsum")); Assert.Single(m1.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "Z:/my-files/file.pdf")); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "X:/formatc.cmd")); // Overwrite custom prop value PropValueRepository.SetCustomTextMaterialProp(m1.Id, textProp.Id, "Foo Bar"); m1 = Repository.GetMaterial(m1.Id); Assert.Equal(2, m1.CustomProps.Count); Assert.Empty(m1.CustomProps.Where(p => p.PropId == textProp.Id && (string)p.Value == "Lorem Ipsum")); Assert.Single(m1.CustomProps.Where(p => p.PropId == textProp.Id && (string)p.Value == "Foo Bar")); Assert.Single(m1.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "Z:/my-files/file.pdf")); // Add second text prop CustomMaterialProp textProp2 = PropRepository.CreateCustomMaterialProp("troll", PropType.Text); PropValueRepository.SetCustomTextMaterialProp(m1.Id, textProp2.Id, "Ak Bars"); m1 = Repository.GetMaterial(m1.Id); Assert.Equal(3, m1.CustomProps.Count); Assert.Single(m1.CustomProps.Where(p => p.PropId == textProp.Id && (string)p.Value == "Foo Bar")); Assert.Single(m1.CustomProps.Where(p => p.PropId == textProp2.Id && (string)p.Value == "Ak Bars")); Assert.Single(m1.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "Z:/my-files/file.pdf")); // Add second file prop CustomMaterialProp fileProp2 = PropRepository.CreateCustomMaterialProp("super-file", PropType.Text); PropValueRepository.SetCustomTextMaterialProp(m2.Id, fileProp2.Id, "F:/ile/path"); m2 = Repository.GetMaterial(m2.Id); Assert.Equal(2, m2.CustomProps.Count); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "X:/formatc.cmd")); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp2.Id && (string)p.Value == "F:/ile/path")); // Check getAll again materials = Repository.GetAllMaterials(); m1 = materials.Single(m => m.Name == "m1"); m2 = materials.Single(m => m.Name == "m2"); m3 = materials.Single(m => m.Name == "m3"); Assert.Equal(3, m1.CustomProps.Count); Assert.Equal(2, m2.CustomProps.Count); Assert.Empty(m3.CustomProps); // Check getter with filters materials = Repository.GetFilteredMaterials(null, "alpha", PE); Assert.Single(materials); m2 = materials.Single(); Assert.Equal(2, m2.CustomProps.Count); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "X:/formatc.cmd")); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp2.Id && (string)p.Value == "F:/ile/path")); // Test removal of prop values PropValueRepository.RemoveCustomTextMaterialProp(m1.Id, textProp.Id); PropValueRepository.RemoveCustomFileMaterialProp(m2.Id, fileProp.Id); m1 = Repository.GetMaterial(m1.Id); m2 = Repository.GetMaterial(m2.Id); Assert.Equal(2, m1.CustomProps.Count); Assert.Single(m1.CustomProps.Where(p => p.PropId == textProp2.Id && (string)p.Value == "Ak Bars")); Assert.Single(m1.CustomProps.Where(p => p.PropId == fileProp.Id && (string)p.Value == "Z:/my-files/file.pdf")); Assert.Single(m2.CustomProps); Assert.Single(m2.CustomProps.Where(p => p.PropId == fileProp2.Id && (string)p.Value == "F:/ile/path")); }
/// <summary> /// Deletes a custom material property. /// </summary> /// <param name="id">The ID of the prop to delete.</param> public void DeleteCustomMaterialProp(Guid id) { PropRepository.DeleteCustomMaterialProp(id); }
/// <summary> /// Creates a custom material property. /// </summary> /// <param name="name">The property's name.</param> /// <param name="type">The property's type.</param> /// <returns>Returns the newly created prop.</returns> public CustomMaterialProp CreateCustomMaterialProp(string name, PropType type) { return(PropRepository.CreateCustomMaterialProp(name, type)); }
/// <summary> /// Gets all custom material properties. /// </summary> /// <returns>Returns a list of props.</returns> public IEnumerable <CustomMaterialProp> GetAllCustomMaterialProps() { return(PropRepository.GetAllCustomMaterialProps()); }
/// <summary> /// Deletes a custom batch property. /// </summary> /// <param name="id">The ID of the prop to delete.</param> public void DeleteCustomBatchProp(Guid id) { PropRepository.DeleteCustomBatchProp(id); }
/// <summary> /// Creates a custom batch property. /// </summary> /// <param name="name">The property's name.</param> /// <returns>Returns the newly created prop.</returns> public CustomBatchProp CreateCustomBatchProp(string name) { return(PropRepository.CreateCustomBatchProp(name)); }
/// <summary> /// Gets all custom batch properties. /// </summary> /// <returns>Returns a list of props.</returns> public IEnumerable <CustomBatchProp> GetAllCustomBatchProps() { return(PropRepository.GetAllCustomBatchProps()); }