Exemplo n.º 1
0
        public static void FillClassLocations(DojoOrganizationCollection dojoOrganizationCollection)
        {
            StringBuilder s;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;

            if (dojoOrganizationCollection.Count > 0)
            {
                s = new StringBuilder("SELECT DojoOrganizationID, GreyFoxContactID FROM kitTessen_OrganizationsChildren_ClassLocations ORDER BY DojoOrganizationID; ");

                // Clone and sort collection by ID first to fill children in one pass
                DojoOrganizationCollection clonedCollection = dojoOrganizationCollection.Clone();
                clonedCollection.Sort();

                database  = DatabaseFactory.CreateDatabase();
                dbCommand = database.GetSqlStringCommand(s.ToString());
                r         = database.ExecuteReader(dbCommand);

                bool more = r.Read();

                foreach (DojoOrganization dojoOrganization in clonedCollection)
                {
                    GreyFoxContactCollection classLocations;
                    if (dojoOrganization.classLocations != null)
                    {
                        classLocations = dojoOrganization.classLocations;
                        classLocations.Clear();
                    }
                    else
                    {
                        classLocations = new GreyFoxContactCollection();
                        dojoOrganization.classLocations = classLocations;
                    }

                    while (more)
                    {
                        if (r.GetInt32(0) < dojoOrganization.iD)
                        {
                            more = r.Read();
                        }
                        else if (r.GetInt32(0) == dojoOrganization.iD)
                        {
                            classLocations.Add(GreyFoxContact.NewPlaceHolder("kitTessen_Locations", r.GetInt32(1)));
                            more = r.Read();
                        }
                        else
                        {
                            break;
                        }
                    }

                    // No need to continue if there are no more records
                    if (!more)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Makes a shallow copy of the current DojoOrganizationCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>DojoOrganizationCollection</returns>
        public DojoOrganizationCollection Clone()
        {
            DojoOrganizationCollection clonedDojoOrganization = new DojoOrganizationCollection(count);

            lock (this)
            {
                foreach (DojoOrganization item in this)
                {
                    clonedDojoOrganization.Add(item);
                }
            }
            return(clonedDojoOrganization);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Makes a deep copy of the current DojoOrganization.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the DojoOrganizationCollection from their children.</param>
        public DojoOrganizationCollection Copy(bool isolated)
        {
            DojoOrganizationCollection isolatedCollection = new DojoOrganizationCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoOrganizationArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DojoOrganizationArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Exemplo n.º 4
0
        public DojoOrganizationCollection GetCollection(int topCount, string whereClause, string sortClause, params DojoOrganizationFlags[] optionFlags)
        {
            StringBuilder query;
            Database      database;
            DbCommand     dbCommand;
            IDataReader   r;
            DojoOrganizationCollection dojoOrganizationCollection;
            int hashcode;

            // Cache Handling

            hashcode = 0;

            if (cacheEnabled)
            {
                hashcode = topCount.GetHashCode() +
                           whereClause.GetHashCode() +
                           sortClause.GetHashCode() +
                           tableName.GetHashCode();

                DojoOrganizationCollection collection = cacheFindCollection(hashcode);
                if (collection != null)
                {
                    return(collection);
                }
            }

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("DojoOrganization.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int locationOffset = -1;
            int administrativeContactOffset = -1;
            int defaultMemberTypeOffset     = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoOrganizationFlags.Location:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("Location.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        locationOffset  = innerJoinOffset;
                        innerJoinOffset = locationOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoOrganizationFlags.AdministrativeContact:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("AdministrativeContact.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        administrativeContactOffset = innerJoinOffset;
                        innerJoinOffset             = administrativeContactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DojoOrganizationFlags.DefaultMemberType:
                        for (int i = 0; i <= DojoMemberTypeManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("DefaultMemberType.");
                            query.Append(DojoMemberTypeManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        defaultMemberTypeOffset = innerJoinOffset;
                        innerJoinOffset         = defaultMemberTypeOffset + DojoMemberTypeManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("kitTessen_Organizations AS DojoOrganization");
            }
            else
            {
                query.Append(" FROM kitTessen_Organizations AS DojoOrganization");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DojoOrganizationFlags.Location:
                        query.Append(" LEFT JOIN kitTessen_Locations AS Location ON DojoOrganization.LocationID = Location.GreyFoxContactID)");
                        break;

                    case DojoOrganizationFlags.AdministrativeContact:
                        query.Append(" LEFT JOIN sysGlobal_Contacts AS AdministrativeContact ON DojoOrganization.AdministrativeContactID = AdministrativeContact.GreyFoxContactID)");
                        break;

                    case DojoOrganizationFlags.DefaultMemberType:
                        query.Append(" LEFT JOIN kitTessen_MemberTypes AS DefaultMemberType ON DojoOrganization.DefaultMemberTypeID = DefaultMemberType.DojoMemberTypeID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            dojoOrganizationCollection = new DojoOrganizationCollection();

            while (r.Read())
            {
                DojoOrganization dojoOrganization = ParseFromReader(r, 0, 1);

                // Fill Location
                if (locationOffset != -1 && !r.IsDBNull(locationOffset))
                {
                    GreyFoxContactManager.FillFromReader(dojoOrganization.location, "kitTessen_Locations", r, locationOffset, locationOffset + 1);
                }

                // Fill AdministrativeContact
                if (administrativeContactOffset != -1 && !r.IsDBNull(administrativeContactOffset))
                {
                    GreyFoxContactManager.FillFromReader(dojoOrganization.administrativeContact, "sysGlobal_Contacts", r, administrativeContactOffset, administrativeContactOffset + 1);
                }

                // Fill DefaultMemberType
                if (defaultMemberTypeOffset != -1 && !r.IsDBNull(defaultMemberTypeOffset))
                {
                    DojoMemberTypeManager.FillFromReader(dojoOrganization.defaultMemberType, r, defaultMemberTypeOffset, defaultMemberTypeOffset + 1);
                }

                dojoOrganizationCollection.Add(dojoOrganization);
            }

            // Microsoft DAAB still needs to close readers.
            r.Close();

            if (cacheEnabled)
            {
                cacheStoreCollection(hashcode, dojoOrganizationCollection);
            }

            return(dojoOrganizationCollection);
        }
Exemplo n.º 5
0
        private void cacheStoreCollection(int hashCode, DojoOrganizationCollection dojoOrganizationCollection)
        {
            CacheManager cache = CacheFactory.GetCacheManager();

            cache.Add(tableName + "_Collection_" + hashCode.ToString(), dojoOrganizationCollection);
        }