///--------------------------------------------------------------------------------
        /// <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 override bool AssignProperty(string propertyName, object propertyValue)
        {
            if (this.SetPropertyValue(propertyName, propertyValue) == true)
            {
                if (ReverseInstance == null)
                {
                    ReverseInstance = new DatabaseSource();
                    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 property returns a copy of the forward engineering data for the solution.</summary>
        ///--------------------------------------------------------------------------------
        public new DatabaseSource GetForwardInstance(Solution forwardSolution)
        {
            bool           isCustomized = false;
            DatabaseSource forwardItem  = new DatabaseSource();

            if (ForwardInstance != null)
            {
                forwardItem.TransformDataFromObject(ForwardInstance, null, false);
                isCustomized = true;
            }
            else if (IsAutoUpdated == false)
            {
                forwardItem.TransformDataFromObject(this, null, false);
                isCustomized = true;
            }
            else
            {
                forwardItem.SpecificationSourceID = SpecificationSourceID;
            }
            if (isCustomized == false)
            {
                return(null);
            }
            forwardItem.SpecSourceName = DefaultSourceName;
            if (forwardSolution.ReferencedModelIDs.Find("ItemName", forwardItem.SpecSourceName) == null)
            {
                forwardSolution.ReferencedModelIDs.Add(CreateIDReference());
            }

            #region protected
            #endregion protected

            return(forwardItem);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method determines whether or not any metadata is
        /// different between the input instance and the current instance.</summary>
        ///
        /// <param name="inputDatabaseSource">The databasesource to compare metadata.</param>
        ///--------------------------------------------------------------------------------
        public bool IsIdenticalMetadata(DatabaseSource inputDatabaseSource)
        {
            if (SourceDbServerName.GetString() != inputDatabaseSource.SourceDbServerName.GetString())
            {
                return(false);
            }
            if (SourceDbName.GetString() != inputDatabaseSource.SourceDbName.GetString())
            {
                return(false);
            }
            if (DatabaseTypeCode.GetInt() != inputDatabaseSource.DatabaseTypeCode.GetInt())
            {
                return(false);
            }
            if (UserName.GetString() != inputDatabaseSource.UserName.GetString())
            {
                return(false);
            }
            if (Password.GetString() != inputDatabaseSource.Password.GetString())
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }
        ///--------------------------------------------------------------------------------
        /// <summary>This method returns a copy of the forward engineering data for the solution.</summary>
        ///--------------------------------------------------------------------------------
        public DatabaseSource GetForwardInstance()
        {
            DatabaseSource forwardItem = new DatabaseSource();

            forwardItem.TransformDataFromObject(this, null, false);
            return(forwardItem);
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method deletes the current DatabaseSource item from the solution.</summary>
 ///
 /// <param name="solutionContext">The associated solution.</param>
 ///--------------------------------------------------------------------------------
 public static void DeleteCurrentItemFromSolution(Solution solutionContext)
 {
     if (solutionContext.CurrentDatabaseSource != null)
     {
         DatabaseSource existingItem = solutionContext.DatabaseSourceList.Find(i => i.SpecificationSourceID == solutionContext.CurrentDatabaseSource.SpecificationSourceID);
         if (existingItem != null)
         {
             solutionContext.DatabaseSourceList.Remove(solutionContext.CurrentDatabaseSource);
         }
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method copies changed metadata between the input
        /// instance and the current instance.</summary>
        ///
        /// <param name="inputDatabaseSource">The databasesource to get metadata.</param>
        ///--------------------------------------------------------------------------------
        public void CopyChangedMetadata(DatabaseSource inputDatabaseSource)
        {
            SourceDbServerName = inputDatabaseSource.SourceDbServerName;
            SourceDbName       = inputDatabaseSource.SourceDbName;
            DatabaseTypeCode   = inputDatabaseSource.DatabaseTypeCode;
            UserName           = inputDatabaseSource.UserName;
            Password           = inputDatabaseSource.Password;

            #region protected
            #endregion protected
        }
 ///--------------------------------------------------------------------------------
 /// <summary>This method adds a tag to TagList.</summary>
 ///--------------------------------------------------------------------------------
 public override void AddTag(string tagName)
 {
     if (ReverseInstance == null && IsAutoUpdated == true)
     {
         ReverseInstance = new DatabaseSource();
         ReverseInstance.TransformDataFromObject(this, null, false);
         IsAutoUpdated = false;
     }
     base.AddTag(tagName);
     if (ForwardInstance == null)
     {
         ForwardInstance = new DatabaseSource();
         ForwardInstance.SpecificationSourceID = SpecificationSourceID;
     }
     if (ForwardInstance.TagList.Find(t => t.TagName == tagName) == null)
     {
         ForwardInstance.TagList.Add(new Tag(Guid.NewGuid(), tagName));
     }
 }
 ///--------------------------------------------------------------------------------
 /// <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.CurrentDatabaseSource != null)
     {
         string validationErrors = solutionContext.CurrentDatabaseSource.GetValidationErrors();
         if (!String.IsNullOrEmpty(validationErrors))
         {
             templateContext.LogException(solutionContext, solutionContext.CurrentDatabaseSource, validationErrors, lineNumber, InterpreterTypeCode.Output);
         }
         // link item to known id, solution, and parent
         solutionContext.CurrentDatabaseSource.Solution = solutionContext;
         solutionContext.CurrentDatabaseSource.AddToParent();
         DatabaseSource existingItem = solutionContext.DatabaseSourceList.Find(i => i.SpecificationSourceID == solutionContext.CurrentDatabaseSource.SpecificationSourceID);
         if (existingItem == null)
         {
             // add new item to solution
             solutionContext.CurrentDatabaseSource.AssignProperty("SpecificationSourceID", solutionContext.CurrentDatabaseSource.SpecificationSourceID);
             solutionContext.CurrentDatabaseSource.ReverseInstance.ResetModified(false);
             solutionContext.DatabaseSourceList.Add(solutionContext.CurrentDatabaseSource);
         }
         else
         {
             // update existing item in solution
             if (existingItem.Solution == null)
             {
                 existingItem.Solution = solutionContext;
             }
             if (existingItem.ForwardInstance == null && existingItem.IsAutoUpdated == false)
             {
                 existingItem.ForwardInstance = new DatabaseSource();
                 existingItem.ForwardInstance.TransformDataFromObject(existingItem, null, false);
             }
             existingItem.TransformDataFromObject(solutionContext.CurrentDatabaseSource, null, false);
             existingItem.AddToParent();
             existingItem.AssignProperty("SpecificationSourceID", existingItem.SpecificationSourceID);
             existingItem.ReverseInstance.ResetModified(false);
             solutionContext.CurrentDatabaseSource = existingItem;
         }
         #region protected
         #endregion protected
     }
 }
        ///--------------------------------------------------------------------------------
        /// <summary>This method determines whether the input instance metadata is
        /// effectively empty.</summary>
        ///
        /// <param name="inputDatabaseSource">The databasesource to compare metadata.</param>
        ///--------------------------------------------------------------------------------
        public bool IsEmptyMetadata(DatabaseSource inputDatabaseSource)
        {
            if (inputDatabaseSource == null)
            {
                return(true);
            }
            if (inputDatabaseSource.TagList.Count > 0)
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputDatabaseSource.SourceDbServerName))
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputDatabaseSource.SourceDbName))
            {
                return(false);
            }
            if (DatabaseTypeCode != DefaultValue.Int)
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputDatabaseSource.UserName))
            {
                return(false);
            }
            if (!String.IsNullOrEmpty(inputDatabaseSource.Password))
            {
                return(false);
            }

            #region protected
            #endregion protected

            return(true);
        }