Example #1
0
        public void Search()
        {
            // Basic integration test: search algorithms are already extensively tested with InMemoryIndexBase

            MockRepository mocks = new MockRepository();

            IIndexConnector conn = mocks.StrictMock<IIndexConnector>();
            ScrewTurn.Wiki.SearchEngine.IWordFetcher fetcher = mocks.StrictMock<ScrewTurn.Wiki.SearchEngine.IWordFetcher>();

            ScrewTurn.Wiki.SearchEngine.Word dummy = null;
            Expect.Call(fetcher.TryGetWord("test", out dummy)).Return(false);
            Expect.Call(fetcher.TryGetWord("query", out dummy)).Return(false);
            fetcher.Dispose();
            LastCall.On(fetcher);

            Expect.Call(conn.GetWordFetcher()).Return(fetcher);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(0, index.Search(new ScrewTurn.Wiki.SearchEngine.SearchParameters("test query")).Count, "Wrong search result count");

            mocks.VerifyAll();
        }
Example #2
0
        public void Search()
        {
            // Basic integration test: search algorithms are already extensively tested with InMemoryIndexBase

            MockRepository mocks = new MockRepository();

            IIndexConnector conn = mocks.StrictMock <IIndexConnector>();

            ScrewTurn.Wiki.SearchEngine.IWordFetcher fetcher = mocks.StrictMock <ScrewTurn.Wiki.SearchEngine.IWordFetcher>();

            ScrewTurn.Wiki.SearchEngine.Word dummy = null;
            Expect.Call(fetcher.TryGetWord("test", out dummy)).Return(false);
            Expect.Call(fetcher.TryGetWord("query", out dummy)).Return(false);
            fetcher.Dispose();
            LastCall.On(fetcher);

            Expect.Call(conn.GetWordFetcher()).Return(fetcher);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(0, index.Search(new ScrewTurn.Wiki.SearchEngine.SearchParameters("test query")).Count, "Wrong search result count");

            mocks.VerifyAll();
        }
Example #3
0
 public void Constructor_NullConnector( )
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var x = new SqlIndex(null);
     });
 }
Example #4
0
 /// <summary>
 /// Removes a SqlIndex item to the collection.
 /// </summary>
 /// <param name="item">The item to remove.</param>
 public void Remove(SqlIndex item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     List.Remove(item);
 }
Example #5
0
 /// <summary>
 /// Inserts a SqlIndex instance into the collection.
 /// </summary>
 /// <param name="item">The item to add.</param>
 public void Insert(int index, SqlIndex item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     List.Insert(index, item);
 }
