示例#1
0
		public Command Run (WindowFrame transientFor, MessageDescription message)
		{
			this.icon = GetIcon (message.Icon);
			if (ConvertButtons (message.Buttons, out buttons)) {
				// Use a system message box
				if (message.SecondaryText == null)
					message.SecondaryText = String.Empty;
				else {
					message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
					message.SecondaryText = String.Empty;
				}
				var wb = (WindowFrameBackend)Toolkit.GetBackend (transientFor);
				if (wb != null) {
					this.dialogResult = MessageBox.Show (wb.Window, message.Text, message.SecondaryText,
														this.buttons, this.icon, this.defaultResult, this.options);
				}
				else {
					this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons,
														this.icon, this.defaultResult, this.options);
				}
				return ConvertResultToCommand (this.dialogResult);
			}
			else {
				// Custom message box required
				Dialog dlg = new Dialog ();
				dlg.Resizable = false;
				dlg.Padding = 0;
				HBox mainBox = new HBox { Margin = 25 };

				if (message.Icon != null) {
					var image = new ImageView (message.Icon.WithSize (32,32));
					mainBox.PackStart (image, vpos: WidgetPlacement.Start);
				}
				VBox box = new VBox () { Margin = 3, MarginLeft = 8, Spacing = 15 };
				mainBox.PackStart (box, true);
				var text = new Label {
					Text = message.Text ?? ""
				};
				Label stext = null;
				box.PackStart (text);
				if (!string.IsNullOrEmpty (message.SecondaryText)) {
					stext = new Label {
						Text = message.SecondaryText
					};
					box.PackStart (stext);
				}
				dlg.Buttons.Add (message.Buttons.ToArray ());
				if (mainBox.Surface.GetPreferredSize (true).Width > 480) {
					text.Wrap = WrapMode.Word;
					if (stext != null)
						stext.Wrap = WrapMode.Word;
					mainBox.WidthRequest = 480;
				}
				var s = mainBox.Surface.GetPreferredSize (true);

				dlg.Content = mainBox;
				return dlg.Run ();
			}
		}
示例#2
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.MessageText = (message.Text != null) ? message.Text : String.Empty;
            this.InformativeText = (message.SecondaryText != null) ? message.SecondaryText : String.Empty;
            //TODO Set Icon
            //TODO Sort Buttons to have the default button first
            foreach (Command cmd in message.Buttons) {
                this.AddButton (cmd.Label);
            }

            return message.Buttons [this.RunModal () - 1000];
        }
 // Methods
 internal MessageDescription(MessageDescription other)
 {
     this.action = other.action;
     this.direction = other.direction;
     this.Items.Body = other.Items.Body.Clone();
     foreach (MessageHeaderDescription description in other.Items.Headers)
     {
         this.Items.Headers.Add(description.Clone() as MessageHeaderDescription);
     }
     foreach (MessagePropertyDescription description2 in other.Items.Properties)
     {
         this.Items.Properties.Add(description2.Clone() as MessagePropertyDescription);
     }
     this.MessageName = other.MessageName;
     this.MessageType = other.MessageType;
     this.XsdTypeName = other.XsdTypeName;
     this.hasProtectionLevel = other.hasProtectionLevel;
     this.ProtectionLevel = other.ProtectionLevel;
 }
示例#4
0
		public Command Run (WindowFrame transientFor, MessageDescription message)
		{
			this.MessageText = (message.Text != null) ? message.Text : String.Empty;
			this.InformativeText = (message.SecondaryText != null) ? message.SecondaryText : String.Empty;
			//TODO Set Icon

			var sortedButtons = new Command [message.Buttons.Count];
			sortedButtons [0] = message.Buttons [message.DefaultButton];
			this.AddButton (message.Buttons [message.DefaultButton].Label);
			var j = 1;
			for (var i = 0; i < message.Buttons.Count; i++) {
				if (i == message.DefaultButton)
					continue;
				sortedButtons [j++] = message.Buttons [i];
				this.AddButton (message.Buttons [i].Label);
			}

			return sortedButtons [this.RunModal () - 1000];
		}
示例#5
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon = GetIcon (message.Icon);
            this.buttons = ConvertButtons (message.Buttons);
            if (message.SecondaryText == null)
                message.SecondaryText = String.Empty;
            else {
                message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
                message.SecondaryText = String.Empty;
            }

            var wb = (WindowFrameBackend)Toolkit.GetBackend (transientFor);
            if (wb != null) {
                this.dialogResult = MessageBox.Show (wb.Window, message.Text,message.SecondaryText,
                                                    this.buttons, this.icon, this.defaultResult, this.options);
            } else {
                this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons,
                                                    this.icon, this.defaultResult, this.options);
            }

            return ConvertResultToCommand (this.dialogResult);
        }
示例#6
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            GtkAlertDialog alertDialog = new GtkAlertDialog (message);
            alertDialog.FocusButton (message.DefaultButton);
            var wb = (WindowFrameBackend)Toolkit.GetBackend (transientFor);
            var win = wb != null ? wb.Window : null;
            MessageService.ShowCustomDialog (alertDialog, win);
            if (alertDialog.ApplyToAll)
                ApplyToAll = true;
            var res = alertDialog.ResultButton;

            if (res == null) {
                // If the dialog is closed clicking the close window button we may have no result.
                // In that case, try to find a cancelling button
                if (message.Buttons.Contains (Command.Cancel))
                    return Command.Cancel;
                else if (message.Buttons.Contains (Command.No))
                    return Command.No;
                else if (message.Buttons.Contains (Command.Close))
                    return Command.Close;
            }
            return res;
        }
 public AlertDialog(MessageDescription message)
 {
     data.Message = message;
 }
示例#8
0
        protected override Dictionary <MessageHeaderDescription, object> MessageToHeaderObjects(MessageDescription md, Message message)
        {
            if (message.IsEmpty || md.Headers.Count == 0)
            {
                return(null);
            }

            var dic = new Dictionary <MessageHeaderDescription, object> ();

            for (int i = 0; i < message.Headers.Count; i++)
            {
                var r  = message.Headers.GetReaderAtHeader(i);
                var mh = md.Headers.FirstOrDefault(h => h.Name == r.LocalName && h.Namespace == r.NamespaceURI);
                if (mh != null)
                {
                    dic [mh] = ReadHeaderObject(mh.Type, GetSerializer(mh), r);
                }
            }
            return(dic);
        }
示例#9
0
        public GtkAlertDialog(MessageDescription message)
        {
            Init();
            this.buttons = message.Buttons.ToArray();

            Modal = true;

            string primaryText;
            string secondaryText;

            if (string.IsNullOrEmpty(message.SecondaryText))
            {
                secondaryText = message.Text;
                primaryText   = null;
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            if (!string.IsNullOrEmpty(message.Icon))
            {
                image        = new ImageView();
                image.Yalign = 0.00f;
                image.Image  = ImageService.GetIcon(message.Icon, IconSize.Dialog);
                hbox.PackStart(image, false, false, 0);
                hbox.ReorderChild(image, 0);
            }

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(GLib.Markup.EscapeText(primaryText));
            markup.Append("</span>");
            if (!String.IsNullOrEmpty(secondaryText))
            {
                if (!String.IsNullOrEmpty(primaryText))
                {
                    markup.AppendLine();
                    markup.AppendLine();
                }
                markup.Append(GLib.Markup.EscapeText(secondaryText));
            }
            label.Markup     = markup.ToString();
            label.Selectable = true;
            label.CanFocus   = false;

            foreach (AlertButton button in message.Buttons)
            {
                Button newButton = new Button();
                newButton.Label        = button.Label;
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (!String.IsNullOrEmpty(button.Icon))
                {
                    newButton.Image = new Image(button.Icon, IconSize.Button);
                }
                newButton.Clicked += ButtonClicked;
                ActionArea.Add(newButton);
            }

            foreach (var op in message.Options)
            {
                CheckButton check = new CheckButton(op.Text);
                check.Active = op.Value;
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                CheckButton check = new CheckButton(GettextCatalog.GetString("Apply to all"));
                labelsBox.PackStart(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
示例#10
0
 protected abstract Message PartsToMessage(
     MessageDescription md, MessageVersion version, string action, object [] parts);
示例#11
0
 protected abstract Dictionary <MessageHeaderDescription, object> MessageToHeaderObjects(MessageDescription md, Message message);
示例#12
0
 protected abstract void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest);
示例#13
0
 public CSharpMessageBuilder(MessageDescription description)
 {
     _description = description;
 }
示例#14
0
        protected override void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            try
            {
                XmlSerializer serializer;
                MessageHeaderDescriptionTable headerDescriptionTable;
                MessageHeaderDescription      unknownHeaderDescription;
                if (isRequest)
                {
                    serializer               = _requestMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _requestMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _requestMessageInfo.UnknownHeaderDescription;
                }
                else
                {
                    serializer               = _replyMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _replyMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _replyMessageInfo.UnknownHeaderDescription;
                }
                MessageHeaders headers        = message.Headers;
                ArrayList      unknownHeaders = null;
                XmlDocument    xmlDoc         = null;
                if (unknownHeaderDescription != null)
                {
                    unknownHeaders = new ArrayList();
                    xmlDoc         = new XmlDocument();
                }
                if (serializer == null)
                {
                    if (unknownHeaderDescription != null)
                    {
                        for (int headerIndex = 0; headerIndex < headers.Count; headerIndex++)
                        {
                            AddUnknownHeader(unknownHeaderDescription, unknownHeaders, xmlDoc, null /*bufferWriter*/, headers[headerIndex], headers.GetReaderAtHeader(headerIndex));
                        }

                        parameters[unknownHeaderDescription.Index] = unknownHeaders.ToArray(unknownHeaderDescription.TypedHeader ? typeof(MessageHeader <XmlElement>) : typeof(XmlElement));
                    }
                    return;
                }


                MemoryStream        memoryStream = new MemoryStream();
                XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream);
                message.WriteStartEnvelope(bufferWriter);
                message.WriteStartHeaders(bufferWriter);
                MessageHeaderOfTHelper messageHeaderOfTHelper = null;
                for (int headerIndex = 0; headerIndex < headers.Count; headerIndex++)
                {
                    MessageHeaderInfo        header       = headers[headerIndex];
                    XmlDictionaryReader      headerReader = headers.GetReaderAtHeader(headerIndex);
                    MessageHeaderDescription matchingHeaderDescription = headerDescriptionTable.Get(header.Name, header.Namespace);
                    if (matchingHeaderDescription != null)
                    {
                        if (header.MustUnderstand)
                        {
                            headers.UnderstoodHeaders.Add(header);
                        }

                        if (matchingHeaderDescription.TypedHeader)
                        {
                            if (messageHeaderOfTHelper == null)
                            {
                                messageHeaderOfTHelper = new MessageHeaderOfTHelper(parameters.Length);
                            }

                            messageHeaderOfTHelper.SetHeaderAttributes(matchingHeaderDescription, header.MustUnderstand, header.Relay, header.Actor);
                        }
                    }
                    if (matchingHeaderDescription == null && unknownHeaderDescription != null)
                    {
                        AddUnknownHeader(unknownHeaderDescription, unknownHeaders, xmlDoc, bufferWriter, header, headerReader);
                    }
                    else
                    {
                        bufferWriter.WriteNode(headerReader, false);
                    }

                    headerReader.Dispose();
                }
                bufferWriter.WriteEndElement();
                bufferWriter.WriteEndElement();
                bufferWriter.Flush();

                /*
                 * XmlDocument doc = new XmlDocument();
                 * memoryStream.Position = 0;
                 * doc.Load(memoryStream);
                 * doc.Save(Console.Out);
                 */

                memoryStream.Position = 0;
                ArraySegment <byte> memoryBuffer;
                memoryStream.TryGetBuffer(out memoryBuffer);
                XmlDictionaryReader bufferReader = XmlDictionaryReader.CreateTextReader(memoryBuffer.Array, 0, (int)memoryStream.Length, XmlDictionaryReaderQuotas.Max);

                bufferReader.ReadStartElement();
                bufferReader.MoveToContent();
                if (!bufferReader.IsEmptyElement)
                {
                    bufferReader.ReadStartElement();
                    object[] headerValues = (object[])serializer.Deserialize(bufferReader, _isEncoded ? GetEncoding(message.Version.Envelope) : null);
                    int      headerIndex  = 0;
                    foreach (MessageHeaderDescription headerDescription in messageDescription.Headers)
                    {
                        if (!headerDescription.IsUnknownHeaderCollection)
                        {
                            object parameterValue = headerValues[headerIndex++];
                            if (headerDescription.TypedHeader && parameterValue != null)
                            {
                                parameterValue = messageHeaderOfTHelper.CreateMessageHeader(headerDescription, parameterValue);
                            }

                            parameters[headerDescription.Index] = parameterValue;
                        }
                    }
                    bufferReader.Dispose();
                }
                if (unknownHeaderDescription != null)
                {
                    parameters[unknownHeaderDescription.Index] = unknownHeaders.ToArray(unknownHeaderDescription.TypedHeader ? typeof(MessageHeader <XmlElement>) : typeof(XmlElement));
                }
            }
            catch (InvalidOperationException e)
            {
                // all exceptions from XmlSerializer get wrapped in InvalidOperationException,
                // so we must be conservative and never turn this into a fault
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorDeserializingHeader, messageDescription.MessageName), e));
            }
        }
