///-------------------------------------------------------------------------------- /// <summary>This method assigns a value to a property, and updates corresponding /// forward and reverse engineering data.</summary> /// /// <param name="propertyName">The property name.</param> /// <param name="propertyValue">The property value.</param> ///-------------------------------------------------------------------------------- public virtual bool AssignProperty(string propertyName, object propertyValue) { if (this.SetPropertyValue(propertyName, propertyValue) == true) { if (ReverseInstance == null) { ReverseInstance = new IndexProperty(); ReverseInstance.TransformDataFromObject(this, null, false); } else { ReverseInstance.SetPropertyValue(propertyName, propertyValue); } if (ForwardInstance != null) { this.TransformDataFromObject(ForwardInstance, null, false, true); } } else { return(false); } #region protected #endregion protected return(true); }
///-------------------------------------------------------------------------------- /// <summary>This method determines whether or not any metadata is /// different between the input instance and the current instance.</summary> /// /// <param name="inputIndexProperty">The indexproperty to compare metadata.</param> ///-------------------------------------------------------------------------------- public bool IsIdenticalMetadata(IndexProperty inputIndexProperty) { if (IndexID.GetGuid() != inputIndexProperty.IndexID.GetGuid()) { return(false); } if (PropertyID.GetGuid() != inputIndexProperty.PropertyID.GetGuid()) { return(false); } if (Order.GetInt() != inputIndexProperty.Order.GetInt()) { return(false); } if (IsAutoUpdated.GetBool() != inputIndexProperty.IsAutoUpdated.GetBool()) { return(false); } if (Description.GetString() != inputIndexProperty.Description.GetString()) { return(false); } #region protected #endregion protected return(true); }
///-------------------------------------------------------------------------------- /// <summary>This method copies changed metadata between the input /// instance and the current instance.</summary> /// /// <param name="inputIndexProperty">The indexproperty to get metadata.</param> ///-------------------------------------------------------------------------------- public void CopyChangedMetadata(IndexProperty inputIndexProperty) { IndexID = inputIndexProperty.IndexID; PropertyID = inputIndexProperty.PropertyID; Order = inputIndexProperty.Order; IsAutoUpdated = inputIndexProperty.IsAutoUpdated; Description = inputIndexProperty.Description; #region protected #endregion protected }
///-------------------------------------------------------------------------------- /// <summary>This method deletes the current IndexProperty item from the solution.</summary> /// /// <param name="solutionContext">The associated solution.</param> ///-------------------------------------------------------------------------------- public static void DeleteCurrentItemFromSolution(Solution solutionContext) { if (solutionContext.CurrentIndexProperty != null) { IndexProperty existingItem = solutionContext.IndexPropertyList.Find(i => i.IndexPropertyID == solutionContext.CurrentIndexProperty.IndexPropertyID); if (existingItem != null) { solutionContext.IndexPropertyList.Remove(solutionContext.CurrentIndexProperty); } } }
///-------------------------------------------------------------------------------- /// <summary>This method adds a tag to TagList.</summary> ///-------------------------------------------------------------------------------- public override void AddTag(string tagName) { if (ReverseInstance == null && IsAutoUpdated == true) { ReverseInstance = new IndexProperty(); ReverseInstance.TransformDataFromObject(this, null, false); IsAutoUpdated = false; } base.AddTag(tagName); if (ForwardInstance == null) { ForwardInstance = new IndexProperty(); ForwardInstance.IndexPropertyID = IndexPropertyID; } if (ForwardInstance.TagList.Find(t => t.TagName == tagName) == null) { ForwardInstance.TagList.Add(new Tag(Guid.NewGuid(), tagName)); } }
///-------------------------------------------------------------------------------- /// <summary>This property returns a copy of the forward engineering data for the solution.</summary> ///-------------------------------------------------------------------------------- public IndexProperty GetForwardInstance(Solution forwardSolution) { bool isCustomized = false; IndexProperty forwardItem = new IndexProperty(); if (ForwardInstance != null) { forwardItem.TransformDataFromObject(ForwardInstance, null, false); isCustomized = true; } else if (IsAutoUpdated == false) { forwardItem.TransformDataFromObject(this, null, false); isCustomized = true; } else { forwardItem.IndexPropertyID = IndexPropertyID; } if (isCustomized == false) { return(null); } forwardItem.SpecSourceName = DefaultSourceName; if (forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.SpecSourceName) == null) { forwardSolution.ReferencedModelIDs.Add(CreateIDReference()); } #region protected if (forwardItem.PropertyID != Guid.Empty) { forwardItem.Property = Solution.PropertyList.FindByID(forwardItem.PropertyID); if (forwardItem.Property != null && forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.Property.DefaultSourceName) == null) { forwardSolution.ReferencedModelIDs.Add(forwardItem.Property.CreateIDReference()); } } #endregion protected return(forwardItem); }
///-------------------------------------------------------------------------------- /// <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.CurrentIndexProperty != null) { string validationErrors = solutionContext.CurrentIndexProperty.GetValidationErrors(); if (!String.IsNullOrEmpty(validationErrors)) { templateContext.LogException(solutionContext, solutionContext.CurrentIndexProperty, validationErrors, lineNumber, InterpreterTypeCode.Output); } // link item to known id, solution, and parent solutionContext.CurrentIndexProperty.Solution = solutionContext; solutionContext.CurrentIndexProperty.AddToParent(); IndexProperty existingItem = solutionContext.IndexPropertyList.Find(i => i.IndexPropertyID == solutionContext.CurrentIndexProperty.IndexPropertyID); if (existingItem == null) { // add new item to solution solutionContext.CurrentIndexProperty.AssignProperty("IndexPropertyID", solutionContext.CurrentIndexProperty.IndexPropertyID); solutionContext.CurrentIndexProperty.ReverseInstance.ResetModified(false); solutionContext.IndexPropertyList.Add(solutionContext.CurrentIndexProperty); } else { // update existing item in solution if (existingItem.Solution == null) { existingItem.Solution = solutionContext; } if (existingItem.ForwardInstance == null && existingItem.IsAutoUpdated == false) { existingItem.ForwardInstance = new IndexProperty(); existingItem.ForwardInstance.TransformDataFromObject(existingItem, null, false); } existingItem.TransformDataFromObject(solutionContext.CurrentIndexProperty, null, false); existingItem.AddToParent(); existingItem.AssignProperty("IndexPropertyID", existingItem.IndexPropertyID); existingItem.ReverseInstance.ResetModified(false); solutionContext.CurrentIndexProperty = existingItem; } #region protected #endregion protected } }
///-------------------------------------------------------------------------------- /// <summary>This method returns a default index property based on db indexed column info.</summary> /// /// <param name="column">The column information.</param> /// <param name="index">The parent index.</param> ///-------------------------------------------------------------------------------- public static IndexProperty BuildIndexPropertyFromSqlIndexedColumn(SqlIndexedColumn column, Index index) { IndexProperty property = new IndexProperty(); property.IsAutoUpdated = true; property.IndexPropertyID = Guid.NewGuid(); property.Order = column.Order; property.Index = index; property.Tags = "DB"; foreach (Property item in index.Entity.PropertyList) { if (item.OriginalName == column.SqlIndexedColumnName) { property.Property = item; break; } } return(property); }
///-------------------------------------------------------------------------------- /// <summary>This method adds this item to the parent, if not found.</summary> ///-------------------------------------------------------------------------------- public void AddToParent() { Index index = Solution.IndexList.Find(i => i.IndexID == IndexID); if (index != null) { Index = index; SetID(); // id (from saved ids) may change based on parent info IndexProperty indexProperty = index.IndexPropertyList.Find(i => i.IndexPropertyID == IndexPropertyID); if (indexProperty != null) { if (indexProperty != this) { index.IndexPropertyList.Remove(indexProperty); index.IndexPropertyList.Add(this); } } else { index.IndexPropertyList.Add(this); } } }
///-------------------------------------------------------------------------------- /// <summary>This method determines whether the input instance metadata is /// effectively empty.</summary> /// /// <param name="inputIndexProperty">The indexproperty to compare metadata.</param> ///-------------------------------------------------------------------------------- public bool IsEmptyMetadata(IndexProperty inputIndexProperty) { if (inputIndexProperty == null) { return(true); } if (inputIndexProperty.TagList.Count > 0) { return(false); } if (IndexID != inputIndexProperty.IndexID) { return(false); } if (PropertyID != inputIndexProperty.PropertyID) { return(false); } if (Order != DefaultValue.Int) { return(false); } if (IsAutoUpdated != inputIndexProperty.IsAutoUpdated) { return(false); } if (!String.IsNullOrEmpty(inputIndexProperty.Description)) { return(false); } #region protected #endregion protected return(true); }