/// <summary> /// Refetch the answer to the provided <see cref="SurveyName"/> property in a copy of this node. /// </summary> /// <param name="surveyTree">The owning <see cref="SurveyTree{SurveyContextType}"/> container</param> /// <param name="contextElement">The parent element, or null for a root expansion context</param> /// <param name="survey">survey</param> /// <param name="questionTypes">types of the questions that are affected by the change</param> /// <returns>A new <see cref="SampleDataElementNode"/>. This node is not modified.</returns> public SampleDataElementNode UpdateAnswers(SurveyTree <SurveyContextType> surveyTree, object contextElement, Survey survey, Type[] questionTypes) { SampleDataElementNode node = new SampleDataElementNode(surveyTree, contextElement, myElement, myNodeData, myDisplayText, myCustomSortData, false); node.Update(questionTypes, contextElement, survey); return(node); }
/// <summary> /// Private constructor /// </summary> private SampleDataElementNode(SurveyTree <SurveyContextType> surveyTree, object contextElement, object element, int nodeData, string displayText, object customSortData, bool verifyReferences) { if (element == null) { throw new ArgumentNullException("element"); } myElement = element; myNodeData = nodeData; ISurveyNodeReference reference = element as ISurveyNodeReference; object referencedElement = (reference == null) ? null : reference.ReferencedElement; if (verifyReferences && referencedElement != null) { surveyTree.VerifyReferenceTarget(referencedElement); } if (displayText == null) { object textElement = element; ISurveyNode node = textElement as ISurveyNode; object resolvedReferencedElement = referencedElement; if (node == null || null == (displayText = node.SurveyName)) { do { if (null == resolvedReferencedElement || null == (node = (textElement = resolvedReferencedElement) as ISurveyNode) || null == (displayText = node.SurveyName)) { ISurveyNodeReference nextReference; if (null != (resolvedReferencedElement = (null != (nextReference = resolvedReferencedElement as ISurveyNodeReference)) ? nextReference.ReferencedElement : null)) { continue; } displayText = textElement.ToString(); break; } } while (displayText == null && resolvedReferencedElement != null); } } myDisplayText = displayText; myCustomSortData = customSortData; if (null == customSortData) { ICustomComparableSurveyNode customCompare = element as ICustomComparableSurveyNode; if (null != customCompare) { customCompare.ResetCustomSortData(contextElement, ref myCustomSortData); } } if (verifyReferences && referencedElement != null) { // Add a link relating the target element to this node. Note that we're fully constructed at this point Dictionary <object, LinkedNode <SurveyNodeReference> > links = surveyTree.myReferenceDictionary; SurveyNodeReference newReference = new SurveyNodeReference(this, contextElement); LinkedNode <SurveyNodeReference> firstLink = null; if (links.TryGetValue(referencedElement, out firstLink)) { LinkedNode <SurveyNodeReference> existingLink = firstLink; while (existingLink != null) { SurveyNodeReference testRef = existingLink.Value; if ((contextElement == null ? testRef.ContextElement == null : contextElement.Equals(testRef.ContextElement)) && element.Equals(testRef.Node.Element)) { existingLink.Value = newReference; return; } existingLink = existingLink.Next; } } LinkedNode <SurveyNodeReference> newLink = new LinkedNode <SurveyNodeReference>(newReference); newLink = new LinkedNode <SurveyNodeReference>(newReference); if (firstLink != null) { newLink.SetNext(firstLink, ref firstLink); } links[referencedElement] = newLink; } }
/// <summary> /// Refetch the current settings of the <see cref="SurveyName"/> property /// </summary> /// <param name="surveyTree">The owning <see cref="SurveyTree{SurveyContextType}"/> container</param> /// <param name="contextElement">The parent element, or null for a root expansion context</param> /// <param name="customSortData">Updated sort data</param> /// <returns>A new <see cref="SampleDataElementNode"/>. This node is not modified.</returns> public SampleDataElementNode UpdateCustomSortData(SurveyTree <SurveyContextType> surveyTree, object contextElement, object customSortData) { return(new SampleDataElementNode(surveyTree, contextElement, myElement, myNodeData, myDisplayText, customSortData, false)); }
/// <summary> /// Refetch the current settings of the <see cref="SurveyName"/> property /// </summary> /// <param name="surveyTree">The owning <see cref="SurveyTree{SurveyContextType}"/> container</param> /// <param name="contextElement">The parent element, or null for a root expansion context</param> /// <returns>A new <see cref="SampleDataElementNode"/>. This node is not modified.</returns> public SampleDataElementNode UpdateSurveyName(SurveyTree <SurveyContextType> surveyTree, object contextElement) { return(new SampleDataElementNode(surveyTree, contextElement, myElement, myNodeData, null, myCustomSortData, false)); }
/// <summary> /// Create a new <see cref="SampleDataElementNode"/> /// </summary> /// <param name="surveyTree">The owning <see cref="SurveyTree{SurveyContextType}"/> container</param> /// <param name="survey">The <see cref="Survey"/> this node is associated with</param> /// <param name="contextElement">The parent element, or null for a root expansion context</param> /// <param name="element">The element to create a node for</param> /// <returns>A fully initialized <see cref="SampleDataElementNode"/>.</returns> public static SampleDataElementNode Create(SurveyTree <SurveyContextType> surveyTree, Survey survey, object contextElement, object element) { return(new SampleDataElementNode(surveyTree, contextElement, element, InitializeNodeData(element, contextElement, survey), null, null, true)); }