示例#15
0
        protected override void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest)
        {
            if (writer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(writer)));
            }

            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)));
            }

            try
            {
                MessageInfo messageInfo;
                if (isRequest)
                {
                    messageInfo = _requestMessageInfo;
                }
                else
                {
                    messageInfo = _replyMessageInfo;
                }

                if (messageInfo.RpcEncodedTypedMessageBodyParts == null)
                {
                    SerializeBody(writer, version, messageInfo.BodySerializer, messageDescription.Body.ReturnValue, messageDescription.Body.Parts, returnValue, parameters);
                    return;
                }

                object[] bodyPartValues = new object[messageInfo.RpcEncodedTypedMessageBodyParts.Count];
                object   bodyObject     = parameters[messageDescription.Body.Parts[0].Index];
                if (bodyObject == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFxBodyCannotBeNull, messageDescription.MessageName)));
                }

                int i = 0;
                foreach (MessagePartDescription bodyPart in messageInfo.RpcEncodedTypedMessageBodyParts)
                {
                    MemberInfo member = bodyPart.MemberInfo;
                    FieldInfo  field  = member as FieldInfo;
                    if (field != null)
                    {
                        bodyPartValues[i++] = field.GetValue(bodyObject);
                    }
                    else
                    {
                        PropertyInfo property = member as PropertyInfo;
                        if (property != null)
                        {
                            bodyPartValues[i++] = property.GetValue(bodyObject, null);
                        }
                    }
                }
                SerializeBody(writer, version, messageInfo.BodySerializer, null /*returnPart*/, messageInfo.RpcEncodedTypedMessageBodyParts, null /*returnValue*/, bodyPartValues);
            }
            catch (InvalidOperationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorSerializingBody, messageDescription.MessageName, e.Message), e));
            }
        }
        protected override void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo = isRequest ? requestMessageInfo : replyMessageInfo;

            if (!messageInfo.AnyHeaders)
            {
                return;
            }
            MessageHeaders headers = message.Headers;

            KeyValuePair <Type, ArrayList>[] multipleHeaderValues = null;
            ArrayList elementList = null;

            if (messageInfo.UnknownHeaderDescription != null)
            {
                elementList = new ArrayList();
            }

            for (int i = 0; i < headers.Count; i++)
            {
                MessageHeaderInfo        header            = headers[i];
                MessageHeaderDescription headerDescription = messageInfo.HeaderDescriptionTable.Get(header.Name, header.Namespace);
                if (headerDescription != null)
                {
                    if (header.MustUnderstand)
                    {
                        headers.UnderstoodHeaders.Add(header);
                    }

                    object item = null;
                    XmlDictionaryReader headerReader = headers.GetReaderAtHeader(i);
                    try
                    {
                        object dataValue = DeserializeHeaderContents(headerReader, messageDescription, headerDescription);
                        if (headerDescription.TypedHeader)
                        {
                            item = TypedHeaderManager.Create(headerDescription.Type, dataValue, headers[i].MustUnderstand, headers[i].Relay, headers[i].Actor);
                        }
                        else
                        {
                            item = dataValue;
                        }
                    }
                    finally
                    {
                        headerReader.Dispose();
                    }

                    if (headerDescription.Multiple)
                    {
                        if (multipleHeaderValues == null)
                        {
                            multipleHeaderValues = new KeyValuePair <Type, ArrayList> [parameters.Length];
                        }
                        if (multipleHeaderValues[headerDescription.Index].Key == null)
                        {
                            multipleHeaderValues[headerDescription.Index] = new KeyValuePair <System.Type, System.Collections.ArrayList>(headerDescription.TypedHeader ? TypedHeaderManager.GetMessageHeaderType(headerDescription.Type) : headerDescription.Type, new ArrayList());
                        }
                        multipleHeaderValues[headerDescription.Index].Value.Add(item);
                    }
                    else
                    {
                        parameters[headerDescription.Index] = item;
                    }
                }
                else if (messageInfo.UnknownHeaderDescription != null)
                {
#if FEATURE_CORECLR
                    MessageHeaderDescription unknownHeaderDescription = messageInfo.UnknownHeaderDescription;
                    XmlDictionaryReader      headerReader             = headers.GetReaderAtHeader(i);
                    try
                    {
                        XmlDocument doc       = new XmlDocument();
                        object      dataValue = doc.ReadNode(headerReader);
                        if (dataValue != null && unknownHeaderDescription.TypedHeader)
                        {
                            dataValue = TypedHeaderManager.Create(unknownHeaderDescription.Type, dataValue, headers[i].MustUnderstand, headers[i].Relay, headers[i].Actor);
                        }
                        elementList.Add(dataValue);
                    }
                    finally
                    {
                        headerReader.Dispose();
                    }
#else
                    throw ExceptionHelper.PlatformNotSupported(); // XmlDocument not available in native
#endif
                }
            }
            if (multipleHeaderValues != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (multipleHeaderValues[i].Key != null)
                    {
                        parameters[i] = multipleHeaderValues[i].Value.ToArray(multipleHeaderValues[i].Key);
                    }
                }
            }
        }
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("reader"));
            }
            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }

            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = requestMessageInfo;
            }
            else
            {
                messageInfo = replyMessageInfo;
            }

            if (messageInfo.WrapperName != null)
            {
                if (!reader.IsStartElement(messageInfo.WrapperName, messageInfo.WrapperNamespace))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(SR.Format(SR.SFxInvalidMessageBody, messageInfo.WrapperName, messageInfo.WrapperNamespace, reader.NodeType, reader.Name, reader.NamespaceURI)));
                }
                bool isEmptyElement = reader.IsEmptyElement;
                reader.Read();
                if (isEmptyElement)
                {
                    return(null);
                }
            }
            object returnValue = null;

            if (messageInfo.ReturnPart != null)
            {
                while (true)
                {
                    PartInfo part = messageInfo.ReturnPart;
                    if (part.Serializer.IsStartObject(reader))
                    {
                        returnValue = DeserializeParameter(reader, part, isRequest);
                        break;
                    }
                    if (!reader.IsStartElement())
                    {
                        break;
                    }
                    OperationFormatter.TraceAndSkipElement(reader);
                }
            }
            DeserializeParameters(reader, messageInfo.BodyParts, parameters, isRequest);
            if (messageInfo.WrapperName != null)
            {
                reader.ReadEndElement();
            }
            return(returnValue);
        }
        protected override void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest)
        {
            if (writer == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
            }
            if (parameters == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("parameters"));
            }

            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = requestMessageInfo;
            }
            else
            {
                messageInfo = replyMessageInfo;
            }
            if (messageInfo.WrapperName != null)
            {
                writer.WriteStartElement(messageInfo.WrapperName, messageInfo.WrapperNamespace);
            }
            if (messageInfo.ReturnPart != null)
            {
                SerializeParameter(writer, messageInfo.ReturnPart, returnValue);
            }
            SerializeParameters(writer, messageInfo.BodyParts, parameters);
            if (messageInfo.WrapperName != null)
            {
                writer.WriteEndElement();
            }
        }
示例#19
0
        public void InternalTestGetContract(ContractDescription cd)
        {
            ServiceAssert.AssertContractDescription(
                "IFoo", "http://tempuri.org/", SessionMode.Allowed, typeof(IFoo), null,
                cd, "contract");

            Assert.AreEqual(2, cd.Operations.Count, "Operation count");

            // Operation #1
            OperationDescription od = cd.Operations [0];

            ServiceAssert.AssertOperationDescription(
                "HeyDude", null, null,
                typeof(IFoo).GetMethod("HeyDude"),
                true, false, false,
                od, "HeyDude");

            // Operation #1 -> Message #1
            MessageDescription md = od.Messages [0];

            ServiceAssert.AssertMessageAndBodyDescription(
                "http://tempuri.org/IFoo/HeyDude",
                MessageDirection.Input,
                null, "HeyDude", "http://tempuri.org/", false,
                md, "HeyDude");

            ServiceAssert.AssertMessagePartDescription(
                "msg", "http://tempuri.org/", 0, false,
                ProtectionLevel.None, typeof(string), md.Body.Parts [0], "HeyDude.msg");
            ServiceAssert.AssertMessagePartDescription(
                "msg2", "http://tempuri.org/", 1, false,
                ProtectionLevel.None, typeof(string), md.Body.Parts [1], "HeyDude.msg");

            // Operation #1 -> Message #2
            md = od.Messages [1];

            ServiceAssert.AssertMessageAndBodyDescription(
                "http://tempuri.org/IFoo/HeyDudeResponse",
                MessageDirection.Output,
                null, "HeyDudeResponse",
                "http://tempuri.org/", true,
                md, "HeyDude");

            ServiceAssert.AssertMessagePartDescription(
                "HeyDudeResult", "http://tempuri.org/", 0, false,
                ProtectionLevel.None, typeof(string), md.Body.ReturnValue, "HeyDudeResponse ReturnValue");

            // Operation #2
            od = cd.Operations [1];

            ServiceAssert.AssertOperationDescription(
                "HeyHey", null, null,
                typeof(IFoo).GetMethod("HeyHey"),
                true, false, false,
                od, "HeyHey");

            // Operation #2 -> Message #1
            md = od.Messages [0];

            ServiceAssert.AssertMessageAndBodyDescription(
                "http://tempuri.org/IFoo/HeyHey",
                MessageDirection.Input,
                null, "HeyHey", "http://tempuri.org/", false,
                md, "HeyHey");

            ServiceAssert.AssertMessagePartDescription(
                "ref1", "http://tempuri.org/", 0, false,
                ProtectionLevel.None, typeof(string), md.Body.Parts [0], "HeyHey.ref1");

            // Operation #2 -> Message #2
            md = od.Messages [1];

            ServiceAssert.AssertMessageAndBodyDescription(
                "http://tempuri.org/IFoo/HeyHeyResponse",
                MessageDirection.Output,
                null, "HeyHeyResponse",
                "http://tempuri.org/", true,
                md, "HeyHey");

            ServiceAssert.AssertMessagePartDescription(
                "HeyHeyResult", "http://tempuri.org/", 0, false,
                ProtectionLevel.None, typeof(void), md.Body.ReturnValue, "HeyHeyResponse ReturnValue");

            ServiceAssert.AssertMessagePartDescription(
                "out1", "http://tempuri.org/", 0, false,
                ProtectionLevel.None, typeof(string), md.Body.Parts [0], "HeyHey.out1");
            ServiceAssert.AssertMessagePartDescription(
                "ref1", "http://tempuri.org/", 1, false,
                ProtectionLevel.None, typeof(string), md.Body.Parts [1], "HeyHey.ref1");
        }
        public static void ValidateParametersContent(NativeActivityContext context, MessageDescription targetMessage, IDictionary parameters,
                                                     OperationDescription targetOperation, bool isResponse)
        {
            // The following properties can only be set via message contract. Therefore, we do not need to validate them here.
            // MessageDescription: Headers, Properties, ProtectionLevel
            // MessagePartDescription: Namespace, ProtectionLevel, Multiple, Index
            MessageBodyDescription targetMessageBody = targetMessage.Body;

            Fx.Assert(targetMessageBody != null, "MessageDescription.Body is never null!");

            if (targetMessageBody.WrapperName == null)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.UnwrappedMessageNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name)));
            }
            if (targetMessageBody.WrapperNamespace == null)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.UnwrappedMessageNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name)));
            }

            IDictionaryEnumerator iterator = parameters.GetEnumerator();
            int benchmarkIndex             = 0;
            int hitCount = 0;

            // Return value needs to be treated specially since ReceiveParametersContent does not have return value on the OM.
            bool targetHasReturnValue = isResponse && targetMessageBody.ReturnValue != null && targetMessageBody.ReturnValue.Type != TypeHelper.VoidType;

            if (targetHasReturnValue)
            {
                if (iterator.MoveNext() && (string)iterator.Key == targetMessageBody.ReturnValue.Name)
                {
                    Argument argument = (Argument)iterator.Value;
                    if (argument != null && argument.ArgumentType != targetMessageBody.ReturnValue.Type)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.FirstParameterDoesnotMatchTheReturnValue(argument.ArgumentType.FullName, targetMessageBody.ReturnValue.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }
                    hitCount++;
                }
                else if (parameters.Contains(targetMessageBody.ReturnValue.Name))
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.ParameterPositionMismatch(targetMessageBody.ReturnValue.Name, targetOperation.Name, targetOperation.DeclaringContract.Name, "0")));
                    hitCount++;
                }
                else
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.ReturnValueMissing(targetMessageBody.ReturnValue.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                }

                benchmarkIndex++;
            }

            foreach (MessagePartDescription targetPart in targetMessageBody.Parts)
            {
                if (iterator.MoveNext() && (string)iterator.Key == targetPart.Name)
                {
                    Argument argument = (Argument)iterator.Value;
                    if (argument != null && argument.ArgumentType != targetPart.Type)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(targetPart.Name, targetPart.Type.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                    }
                    hitCount++;
                }
                else if (parameters.Contains(targetPart.Name))
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.ParameterPositionMismatch(targetPart.Name, targetOperation.Name, targetOperation.DeclaringContract.Name, benchmarkIndex)));
                    hitCount++;
                }
                else
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.MissingParameter(targetPart.Name, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                }

                benchmarkIndex++;
            }

            if (hitCount != parameters.Count)
            {
                foreach (string name in parameters.Keys)
                {
                    XmlQualifiedName qName = new XmlQualifiedName(name, targetOperation.DeclaringContract.Namespace);
                    if (!targetMessageBody.Parts.Contains(qName))
                    {
                        if (!targetHasReturnValue || targetHasReturnValue && name != targetMessageBody.ReturnValue.Name)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ExtraParameter(name, targetOperation.Name, targetOperation.DeclaringContract.Name)));
                        }
                    }
                }
            }
        }
		public AlertDialog (MessageDescription message)
		{
			Init ();
			this.buttons = message.buttons.ToArray ();
			
			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}
			
			image.Pixbuf = ImageService.GetPixbuf (message.Icon, IconSize.Dialog);
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (GLib.Markup.EscapeText (secondaryText));
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			
			foreach (AlertButton button in message.buttons) {
				Button newButton = new Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (!String.IsNullOrEmpty (button.Icon))
					newButton.Image = new Image (button.Icon, IconSize.Button);
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (MessageDescription.Option op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton (GettextCatalog.GetString ("Apply to all"));
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			this.ShowAll ();
		}
示例#22
0
        protected override object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            MessageInfo messageInfo;

            if (isRequest)
            {
                messageInfo = _requestMessageInfo;
            }
            else
            {
                messageInfo = _replyMessageInfo;
            }

            if (messageInfo.RpcEncodedTypedMessageBodyParts == null)
            {
                return(DeserializeBody(reader, version, messageInfo.BodySerializer, messageDescription.Body.ReturnValue, messageDescription.Body.Parts, parameters, isRequest));
            }

            object[] bodyPartValues = new object[messageInfo.RpcEncodedTypedMessageBodyParts.Count];
            DeserializeBody(reader, version, messageInfo.BodySerializer, null /*returnPart*/, messageInfo.RpcEncodedTypedMessageBodyParts, bodyPartValues, isRequest);
            object bodyObject = Activator.CreateInstance(messageDescription.Body.Parts[0].Type);
            int    i          = 0;

            foreach (MessagePartDescription bodyPart in messageInfo.RpcEncodedTypedMessageBodyParts)
            {
                MemberInfo member = bodyPart.MemberInfo;
                FieldInfo  field  = member as FieldInfo;
                if (field != null)
                {
                    field.SetValue(bodyObject, bodyPartValues[i++]);
                }
                else
                {
                    PropertyInfo property = member as PropertyInfo;
                    if (property != null)
                    {
                        property.SetValue(bodyObject, bodyPartValues[i++], null);
                    }
                }
            }
            parameters[messageDescription.Body.Parts[0].Index] = bodyObject;
            return(null);
        }
        public static void ValidateMessageContent(NativeActivityContext context, MessageDescription targetMessage, Type declaredMessageType,
                                                  SerializerOption serializerOption, OperationDescription operation, bool isResponse)
        {
            // MessageContract is allowed only if the WCF contract interface specifies the same message contract type.
            if (MessageBuilder.IsMessageContract(declaredMessageType))
            {
                // if it is a typed message contract, we just validate the type of the message matches
                if (targetMessage.MessageType != null)
                {
                    if (declaredMessageType != targetMessage.MessageType)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", targetMessage.MessageType.ToString(), operation.Name, operation.DeclaringContract.Name)));
                    }
                }
                else
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(declaredMessageType.ToString(), "type", "null", operation.Name, operation.DeclaringContract.Name)));
                }
                return;
            }
            else if (declaredMessageType != null && declaredMessageType.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
            {
                //This is an untyped message contract
                if (targetMessage.Body == null)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.BodyCannotBeNull));
                }
                else
                {
                    if (isResponse)
                    {
                        if (targetMessage.Body.ReturnValue == null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ExtraReturnValue));
                        }
                        else if (!targetMessage.Body.ReturnValue.Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.FirstParameterDoesnotMatchTheReturnValue(declaredMessageType.FullName, targetMessage.Body.ReturnValue.Type.Name, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    else
                    {
                        if (targetMessage.Body.Parts.Count == 0)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else if (targetMessage.Body.Parts.Count > 1)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            if (!targetMessage.Body.Parts[0].Type.IsAssignableFrom(typeof(System.ServiceModel.Channels.Message)))
                            {
                                Constraint.AddValidationError(context, new ValidationError(SR2.MessageTypeMismatch(targetMessage.Body.Parts[0].Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                            }
                        }
                    }
                }

                return;
            }

            // In case the WCF contract is a typed message, and the Receive activity also uses ReceiveMessageContent to infer a typed message, the contract needs to be matched
            Fx.Assert(targetMessage.Body != null, "MessageDescription.Body is never null!");

            // MessageDescription: Headers, Properties, ProtectionLevel
            // MessageBodyDescription: ReturnValue, WrapperName, WrapperNamespace
            // MessagePartDescription: Name, Namespace, Type, ProtectionLevel, Multiple, Index
            if (targetMessage.Headers.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessageHeaderNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.Properties.Count > 0)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.MessagePropertyIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }
            if (targetMessage.HasProtectionLevel)
            {
                Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
            }

            if (declaredMessageType == null || declaredMessageType == TypeHelper.VoidType)
            {
                if (!targetMessage.IsVoid)
                {
                    Constraint.AddValidationError(context, new ValidationError(SR2.MessageCannotBeEmpty(operation.Name, operation.DeclaringContract.Name)));
                }
            }
            else
            {
                string partName;
                string partNamespace;

                if (serializerOption == SerializerOption.DataContractSerializer)
                {
                    XmlQualifiedName xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetRootElementName(declaredMessageType);
                    if (xmlQualifiedName == null)
                    {
                        xmlQualifiedName = MessageBuilder.XsdDataContractExporter.GetSchemaTypeName(declaredMessageType);
                    }

                    if (!xmlQualifiedName.IsEmpty)
                    {
                        partName      = xmlQualifiedName.Name;
                        partNamespace = xmlQualifiedName.Namespace;
                    }
                    else
                    {
                        // For anonymous type, we assign CLR type name and contract namespace to MessagePartDescription
                        partName      = declaredMessageType.Name;
                        partNamespace = operation.DeclaringContract.Namespace;
                    }
                }
                else
                {
                    XmlTypeMapping xmlTypeMapping = MessageBuilder.XmlReflectionImporter.ImportTypeMapping(declaredMessageType);
                    partName      = xmlTypeMapping.ElementName;
                    partNamespace = xmlTypeMapping.Namespace;
                }

                MessagePartDescription targetPart = null;

                if (isResponse && targetMessage.Body.ReturnValue != null && targetMessage.Body.ReturnValue.Type != TypeHelper.VoidType)
                {
                    if (targetMessage.Body.Parts.Count > 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.NotSupportMoreThanOneParametersInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }
                    targetPart = targetMessage.Body.ReturnValue;
                }
                else if (!isResponse)
                {
                    if (targetMessage.Body.WrapperName != null && targetMessage.Body.WrapperName != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.WrapperNamespace != null && targetMessage.Body.WrapperNamespace != String.Empty)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.WrapperNotSupportedInMessageContract(operation.Name, operation.DeclaringContract.Name)));
                    }

                    if (targetMessage.Body.Parts.Count == 0)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ParameterNumberMismatch(declaredMessageType.FullName, operation.Name, operation.DeclaringContract.Name)));
                    }
                    else if (targetMessage.Body.Parts.Count > 1)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.MessageContentCannotHaveMoreThanOneParameter(operation.Name, operation.DeclaringContract.Name)));
                    }
                    else
                    {
                        targetPart = targetMessage.Body.Parts[0];
                    }
                }

                if (targetPart != null)
                {
                    if (partName != targetPart.Name)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partName, "parameter name", targetPart.Name, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (partNamespace != targetPart.Namespace)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(partNamespace, "parameter namespace", targetPart.Namespace, operation.Name, operation.DeclaringContract.Name)));
                    }
                    if (declaredMessageType != targetPart.Type)
                    {
                        if (declaredMessageType != null)
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(declaredMessageType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                        else
                        {
                            Constraint.AddValidationError(context, new ValidationError(SR2.ParameterTypeMismatch(TypeHelper.VoidType.FullName, targetPart.Type.FullName, operation.Name, operation.DeclaringContract.Name)));
                        }
                    }
                    if (targetPart.HasProtectionLevel)
                    {
                        Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelIsNotSupported(operation.Name, operation.DeclaringContract.Name)));
                    }

                    // Multiple and Index do not need to be validate because there is only one part in the message.
                }
            }
        }
示例#24
0
        protected override void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] parameters, bool isRequest)
        {
            XmlSerializer serializer;
            MessageHeaderDescriptionTable headerDescriptionTable;
            MessageHeaderDescription      unknownHeaderDescription;
            bool   mustUnderstand;
            bool   relay;
            string actor;

            try
            {
                if (isRequest)
                {
                    serializer               = _requestMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _requestMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _requestMessageInfo.UnknownHeaderDescription;
                }
                else
                {
                    serializer               = _replyMessageInfo.HeaderSerializer;
                    headerDescriptionTable   = _replyMessageInfo.HeaderDescriptionTable;
                    unknownHeaderDescription = _replyMessageInfo.UnknownHeaderDescription;
                }
                if (serializer != null)
                {
                    object[] headerValues = new object[headerDescriptionTable.Count];
                    MessageHeaderOfTHelper messageHeaderOfTHelper = null;
                    int headerIndex = 0;

                    foreach (MessageHeaderDescription headerDescription in messageDescription.Headers)
                    {
                        object parameterValue = parameters[headerDescription.Index];
                        if (!headerDescription.IsUnknownHeaderCollection)
                        {
                            if (headerDescription.TypedHeader)
                            {
                                if (messageHeaderOfTHelper == null)
                                {
                                    messageHeaderOfTHelper = new MessageHeaderOfTHelper(parameters.Length);
                                }

                                headerValues[headerIndex++] = messageHeaderOfTHelper.GetContentAndSaveHeaderAttributes(parameters[headerDescription.Index], headerDescription);
                            }
                            else
                            {
                                headerValues[headerIndex++] = parameterValue;
                            }
                        }
                    }

                    MemoryStream        memoryStream = new MemoryStream();
                    XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream);
                    bufferWriter.WriteStartElement("root");
                    serializer.Serialize(bufferWriter, headerValues, null, _isEncoded ? GetEncoding(message.Version.Envelope) : null);
                    bufferWriter.WriteEndElement();
                    bufferWriter.Flush();
                    XmlDocument doc = new XmlDocument();
                    memoryStream.Position = 0;
                    doc.Load(memoryStream);
                    foreach (XmlElement element in doc.DocumentElement.ChildNodes)
                    {
                        MessageHeaderDescription matchingHeaderDescription = headerDescriptionTable.Get(element.LocalName, element.NamespaceURI);
                        if (matchingHeaderDescription == null)
                        {
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            false /*mustUnderstand*/, null /*actor*/, false /*relay*/, element));
                        }
                        else
                        {
                            if (matchingHeaderDescription.TypedHeader)
                            {
                                messageHeaderOfTHelper.GetHeaderAttributes(matchingHeaderDescription, out mustUnderstand, out relay, out actor);
                            }
                            else
                            {
                                mustUnderstand = matchingHeaderDescription.MustUnderstand;
                                relay          = matchingHeaderDescription.Relay;
                                actor          = matchingHeaderDescription.Actor;
                            }
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            mustUnderstand, actor, relay, element));
                        }
                    }
                }
                if (unknownHeaderDescription != null && parameters[unknownHeaderDescription.Index] != null)
                {
                    foreach (object unknownHeader in (IEnumerable)parameters[unknownHeaderDescription.Index])
                    {
                        XmlElement element = (XmlElement)GetContentOfMessageHeaderOfT(unknownHeaderDescription, unknownHeader, out mustUnderstand, out relay, out actor);
                        if (element != null)
                        {
                            message.Headers.Add(new XmlElementMessageHeader(this, message.Version, element.LocalName, element.NamespaceURI,
                                                                            mustUnderstand, actor, relay, element));
                        }
                    }
                }
            }
            catch (InvalidOperationException e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
                                                                              SR.Format(SR.SFxErrorSerializingHeader, messageDescription.MessageName, e.Message), e));
            }
        }
