Example #1
0
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds the current item to the solution, if it is valid
 /// and not already present in the solution.</summary>
 ///
 /// <param name="solutionContext">The associated solution.</param>
 /// <param name="templateContext">The associated template.</param>
 /// <param name="lineNumber">The line number of the associated statement.</param>
 ///--------------------------------------------------------------------------------
 public static void AddCurrentItemToSolution(Solution solutionContext, ITemplate templateContext, int lineNumber)
 {
     if (solutionContext.CurrentPropertyRelationship != null)
     {
         string validationErrors = solutionContext.CurrentPropertyRelationship.GetValidationErrors();
         if (!String.IsNullOrEmpty(validationErrors))
         {
             templateContext.LogException(solutionContext, solutionContext.CurrentPropertyRelationship, validationErrors, lineNumber, InterpreterTypeCode.Output);
         }
         // link item to known id, solution, and parent
         solutionContext.CurrentPropertyRelationship.Solution = solutionContext;
         solutionContext.CurrentPropertyRelationship.AddToParent();
         PropertyRelationship existingItem = solutionContext.PropertyRelationshipList.Find(i => i.PropertyRelationshipID == solutionContext.CurrentPropertyRelationship.PropertyRelationshipID);
         if (existingItem == null)
         {
             // add new item to solution
             solutionContext.CurrentPropertyRelationship.AssignProperty("PropertyRelationshipID", solutionContext.CurrentPropertyRelationship.PropertyRelationshipID);
             solutionContext.CurrentPropertyRelationship.ReverseInstance.ResetModified(false);
             solutionContext.PropertyRelationshipList.Add(solutionContext.CurrentPropertyRelationship);
         }
         else
         {
             // update existing item in solution
             if (existingItem.Solution == null)
             {
                 existingItem.Solution = solutionContext;
             }
             if (existingItem.ForwardInstance == null && existingItem.IsAutoUpdated == false)
             {
                 existingItem.ForwardInstance = new PropertyRelationship();
                 existingItem.ForwardInstance.TransformDataFromObject(existingItem, null, false);
             }
             existingItem.TransformDataFromObject(solutionContext.CurrentPropertyRelationship, null, false);
             existingItem.AddToParent();
             existingItem.AssignProperty("PropertyRelationshipID", existingItem.PropertyRelationshipID);
             existingItem.ReverseInstance.ResetModified(false);
             solutionContext.CurrentPropertyRelationship = existingItem;
         }
         #region protected
         PropertyReference parentProperty = solutionContext.PropertyReferenceList.FindByID(solutionContext.CurrentPropertyRelationship.PropertyID);
         if (parentProperty != null)
         {
             solutionContext.CurrentPropertyRelationship.PropertyBase = parentProperty;
             parentProperty.PropertyRelationshipList.Add(solutionContext.CurrentPropertyRelationship);
         }
         else
         {
             Collection parentProperty2 = solutionContext.CollectionList.FindByID(solutionContext.CurrentPropertyRelationship.PropertyID);
             if (parentProperty2 != null)
             {
                 solutionContext.CurrentPropertyRelationship.PropertyBase = parentProperty2;
                 parentProperty2.PropertyRelationshipList.Add(solutionContext.CurrentPropertyRelationship);
             }
             else
             {
                 EntityReference parentProperty3 = solutionContext.EntityReferenceList.FindByID(solutionContext.CurrentPropertyRelationship.PropertyID);
                 if (parentProperty3 != null)
                 {
                     solutionContext.CurrentPropertyRelationship.PropertyBase = parentProperty3;
                     parentProperty3.PropertyRelationshipList.Add(solutionContext.CurrentPropertyRelationship);
                 }
             }
         }
         #endregion protected
     }
 }