public static string CreateFromDataContractSerializer(XName serviceContractName, string operationName, string parameterName, bool isReply, Type type, MemberInfo[] pathToMember, out XmlNamespaceManager namespaces)
        {
            if (type == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("type"));
            }
            if (pathToMember == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("pathToMember"));
            }
            if (operationName == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("operationName"));
            }
            if (serviceContractName == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractName"));
            }
            if (isReply)
            {
                operationName = operationName + "Response";
            }
            StringBuilder rootElementXpath = new StringBuilder("/xgSc:" + operationName);

            rootElementXpath.Append("/xgSc:" + parameterName);
            string str           = XPathQueryGenerator.CreateFromDataContractSerializer(type, pathToMember, rootElementXpath, out namespaces);
            string namespaceName = serviceContractName.NamespaceName;

            if (string.IsNullOrEmpty(namespaceName))
            {
                namespaceName = "http://tempuri.org/";
            }
            namespaces.AddNamespace("xgSc", namespaceName);
            return(str);
        }
Пример #2
0
        static void GenerateXPath(Type t, MemberInfo[] mi)
        {
            // Create a new name table and name space manager.
            NameTable           nt    = new NameTable();
            XmlNamespaceManager xname = new XmlNamespaceManager(nt);

            // Generate the query and print it.
            string query = XPathQueryGenerator.CreateFromDataContractSerializer(
                t, mi, out xname);

            Console.WriteLine(query);
            Console.WriteLine();

            // Display the namespaces and prefixes used in the data contract.
            foreach (string s in xname)
            {
                Console.WriteLine("{0}  = {1}", s, xname.LookupNamespace(s));
            }

            Console.WriteLine();
        }
Пример #3
0
        public static string CreateFromDataContractSerializer(XName serviceContractName, string operationName, string parameterName, bool isReply, Type type, MemberInfo[] pathToMember, out XmlNamespaceManager namespaces)
        {
            if (type == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("type"));
            }
            if (pathToMember == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("pathToMember"));
            }
            if (operationName == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("operationName"));
            }
            if (serviceContractName == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractName"));
            }
            if (isReply)
            {
                operationName += TypeLoader.ResponseSuffix;
            }

            StringBuilder xPathBuilder = new StringBuilder(XPathSeparator + ServiceContractPrefix + NsSeparator + operationName);

            xPathBuilder.Append(XPathSeparator + ServiceContractPrefix + NsSeparator + parameterName);

            string xpath = XPathQueryGenerator.CreateFromDataContractSerializer(type, pathToMember, xPathBuilder, out namespaces);
            string serviceContractNamespace = serviceContractName.NamespaceName;

            // Use default service contract namespace if the provided serviceContractNamespace is null or empty
            if (string.IsNullOrEmpty(serviceContractNamespace))
            {
                serviceContractNamespace = NamingHelper.DefaultNamespace;
            }
            namespaces.AddNamespace(ServiceContractPrefix, serviceContractNamespace);

            return(xpath);
        }
Пример #4
0
        void OnTypeSelectionChanged(object sender, RoutedEventArgs e)
        {
            var contentCorrelationDesigner = (ContentCorrelationTypeExpander)sender;

            //is selection valid (valid type or property)
            if (contentCorrelationDesigner.IsSelectionValid)
            {
                var path = contentCorrelationDesigner.GetMemberPath();
                var type = contentCorrelationDesigner.GetSelectedType();
                try
                {
                    XmlNamespaceManager namespaceManager = null;
                    string xpathQuery = string.Empty;
                    var    content    = this.Activity.Properties["Content"].Value;
                    if (content.IsAssignableFrom <ReceiveMessageContent>() || content.IsAssignableFrom <SendMessageContent>())
                    {
                        //generating xpath for message content
                        xpathQuery = XPathQueryGenerator.CreateFromDataContractSerializer(type, path, out namespaceManager);
                    }
                    else
                    {
                        //generating xpath for parameter content
                        XName  serviceContractName = null;
                        string operationName       = null;
                        string parameterName       = contentCorrelationDesigner.SelectedTypeEntry.Name;
                        bool   isReply             = this.Activity.IsAssignableFrom <SendReply>() || this.Activity.IsAssignableFrom <ReceiveReply>();
                        if (isReply)
                        {
                            operationName       = (string)this.Activity.Properties["Request"].Value.Properties["OperationName"].ComputedValue;
                            serviceContractName = (XName)this.Activity.Properties["Request"].Value.Properties["ServiceContractName"].ComputedValue;

                            if (string.IsNullOrEmpty(operationName) || null == serviceContractName)
                            {
                                ModelItem requestDisplayName;
                                this.Activity.TryGetPropertyValue(out requestDisplayName, "Request", "DisplayName");
                                throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                                    string.Format(CultureInfo.CurrentUICulture, (string)this.FindResource("parametersRequiredText"), requestDisplayName.GetCurrentValue())));
                            }
                        }
                        else
                        {
                            operationName       = (string)this.Activity.Properties["OperationName"].ComputedValue;
                            serviceContractName = (XName)this.Activity.Properties["ServiceContractName"].ComputedValue;

                            if (string.IsNullOrEmpty(operationName) || null == serviceContractName)
                            {
                                throw FxTrace.Exception.AsError(new InvalidOperationException(
                                                                    string.Format(CultureInfo.CurrentUICulture, (string)this.FindResource("parametersRequiredText"), this.Activity.Properties["DisplayName"].ComputedValue)));
                            }
                        }
                        xpathQuery = ParameterXPathQueryGenerator.CreateFromDataContractSerializer(serviceContractName, operationName, parameterName, isReply, type, path, out namespaceManager);
                    }
                    //use CDF api to build a xpath out of type and its properties
                    string xpath = string.Format(CultureInfo.InvariantCulture, "sm:body(){0}", xpathQuery);

                    //get the context
                    //We need to copy over the namespaces from the manager's table 1 by 1. According to MSDN:
                    //If you specify an existing name table, any namespaces in the name table are not automatically added to XmlNamespaceManager.
                    //You must use AddNamespace and RemoveNamespace to add or remove namespaces.
                    XPathMessageContext messageContext = new XPathMessageContext();
                    foreach (string prefix in namespaceManager)
                    {
                        if (!string.IsNullOrEmpty(prefix) && !messageContext.HasNamespace(prefix) && prefix != "xmlns")
                        {
                            messageContext.AddNamespace(prefix, namespaceManager.LookupNamespace(prefix));
                        }
                    }

                    var typeEntry = (ExpanderTypeEntry)contentCorrelationDesigner.Tag;
                    //construct xpath
                    XPathMessageQuery query = new XPathMessageQuery(xpath, messageContext);
                    //store the xpath in the Tag property; this combo's selectedValue is bound to i
                    typeEntry.Tag       = query;
                    this.SelectedIndex  = 0;
                    this.IsDropDownOpen = false;
                    this.Query          = query;
                    this.RaiseEvent(new RoutedEventArgs(XPathCreatedEvent, this));
                }
                catch (Exception err)
                {
                    MessageBox.Show(
                        err.Message,
                        (string)this.Resources["controlTitle"],
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }