ToString() public method

public ToString ( ) : string
return string
Esempio n. 1
0
		public void MatchesKeyIdentifierClause ()
		{
			UniqueId id = new UniqueId ();
			X509SecurityToken t = new X509SecurityToken (cert, id.ToString ());
			LocalIdKeyIdentifierClause l =
				new LocalIdKeyIdentifierClause (id.ToString ());
			Assert.IsTrue (t.MatchesKeyIdentifierClause (l), "#1-1");

			l = new LocalIdKeyIdentifierClause ("#" + id.ToString ());
			Assert.IsFalse (t.MatchesKeyIdentifierClause (l), "#1-2");

			X509ThumbprintKeyIdentifierClause h =
				new X509ThumbprintKeyIdentifierClause (cert);
			Assert.IsTrue (t.MatchesKeyIdentifierClause (h), "#2-1");

			h = new X509ThumbprintKeyIdentifierClause (cert2);
			Assert.IsFalse (t.MatchesKeyIdentifierClause (h), "#2-2");

			X509IssuerSerialKeyIdentifierClause i =
				new X509IssuerSerialKeyIdentifierClause (cert);
			Assert.IsTrue (t.MatchesKeyIdentifierClause (i), "#3-1");

			i = new X509IssuerSerialKeyIdentifierClause (cert2);
			Assert.IsFalse (t.MatchesKeyIdentifierClause (i), "#3-2");

			X509RawDataKeyIdentifierClause s =
				new X509RawDataKeyIdentifierClause (cert);
			Assert.IsTrue (t.MatchesKeyIdentifierClause (s), "#4-1");

			s = new X509RawDataKeyIdentifierClause (cert2);
			Assert.IsFalse (t.MatchesKeyIdentifierClause (s), "#4-2");
		}
Esempio n. 2
0
		public void DefaultValues ()
		{
			UniqueId id = new UniqueId ();
			X509SecurityToken t = new X509SecurityToken (cert, id.ToString ());
			Assert.AreEqual (id.ToString (), t.Id, "#1");
			Assert.AreEqual (cert, t.Certificate, "#2");
			Assert.AreEqual (cert.NotBefore.ToUniversalTime (), t.ValidFrom, "#3");
			Assert.AreEqual (cert.NotAfter.ToUniversalTime (), t.ValidTo, "#4");
			Assert.AreEqual (1, t.SecurityKeys.Count, "#5");
		}
Esempio n. 3
0
		public void DefaultValues ()
		{
			UniqueId id = new UniqueId ();
			UserNameSecurityToken t = new UserNameSecurityToken ("mono", "poly", id.ToString ());
			Assert.AreEqual (id.ToString (), t.Id, "#1");
			Assert.AreEqual ("mono", t.UserName, "#2");
			Assert.AreEqual ("poly", t.Password,"#3");
			Assert.IsTrue (DateTime.Today.ToUniversalTime () <= t.ValidFrom && DateTime.Now.ToUniversalTime () >= t.ValidFrom, "#4");
			Assert.AreEqual (DateTime.MaxValue.AddDays (-1), t.ValidTo, "#5");
			Assert.AreEqual (0, t.SecurityKeys.Count, "#6");
		}
Esempio n. 4
0
 public virtual void WriteValue(UniqueId value)
 {
     if (value == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
     }
     this.WriteString(value.ToString());
 }
Esempio n. 5
0
 public virtual void WriteValue(UniqueId id)
 {
     if (id == null)
     {
         throw new ArgumentNullException("id");
     }
     WriteString(id.ToString());
 }
Esempio n. 6
0
        public virtual void WriteValue(UniqueId value)
        {
            if (value == null)
            {
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
            }

            WriteString(value.ToString());
        }
Esempio n. 7
0
        private Guid ProvideUrnFromHeaderFields(UniqueId headerField)
        {
            var urn = new Guid();

            if (headerField != null)
            {
                var possibleUrnAsString = StripFormattingFromHeaderFields(headerField.ToString());
                Guid.TryParseExact(possibleUrnAsString, "D", out urn);
            }
            return urn;
        }
 public override void Send(Message message, TimeSpan timeout)
 {
     // add the message id if not
     var messageId = new System.Xml.UniqueId();
     if (message.Headers.MessageId == null)
     {
         message.Headers.MessageId = messageId;
     }
     // send message with session id
     var content = GetStringFromWcfMessage(message, RemoteAddress);
     _bus.SendRequest(content, _session.Id, true, ChannelID, null);
     // wait for the acknowledge message from the server side
     _bus.Receive(false, messageId.ToString());
 }
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int    charArrayLength = value.CharArrayLength;
         char[] charBuffer      = this.GetCharBuffer(charArrayLength);
         value.ToCharArray(charBuffer, 0);
         this.WriteText(charBuffer, 0, charArrayLength);
     }
     else
     {
         this.WriteEscapedText(value.ToString());
     }
 }
Esempio n. 10
0
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int    charCount = value.CharArrayLength;
         char[] chars     = GetCharBuffer(charCount);
         value.ToCharArray(chars, 0);
         WriteText(chars, 0, charCount);
     }
     else
     {
         WriteEscapedText(value.ToString());
     }
 }
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int    num;
         byte[] textNodeBuffer = this.GetTextNodeBuffer(0x11, out num);
         textNodeBuffer[num] = 0xac;
         value.TryGetGuid(textNodeBuffer, num + 1);
         base.Advance(0x11);
     }
     else
     {
         this.WriteText(value.ToString());
     }
 }
Esempio n. 12
0
		public void TestDefault ()
		{
			UniqueId id = new UniqueId ();
			Assert.IsTrue (id.IsGuid, "#1");

			Guid g = Guid.NewGuid ();

			UniqueId a = new UniqueId (g);
			UniqueId b = new UniqueId (g.ToByteArray ());

			Assert.AreEqual (a, b, "#2");
			Assert.AreEqual ("urn:uuid:", a.ToString ().Substring (0, 9), "#3");

			a = new UniqueId ("foo");
			Assert.AreEqual ("foo", a.ToString (), "#4");
		}
Esempio n. 13
0
        public void Logger_Log_Success()
        {
            // Arrange
            const string methodName = "Logger_Log_Success";
            var uniqueId = new UniqueId(Urn);
            var messageTextJustInnerXmlOfBody = File.ReadAllText(LoggerSampleRequestJustInnerXmlOfBodyFullPath);
            var messageTextFull = File.ReadAllText(LoggerSampleRequestFullPath).Replace("Method_Name", methodName).Replace("urn:uuid:00000000-0000-0000-0000-000000000000", uniqueId.ToString());
            var xmlReader = XmlReader.Create(new StringReader(messageTextJustInnerXmlOfBody));

            const string sourceType = "WCF Server Side";
            const string incomingRequestText = "incoming request";
            var result = false;

            // Create the Message
            var expectedMessage = Message.CreateMessage(MessageVersion.Soap11WSAddressing10, methodName, xmlReader);

            // Because this is the incoming request, set MessageId
            expectedMessage.Headers.MessageId = uniqueId;

            // Act
            try
            {
                result = LoggerForTests.Log(sourceType, incomingRequestText, Urn, expectedMessage);
            }
            catch (Exception ex)
            {
                Assert.Fail("{0}", ex);
            }

            Assert.IsTrue(result, "Log method returned false");

            // if you want to inspect the value logged in the table, stop the test at this point

            var applicationName = TestHelperForTests.GetAppSettingsKey("SoapRequestsAndResponsesApplicationName");
            const bool isRequest = true;
            const bool isResponse = false;
            var sqlSelectStatement = TestHelperForTests.BuildSqlSelectStatement(applicationName, isRequest, isResponse, Urn, methodName, messageTextFull);
            const int expectedRowCount = 1;
            var rowIdValue = TestHelperForTests.ExecuteSqlSelectStatement(sqlSelectStatement, expectedRowCount);
            var sqlDeleteStatement = TestHelperForTests.BuildSqlDeleteStatement(rowIdValue);
            TestHelperForTests.ExecuteSqlDeleteStatement(sqlDeleteStatement, expectedRowCount);
        }
        public void DebugMessageDispatcher_AfterReceiveRequest_Success()
        {
            // Arrange
            const string methodName = "DebugMessageDispatcher_AfterReceiveRequest_Success";
            var uniqueId = new UniqueId(Urn);
            IClientChannel channel = null;
            InstanceContext context = null;
            var messageTextJustInnerXmlOfBody = File.ReadAllText(DispatcherSampleRequestJustInnerXmlOfBodyFullPath);
            var messageTextFull = File.ReadAllText(DispatcherSampleRequestFullPath).Replace("Method_Name", methodName).Replace("urn:uuid:00000000-0000-0000-0000-000000000000", uniqueId.ToString());
            var xmlReader = XmlReader.Create(new StringReader(messageTextJustInnerXmlOfBody));

            // Create the Message
            var expectedMessage = Message.CreateMessage(MessageVersion.Soap11WSAddressing10, methodName, xmlReader);

            // Because this is the incoming request, set MessageId
            expectedMessage.Headers.MessageId = uniqueId;

            // Act
            try
            {
                // Note: If the SoapRequestsAndResponsesShouldLog in test project App.config is true, then the value should be logged to the DB
                // However, since we are using TPL (Task Parallel Library) Task.Factory.StartNew, the below call will finish before the item is
                // actually logged to the DB
                var actualMessage = DebugMessageDispatcherForTests.AfterReceiveRequest(ref expectedMessage, channel, context);
            }
            catch (Exception ex)
            {
                Assert.Fail("{0}", ex);
            }

            // if you want to inspect the value logged in the table, stop the test at this point

            var applicationName = TestHelperForTests.GetAppSettingsKey("SoapRequestsAndResponsesApplicationName");
            const bool isRequest = true;
            const bool isResponse = false;
            var sqlSelectStatement = TestHelperForTests.BuildSqlSelectStatement(applicationName, isRequest, isResponse, Urn, methodName, messageTextFull);
            const int expectedRowCount = 1;
            var rowIdValue = TestHelperForTests.ExecuteSqlSelectStatement(sqlSelectStatement, expectedRowCount);
            var sqlDeleteStatement = TestHelperForTests.BuildSqlDeleteStatement(rowIdValue);
            TestHelperForTests.ExecuteSqlDeleteStatement(sqlDeleteStatement, expectedRowCount);
        }
        public void DebugMessageInspector_AfterReceiveReply_Success()
        {
            // Arrange
            const string methodName = "DebugMessageInspector_AfterReceiveReply_Success";
            var uniqueId = new UniqueId(Urn);
            var messageTextJustInnerXmlOfBody = File.ReadAllText(InspectorSampleReplyJustInnerXmlOfBodyFullPath);
            var messageTextFull = File.ReadAllText(InspectorSampleReplyFullPath).Replace("Method_Name", methodName).Replace("urn:uuid:00000000-0000-0000-0000-000000000000", uniqueId.ToString());
            var xmlReader = XmlReader.Create(new StringReader(messageTextJustInnerXmlOfBody));

            // Create the Message
            var expectedMessage = Message.CreateMessage(MessageVersion.Default, methodName, xmlReader);

            // Because this is the incoming reply, set RelatesTo
            expectedMessage.Headers.RelatesTo = uniqueId;

            // Act
            object myCorrelationState = null;
            try
            {
                // Note: If the SoapRequestsAndResponsesShouldLog in App.config is true, then the value should be logged to the DB
                DebugMessageInspectorForTests.AfterReceiveReply(ref expectedMessage, myCorrelationState);
            }
            catch (Exception ex)
            {
                Assert.Fail("{0}", ex);
            }

            // if you want to inspect the value logged in the table, stop the test at this point

            var applicationName = TestHelperForTests.GetAppSettingsKey("SoapRequestsAndResponsesApplicationName");
            const bool isRequest = false;
            const bool isResponse = true;
            var sqlSelectStatement = TestHelperForTests.BuildSqlSelectStatement(applicationName, isRequest, isResponse, Urn, methodName, messageTextFull);
            const int expectedRowCount = 1;
            var rowIdValue = TestHelperForTests.ExecuteSqlSelectStatement(sqlSelectStatement, expectedRowCount);
            var sqlDeleteStatement = TestHelperForTests.BuildSqlDeleteStatement(rowIdValue);
            TestHelperForTests.ExecuteSqlDeleteStatement(sqlDeleteStatement, expectedRowCount);
        }
