Пример #1
0
        public override string ToString()
        {
            // XmlSerializer serializer = new XmlSerializer( GetType() );
            XmlSerializer           serializer   = XmlSerializerManager.GetSerializer(GetType());
            UTF8EncodedStringWriter stringWriter = new UTF8EncodedStringWriter();

            try
            {
                serializer.Serialize(stringWriter, this);
                return(stringWriter.ToString());
            }
            finally
            {
                stringWriter.Close();
            }
        }
Пример #2
0
        /// ****************************************************************
        ///   public Get
        /// ----------------------------------------------------------------
        ///   <summary>
        ///   </summary>
        /// ****************************************************************
        ///
        public ChangeRecordDetail Get()
        {
            Debug.VerifySetting("OperatorKey");

            ChangeRecordDetail detail = new ChangeRecordDetail();

            try
            {
                //
                // Get the list of known operators.
                //
                StringCollection operators = new StringCollection();

                SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();

                sp.ProcedureName = "net_operators_get";
                SqlDataReaderAccessor reader = sp.ExecuteReader();

                try
                {
                    while (reader.Read())
                    {
                        operators.Add(reader.GetGuidString("operatorKey"));
                    }
                }
                finally
                {
                    reader.Close();
                }

                //
                // Set the search criteria for change records.
                //
                foreach (string operatorKey in operators)
                {
                    long startUSN;
                    long stopUSN;

                    startUSN = 0;
                    foreach (ChangeRecordVector mark in ChangesAlreadySeen)
                    {
                        if (0 == String.Compare(operatorKey, mark.NodeID, true))
                        {
                            startUSN = mark.OriginatingUSN + 1;
                            break;
                        }
                    }

                    stopUSN = System.Int64.MaxValue;
                    foreach (ChangeRecordVector mark in ResponseLimitVector)
                    {
                        if (0 == String.Compare(operatorKey, mark.NodeID, true))
                        {
                            stopUSN = mark.OriginatingUSN;
                            break;
                        }
                    }

                    FindChangeRecords.SetRange(operatorKey, startUSN, stopUSN);
                }

                //
                // Retrieve the change records.
                //
                int limit = Config.GetInt("Replication.ResponseLimitCountDefault");

                if (ResponseLimitCount >= 0 && ResponseLimitCount <= limit)
                {
                    limit = ResponseLimitCount;
                }

                reader = FindChangeRecords.RetrieveResults(limit);

                try
                {
                    while (reader.Read())
                    {
                        XmlSerializer serializer = null;

                        switch ((ChangeRecordPayloadType)reader.GetShort("changeTypeID"))
                        {
                        case ChangeRecordPayloadType.ChangeRecordNull:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordNull));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordNewData:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordNewData));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordDelete:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordDelete));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordPublisherAssertion:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordPublisherAssertion));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordHide:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordHide));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordDeleteAssertion:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordDeleteAssertion));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordAcknowledgement:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordAcknowledgement));
                            break;

                        case ChangeRecordPayloadType.ChangeRecordCorrection:
                            serializer = XmlSerializerManager.GetSerializer(typeof(ChangeRecordCorrection));
                            break;
                        }

                        StringReader stringReader = new StringReader(reader.GetString("changeData"));

                        try
                        {
                            ChangeRecord changeRecord = new ChangeRecord();

                            changeRecord.AcknowledgementRequested = (reader.GetInt("flag") & (int)ChangeRecordFlags.AcknowledgementRequested) > 0;
                            changeRecord.ChangeID.NodeID          = reader.GetString("OperatorKey");
                            changeRecord.ChangeID.OriginatingUSN  = reader.GetLong("USN");

                            ChangeRecordBase changeRecordBase = ( ChangeRecordBase )serializer.Deserialize(stringReader);
                            if (changeRecordBase is ChangeRecordCorrection)
                            {
                                //
                                // The query to find change records will do correction 'fixups'.  That is, the changeData of this
                                // change record will be replaced with the changeData from the correction.  The problem with this is
                                // that the original change data will now look like a correction.  To distinguish these types of
                                // change records, we look to see if the OriginatingUSN's match.  If the OriginatingUSN's match,
                                // we want they payload of the change record in this correction.  This payload will contain the
                                // corrected data that we want.
                                //
                                ChangeRecordCorrection changeRecordCorrection = ( ChangeRecordCorrection )changeRecordBase;
                                if (changeRecordCorrection.ChangeRecord.ChangeID.OriginatingUSN == changeRecord.ChangeID.OriginatingUSN)
                                {
                                    changeRecordBase = changeRecordCorrection.ChangeRecord.Payload;
                                }
                            }

                            changeRecord.Payload = changeRecordBase;

                            detail.ChangeRecords.Add(changeRecord);
                        }
                        finally
                        {
                            stringReader.Close();
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            catch (Exception e)
            {
                Debug.OperatorMessage(
                    SeverityType.Error,
                    CategoryType.Replication,
                    OperatorMessageType.None,
                    "Could not retrieve change records:\r\n" + e.ToString());

                FindChangeRecords.CleanUp();
                throw;
            }

            return(detail);
        }
