/// <summary> /// Creates a copy of this <see cref="InputGroup"/>. /// </summary> /// <returns>The copy.</returns> /// <param name="newId">If set to <c>true</c>, set new random <see cref="Id"/> and <see cref="Input.Id"/> values for the current group /// and <see cref="Input"/>s associated with this <see cref="InputGroup"/>.</param> public InputGroup Copy(bool newId) { InputGroup copy = JsonConvert.DeserializeObject <InputGroup>(JsonConvert.SerializeObject(this, SensusServiceHelper.JSON_SERIALIZER_SETTINGS), SensusServiceHelper.JSON_SERIALIZER_SETTINGS); if (newId) { copy.Id = Guid.NewGuid().ToString(); // update all inputs to have the new group ID and new IDs themselves. foreach (Input input in copy.Inputs) { input.GroupId = copy.Id; input.Id = Guid.NewGuid().ToString(); } } return(copy); }
/// <summary> /// Initializes a new instance of the <see cref="T:Sensus.UI.Inputs.InputGroup"/> class as a copy of another. WARNING: You must call /// UpdateDisplayConditionInputs on the resulting object to ensure that all display conditions are properly set up. /// </summary> public InputGroup(InputGroup inputGroup, bool newGroupId) { Id = inputGroup.Id; Name = inputGroup.Name; Geotag = inputGroup.Geotag; ForceValidInputs = inputGroup.ForceValidInputs; ShuffleInputs = inputGroup.ShuffleInputs; Inputs = JsonConvert.DeserializeObject <ObservableCollection <Input> >(JsonConvert.SerializeObject(inputGroup.Inputs, SensusServiceHelper.JSON_SERIALIZER_SETTINGS), SensusServiceHelper.JSON_SERIALIZER_SETTINGS); if (newGroupId) { Id = Guid.NewGuid().ToString(); // update all inputs to have the new group ID. because we are creating a new group, all inputs should get new IDs to break // all connections with the passed-in group. foreach (Input input in Inputs) { input.GroupId = Id; input.Id = Guid.NewGuid().ToString(); } } }