Esempio n. 16
0
        public override void WriteValue(UniqueId value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            Guid guid;

            if (value.TryGetGuid(out guid))
            {
                // this conditional branching is required for
                // attr_typed_value not being true.
                ProcessTypedValue();

                writer.Write(BF.UniqueId);
                byte [] bytes = guid.ToByteArray();
                writer.Write(bytes, 0, bytes.Length);
            }
            else
            {
                WriteValue(value.ToString());
            }
        }
 public virtual void WriteValue(UniqueId value)
 {
     if (value == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
     }
     this.WriteString(value.ToString());
 }
Esempio n. 18
0
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int charCount = value.CharArrayLength;
         char[] chars = GetCharBuffer(charCount);
         value.ToCharArray(chars, 0);
         WriteText(chars, 0, charCount);
     }
     else
     {
         WriteEscapedText(value.ToString());
     }
 }
Esempio n. 19
0
 public static string ToString(UniqueId value)
 {
     return(value.ToString());
 }
        public virtual void WriteValue(UniqueId value)
        {
            if (value == null)
                throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");

            WriteString(value.ToString());
        }
Esempio n. 21
0
		public virtual void WriteValue (UniqueId id)
		{
			if (id == null)
				throw new ArgumentNullException ("id");
			WriteString (id.ToString ());
		}