Пример #3
0
        public void ProcessRequest(HttpContext ctx)
        {
            try
            {
                //
                // Verify the GET verb was used and that a query string is
                // specified.
                //
                if ("GET" != ctx.Request.RequestType.ToUpper())
                {
                    ctx.Response.AddHeader("Allow", "GET");
                    ctx.Response.StatusCode = 405;                     // Method Not Allowed

                    return;
                }

                if (null == ctx.Request.QueryString["businessKey"])
                {
                    ctx.Response.StatusCode = 400;                     // Bad Request
                    ctx.Response.Write("<h1>400 Bad Request</h1>Missing required argument 'businessKey'");

                    return;
                }

                //
                // Attempt to retrieve the business entity.
                //
                ConnectionManager.Open(false, false);
                string         businessKey = ctx.Request.QueryString["businessKey"];
                BusinessEntity be          = new BusinessEntity(businessKey);
                be.Get();

                //
                // Serialize the business Entity to the response stream
                // using UTF-8 encoding
                //
                // XmlSerializer serializer = new XmlSerializer( be.GetType() );
                XmlSerializer serializer = XmlSerializerManager.GetSerializer(be.GetType());

                UTF8Encoding utf8 = new UTF8Encoding(false);
                StreamWriter sr   = new StreamWriter(ctx.Response.OutputStream, utf8);
                serializer.Serialize(sr, be);

                ctx.Response.AddHeader("Content-Type", "text/xml; charset=utf-8");
            }
            catch (FormatException e)
            {
                //
                // We get a FormatException when passed a bad GUID.
                //
                ctx.Response.StatusCode = 400;                 // Bad Request
                ctx.Response.Write("<h1>400 Bad Request</h1>" + e.Message);
            }
            catch (SqlException e)
            {
                //
                // We get a SqlException when we could not get the data.
                //
                ctx.Response.StatusCode = 400;                 // Bad Request
                ctx.Response.Write("<h1>400 Bad Request</h1>" + e.Message);
            }
            catch (UDDIException e)
            {
                ctx.Response.StatusCode = 400;                 // Bad Request
                ctx.Response.Write("<h1>400 Bad Request</h1>" + e.Message);
            }
            catch (Exception e)
            {
                ctx.Response.StatusCode = 500;                 // Internal Server Error
                ctx.Response.Write("<h1>500 Internal Server Error</h1>");

                Debug.OperatorMessage(SeverityType.Error, CategoryType.None, OperatorMessageType.None, e.ToString());
            }
            finally
            {
                ConnectionManager.Close();
            }
        }
Пример #4
0
        public long Log()
        {
            string changeData;

            //
            // Serialize the change data.
            //
            Type type = Payload.GetType();

            //XmlSerializer serializer = new XmlSerializer( type );
            XmlSerializer           serializer   = XmlSerializerManager.GetSerializer(type);
            XmlSerializerNamespaces namespaces   = new XmlSerializerNamespaces();
            UTF8EncodedStringWriter stringWriter = new UTF8EncodedStringWriter();

            try
            {
                namespaces.Add("", "urn:uddi-org:repl");

                serializer.Serialize(stringWriter, Payload, namespaces);
                changeData = stringWriter.ToString();
            }
            finally
            {
                stringWriter.Close();
            }

            //
            // Store the record in the change log.
            //
            SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor("net_changeRecord_save");

            sp.Parameters.Add("@USN", SqlDbType.BigInt);
            sp.Parameters.Add("@PUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID);
            sp.Parameters.Add("@delegatePUID", SqlDbType.NVarChar, UDDI.Constants.Lengths.UserID);
            sp.Parameters.Add("@operatorKey", SqlDbType.UniqueIdentifier);
            sp.Parameters.Add("@entityKey", SqlDbType.UniqueIdentifier);
            sp.Parameters.Add("@entityTypeID", SqlDbType.TinyInt);
            sp.Parameters.Add("@changeTypeID", SqlDbType.TinyInt);
            sp.Parameters.Add("@contextID", SqlDbType.UniqueIdentifier);
            sp.Parameters.Add("@contextTypeID", SqlDbType.TinyInt);
            sp.Parameters.Add("@lastChange", SqlDbType.BigInt);
            sp.Parameters.Add("@changeData", SqlDbType.NText);
            sp.Parameters.Add("@flag", SqlDbType.Int);
            sp.Parameters.Add("@seqNo", SqlDbType.BigInt, ParameterDirection.Output);

            if (Utility.StringEmpty(ChangeID.NodeID) ||
                0 == String.Compare(Config.GetString("OperatorKey"), ChangeID.NodeID, true))
            {
                sp.Parameters.SetNull("@USN");
                sp.Parameters.SetString("@PUID", Context.User.ID);
                sp.Parameters.SetString("@delegatePUID", Context.User.ImpersonatorID);
                sp.Parameters.SetNull("@operatorKey");
            }
            else
            {
                sp.Parameters.SetLong("@USN", changeID.OriginatingUSN);
                sp.Parameters.SetNull("@PUID");
                sp.Parameters.SetNull("@delegatePUID");
                sp.Parameters.SetGuidFromString("@operatorKey", changeID.NodeID);
            }

            sp.Parameters.SetGuid("@contextID", Context.ContextID);
            sp.Parameters.SetInt("@flag", AcknowledgementRequested ? 0x1 : 0x0);
            sp.Parameters.SetLong("@lastChange", DateTime.UtcNow.Ticks);
            sp.Parameters.SetShort("@contextTypeID", (short)Context.ContextType);
            sp.Parameters.SetShort("@changeTypeID", (short)Payload.ChangeRecordPayloadType);

            if (Payload is ChangeRecordNewData)
            {
                ChangeRecordNewData payload = (ChangeRecordNewData)Payload;

                sp.Parameters.SetShort("@entityTypeID", (short)payload.EntityType);

                if (EntityType.TModel == payload.EntityType)
                {
                    sp.Parameters.SetGuidFromKey("@entityKey", payload.Entity.EntityKey);
                }
                else
                {
                    sp.Parameters.SetGuidFromString("@entityKey", payload.Entity.EntityKey);
                }
            }
            else if (Payload is ChangeRecordDelete)
            {
                ChangeRecordDelete payload = (ChangeRecordDelete)Payload;

                sp.Parameters.SetShort("@entityTypeID", (short)payload.EntityType);

                if (EntityType.TModel == payload.EntityType)
                {
                    sp.Parameters.SetGuidFromKey("@entityKey", payload.EntityKey);
                }
                else
                {
                    sp.Parameters.SetGuidFromString("@entityKey", payload.EntityKey);
                }
            }
            else if (Payload is ChangeRecordHide)
            {
                sp.Parameters.SetShort("@entityTypeID", (short)EntityType.TModel);
                sp.Parameters.SetGuidFromKey("@entityKey", ((ChangeRecordHide)Payload).TModelKey);
            }
            else
            {
                sp.Parameters.SetNull("@entityTypeID");
                sp.Parameters.SetNull("@entityKey");
            }

            sp.Parameters.SetString("@changeData", changeData);

            sp.ExecuteNonQuery();

            return(sp.Parameters.GetLong("@seqNo"));
        }
Пример #5
0
        public static void Throw(Exception e)
        {
            Debug.Enter();

            //
            // If this is a UDDI exception get the error number
            // Otherwise map all other errors to E_fatalError
            //
            ErrorType et           = ErrorType.E_fatalError;
            string    debugMessage = "";

            if (e is UDDI.UDDIException)
            {
                et = (ErrorType)((UDDIException)e).Number;
            }
            else if (e is System.Data.SqlClient.SqlException)
            {
                //
                // SECURITY: SqlException's include stored procedure names
                // This information is flowing back to the client in the SOAPFault
                // information. This information should be logged and not returned.
                //
                System.Data.SqlClient.SqlException se = (System.Data.SqlClient.SqlException)e;

                //
                // Build a detailed message about the exception; this text is not sent back to the user.
                //
                debugMessage = "SQL Exception in " + se.Procedure +
                               " line " + se.LineNumber +
                               " [severity " + se.Class +
                               ", state " + se.State;

                debugMessage += ", server " + se.Server;
                debugMessage += "]";

                //
                // Is this one of our custom error messages?  If so, we'll masssage the
                // error code into one of the UDDIException error types (custom errors
                // are thrown as ErrorType + 50000).  Otherwise, we'll simply use
                // E_fatalError.
                //
                if (16 == se.Class)
                {
                    et = (ErrorType)(se.Number - 50000);
                }
                else
                {
                    //
                    // 739178 - See if this was a SQL deadlock issue.  If it was, then return an E_serverBusy error
                    // instead.  The 1205 number is a retrieved from sysmessages table in the masters database of
                    // SQL Server.  See the SQL Books Online for more information about 1205.
                    //
                    if (1205 == se.Number)
                    {
                        //
                        // Change the 'e' variable to a new exception; need to do this since e.Message
                        // is read-only.  Keep track of the original exception so we can log it.
                        //
                        Exception originalException = e;
                        e  = new UDDIException(ErrorType.E_busy, "ERROR_BUSY");
                        et = ErrorType.E_busy;

                        Debug.Write(SeverityType.Info, CategoryType.Data, "A deadlock exception has been converted to an E_busy exception.  The original exception was:\r\n" + originalException.ToString());
                    }
                    else
                    {
                        et = ErrorType.E_fatalError;
                    }
                }
            }

            //
            // Log this error message.
            //
            Debug.Write(SeverityType.Info, CategoryType.Data, "An exception occurred. Details Follow:\r\n" + e.ToString() + "\r\n\r\n" + debugMessage);

            //
            // if this is a V1.0 call, map any new V2.0 error codes to
            // v1.0 error codes
            //
            if (1 == Context.ApiVersionMajor)
            {
                switch (et)
                {
                case ErrorType.E_invalidValue:
                case ErrorType.E_valueNotAllowed:
                case ErrorType.E_invalidProjection:
                case ErrorType.E_assertionNotFound:
                case ErrorType.E_invalidCompletionStatus:
                case ErrorType.E_messageTooLarge:
                case ErrorType.E_transferAborted:
                case ErrorType.E_publisherCancelled:
                case ErrorType.E_requestDenied:
                case ErrorType.E_secretUnknown:
                    et = ErrorType.E_fatalError;
                    break;
                }
            }

            //
            // Construct a new instance of a disposition report
            //
            DispositionReport dr = new DispositionReport(et, e.Message);

            //
            // Serialize the disposition report to a stream and load into
            // a DOM.
            //
            XmlDocument doc = new XmlDocument();

            MemoryStream strm = new MemoryStream();

            // XmlSerializer serializer = new XmlSerializer( typeof( DispositionReport ) );
            XmlSerializer serializer = XmlSerializerManager.GetSerializer(typeof(DispositionReport));

            serializer.Serialize(strm, dr);
            strm.Position = 0;

            doc.Load(strm);

            //
            // Wrap the disposition report with a detail node.
            //
            XmlNode detail = doc.CreateNode(
                XmlNodeType.Element,
                SoapException.DetailElementName.Name,
                SoapException.DetailElementName.Namespace);

            detail.AppendChild(doc.FirstChild.NextSibling);

            //
            // Construct the SOAP exception using the dr XML
            // as details and the received Exception as the inner exception.
            //

            UDDIText uddiText = new UDDIText("ERROR_FATAL_ERROR");

            throw new UDDISoapException(uddiText.GetText(),
                                        SoapException.ClientFaultCode,
                                        "",
                                        detail,
                                        e);
        }