Пример #1
0
        /// ****************************************************************
        ///   internal Validate
        /// ----------------------------------------------------------------
        ///   <summary>
        ///   </summary>
        /// ****************************************************************
        ///
        internal void Validate()
        {
            Debug.Enter();

            //
            // Check to make sure publisher's limit allows save of this
            // entity.  If this is an update, we won't check since they are
            // simply replacing an existing entity.  We also won't check if
            // the limit is 0, since this indicates unlimited publishing
            // rights.
            //
            int limit = Context.User.BusinessLimit;
            int count = Context.User.BusinessCount;

            if (Utility.StringEmpty(BusinessKey) && 0 != limit)
            {
                //
                // Verify that the publisher has not exceeded their limit.
                //
                if (count >= limit)
                {
                    throw new UDDIException(ErrorType.E_accountLimitExceeded, "UDDI_ERROR_ACCOUNTLIMITEXCEEDED_BUSINESS", limit, count);
                }
            }

            //
            // Check to see if this is an update of an existing businessEntity.  If
            // it is, we'll need to perform further validation in the database.
            //
            if (!Utility.StringEmpty(BusinessKey))
            {
                SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor("net_businessEntity_validate");

                sp.Parameters.Add("@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID);
                sp.Parameters.Add("@businessKey", SqlDbType.UniqueIdentifier);
                sp.Parameters.Add("@flag", SqlDbType.Int);

                sp.Parameters.SetString("@PUID", Context.User.ID);
                sp.Parameters.SetGuidFromString("@businessKey", BusinessKey);
                if (Context.User.AllowPreassignedKeys)
                {
                    sp.Parameters.SetInt("@flag", 1);
                }
                else
                {
                    sp.Parameters.SetInt("@flag", 0);
                }


                sp.ExecuteNonQuery();
            }

            //
            // Validate the contained elements.
            //
            DiscoveryUrls.Validate();
            Names.Validate();
            Descriptions.Validate();
            Contacts.Validate();
            BusinessServices.Validate(BusinessKey);
            IdentifierBag.Validate(BusinessKey, KeyedReferenceType.IdentifierBag);
            CategoryBag.Validate(BusinessKey, KeyedReferenceType.CategoryBag);

            Debug.Leave();
        }
Пример #2
0
        public BusinessList Find()
        {
            BusinessList businessList = new BusinessList();

            QueryLog.Write(QueryType.Find, EntityType.BusinessEntity);

            //
            // Process each find constraint.
            //
            FindBuilder find = new FindBuilder(EntityType.BusinessEntity, FindQualifiers);

            //
            // If no search arguments are specified, return an empty result
            // set.
            //
            if (Utility.CollectionEmpty(Names) &&
                Utility.CollectionEmpty(DiscoveryUrls) &&
                Utility.CollectionEmpty(IdentifierBag) &&
                Utility.CollectionEmpty(CategoryBag) &&
                Utility.CollectionEmpty(TModelBag))
            {
                return(businessList);
            }

            //
            // Validate find parameters.
            //

            if (!Utility.CollectionEmpty(Names))
            {
                Names.ValidateForFind();
            }
            else
            {
                Debug.Verify(!find.CaseSensitiveMatch && !find.ExactNameMatch,
                             "UDDI_ERROR_UNSUPPORTED_FINDBE_NAMEFQNONAMES", ErrorType.E_unsupported);
            }


            //
            // TODO: Override may be better for these calls to KeyedReference.Validate because no parent key is used
            //
            if (!Utility.CollectionEmpty(IdentifierBag))
            {
                IdentifierBag.Validate("", KeyedReferenceType.IdentifierBag);
            }

            if (!Utility.CollectionEmpty(CategoryBag))
            {
                CategoryBag.Validate("", KeyedReferenceType.CategoryBag);
            }

            try
            {
                int rows = 1;

                //
                // Find entities with matching identifier bag items.
                //
                if (!Utility.CollectionEmpty(IdentifierBag))
                {
                    rows = find.FindByKeyedReferences(KeyedReferenceType.IdentifierBag, IdentifierBag);
                }

                //
                // Find entities with matching category bag items.
                //
                if (rows > 0 && !Utility.CollectionEmpty(CategoryBag))
                {
                    rows = find.FindByKeyedReferences(KeyedReferenceType.CategoryBag, CategoryBag);
                }

                //
                // Find entities with matching TModel bag items.
                //
                if (rows > 0 && !Utility.CollectionEmpty(TModelBag))
                {
                    rows = find.FindByTModelBag(TModelBag);
                }

                //
                // Find entities with matching discovery URLs
                //
                if (rows > 0 && !Utility.CollectionEmpty(DiscoveryUrls))
                {
                    rows = find.FindByDiscoveryUrls(DiscoveryUrls);
                }

                //
                // Find entities with matching names
                //
                if (rows > 0 && !Utility.CollectionEmpty(Names))
                {
                    rows = find.FindByNames(Names);
                }

                //
                // Process the find result set.
                //
                if (0 == rows)
                {
                    //
                    // Cleanup any temporary tables.
                    //
                    find.Abort();
                }                 // TODO: review
                else if (0 == MaxRows)
                {
                    businessList.Truncated = Truncated.True;
                    return(businessList);
                }
                else
                {
                    //
                    // Read in the find results.
                    //
                    SqlDataReaderAccessor      reader;
                    SqlStoredProcedureAccessor sp;
                    sp = find.RetrieveResults(MaxRows);
//
// TODO: return reader, not the whole SPA
//
                    reader = sp.ExecuteReader();

                    try
                    {
                        if (find.ServiceSubset)
                        {
                            //
                            // For a service subset search, we limit the result set
                            // to those services that matched the category bag
                            // search criteria.
                            //
                            BusinessInfo businessInfo = null;
                            string       prevKey      = null;

                            while (reader.Read())
                            {
                                string businessKey = reader.GetString("entityKey");

                                if (prevKey != businessKey)
                                {
                                    businessInfo = new BusinessInfo(businessKey);
                                    businessList.BusinessInfos.Add(businessInfo);
                                }

                                businessInfo.ServiceInfos.Add(
                                    reader.GetString("subEntityKey"),
                                    businessKey);

                                prevKey = businessKey;
                            }
                        }
                        else
                        {
                            //
                            // For non-service subset searches, we will simply
                            // return a list of businesses with all services.
                            //
                            while (reader.Read())
                            {
                                businessList.BusinessInfos.Add(reader.GetString("entityKey"));
                            }
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }

                    if (sp.Parameters.GetBool("@truncated"))
                    {
                        businessList.Truncated = Truncated.True;
                    }
                    else
                    {
                        businessList.Truncated = Truncated.False;
                    }

                    //
                    // Get the actual business info and service info data.  For
                    // a service subset, we'll grab just those services that we
                    // populated.  For all other searches, we'll get all service
                    // infos.
                    //
                    if (find.ServiceSubset)
                    {
                        foreach (BusinessInfo businessInfo in businessList.BusinessInfos)
                        {
                            businessInfo.Get(false);

                            foreach (ServiceInfo serviceInfo in businessInfo.ServiceInfos)
                            {
                                serviceInfo.Get();
                            }
                        }
                    }
                    else
                    {
                        foreach (BusinessInfo businessInfo in businessList.BusinessInfos)
                        {
                            businessInfo.Get(true);
                        }
                    }
                }
            }
            catch (Exception)
            {
                find.Abort();
                throw;
            }

            return(businessList);
        }