Esempio n. 22
0
        public virtual void WriteValue(UniqueId value)
        {
            ArgumentNullException.ThrowIfNull(value);

            WriteString(value.ToString());
        }
Esempio n. 23
0
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int offset;
         byte[] buffer = GetTextNodeBuffer(17, out offset);
         buffer[offset] = (byte)XmlBinaryNodeType.UniqueIdText;
         value.TryGetGuid(buffer, offset + 1);
         Advance(17);
     }
     else
     {
         WriteText(value.ToString());
     }
 }
        /// <summary>
        /// Reads the SessionSecurityToken from the given reader.
        /// </summary>
        /// <param name="reader">XmlReader over the SessionSecurityToken.</param>
        /// <param name="tokenResolver">SecurityTokenResolver that can used to resolve SessionSecurityToken.</param>
        /// <returns>An instance of <see cref="SessionSecurityToken"/>.</returns>
        /// <exception cref="ArgumentNullException">The input argument 'reader' is null.</exception>
        /// <exception cref="SecurityTokenException">The 'reader' is not positioned at a SessionSecurityToken
        /// or the SessionSecurityToken cannot be read.</exception>
        public override SecurityToken ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            if (tokenResolver == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("tokenResolver");
            }

            byte[]      encodedCookie = null;
            SysUniqueId contextId     = null;
            SysUniqueId keyGeneration = null;

            string ns         = null;
            string identifier = null;
            string instance   = null;

            SecurityToken     securityContextToken = null;
            SessionDictionary dictionary           = SessionDictionary.Instance;

            XmlDictionaryReader dicReader = XmlDictionaryReader.CreateDictionaryReader(reader);

            if (dicReader.IsStartElement(WSSecureConversationFeb2005Constants.ElementNames.Name, WSSecureConversationFeb2005Constants.Namespace))
            {
                ns         = WSSecureConversationFeb2005Constants.Namespace;
                identifier = WSSecureConversationFeb2005Constants.ElementNames.Identifier;
                instance   = WSSecureConversationFeb2005Constants.ElementNames.Instance;
            }
            else if (dicReader.IsStartElement(WSSecureConversation13Constants.ElementNames.Name, WSSecureConversation13Constants.Namespace))
            {
                ns         = WSSecureConversation13Constants.Namespace;
                identifier = WSSecureConversation13Constants.ElementNames.Identifier;
                instance   = WSSecureConversation13Constants.ElementNames.Instance;
            }
            else
            {
                //
                // Something is wrong
                //
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(
                                                                              SR.GetString(SR.ID4230, WSSecureConversationFeb2005Constants.ElementNames.Name, dicReader.Name)));
            }

            string id = dicReader.GetAttribute(WSUtilityConstants.Attributes.IdAttribute, WSUtilityConstants.NamespaceURI);

            dicReader.ReadFullStartElement();
            if (!dicReader.IsStartElement(identifier, ns))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(
                                                                              SR.GetString(SR.ID4230, WSSecureConversation13Constants.ElementNames.Identifier, dicReader.Name)));
            }

            contextId = dicReader.ReadElementContentAsUniqueId();
            if (contextId == null || string.IsNullOrEmpty(contextId.ToString()))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4242)));
            }

            //
            // The token can be a renewed token, in which case we need to know the
            // instance id, which will be the secondary key to the context id for
            // cache lookups
            //
            if (dicReader.IsStartElement(instance, ns))
            {
                keyGeneration = dicReader.ReadElementContentAsUniqueId();
            }

            if (dicReader.IsStartElement(CookieElementName, CookieNamespace))
            {
                // Get the token from the Cache, which is returned as an SCT
                SecurityToken cachedToken = null;

                SecurityContextKeyIdentifierClause sctClause = null;
                if (keyGeneration == null)
                {
                    sctClause = new SecurityContextKeyIdentifierClause(contextId);
                }
                else
                {
                    sctClause = new SecurityContextKeyIdentifierClause(contextId, keyGeneration);
                }

                tokenResolver.TryResolveToken(sctClause, out cachedToken);

                if (cachedToken != null)
                {
                    securityContextToken = cachedToken;

                    dicReader.Skip();
                }
                else
                {
                    //
                    // CookieMode
                    //
                    encodedCookie = dicReader.ReadElementContentAsBase64();

                    if (encodedCookie == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4237)));
                    }
                    //
                    // appply transforms
                    //
                    byte[] decodedCookie = ApplyTransforms(encodedCookie, false);

                    using (MemoryStream ms = new MemoryStream(decodedCookie))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        securityContextToken = formatter.Deserialize(ms) as SecurityToken;
                    }

                    SessionSecurityToken sessionToken = securityContextToken as SessionSecurityToken;
                    if (sessionToken != null && sessionToken.ContextId != contextId)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4229, sessionToken.ContextId, contextId)));
                    }

                    if (sessionToken != null && sessionToken.Id != id)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4227, sessionToken.Id, id)));
                    }
                }
            }
            else
            {
                //
                // SessionMode
                //

                // Get the token from the Cache.
                SecurityToken cachedToken = null;

                SecurityContextKeyIdentifierClause sctClause = null;
                if (keyGeneration == null)
                {
                    sctClause = new SecurityContextKeyIdentifierClause(contextId);
                }
                else
                {
                    sctClause = new SecurityContextKeyIdentifierClause(contextId, keyGeneration);
                }

                tokenResolver.TryResolveToken(sctClause, out cachedToken);

                if (cachedToken != null)
                {
                    securityContextToken = cachedToken;
                }
            }

            dicReader.ReadEndElement();

            if (securityContextToken == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenException(SR.GetString(SR.ID4243)));
            }

            return(securityContextToken);
        }