Example #6
0
 /// <summary>
 /// Discovers if the given item is in the collection.
 /// </summary>
 /// <param name="item">The item to find.</param>
 /// <returns>Returns true if the given item is in the collection.</returns>
 public bool Contains(SqlIndex item)
 {
     if (IndexOf(item) == -1)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
        public void Test30GetNonPrimaryKeyIndexesOk()
        {
            //SETUP
            var connection = ConfigurationManager.ConnectionStrings[MiscConstants.GetEfDatabaseConfigName()].ConnectionString;

            //EXECUTE
            var result = SqlIndex.GetAllIndexes(connection);

            //VERIFY
            result.Count.ShouldBeGreaterThan(8);
        }
Example #8
0
        private void AddIncludedColumns(SqlTable table, SqlIndex index)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (index == null)
            {
                throw new ArgumentNullException("index");
            }

            // go...
            DataTable dt = this.ExecuteDataTable(new SqlStatement(@"SELECT
                (CASE ic.key_ordinal WHEN 0 THEN CAST(1 AS tinyint) ELSE ic.key_ordinal END) AS [ID],
                clmns.name AS [Name],
                CAST(COLUMNPROPERTY(ic.object_id, clmns.name, N'IsComputed') AS bit) AS [IsComputed],
                ic.is_descending_key AS [Descending],
                ic.is_included_column AS [IsIncluded]
                FROM sys.tables AS tbl
                   INNER JOIN sys.indexes AS i 
                      ON (i.index_id > 0 AND i.is_hypothetical = 0) AND (i.object_id = tbl.object_id)
                   INNER JOIN sys.index_columns AS ic 
                      ON (ic.column_id > 0 AND (ic.key_ordinal > 0 OR ic.partition_ordinal = 0 OR ic.is_included_column != 0)) 
                         AND (ic.index_id = CAST(i.index_id AS int) AND ic.object_id = i.object_id)
                   INNER JOIN sys.columns AS clmns 
                   ON clmns.object_id = ic.object_id AND clmns.column_id = ic.column_id
                WHERE (i.name = @p0) AND (tbl.name = @p1)
                ORDER BY IsIncluded, [ID] ASC", new object[] { index.NativeName, table.NativeName }, this.Dialect));

            foreach (DataRow row in dt.Rows)
            {
                // add...
                string    columnName = (string)row["name"];
                SqlColumn column     = table.Columns[columnName];
                if (column == null)
                {
                    throw new InvalidOperationException(string.Format("Column '{0}' not found on table '{1}'.", column.NativeName, table.NativeName));
                }

                bool included = ConversionHelper.ToBoolean(row["isincluded"], Cultures.System);
                if (included)
                {
                    index.IncludedColumns.Add(column);
                }

                bool computed = ConversionHelper.ToBoolean(row["iscomputed"], Cultures.System);
                if (computed)
                {
                    index.ComputedColumns.Add(column);
                }
            }
        }
Example #9
0
        public void StoreDocument()
        {
            MockRepository  mocks = new MockRepository();
            IIndexConnector conn  = mocks.StrictMock <IIndexConnector>();

            ScrewTurn.Wiki.SearchEngine.IDocument doc = mocks.StrictMock <ScrewTurn.Wiki.SearchEngine.IDocument>();

            string dummyState = "state";

            string content = "This is some test content.";
            string title   = "My Document";

            Expect.Call(doc.Title).Return(title).Repeat.AtLeastOnce();
            Expect.Call(doc.Tokenize(content)).Return(ScrewTurn.Wiki.SearchEngine.Tools.Tokenize(content, ScrewTurn.Wiki.SearchEngine.WordLocation.Content));
            Expect.Call(doc.Tokenize(title)).Return(ScrewTurn.Wiki.SearchEngine.Tools.Tokenize(title, ScrewTurn.Wiki.SearchEngine.WordLocation.Title));

            Predicate <ScrewTurn.Wiki.SearchEngine.WordInfo[]> contentPredicate = (array) => {
                return
                    (array.Length == 5 &&
                     array[0].Text == "this" &&
                     array[1].Text == "is" &&
                     array[2].Text == "some" &&
                     array[3].Text == "test" &&
                     array[4].Text == "content");
            };
            Predicate <ScrewTurn.Wiki.SearchEngine.WordInfo[]> titlePredicate = (array) => {
                return
                    (array.Length == 2 &&
                     array[0].Text == "my" &&
                     array[1].Text == "document");
            };
            Predicate <ScrewTurn.Wiki.SearchEngine.WordInfo[]> keywordsPredicate = (array) => {
                return
                    (array.Length == 1 &&
                     array[0].Text == "test");
            };

            conn.DeleteDataForDocument(doc, dummyState);
            LastCall.On(conn);
            Expect.Call(conn.SaveDataForDocument(null, null, null, null, null)).IgnoreArguments()
            .Constraints(RC.Is.Same(doc), RC.Is.Matching(contentPredicate), RC.Is.Matching(titlePredicate), RC.Is.Matching(keywordsPredicate), RC.Is.Same(dummyState))
            .Return(8);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(8, index.StoreDocument(doc, new string[] { "test" }, content, dummyState), "Wrong occurrence count");

            mocks.VerifyAll();
        }
Example #10
0
        private ISuccessOrErrors CheckSpecificIndex(SqlIndex refIndex, SqlIndex indexToCheck)
        {
            var status = SuccessOrErrors.Success("All Ok");

            if (refIndex.IsPrimaryIndex != indexToCheck.IsPrimaryIndex)
            {
                SetAppropriateIndexError(status,
                                         "Index Mismatch: The '{0}' SQL database, the index on {1} is {2} primary key index," +
                                         " while the index on the same table.column in SQL database {3} is {4} primary key index.",
                                         _refDatabaseName, refIndex.CombinedName,
                                         refIndex.IsPrimaryIndex ? "a" : "NOT a",
                                         _toBeCheckDatabaseName,
                                         indexToCheck.IsPrimaryIndex ? "a" : "NOT a");
            }

            if (refIndex.Clustered != indexToCheck.Clustered)
            {
                SetAppropriateIndexError(status,
                                         "Index Mismatch: The '{0}' SQL database, the index on {1} is {2}clustered," +
                                         " while the index on the same table.column in SQL database {3} is {4}clustered.",
                                         _refDatabaseName, refIndex.CombinedName,
                                         refIndex.Clustered ? "" : "NOT ",
                                         _toBeCheckDatabaseName,
                                         indexToCheck.Clustered ? "" : "NOT ");
            }
            if (refIndex.IsUnique != indexToCheck.IsUnique)
            {
                SetAppropriateIndexError(status,
                                         "Index Mismatch: The '{0}' SQL database, index on {1} is {2}unique," +
                                         " while the index on the same table.column in SQL database {3} is {4}unique.",
                                         _refDatabaseName, refIndex.CombinedName,
                                         refIndex.IsUnique ? "" : "NOT ",
                                         _toBeCheckDatabaseName,
                                         indexToCheck.IsUnique ? "" : "NOT ");
            }
            if (refIndex.IsIdentity != indexToCheck.IsIdentity)
            {
                SetAppropriateIndexError(status,
                                         "Index Mismatch: The '{0}' SQL database, index on {1} is {2} identity column," +
                                         " while the index on the same table.column in SQL database {3} is {4} identity column.",
                                         _refDatabaseName, refIndex.CombinedName,
                                         refIndex.IsIdentity ? "an" : "NOT an",
                                         _toBeCheckDatabaseName,
                                         indexToCheck.IsIdentity ? "an" : "NOT an");
            }


            return(status);
        }
Example #11
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method returns a default index based on db index info.</summary>
        ///
        /// <param name="index">The index information.</param>
        /// <param name="entity">The parent entity.</param>
        ///--------------------------------------------------------------------------------
        public static Index BuildIndexFromSqlIndex(SqlIndex sqlIndex, Entity entity)
        {
            Index index = new Index();

            index.IsAutoUpdated     = true;
            index.IndexID           = Guid.NewGuid();
            index.IndexName         = sqlIndex.SqlIndexName.Replace(" ", "_");
            index.Entity            = entity;
            index.Tags              = "DB";
            index.SourceName        = sqlIndex.SqlIndexName;
            index.IsUniqueIndex     = sqlIndex.IsUnique ?? false;
            index.IsPrimaryKeyIndex = sqlIndex.IsClustered ?? false;

            return(index);
        }
                    public static SqlIndex FromBaseObject(BaseObject baseObj)
                    {
                        if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
                        {
                            return(null);
                        }
                        SqlIndex obj = baseObj as  SqlIndex;

                        if (object.Equals(obj, null))
                        {
                            obj = new SqlIndex(CreatedWhenConstruct.CWC_NotToCreate);
                            obj.BindNativeObject(baseObj.NativeObject, "CSqlIndex");
                            obj.IncreaseCast();
                        }

                        return(obj);
                    }
Example #13
0
        static bool CheckIndexChanged(SqlIndex lhs, SqlIndex rhs)
        {
            if (lhs.Columns.Count != lhs.Columns.Count)
            {
                return(true);
            }

            for (var i = 0; i < lhs.Columns.Count; i++)
            {
                if (lhs.Columns[i] != rhs.Columns[i])
                {
                    return(true);
                }
            }

            return(false);
        }
        public override IEnumerator<Index> GetIndices(string qualifiedTableName)
        {
            if (qualifiedTableName == null)
            {
                throw new ArgumentNullException();
            }
            if (0 <= qualifiedTableName.IndexOf('.'))
            {
                throw new ArgumentException();
            }
            var indices_raw = this.DataContext.ExecuteQuery<RawIndex>(@"SELECT i.name AS index_name, i.is_unique, i.is_primary_key, 
                        i.is_unique_constraint, c.name AS column_name, 
                        ic.partition_ordinal, ic.is_descending_key, 
                        ic.is_included_column
                    FROM sys.tables t, sys.indexes i, sys.index_columns ic, sys.columns c
                    WHERE 
	                    t.schema_id = schema_id() AND 
	                    t.object_id = i.object_id AND 
	                    i.object_id = ic.object_id AND
	                    i.index_id = ic.index_id AND
	                    t.object_id = c.object_id AND
	                    ic.column_id = c.column_id AND
	                    t.name = {0}
                    ORDER BY i.name, ic.key_ordinal", qualifiedTableName);

            var indices_sql = indices_raw.GroupBy(idx_col => idx_col.index_name).Select(idx_with_cols =>
            {
                var idx_raw = idx_with_cols.First();
                var idx_sql = new SqlIndex();
                idx_sql.Name = idx_raw.index_name;
                idx_sql.IsUnique = idx_raw.is_unique;
                idx_sql.IsPrimaryKey = idx_raw.is_primary_key;
                idx_sql.IsUniqueConstraint = idx_raw.is_unique_constraint;
                idx_sql.Columns = new SqlIndexColumnCollection(idx_with_cols.Select(idx_col => new SqlIndexColumn()
                {
                    ColumnName = idx_col.column_name,
                    IsDescendingKey = idx_col.is_descending_key,
                    PartitionOrdinal = idx_col.partition_ordinal,
                    IsIncludedColumn = idx_col.is_included_column,
                }));
                return idx_sql;
            });

            return ((IEnumerable<Index>)indices_sql).GetEnumerator();
        }
Example #15
0
        public void Clear()
        {
            MockRepository  mocks = new MockRepository();
            IIndexConnector conn  = mocks.StrictMock <IIndexConnector>();

            string dummyState = "state";

            conn.ClearIndex(dummyState);
            LastCall.On(conn);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            index.Clear(dummyState);

            mocks.VerifyAll();
        }
Example #16
0
        public void Clear()
        {
            MockRepository mocks = new MockRepository();
            IIndexConnector conn = mocks.StrictMock<IIndexConnector>();

            string dummyState = "state";

            conn.ClearIndex(dummyState);
            LastCall.On(conn);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            index.Clear(dummyState);

            mocks.VerifyAll();
        }
Example #17
0
        public void TotalDocuments_TotalWords_TotalOccurrences()
        {
            MockRepository  mocks = new MockRepository();
            IIndexConnector conn  = mocks.StrictMock <IIndexConnector>();

            Expect.Call(conn.GetCount(IndexElementType.Documents)).Return(12);
            Expect.Call(conn.GetCount(IndexElementType.Words)).Return(567);
            Expect.Call(conn.GetCount(IndexElementType.Occurrences)).Return(3456);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(12, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(567, index.TotalWords, "Wrong word count");
            Assert.AreEqual(3456, index.TotalOccurrences, "Wrong occurence count");

            mocks.VerifyAll();
        }
Example #18
0
        public void CreateIndex(SqlIndex index)
        {
            if (index.TableName.ContainsDigits())
            {
                index.TableName = String.Format("\"{0}\"", index.TableName);
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("CREATE ");
            if (index.Unique)
            {
                stringBuilder.Append("UNIQUE ");
            }
            stringBuilder.AppendFormat("INDEX IF NOT EXISTS {1}.{0} ", index.IndexName, index.SchemaName);
            stringBuilder.AppendFormat("ON {0} (", index.TableName);
            for (int i = 0; i < index.Columns.Length; i++)
            {
                if (i > 0)
                {
                    stringBuilder.Append(",");
                }
                stringBuilder.Append(index.Columns[i]);
            }
            stringBuilder.Append(")");

            SQLiteConnection connection = GetConnectionForTable(String.Format("{0}.{1}", index.SchemaName, index.TableName));
            SQLiteCommand    command    = connection.CreateCommand();

            command.CommandText = stringBuilder.ToString();
            int result = command.ExecuteNonQuery();

            Debug.WriteLine("CREATE INDEX affected {0} rows", result);

            PrepareIndexXmlSerializer();
            sqlIndexes.Add(index);
            FileStream outStream = indexXmlFileInfo.OpenWrite();

            indexXmlSerializer.Serialize(outStream, sqlIndexes);
            outStream.Flush(true);
            outStream.Close();
        }
Example #19
0
        public override string[] GetDropIndexStatement(SqlTable table, SqlIndex index)
        {
            //DROP INDEX CompaniesSiteIdActive ON dbo.SSCompanies
            if (index == null)
            {
                throw new ArgumentNullException("table");
            }

            StringBuilder builder = new StringBuilder();

            builder.Append(this.DropIndexKeyword);
            builder.Append(" ");

            // mbr - 14-03-2006 - changed this to be [table].[column].  not sure on SQL 2000 support.
            builder.Append(FormatTableName(table.NativeName));
            builder.Append(".");
            builder.Append(this.FormatIndexName(index.NativeName));

            // return...
            return(new string[] { builder.ToString() });
        }
Example #20
0
        /// <summary>
        /// Creates a SQL table from an entity type.
        /// </summary>
        /// <param name="entityType"></param>
        public SqlTable(SqlSchema schema, EntityType entityType)
            : base(entityType.NativeName.Name, entityType.Name)
        {
            // store the entity type for later use
            _entityType = entityType;

            // init...
            this.Initialize();

            // mbr - 04-10-2007 - set the schema...
            this.SetSchema(schema);

            // columns...
            foreach (EntityField field in entityType.Fields)
            {
                // mbr - 07-12-2005 - only non-extended...
                if (!(field.IsExtendedProperty))
                {
                    // mbr - 04-10-2007 - set schema...
                    SqlColumn column = new SqlColumn(field);
                    column.SetSchema(schema);
                    this.Columns.Add(column);
                }
            }

            // indexes...
            foreach (EntityIndex index in entityType.Indexes)
            {
                // mbr - 04-10-2007 - set schema...
                SqlIndex sqlIndex = new SqlIndex(this, index);
                sqlIndex.SetSchema(schema);
                this.Indexes.Add(sqlIndex);
            }

            // relationships...
            foreach (ChildToParentEntityLink relationship in entityType.Links)
            {
                this.LinksToParents.Add(new SqlChildToParentLink(schema, relationship));
            }
        }
Example #21
0
        /// <summary>
        /// Gets the schema work units specific to this table.
        /// </summary>
        /// <param name="existingTable"></param>
        /// <returns></returns>
        internal WorkUnitCollection GetSchemaWorkUnits(SqlTable existingTable)
        {
            if (_entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            if (existingTable == null)
            {
                throw new ArgumentNullException("existingTable");
            }

            // results...
            WorkUnitCollection results = new WorkUnitCollection();

            // Removed indexes.
            SqlIndexCollection removedIndexes = new SqlIndexCollection();

            // Removed indexes.
            SqlChildToParentLinkCollection removedForeignKeys = new SqlChildToParentLinkCollection();

            // find missing columns...
            foreach (SqlColumn column in this.Columns)
            {
                SqlColumn existingColumn = null;
                foreach (SqlColumn scanColumn in existingTable.Columns)
                {
                    if (string.Compare(column.NativeName, scanColumn.NativeName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)
                    {
                        existingColumn = scanColumn;
                        break;
                    }
                }

                // found?
                if (existingColumn == null)
                {
                    results.Add(new AddColumnSchemaWorkUnit(_entityType, column));
                }
                else
                {
                    // get the new column metrics.  this is tricky, because if the length changes to be less than what it was,
                    // we don't want to change the length, but we might want to change other metrics.
                    bool   changed = false;
                    string reason  = null;

                    // check...
                    long newLength = existingColumn.Length;
                    if (column.Length > newLength && newLength != -1)
                    {
                        newLength = column.Length;

                        // mbr - 24-07-2007 - case 321 - added reason...
                        changed = true;
                        reason  = string.Format("Length changed from {0} to {1}", existingColumn.Length, column.Length);
                    }

                    // flags?
                    bool newIsNullable = false;
                    if (!(existingColumn.IsKey))
                    {
                        newIsNullable = existingColumn.IsNullable;
                        if (column.IsNullable != newIsNullable)
                        {
                            newIsNullable = column.IsNullable;

                            // mbr - 24-07-2007 - case 321 - added reason...
                            changed = true;
                            reason  = string.Format("Nullability changed to '{0}'", column.IsNullable);
                        }
                    }
                    else
                    {
                        newIsNullable = false;
                    }

                    // type...
                    DbType newType    = existingColumn.DbType;
                    bool   newIsLarge = existingColumn.IsLarge;
                    if (column.DbType != newType || column.IsLarge != newIsLarge)
                    {
                        // mbr - 24-07-2007 - case 308 - this didn't do anything, hence have changed the code
                        // to the original intention - i.e. if something was an int and it's now a string, it will try and
                        // convert.  the original meaning of CanUpgradeType was to make sure the fx knew how
                        // to go from

                        //						// are the compatible?
                        //						bool ok = false;
                        //						try
                        //						{
                        //							this.CanUpgradeType(newType, newIsLarge, column.DbType, column.IsLarge);
                        //						}
                        //						catch(Exception ex)
                        //						{
                        //							throw new InvalidOperationException(string.Format("Failed to check upgradability of '{0}' on '{1}'.", column, column.Table), ex);
                        //						}

                        // can we?
                        //if(ok)
                        {
                            newType    = column.DbType;
                            newIsLarge = column.IsLarge;

                            // mbr - 24-07-2007 - case 321 - added reason...
                            changed = true;
                            string fromAsString = existingColumn.DbType.ToString();
                            if (existingColumn.IsLarge)
                            {
                                fromAsString += " (large)";
                            }
                            string toAsString = column.DbType.ToString();
                            if (column.IsLarge)
                            {
                                toAsString += " (large)";
                            }
                            reason = string.Format("Type changed from '{0}' to '{1}'", fromAsString, toAsString);
                        }
                    }

                    // now check the default default...
                    SqlDatabaseDefault existingDefault = existingColumn.DefaultExpression;
                    SqlDatabaseDefault newDefault      = column.DefaultExpression;

                    // alter...
                    if (changed && !(column.IsLarge))
                    {
                        // Now we can check the indexes are on this column as they need to be removed
                        foreach (SqlIndex index in existingTable.Indexes)
                        {
                            if (index.Columns.Contains(column.NativeName))
                            {
                                removedIndexes.Add(index);
                                results.Add(new DropIndexSchemaWorkUnit(_entityType, existingTable, index));
                            }
                        }

                        // Now we can check the foreign keys are on this column as they need to be removed
                        foreach (SqlChildToParentLink foreignKey in existingTable.LinksToParents)
                        {
                            if (foreignKey.Columns.Contains(column.NativeName))
                            {
                                removedForeignKeys.Add(foreignKey);
                                results.Add(new DropForeignKeySchemaWorkUnit(_entityType, foreignKey));
                            }
                        }

                        // mbr - 24-07-2007 - case 321 - added reason.
                        results.Add(new AlterColumnSchemaWorkUnit(_entityType, column, newType, newLength,
                                                                  newIsLarge, newIsNullable, newDefault, reason));
                    }

                    if (((existingDefault != null && newDefault == null) || (existingDefault == null && newDefault != null)) ||
                        (existingDefault != null && newDefault != null && !(existingDefault.Equals(newDefault))))
                    {
                        if (existingDefault != null)
                        {
                            results.Add(new DropConstraintSchemaWorkUnit(_entityType, column, existingDefault));
                        }

                        if (newDefault != null)
                        {
                            results.Add(new AddConstraintSchemaWorkUnit(_entityType, column, newDefault));
                        }
                    }
                }
            }


            // Check existing indexes
            foreach (SqlIndex index in Indexes)
            {
                SqlIndex existingIndex = null;
                foreach (SqlIndex scanIndex in existingTable.Indexes)
                {
                    //
                    if (string.Compare(scanIndex.NativeName, index.NativeName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)
                    {
                        // mbr - 2011-11-02 - do we need to drop it?
                        if (!(scanIndex.DoesMatch(index)))
                        {
                            // drop...
                            results.Add(new DropIndexSchemaWorkUnit(_entityType, this, index));
                        }
                        else
                        {
                            // create...
                            existingIndex = scanIndex;
                        }

                        // stop...
                        break;
                    }
                }

                // found?
                if (existingIndex == null || removedIndexes[existingIndex.Name] != null)
                {
                    results.Add(new CreateIndexSchemaWorkUnit(_entityType, this, index));
                }
            }

            // Check existing foreign keys
            foreach (SqlChildToParentLink foreignKey in LinksToParents)
            {
                SqlChildToParentLink existingForeignKey = null;
                foreach (SqlChildToParentLink scanForeignKey in existingTable.LinksToParents)
                {
                    //
                    if (string.Compare(scanForeignKey.NativeName, foreignKey.NativeName, true, System.Globalization.CultureInfo.InvariantCulture) == 0)
                    {
                        existingForeignKey = scanForeignKey;
                        break;
                    }
                }

                // found?
                if (existingForeignKey == null || removedIndexes[existingForeignKey.Name] != null)
                {
                    // mbr - 04-10-2007 - case 825 - only do this if the parent is referenced in the schema...
                    if (Schema == null)
                    {
                        throw new InvalidOperationException("Schema is null.");
                    }
                    bool ok = foreignKey.IsSupported(this.Schema);

                    // ok?
                    if (ok)
                    {
                        results.Add(new CreateForeignKeySchemaWorkUnit(_entityType, foreignKey));
                    }
                }
            }

            // return...
            return(results);
        }
Example #22
0
        public void StoreDocument()
        {
            MockRepository mocks = new MockRepository();
            IIndexConnector conn = mocks.StrictMock<IIndexConnector>();
            ScrewTurn.Wiki.SearchEngine.IDocument doc = mocks.StrictMock<ScrewTurn.Wiki.SearchEngine.IDocument>();

            string dummyState = "state";

            string content = "This is some test content.";
            string title = "My Document";

            Expect.Call(doc.Title).Return(title).Repeat.AtLeastOnce();
            Expect.Call(doc.Tokenize(content)).Return(ScrewTurn.Wiki.SearchEngine.Tools.Tokenize(content, ScrewTurn.Wiki.SearchEngine.WordLocation.Content));
            Expect.Call(doc.Tokenize(title)).Return(ScrewTurn.Wiki.SearchEngine.Tools.Tokenize(title, ScrewTurn.Wiki.SearchEngine.WordLocation.Title));

            Predicate<ScrewTurn.Wiki.SearchEngine.WordInfo[]> contentPredicate = (array) => {
                return
                    array.Length == 5 &&
                    array[0].Text == "this" &&
                    array[1].Text == "is" &&
                    array[2].Text == "some" &&
                    array[3].Text == "test" &&
                    array[4].Text == "content";
            };
            Predicate<ScrewTurn.Wiki.SearchEngine.WordInfo[]> titlePredicate = (array) => {
                return
                    array.Length == 2 &&
                    array[0].Text == "my" &&
                    array[1].Text == "document";
            };
            Predicate<ScrewTurn.Wiki.SearchEngine.WordInfo[]> keywordsPredicate = (array) => {
                return
                    array.Length == 1 &&
                    array[0].Text == "test";
            };

            conn.DeleteDataForDocument(doc, dummyState);
            LastCall.On(conn);
            Expect.Call(conn.SaveDataForDocument(null, null, null, null, null)).IgnoreArguments()
                .Constraints(RC.Is.Same(doc), RC.Is.Matching(contentPredicate), RC.Is.Matching(titlePredicate), RC.Is.Matching(keywordsPredicate), RC.Is.Same(dummyState))
                .Return(8);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(8, index.StoreDocument(doc, new string[] { "test" }, content, dummyState), "Wrong occurrence count");

            mocks.VerifyAll();
        }
Example #23
0
 /// <summary>
 /// Returns the index of the item in the collection.
 /// </summary>
 /// <param name="item">The item to find.</param>
 /// <returns>The index of the item, or -1 if it is not found.</returns>
 public int IndexOf(SqlIndex item)
 {
     return(List.IndexOf(item));
 }
Example #24
0
        public void TotalDocuments_TotalWords_TotalOccurrences()
        {
            MockRepository mocks = new MockRepository();
            IIndexConnector conn = mocks.StrictMock<IIndexConnector>();

            Expect.Call(conn.GetCount(IndexElementType.Documents)).Return(12);
            Expect.Call(conn.GetCount(IndexElementType.Words)).Return(567);
            Expect.Call(conn.GetCount(IndexElementType.Occurrences)).Return(3456);

            mocks.ReplayAll();

            SqlIndex index = new SqlIndex(conn);

            Assert.AreEqual(12, index.TotalDocuments, "Wrong document count");
            Assert.AreEqual(567, index.TotalWords, "Wrong word count");
            Assert.AreEqual(3456, index.TotalOccurrences, "Wrong occurence count");

            mocks.VerifyAll();
        }
Example #25
0
        /// <summary>
        /// Gets the statement that can create the given table.
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public override string[] GetCreateIndexStatement(SqlTable table, SqlIndex index)
        {
            if (index == null)
            {
                throw new ArgumentNullException("table");
            }

            StringBuilder builder = new StringBuilder();

            if (!index.HasUniqueValues)
            {
                builder.Append(this.CreateIndexKeyword);
            }
            else
            {
                builder.Append(this.CreateUniqueIndexKeyword);
            }

            builder.Append(" ");
            builder.Append(this.FormatIndexName(index.NativeName));
            builder.Append(" ON ");
            builder.Append(FormatTableName(table.NativeName));

            // mbr -- which columns to use? mysql doesn't support included columns...
            var toUse = new List <SqlColumn>(index.Columns.ToArray());

            if (!(this.SupportsIncludedColumns))
            {
                toUse.AddRange(index.IncludedColumns.ToArray());
            }

            builder.Append(" (");

            for (int column = 0; column < toUse.Count; column++)
            {
                if (column > 0)
                {
                    builder.Append(", ");
                }
                builder.Append("\r\n\t");

                // column...
                SqlColumn indexColumn = toUse[column];
                builder.Append(FormatIndexName(indexColumn.NativeName));
            }
            builder.Append("\r\n\t)");

            // mbr  - 2011-11-02 - include...
            if (this.SupportsIncludedColumns && index.IncludedColumns.Count > 0)
            {
                builder.Append(" INCLUDE ");
                builder.Append("(");
                for (int column = 0; column < index.IncludedColumns.Count; column++)
                {
                    if (column > 0)
                    {
                        builder.Append(", ");
                    }
                    SqlColumn indexColumn = index.IncludedColumns[column];
                    builder.Append(FormatIndexName(indexColumn.NativeName));
                }
                builder.Append(")");
            }

            // mbr - 2011-11-02 - calculated...
            if (index.ComputedColumns.Count > 0)
            {
                throw new NotSupportedException("Computed columns are not supported.");
            }

            // return...
            return(new string[] { builder.ToString() });
        }
Example #26
0
        /// <summary>
        /// Adds indexes to the schema.
        /// </summary>
        /// <param name="schema"></param>
        private void AddIndexesToSchema(SqlSchema schema)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }

            foreach (SqlTable table in schema.Tables)
            {
                // create...
                SqlStatement statement = new SqlStatement("sp_MShelpindex", this.Dialect);
                statement.CommandType = CommandType.StoredProcedure;
                statement.Parameters.Add(new SqlStatementParameter("tablename", DbType.String, table.NativeName));
                statement.Parameters.Add(new SqlStatementParameter("indexname", DbType.String, DBNull.Value));
                statement.Parameters.Add(new SqlStatementParameter("flags", DbType.Int32, 1));

                // exec...
                DataTable indexes = this.ExecuteDataTable(statement);
                if (indexes == null)
                {
                    throw new InvalidOperationException("indexes is null.");
                }

                // walk...
                foreach (DataRow indexRow in indexes.Rows)
                {
                    // If we have a primary key
                    if ((((int)indexRow["status"]) & 2048) != 0)
                    {
                        continue;
                    }

                    // get the columns...
                    ArrayList columnNames = new ArrayList();
                    for (int index = 1; index <= 16; index++)
                    {
                        // name...
                        string indexColumnName = "indcol" + index.ToString();
                        if (indexRow.IsNull(indexColumnName) == false)
                        {
                            columnNames.Add(indexRow[indexColumnName]);
                        }
                    }

                    // any?
                    if (columnNames.Count > 0)
                    {
                        // create a new index...
                        SqlIndex index = new SqlIndex((string)indexRow["name"]);
                        table.Indexes.Add(index);

                        // mbr - 04-10-2007 - set owner...
                        index.SetSchema(schema);

                        // unique values?
                        int flags = (int)indexRow["status"];
                        if ((flags & 2) == 2)
                        {
                            index.HasUniqueValues = true;
                        }

                        // setup the columns...
                        foreach (string columnName in columnNames)
                        {
                            // find...
                            SqlColumn column = table.Columns[columnName];
                            if (column == null)
                            {
                                throw new InvalidOperationException(string.Format("Column '{0}' not found on table '{1}'.", column.NativeName, table.NativeName));
                            }

                            // add...
                            index.Columns.Add(column);
                        }

                        // mbr - 2011-11-02 we also need to do included columns...
                        AddIncludedColumns(table, index);
                    }
                }
            }
        }
Example #27
0
 public void CreateIndex(SqlIndex index)
 {
     throw new NotImplementedException();
 }
                    public BaseObject Create()
                    {
                        SqlIndex emptyInstance = new SqlIndex(CreatedWhenConstruct.CWC_NotToCreate);

                        return(emptyInstance);
                    }
Example #29
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method gets the model context associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        /// <param name="isValidContext">Output flag, signifying whether context returned is a valid one.</param>
        ///--------------------------------------------------------------------------------
        public IDomainEnterpriseObject GetModelContext(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext, out bool isValidContext)
        {
            IDomainEnterpriseObject nodeContext      = modelContext;
            IDomainEnterpriseObject currentContext   = modelContext;
            ModelContextNode        leafModelContext = ModelContext;

            isValidContext = false;
            if (ThisContext != null)
            {
                templateContext.PopCount = templateContext.ModelContextStack.Count - 1;
            }
            else if (PopContext != null)
            {
                // go through pop context nodes directly here
                ModelContextNode contextNode = this;
                while (contextNode != null)
                {
                    if (contextNode.PopContext != null)
                    {
                        leafModelContext = contextNode.ModelContext;
                        templateContext.PopCount++;
                    }
                    contextNode = contextNode.ModelContext;
                }
            }
            if (templateContext.PopCount > 0)
            {
                // pop context executes first
                nodeContext = templateContext.GetModelContext(templateContext.PopCount);
                templateContext.PopCount = 0;
            }
            if (leafModelContext != null)
            {
                // model context nodes execute next (then, nodes are evaluated)
                nodeContext = leafModelContext.GetModelContext(solutionContext, templateContext, nodeContext, out isValidContext);
            }
            if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.AuditProperty))
            {
                nodeContext = AuditProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Collection))
            {
                nodeContext = Collection.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Entity))
            {
                nodeContext = Entity.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.EntityReference))
            {
                nodeContext = EntityReference.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Enumeration))
            {
                nodeContext = Enumeration.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Feature))
            {
                nodeContext = Feature.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Index))
            {
                nodeContext = Index.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.IndexProperty))
            {
                nodeContext = IndexProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Method))
            {
                nodeContext = Method.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.MethodRelationship))
            {
                nodeContext = MethodRelationship.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Model))
            {
                nodeContext = Model.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ModelObject))
            {
                nodeContext = ModelObject.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ModelProperty))
            {
                nodeContext = ModelProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ObjectInstance))
            {
                nodeContext = ObjectInstance.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Parameter))
            {
                nodeContext = Parameter.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Project))
            {
                nodeContext = Project.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Property))
            {
                nodeContext = Property.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyInstance))
            {
                nodeContext = PropertyInstance.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyReference))
            {
                nodeContext = PropertyReference.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyRelationship))
            {
                nodeContext = PropertyRelationship.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Relationship))
            {
                nodeContext = Relationship.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.RelationshipProperty))
            {
                nodeContext = RelationshipProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Solution))
            {
                nodeContext = Solution.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Stage))
            {
                nodeContext = Stage.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StageTransition))
            {
                nodeContext = StageTransition.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.State))
            {
                nodeContext = State.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StateModel))
            {
                nodeContext = StateModel.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StateTransition))
            {
                nodeContext = StateTransition.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Step))
            {
                nodeContext = Step.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StepTransition))
            {
                nodeContext = StepTransition.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Value))
            {
                nodeContext = Value.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.View))
            {
                nodeContext = View.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ViewProperty))
            {
                nodeContext = ViewProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Workflow))
            {
                nodeContext = Workflow.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlColumn))
            {
                nodeContext = SqlColumn.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlDatabase))
            {
                nodeContext = SqlDatabase.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlExtendedProperty))
            {
                nodeContext = SqlExtendedProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlForeignKey))
            {
                nodeContext = SqlForeignKey.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlForeignKeyColumn))
            {
                nodeContext = SqlForeignKeyColumn.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlIndex))
            {
                nodeContext = SqlIndex.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlIndexedColumn))
            {
                nodeContext = SqlIndexedColumn.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlProperty))
            {
                nodeContext = SqlProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlTable))
            {
                nodeContext = SqlTable.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlView))
            {
                nodeContext = SqlView.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlViewProperty))
            {
                nodeContext = SqlViewProperty.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlAttribute))
            {
                nodeContext = XmlAttribute.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlDocument))
            {
                nodeContext = XmlDocument.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlNode))
            {
                nodeContext = XmlNode.GetModelContext(solutionContext, nodeContext, out isValidContext);
            }
            #region protected
            else if (ModelContextName == "ReferencedEntity")
            {
                currentContext = nodeContext;
                nodeContext    = Collection.GetModelContext(solutionContext, currentContext, out isValidContext);
                if (nodeContext is Collection)
                {
                    nodeContext = (nodeContext as Collection).ReferencedEntity;
                }
                else
                {
                    nodeContext = EntityReference.GetModelContext(solutionContext, currentContext, out isValidContext);
                    if (nodeContext is EntityReference)
                    {
                        nodeContext = (nodeContext as EntityReference).ReferencedEntity;
                    }
                    else
                    {
                        nodeContext = Relationship.GetModelContext(solutionContext, currentContext, out isValidContext);
                        if (nodeContext is Relationship)
                        {
                            nodeContext = (nodeContext as Relationship).ReferencedEntity;
                        }
                        else
                        {
                            nodeContext = Parameter.GetModelContext(solutionContext, currentContext, out isValidContext);
                            if (nodeContext is Parameter)
                            {
                                nodeContext = (nodeContext as Parameter).ReferencedEntity;
                            }
                        }
                    }
                }
            }
            else if (ModelContextName == "ReferencedProperty")
            {
                currentContext = nodeContext;
                nodeContext    = RelationshipProperty.GetModelContext(solutionContext, currentContext, out isValidContext);
                if (nodeContext is RelationshipProperty)
                {
                    nodeContext = (nodeContext as RelationshipProperty).ReferencedProperty;
                }
                else
                {
                    nodeContext = PropertyReference.GetModelContext(solutionContext, currentContext, out isValidContext);
                    if (nodeContext is PropertyReference)
                    {
                        nodeContext = (nodeContext as PropertyReference).ReferencedProperty;
                    }
                    else
                    {
                        nodeContext = Parameter.GetModelContext(solutionContext, currentContext, out isValidContext);
                        if (nodeContext is Parameter)
                        {
                            nodeContext = (nodeContext as Parameter).ReferencedPropertyBase as Property;
                        }
                    }
                }
            }
            else if (ModelContextName == "BaseEntity")
            {
                nodeContext = Entity.GetModelContext(solutionContext, nodeContext, out isValidContext);
                if (nodeContext is Entity)
                {
                    nodeContext = (nodeContext as Entity).BaseEntity;
                }
            }
            else if (solutionContext.ModelObjectPropertyNames[ModelContextName] != null)
            {
                nodeContext = ObjectInstance.GetModelContextViaProperty(solutionContext, ModelContextName, nodeContext, out isValidContext);
            }
            #endregion protected
            else if (solutionContext.ModelObjectNames.AllKeys.Contains(ModelContextName) == true)
            {
                return(ObjectInstance.GetModelContext(solutionContext, ModelContextName, nodeContext, out isValidContext));
            }
            if (nodeContext == null && isValidContext == false)
            {
                LogException(solutionContext, templateContext, modelContext, String.Format(DisplayValues.Exception_InvalidModelContext, ModelContextName, modelContext.Name, modelContext.GetType().Name), InterpreterTypeCode.None);
            }
            return(nodeContext);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="table"></param>
 /// <param name="index"></param>
 internal CreateIndexSchemaWorkUnit(EntityType entityType, SqlTable table, SqlIndex index) : base(entityType)
 {
     _index = index;
     _table = table;
 }
