Пример #1
0
        internal void Validate(string parentKey, KeyedReferenceType keyedReferenceType)
        {
            Debug.Enter();

            //
            // IN69: 4. When a keyedReference is saved within a categoryBag without specifying
            // a tModelKey (that is no tModelKey attribute at all) the UDDI server MUST
            // assume the urn:uddi-org:general_keywords tModelKey.  The resulting response
            // MUST add to the keyedReference the attribute
            // tModelKey=”uuid:A035A07C-F362-44dd-8F95-E2B134BF43B4” (case does not matter).
            //
            if (KeyedReferenceType.CategoryBag == keyedReferenceType && Utility.StringEmpty(TModelKey))
            {
                TModelKey = Config.GetString("TModelKey.GeneralKeywords");
            }

            //
            // IN69: 3. A UDDI server MUST reject a save_xxx request with a keyedReferences
            // in an identifierBag where no tModelKey attribute is specified.
            //
            if (KeyedReferenceType.IdentifierBag == keyedReferenceType && Utility.StringEmpty(TModelKey))
            {
                throw new UDDIException(
                          ErrorType.E_fatalError,
                          "UDDI_ERROR_FATALERROR_IDBAG_MISSINGTMODELKEY");
            }

            //
            // IN69: 1. A UDDI server MUST reject a save_xxx request with a keyedReference
            // with no keyName when the urn:uddi-org:general_keywords is involved
            //
            // #1718, make sure the comparison is not case sensitive.
            //
            if (Config.GetString("TModelKey.GeneralKeywords").ToLower().Equals(TModelKey) && null == keyname)
            {
                throw new UDDIException(
                          ErrorType.E_fatalError,
                          "UDDI_ERROR_FATALERROR_GENERALKEYWORDS_BLANKNAME");
            }

            //
            // IN69: 2. A UDDI server MUST reject a save_xxx request with a
            // keyedReference where only the keyValue is specified
            //
            if (Utility.StringEmpty(tmodelkey) && Utility.StringEmpty(keyname))
            {
                throw new UDDIException(
                          ErrorType.E_fatalError,
                          "UDDI_ERROR_FATALERROR_ASSERTION_MISSINGTMODELKEYORNAME");
            }

            //
            // Validate TModelKey, KeyName, and KeyValue length.
            //
            if (KeyedReferenceType.Assertion == keyedReferenceType)
            {
                if (Utility.StringEmpty(tmodelkey) ||
                    null == keyname ||
                    null == keyvalue)
                {
                    throw new UDDIException(
                              ErrorType.E_fatalError,
                              "UDDI_ERROR_FATALERROR_ASSERTION_MISSINGKEYNAMEORVALUE");
                }
            }

            Utility.ValidateLength(ref tmodelkey, "tModelKey", UDDI.Constants.Lengths.TModelKey);
            Utility.ValidateLength(ref keyname, "keyName", UDDI.Constants.Lengths.KeyName);
            Utility.ValidateLength(ref keyvalue, "keyValue", UDDI.Constants.Lengths.KeyValue);

            Debug.VerifyKey(tmodelkey);

            //
            // TODO: We are skipping validation of this keyedreference here if the parent entity key is
            // the same as the tModelKey for the identifer bag or category bag. Why???
            //
            // Please insert a comment to describe why this is necessary
            //
            if (parentKey != TModelKey)
            {
                //
                // call net_keyedReference_validate
                //
                SqlCommand cmd = new SqlCommand("net_keyedReference_validate", ConnectionManager.GetConnection());

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Transaction = ConnectionManager.GetTransaction();

                cmd.Parameters.Add(new SqlParameter("@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID)).Direction = ParameterDirection.Input;
                cmd.Parameters.Add(new SqlParameter("@keyedRefType", SqlDbType.TinyInt)).Direction = ParameterDirection.Input;
                cmd.Parameters.Add(new SqlParameter("@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue)).Direction = ParameterDirection.Input;
                cmd.Parameters.Add(new SqlParameter("@tModelKey", SqlDbType.UniqueIdentifier)).Direction = ParameterDirection.Input;

                SqlParameterAccessor paramacc = new SqlParameterAccessor(cmd.Parameters);

                paramacc.SetString("@PUID", Context.User.ID);
                paramacc.SetShort("@keyedRefType", (short)keyedReferenceType);
                paramacc.SetString("@keyValue", KeyValue);
                paramacc.SetGuidFromKey("@tModelKey", TModelKey);

                cmd.ExecuteNonQuery();
            }

            Debug.Leave();
        }