Esempio n. 25
0
		public void Ctor_Chars ()
		{
			var a = new UniqueId ("Hello!".ToCharArray (), 0, 5);
			Assert.IsFalse (a.IsGuid);
			Assert.AreEqual ("Hello", a.ToString ());

			a = new UniqueId ();
			var b = new UniqueId (a.ToString ().ToCharArray (), 0, 45);
			Assert.IsTrue (b.IsGuid);
			Assert.AreEqual (a, b);

			string s = "foo" + a.ToString () + "bar";
			b = new UniqueId (s.ToCharArray (), 3, s.Length-6);
			Assert.IsTrue (b.IsGuid);
			Assert.AreEqual (a, b);

			a = new UniqueId (new Guid ());
			b = new UniqueId (a.ToString ().ToCharArray (), 0, 45);
			Assert.IsFalse (b.IsGuid);
			Assert.AreEqual (a, b);
		}
Esempio n. 26
0
 static public string ToString(UniqueId value) { return value.ToString(); }
 internal static PeerDictionaryHeader CreateMessageIdHeader(UniqueId messageId)
 {
     return new PeerDictionaryHeader(XD.AddressingDictionary.MessageId, XD.PeerWireStringsDictionary.Namespace, messageId.ToString());
 }
Esempio n. 28
0
		public void CharArrayLength ()
		{
			var u = new UniqueId ("string");
			Assert.AreEqual (6, u.CharArrayLength);
			Assert.AreEqual (u.ToString().Length, u.CharArrayLength);

			u = new UniqueId (new Guid());
			Assert.AreEqual (45, u.CharArrayLength);
			Assert.AreEqual (u.ToString().Length, u.CharArrayLength);
		}
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int num;
         byte[] textNodeBuffer = this.GetTextNodeBuffer(0x11, out num);
         textNodeBuffer[num] = 0xac;
         value.TryGetGuid(textNodeBuffer, num + 1);
         base.Advance(0x11);
     }
     else
     {
         this.WriteText(value.ToString());
     }
 }
 public override void WriteUniqueIdText(UniqueId value)
 {
     if (value.IsGuid)
     {
         int charArrayLength = value.CharArrayLength;
         char[] charBuffer = this.GetCharBuffer(charArrayLength);
         value.ToCharArray(charBuffer, 0);
         this.WriteText(charBuffer, 0, charArrayLength);
     }
     else
     {
         this.WriteEscapedText(value.ToString());
     }
 }
		public override void WriteValue (UniqueId value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");

			Guid guid;
			if (value.TryGetGuid (out guid)) {
				// this conditional branching is required for
				// attr_typed_value not being true.
				ProcessTypedValue ();

				writer.Write (BF.UniqueId);
				byte [] bytes = guid.ToByteArray ();
				writer.Write (bytes, 0, bytes.Length);
			} else {
				WriteValue (value.ToString ());
			}
		}
 static internal PeerDictionaryHeader CreateMessageIdHeader(System.Xml.UniqueId messageId)
 {
     return(new PeerDictionaryHeader(XD.AddressingDictionary.MessageId, XD.PeerWireStringsDictionary.Namespace, messageId.ToString()));
 }