Example #31
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method gets the collection context associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        ///--------------------------------------------------------------------------------
        public IEnterpriseEnumerable GetCollection(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext)
        {
            IDomainEnterpriseObject nodeContext = modelContext;
            bool isValidContext;

            if (ModelContext != null)
            {
                nodeContext = ModelContext.GetModelContext(solutionContext, templateContext, modelContext, out isValidContext);
            }
            if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.AuditProperty))
            {
                return(AuditProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Collection))
            {
                return(Collection.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Entity))
            {
                return(Entity.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.EntityReference))
            {
                return(EntityReference.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Enumeration))
            {
                return(Enumeration.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Feature))
            {
                return(Feature.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Index))
            {
                return(Index.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.IndexProperty))
            {
                return(IndexProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Method))
            {
                return(Method.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.MethodRelationship))
            {
                return(MethodRelationship.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Model))
            {
                return(Model.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ModelObject))
            {
                return(ModelObject.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ModelProperty))
            {
                return(ModelProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ObjectInstance))
            {
                return(ObjectInstance.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Parameter))
            {
                return(Parameter.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Project))
            {
                return(Project.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Property))
            {
                return(Property.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyInstance))
            {
                return(PropertyInstance.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyReference))
            {
                return(PropertyReference.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.PropertyRelationship))
            {
                return(PropertyRelationship.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Relationship))
            {
                return(Relationship.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.RelationshipProperty))
            {
                return(RelationshipProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Solution))
            {
                return(Solution.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Stage))
            {
                return(Stage.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StageTransition))
            {
                return(StageTransition.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.State))
            {
                return(State.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StateModel))
            {
                return(StateModel.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StateTransition))
            {
                return(StateTransition.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Step))
            {
                return(Step.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.StepTransition))
            {
                return(StepTransition.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Value))
            {
                return(Value.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.View))
            {
                return(View.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.ViewProperty))
            {
                return(ViewProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Workflow))
            {
                return(Workflow.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlColumn))
            {
                return(SqlColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlDatabase))
            {
                return(SqlDatabase.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlExtendedProperty))
            {
                return(SqlExtendedProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlForeignKey))
            {
                return(SqlForeignKey.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlForeignKeyColumn))
            {
                return(SqlForeignKeyColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlIndex))
            {
                return(SqlIndex.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlIndexedColumn))
            {
                return(SqlIndexedColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlProperty))
            {
                return(SqlProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlTable))
            {
                return(SqlTable.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlView))
            {
                return(SqlView.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.SqlViewProperty))
            {
                return(SqlViewProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlAttribute))
            {
                return(XmlAttribute.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlDocument))
            {
                return(XmlDocument.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (ModelContextName == Enum.GetName(typeof(SpecModelContextTypeCode), SpecModelContextTypeCode.XmlNode))
            {
                return(XmlNode.GetCollectionContext(solutionContext, nodeContext));
            }
            #region protected
            else if (ModelContextName == Enum.GetName(typeof(ModelContextTypeCode), ModelContextTypeCode.Tag))
            {
                return(Tag.GetCollectionContext(solutionContext, modelContext));
            }
            #endregion protected
            else if (solutionContext.ModelObjectNames.AllKeys.Contains(ModelContextName) == true)
            {
                return(ObjectInstance.GetCollectionContext(solutionContext, ModelContextName, nodeContext));
            }
            LogException(solutionContext, templateContext, modelContext, String.Format(DisplayValues.Exception_InvalidModelContext, ModelContextName, modelContext.GetType().Name), InterpreterTypeCode.None);
            return(null);
        }
Example #32
0
        ///--------------------------------------------------------------------------------
        /// <summary>This method gets the collection context associated with this node.</summary>
        ///
        /// <param name="solutionContext">The associated solution.</param>
        /// <param name="templateContext">The associated template.</param>
        /// <param name="modelContext">The associated model context.</param>
        ///--------------------------------------------------------------------------------
        public IEnterpriseEnumerable GetCollection(Solution solutionContext, ITemplate templateContext, IDomainEnterpriseObject modelContext)
        {
            IDomainEnterpriseObject nodeContext = modelContext;

            if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlColumn))
            {
                return(SqlColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlDatabase))
            {
                return(SqlDatabase.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlExtendedProperty))
            {
                return(SqlExtendedProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlForeignKey))
            {
                return(SqlForeignKey.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlForeignKeyColumn))
            {
                return(SqlForeignKeyColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlIndex))
            {
                return(SqlIndex.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlIndexedColumn))
            {
                return(SqlIndexedColumn.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlProperty))
            {
                return(SqlProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlTable))
            {
                return(SqlTable.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlView))
            {
                return(SqlView.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentSqlViewProperty))
            {
                return(SqlViewProperty.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentXmlAttribute))
            {
                return(XmlAttribute.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentXmlDocument))
            {
                return(XmlDocument.GetCollectionContext(solutionContext, nodeContext));
            }
            else if (CurrentItemName == Enum.GetName(typeof(SpecCurrentItemTypeCode), SpecCurrentItemTypeCode.CurrentXmlNode))
            {
                return(XmlNode.GetCollectionContext(solutionContext, nodeContext));
            }
            #region protected
            #endregion protected
            return(null);
        }