Exemple #1
0
 /// <summary>
 /// Implements <see cref="ISurveyNodeReferenceDeletion.PreserveSurveyNodeReference"/>.
 /// By default, references to elements are preserved if the element is not deleted.
 /// </summary>
 protected bool PreserveSurveyNodeReference(ISurveyNodeReference reference)
 {
     return(!this.IsDeleted);
 }
Exemple #2
0
 bool ISurveyNodeReferenceDeletion.PreserveSurveyNodeReference(ISurveyNodeReference reference)
 {
     return(PreserveSurveyNodeReference(reference));
 }
Exemple #3
0
            /// <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;
                }
            }