示例#25
0
 protected abstract object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, MessageDescription messageDescription, object[] parameters, bool isRequest);
 private static void Show(MessageDescription desc)
 {
     Push(desc);
     Show();
 }
示例#27
0
        public void CheckOperationDescriptionDouble_it(OperationDescription od)
        {
            //OperationDescription od = cd.Operations [0];
            Assert.AreEqual("DoubleIt", od.Name, "#CD9");

            Assert.IsNull(od.BeginMethod, "#CD11");
            Assert.IsNull(od.EndMethod, "#CD12");

            Assert.AreEqual(0, od.Faults.Count, "#CD13");
            Assert.IsTrue(od.IsInitiating, "#CD14");
            Assert.IsFalse(od.IsOneWay, "#CD15");
            Assert.IsFalse(od.IsTerminating, "#CD16");

            //FIXME: Behaviors

            //OperationDescription.Message
            Assert.AreEqual(2, od.Messages.Count, "#CD17");

            MessageDescription md = od.Messages [0];

            #region MessageDescription 0
            Assert.AreEqual("http://myns/echo/IEchoService/DoubleIt", md.Action, "#CD18");
            Assert.AreEqual(MessageDirection.Input, md.Direction, "#CD19");
            Assert.AreEqual(0, md.Headers.Count, "#CD20");
            Assert.AreEqual(0, md.Properties.Count, "#CD21");

            //MessageDescription.MessageBodyDescription

            Assert.IsNull(md.Body.ReturnValue, "#CD22");
            Assert.AreEqual("DoubleIt", md.Body.WrapperName, "#CD23");
            Assert.AreEqual("http://myns/echo", md.Body.WrapperNamespace, "#CD24");
            #region MessagePartDescription
            //MessagePartDescription 0

            //Assert.AreEqual (0, md.Body.Parts.Count, "#CD25");
            MessagePartDescription mpd = md.Body.Parts [0];

            Assert.AreEqual(0, mpd.Index, "#CD26");
            Assert.IsFalse(mpd.Multiple, "#CD27");
            Assert.AreEqual("it", mpd.Name, "#CD28");
            Assert.AreEqual("http://myns/echo", mpd.Namespace, "#CD29");
            Assert.IsNull(mpd.Type, "#CD30");

            //MessagePartDescription 1

            mpd = md.Body.Parts [1];

            Assert.AreEqual(0, mpd.Index, "#CD31");
            Assert.IsFalse(mpd.Multiple, "#CD32");
            Assert.AreEqual("prefix", mpd.Name, "#CD33");
            Assert.AreEqual("http://myns/echo", mpd.Namespace, "#CD34");
            Assert.IsNull(mpd.Type, "#CD35");

            #endregion
            #endregion

            md = od.Messages [1];

            #region MessageDescription 1

            Assert.AreEqual("http://myns/echo/IEchoService/DoubleItResponse", md.Action, "#CD36");
            Assert.AreEqual(MessageDirection.Output, md.Direction, "#CD37");
            Assert.AreEqual(0, md.Headers.Count, "#CD38");
            Assert.AreEqual(0, md.Properties.Count, "#CD39");

            //MessageDescription.MessageBodyDescription

            //Return value
            Assert.IsNotNull(md.Body.ReturnValue, "#CD40");

            Assert.AreEqual("DoubleItResponse", md.Body.WrapperName, "#CD44");
            Assert.AreEqual("http://myns/echo", md.Body.WrapperNamespace, "#CD45");
            Assert.AreEqual(0, md.Body.Parts.Count, "#CD46");

            #endregion
        }
示例#28
0
 internal static bool IsStream(MessageDescription messageDescription)
 {
     return(GetStreamPart(messageDescription) != null);
 }
示例#29
0
 protected abstract object [] MessageToParts(MessageDescription md, Message message);
示例#30
0
        /// <summary>
        /// Create operation corresponding to given DomainService operation.
        /// </summary>
        /// <param name="declaringContract">Contract to which operation will belong.</param>
        /// <param name="operation">DomainService operation.</param>
        /// <returns>Created operation.</returns>
        private static OperationDescription CreateOperationDescription(ContractDescription declaringContract, DomainOperationEntry operation)
        {
            OperationDescription operationDesc = new OperationDescription(operation.Name, declaringContract);

            // Propagate behaviors.
            foreach (IOperationBehavior behavior in operation.Attributes.OfType <IOperationBehavior>())
            {
                operationDesc.Behaviors.Add(behavior);
            }

            // Add standard web behaviors.
            if ((operation.Operation == DomainOperation.Query && ((QueryAttribute)operation.OperationAttribute).HasSideEffects) ||
                (operation.Operation == DomainOperation.Invoke && ((InvokeAttribute)operation.OperationAttribute).HasSideEffects))
            {
                // For operations with side-effects i.e. with WebInvoke attribute, we need to build a default GET like
                // URI template so that, the parameter processing is taken care of by the WebHttpBehavior selector.
                WebInvokeAttribute attrib = ServiceUtils.EnsureBehavior <WebInvokeAttribute>(operationDesc);
                if (attrib.UriTemplate == null)
                {
                    attrib.UriTemplate = ODataEndpointFactory.BuildDefaultUriTemplate(operation);
                }
            }
            else
            {
                ServiceUtils.EnsureBehavior <WebGetAttribute>(operationDesc);
            }

            string action = ServiceUtils.GetRequestMessageAction(declaringContract, operationDesc.Name, null);

            // Define operation input.
            MessageDescription inputMessageDesc = new MessageDescription(action, MessageDirection.Input);

            inputMessageDesc.Body.WrapperName      = operationDesc.Name;
            inputMessageDesc.Body.WrapperNamespace = ServiceUtils.DefaultNamespace;

            for (int i = 0; i < operation.Parameters.Count; i++)
            {
                DomainOperationParameter parameter = operation.Parameters[i];

                MessagePartDescription parameterPartDesc = new MessagePartDescription(parameter.Name, ServiceUtils.DefaultNamespace)
                {
                    Index = i,
                    Type  = TypeUtils.GetClientType(parameter.ParameterType)
                };
                inputMessageDesc.Body.Parts.Add(parameterPartDesc);
            }

            operationDesc.Messages.Add(inputMessageDesc);

            // Define operation output.
            string responseAction = ServiceUtils.GetResponseMessageAction(declaringContract, operationDesc.Name, null);

            MessageDescription outputMessageDesc = new MessageDescription(responseAction, MessageDirection.Output);

            outputMessageDesc.Body.WrapperName      = operationDesc.Name + "Response";
            outputMessageDesc.Body.WrapperNamespace = ServiceUtils.DefaultNamespace;

            if (operation.ReturnType != typeof(void))
            {
                outputMessageDesc.Body.ReturnValue = new MessagePartDescription(operationDesc.Name + "Result", ServiceUtils.DefaultNamespace)
                {
                    Type = TypeUtils.GetClientType(operation.ReturnType)
                };
            }
            operationDesc.Messages.Add(outputMessageDesc);

            return(operationDesc);
        }
