Skip to content

Commit 1675036

Browse files
authored
Merge pull request #36 from M-Files/arrayElementGuid
Added section on array element guid
2 parents 8d4ca08 + 55e993f commit 1675036

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

  • Frameworks/Vault-Application-Framework/Configuration/Hierarchical-Configuration

Frameworks/Vault-Application-Framework/Configuration/Hierarchical-Configuration/index.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,92 @@ namespace MFVaultApplication1
4444
}
4545
{% endhighlight %}
4646

47+
## Array Element Guid
48+
49+
When working with collections it is important that each collection member has an ID which can be used to subsequently refer to the member. This is used when saving the configuration, for example, to understand what has changed. If you do not include this member then the system may not correctly persist passwords, or may require system-administrator permission to save the configuration, even if only vault-admin level is required for the changed elements.
50+
51+
This can be done in two ways: either by adding a member to the class in the collection, or by inheriting from the [ConfigurationCollectionItemBase](https://github.com/M-Files/VAF.Extensions.Community/blob/master/MFiles.VAF.Extensions/Configuration/ConfigurationCollectionItemBase.cs) class in the VAF Extensions library.
52+
53+
### Using the VAF Extensions
54+
55+
Ensure that your configuration item class inherits from the correct base class:
56+
57+
```csharp
58+
[DataContract]
59+
public class Configuration
60+
{
61+
[DataMember]
62+
public ConfigurationChild MySubConfiguration { get; set; }
63+
64+
[DataMember]
65+
public List<ConfigurationChild> Children { get; set; }
66+
}
67+
68+
[DataContract]
69+
public class ConfigurationChild
70+
: MFiles.VAF.Extensions.Configuration.ConfigurationCollectionItemBase
71+
{
72+
[DataMember]
73+
public string Value1 { get; set; }
74+
75+
[DataMember]
76+
[TextEditor(IsRequired = true)]
77+
public string Name { get; set; }
78+
}
79+
80+
public class VaultApplication
81+
: ConfigurableVaultApplicationBase<Configuration>
82+
{
83+
}
84+
85+
```
86+
87+
### Implementing manually
88+
89+
Add an item to the class with the following signature (`arrayElementGuid`):
90+
91+
```csharp
92+
93+
[DataContract]
94+
public class Configuration
95+
{
96+
[DataMember]
97+
public ConfigurationChild MySubConfiguration { get; set; }
98+
99+
[DataMember]
100+
public List<ConfigurationChild> Children { get; set; }
101+
}
102+
103+
[DataContract]
104+
public class ConfigurationChild
105+
{
106+
[DataMember]
107+
public string Value1 { get; set; }
108+
109+
[DataMember]
110+
[TextEditor(IsRequired = true)]
111+
public string Name { get; set; }
112+
113+
[DataMember(Name = "arrayElementGuid", EmitDefaultValue = false, Order = 99)]
114+
[JsonConfEditor
115+
(
116+
TypeEditor = "guid",
117+
Hidden = true,
118+
IsRequired = true,
119+
ClearOnCopy = true
120+
)]
121+
public string ArrayElementGuid { get; set; }
122+
= System.Guid.NewGuid().ToString();
123+
124+
}
125+
126+
public class VaultApplication
127+
: ConfigurableVaultApplicationBase<Configuration>
128+
{
129+
}
130+
131+
```
132+
47133
## Customising array element names
48134

49135
In the example screenshot above, adding new items to the `Children` collection results in items being added named `ConfigurationChild[1]`, `ConfigurationChild[1]`, etc. In some situations, it is more useful to show a different value for the item name to make locating the correct item more simple.
@@ -79,6 +165,17 @@ namespace MFVaultApplication1
79165
[DataMember]
80166
[TextEditor(IsRequired = true)]
81167
public string Name { get; set; }
168+
169+
[DataMember(Name = "arrayElementGuid", EmitDefaultValue = false, Order = 99)]
170+
[JsonConfEditor
171+
(
172+
TypeEditor = "guid",
173+
Hidden = true,
174+
IsRequired = true,
175+
ClearOnCopy = true
176+
)]
177+
public string ArrayElementGuid { get; set; }
178+
= System.Guid.NewGuid().ToString();
82179
}
83180

84181
public class VaultApplication
@@ -118,6 +215,17 @@ namespace MFVaultApplication1
118215
[DataMember]
119216
[TextEditor(IsRequired = true)]
120217
public string NameProperty { get; set; }
218+
219+
[DataMember(Name = "arrayElementGuid", EmitDefaultValue = false, Order = 99)]
220+
[JsonConfEditor
221+
(
222+
TypeEditor = "guid",
223+
Hidden = true,
224+
IsRequired = true,
225+
ClearOnCopy = true
226+
)]
227+
public string ArrayElementGuid { get; set; }
228+
= System.Guid.NewGuid().ToString();
121229
}
122230

123231
public class VaultApplication

0 commit comments

Comments
 (0)