示例#31
0
 protected override Message PartsToMessage(
     MessageDescription md, MessageVersion version, string action, object [] parts)
 {
     return(Message.CreateMessage(version, action, new DataContractBodyWriter(md.Body, this, parts)));
 }
示例#32
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();
			
			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			var icon = message.Icon.ToImageDescription (actx);
			image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (GLib.Markup.EscapeText (secondaryText));
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			label.CanFocus = false;
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = new Gtk.Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (var op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton ("Apply to all");
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
示例#33
0
 public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 {
     return(binding_assertions);
 }
示例#34
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();

			string primaryText = String.Empty;
			string secondaryText = String.Empty;

			if (string.IsNullOrEmpty (message.Text)) {
				if (!string.IsNullOrEmpty (message.SecondaryText))
					primaryText = message.SecondaryText;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			if (message.Icon == StockIcons.Information)
				base.MessageType = MessageType.Info;
			else if (message.Icon == StockIcons.Question)
				base.MessageType = MessageType.Question;
			else if (message.Icon == StockIcons.Warning)
				base.MessageType = MessageType.Warning;
			else if (message.Icon == StockIcons.Error)
				base.MessageType = MessageType.Error;
			else {
				var icon = message.Icon.ToImageDescription (actx);
				image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
				base.Image = image;
			}

			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");

			base.Markup = markup.ToString ();
			if (!String.IsNullOrEmpty (secondaryText)) {
				base.SecondaryText = GLib.Markup.EscapeText (secondaryText);
				base.SecondaryUseMarkup = true;
			}
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = (Gtk.Button)base.AddButton (button.Label, button.ToResponseType());
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					var icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
			}
			
			foreach (var op in message.Options) {
				Gtk.CheckButton check = new Gtk.CheckButton (op.Text);
				check.Active = op.Value;
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				Gtk.CheckButton check = new Gtk.CheckButton ("Apply to all");
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
示例#35
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon = GetIcon(message.Icon);
            if (ConvertButtons(message.Buttons, out buttons))
            {
                // Use a system message box
                if (message.SecondaryText == null)
                {
                    message.SecondaryText = String.Empty;
                }
                else
                {
                    message.Text          = message.Text + "\r\n\r\n" + message.SecondaryText;
                    message.SecondaryText = String.Empty;
                }
                var parent = Toolkit.CurrentEngine.GetNativeWindow(transientFor) as System.Windows.Window;
                if (parent != null)
                {
                    this.dialogResult = MessageBox.Show(parent, message.Text, message.SecondaryText,
                                                        this.buttons, this.icon, this.defaultResult, this.options);
                }
                else
                {
                    this.dialogResult = MessageBox.Show(message.Text, message.SecondaryText, this.buttons,
                                                        this.icon, this.defaultResult, this.options);
                }
                return(ConvertResultToCommand(this.dialogResult));
            }
            else
            {
                // Custom message box required
                Dialog dlg = new Dialog();
                dlg.Resizable = false;
                dlg.Padding   = 0;
                HBox mainBox = new HBox {
                    Margin = 25
                };

                if (message.Icon != null)
                {
                    var image = new ImageView(message.Icon.WithSize(32, 32));
                    mainBox.PackStart(image, vpos: WidgetPlacement.Start);
                }
                VBox box = new VBox()
                {
                    Margin = 3, MarginLeft = 8, Spacing = 15
                };
                mainBox.PackStart(box, true);
                var text = new Label {
                    Text = message.Text ?? ""
                };
                Label stext = null;
                box.PackStart(text);
                if (!string.IsNullOrEmpty(message.SecondaryText))
                {
                    stext = new Label {
                        Text = message.SecondaryText
                    };
                    box.PackStart(stext);
                }
                dlg.Buttons.Add(message.Buttons.ToArray());
                if (mainBox.Surface.GetPreferredSize(true).Width > 480)
                {
                    text.Wrap = WrapMode.Word;
                    if (stext != null)
                    {
                        stext.Wrap = WrapMode.Word;
                    }
                    mainBox.WidthRequest = 480;
                }
                var s = mainBox.Surface.GetPreferredSize(true);

                dlg.Content = mainBox;
                return(dlg.Run());
            }
        }
 int IEqualityComparerMessageDescription.GetHashCode(MessageDescription obj)
 {
     return obj.XsdTypeName.GetHashCode();
 }
示例#37
0
		public GtkAlertDialog (MessageDescription message)
		{
			Init ();
			this.buttons = message.Buttons.ToArray ();

			Modal = true;

			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			if (!message.UseMarkup) {
				primaryText = GLib.Markup.EscapeText (primaryText);
				secondaryText = GLib.Markup.EscapeText (secondaryText);
			}

			if (!string.IsNullOrEmpty (message.Icon)) {
				image = new ImageView ();
				image.Yalign   = 0.00f;
				image.Image = ImageService.GetIcon (message.Icon, IconSize.Dialog);
				hbox.PackStart (image, false, false, 0);
				hbox.ReorderChild (image, 0);
			}
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (primaryText);
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (secondaryText);
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			label.CanFocus = false;
			
			foreach (AlertButton button in message.Buttons) {
				Button newButton = new Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (!String.IsNullOrEmpty (button.Icon))
					newButton.Image = new Image (button.Icon, IconSize.Button);
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (var op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton (GettextCatalog.GetString ("Apply to all"));
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
示例#38
0
 protected virtual Task SerializeBodyAsync(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest)
 {
     SerializeBody(writer, version, action, messageDescription, returnValue, parameters, isRequest);
     return(Task.CompletedTask);
 }
示例#39
0
        public GtkAlertDialog(ApplicationContext actx, MessageDescription message)
        {
            this.actx = actx;
            Init();
            this.buttons = message.Buttons.ToArray();

            string primaryText   = String.Empty;
            string secondaryText = String.Empty;

            if (string.IsNullOrEmpty(message.Text))
            {
                if (!string.IsNullOrEmpty(message.SecondaryText))
                {
                    primaryText = message.SecondaryText;
                }
            }
            else
            {
                primaryText   = message.Text;
                secondaryText = message.SecondaryText;
            }

            if (message.Icon == StockIcons.Information)
            {
                base.MessageType = MessageType.Info;
            }
            else if (message.Icon == StockIcons.Question)
            {
                base.MessageType = MessageType.Question;
            }
            else if (message.Icon == StockIcons.Warning)
            {
                base.MessageType = MessageType.Warning;
            }
            else if (message.Icon == StockIcons.Error)
            {
                base.MessageType = MessageType.Error;
            }
            else
            {
                var icon = message.Icon.ToImageDescription(actx);
                image.Image = icon.WithDefaultSize(Gtk.IconSize.Dialog);
                base.Image  = image;
            }

            StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">");

            markup.Append(GLib.Markup.EscapeText(primaryText));
            markup.Append("</span>");

            base.Markup = markup.ToString();
            if (!String.IsNullOrEmpty(secondaryText))
            {
                base.SecondaryText = GLib.Markup.EscapeText(secondaryText);
            }

            foreach (Command button in message.Buttons)
            {
                Gtk.Button newButton = (Gtk.Button)base.AddButton(button.Label, button.ToResponseType());
                newButton.UseUnderline = true;
                newButton.UseStock     = button.IsStockButton;
                if (button.Icon != null)
                {
                    var icon = button.Icon.ToImageDescription(actx);
                    newButton.Image = new ImageBox(actx, icon.WithDefaultSize(Gtk.IconSize.Button));
                }
                newButton.Clicked += ButtonClicked;
            }

            foreach (var op in message.Options)
            {
                Gtk.CheckButton check = new Gtk.CheckButton(op.Text);
                check.Active = op.Value;
                this.AddContent(check, false, false, 0);
                check.Toggled += delegate {
                    message.SetOptionValue(op.Id, check.Active);
                };
            }

            if (message.AllowApplyToAll)
            {
                Gtk.CheckButton check = new Gtk.CheckButton("Apply to all");
                this.AddContent(check, false, false, 0);
                check.Toggled += delegate {
                    ApplyToAll = check.Active;
                };
            }

            //don't show this yet, let the consumer decide when
            this.Child.ShowAll();
        }
示例#40
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon = GetIcon (message.Icon);
            if (ConvertButtons (message.Buttons, out buttons) && message.Options.Count == 0) {
                // Use a system message box
                if (message.SecondaryText == null)
                    message.SecondaryText = String.Empty;
                else {
                    message.Text = message.Text + "\r\n\r\n" + message.SecondaryText;
                    message.SecondaryText = String.Empty;
                }
                var parent =  Toolkit.CurrentEngine.GetNativeWindow(transientFor) as System.Windows.Window;
                if (parent != null) {
                    this.dialogResult = MessageBox.Show (parent, message.Text, message.SecondaryText,
                                                        this.buttons, this.icon, this.defaultResult, this.options);
                }
                else {
                    this.dialogResult = MessageBox.Show (message.Text, message.SecondaryText, this.buttons,
                                                        this.icon, this.defaultResult, this.options);
                }
                return ConvertResultToCommand (this.dialogResult);
            }
            else {
                // Custom message box required
                Dialog dlg = new Dialog ();
                dlg.Resizable = false;
                dlg.Padding = 0;
                HBox mainBox = new HBox { Margin = 25 };

                if (message.Icon != null) {
                    var image = new ImageView (message.Icon.WithSize (32,32));
                    mainBox.PackStart (image, vpos: WidgetPlacement.Start);
                }
                VBox box = new VBox () { Margin = 3, MarginLeft = 8, Spacing = 15 };
                mainBox.PackStart (box, true);
                var text = new Label {
                    Text = message.Text ?? ""
                };
                Label stext = null;
                box.PackStart (text);
                if (!string.IsNullOrEmpty (message.SecondaryText)) {
                    stext = new Label {
                        Text = message.SecondaryText
                    };
                    box.PackStart (stext);
                }
                foreach (var option in message.Options) {
                    var check = new CheckBox (option.Text);
                    check.Active = option.Value;
                    box.PackStart(check);
                    check.Toggled += (sender, e) => message.SetOptionValue(option.Id, check.Active);
                }
                dlg.Buttons.Add (message.Buttons.ToArray ());
                if (message.DefaultButton >= 0 && message.DefaultButton < message.Buttons.Count)
                    dlg.DefaultCommand = message.Buttons[message.DefaultButton];
                if (mainBox.Surface.GetPreferredSize (true).Width > 480) {
                    text.Wrap = WrapMode.Word;
                    if (stext != null)
                        stext.Wrap = WrapMode.Word;
                    mainBox.WidthRequest = 480;
                }
                var s = mainBox.Surface.GetPreferredSize (true);

                dlg.Content = mainBox;
                return dlg.Run ();
            }
        }
示例#41
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.MessageText = message.Text ?? String.Empty;
            this.InformativeText = message.SecondaryText ?? String.Empty;

            if (message.Icon != null)
                Icon = message.Icon.ToImageDescription (Context).ToNSImage ();

            var sortedButtons = new Command [message.Buttons.Count];
            var j = 0;
            if (message.DefaultButton >= 0) {
                sortedButtons [0] = message.Buttons [message.DefaultButton];
                this.AddButton (message.Buttons [message.DefaultButton].Label);
                j = 1;
            }
            for (var i = 0; i < message.Buttons.Count; i++) {
                if (i == message.DefaultButton)
                    continue;
                sortedButtons [j++] = message.Buttons [i];
                this.AddButton (message.Buttons [i].Label);
            }
            for (var i = 0; i < sortedButtons.Length; i++) {
                if (sortedButtons [i].Icon != null) {
                    Buttons [i].Image = sortedButtons [i].Icon.WithSize (IconSize.Small).ToImageDescription (Context).ToNSImage ();
                    Buttons [i].ImagePosition = NSCellImagePosition.ImageLeft;
                }
            }

            if (message.AllowApplyToAll) {
                ShowsSuppressionButton = true;
                SuppressionButton.State = NSCellStateValue.Off;
                SuppressionButton.Activated += (sender, e) => ApplyToAll = SuppressionButton.State == NSCellStateValue.On;
            }

            if (message.Options.Count > 0) {
                AccessoryView = new NSView ();
                var optionsSize = new CGSize (0, 3);

                foreach (var op in message.Options) {
                    var chk = new NSButton ();
                    chk.SetButtonType (NSButtonType.Switch);
                    chk.Title = op.Text;
                    chk.State = op.Value ? NSCellStateValue.On : NSCellStateValue.Off;
                    chk.Activated += (sender, e) => message.SetOptionValue (op.Id, chk.State == NSCellStateValue.On);

                    chk.SizeToFit ();
                    chk.Frame = new CGRect (new CGPoint (0, optionsSize.Height), chk.FittingSize);

                    optionsSize.Height += chk.FittingSize.Height + 6;
                    optionsSize.Width = (float) Math.Max (optionsSize.Width, chk.FittingSize.Width);

                    AccessoryView.AddSubview (chk);
                    chk.NeedsDisplay = true;
                }

                AccessoryView.SetFrameSize (optionsSize);
            }

            var win = Toolkit.CurrentEngine.GetNativeWindow (transientFor) as NSWindow;
            if (win != null)
                return sortedButtons [(int)this.RunSheetModal (win) - 1000];
            return sortedButtons [(int)this.RunModal () - 1000];
        }
示例#42
0
 private void SetupStreamAndMessageDescription(bool isRequest, out StreamFormatter streamFormatter, out MessageDescription messageDescription)
 {
     if (isRequest)
     {
         streamFormatter    = requestStreamFormatter;
         messageDescription = _requestDescription;
     }
     else
     {
         streamFormatter    = replyStreamFormatter;
         messageDescription = _replyDescription;
     }
 }
示例#43
0
 protected abstract void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest);
 bool IEqualityComparerMessageDescription.Equals(MessageDescription x, MessageDescription y)
 {
     if (x.XsdTypeName != y.XsdTypeName)
     {
         return false;
     }
     if (x.Headers.Count != y.Headers.Count)
     {
         return false;
     }
     MessageHeaderDescription[] array = new MessageHeaderDescription[x.Headers.Count];
     x.Headers.CopyTo(array, 0);
     MessageHeaderDescription[] descriptionArray2 = new MessageHeaderDescription[y.Headers.Count];
     y.Headers.CopyTo(descriptionArray2, 0);
     if (x.Headers.Count  1)
     {
         Array.SortMessagePartDescription((MessagePartDescription[]) array, MessagePartDescriptionComparer.Singleton);
         Array.SortMessagePartDescription((MessagePartDescription[]) descriptionArray2, MessagePartDescriptionComparer.Singleton);
     }
     for (int i = 0; i  array.Length; i++)
     {
         if (MessagePartDescriptionComparer.Singleton.Compare(array[i], descriptionArray2[i]) != 0)
         {
             return false;
         }
     }
     return true;
 }