Example #1
0
        public ServiceBusHost(ServiceBusHostSettings settings, IServiceBusHostTopology hostTopology, IServiceBusBusConfiguration busConfiguration)
        {
            Settings = settings;
            Topology = hostTopology;
            var busConfiguration1 = busConfiguration;

            _receiveEndpoints = new ReceiveEndpointCollection();

            RetryPolicy = Retry.CreatePolicy(x =>
            {
                x.Ignore <MessagingEntityNotFoundException>();
                x.Ignore <MessagingEntityAlreadyExistsException>();
                x.Ignore <MessageNotFoundException>();
                x.Ignore <MessageSizeExceededException>();

                x.Handle <ServerBusyException>(exception => exception.IsTransient);
                x.Handle <TimeoutException>();

                x.Interval(5, TimeSpan.FromSeconds(10));
            });

            BasePath = settings.ServiceUri.AbsolutePath.Trim('/');

            var serviceBusRetryPolicy = CreateRetryPolicy(settings);

            MessagingFactoryCache = new MessagingFactoryCache(settings.ServiceUri, CreateMessagingFactorySettings(settings), serviceBusRetryPolicy);
            NamespaceCache        = new NamespaceCache(settings.ServiceUri, CreateNamespaceManagerSettings(settings, serviceBusRetryPolicy));

            _receiveEndpointFactory      = new ServiceBusReceiveEndpointFactory(busConfiguration1, this);
            _subscriptionEndpointFactory = new ServiceBusSubscriptionEndpointFactory(busConfiguration1, this);
        }
Example #2
0
 private NamespaceCache Namespace(string key)
 {
     lock (_sync)
     {
         if (!_namespaceCaches.TryGetValue(key, out var value))
         {
             value = new NamespaceCache();
             _namespaceCaches.Add(key, value);
         }
         return(value);
     }
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlXamlWriter"/> class
        /// with the specified settings.
        /// </summary>
        /// <param name="settings">
        /// An instance of <see cref="WpfDrawingSettings"/> specifying the
        /// rendering options.
        /// </param>
        public XmlXamlWriter(XmlWriterSettings settings)
        {
            _nullType          = typeof(NullExtension);
            _namespaceCache    = new NamespaceCache();
            _dicNamespaceMap   = new Dictionary <string, NamespaceMap>(StringComparer.OrdinalIgnoreCase);
            _contentProperties = new Dictionary <Type, string>();

            _windowsPath = "%WINDIR%";
            _windowsDir  = Environment.ExpandEnvironmentVariables(_windowsPath).ToLower();

            _windowsDir  = _windowsDir.Replace(@"\", "/");
            _wpfSettings = settings;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlXamlWriter"/> class
        /// with the specified settings.
        /// </summary>
        /// <param name="settings">
        /// An instance of <see cref="WpfDrawingSettings"/> specifying the
        /// rendering options.
        /// </param>
        public XmlXamlWriter(WpfDrawingSettings settings)
        {
            _culture           = CultureInfo.InvariantCulture;

            _nullType          = typeof(NullExtension);
            _namespaceCache    = new NamespaceCache(_culture);
            _dicNamespaceMap   = new Dictionary<string, NamespaceMap>(StringComparer.OrdinalIgnoreCase);
            _contentProperties = new Dictionary<Type, string>();

            _windowsPath = "%WINDIR%";
            _windowsDir  = Environment.ExpandEnvironmentVariables(_windowsPath).ToLower();

            _windowsDir  = _windowsDir.Replace(@"\", "/");
            _wpfSettings = settings;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlXamlWriter"/> class
        /// with the specified settings.
        /// </summary>
        /// <param name="settings">
        /// An instance of <see cref="WpfDrawingSettings"/> specifying the
        /// rendering options.
        /// </param>
        public XmlXamlWriter(WpfDrawingSettings settings)
        {
            _culture = (CultureInfo)CultureInfo.InvariantCulture.Clone();
            _culture.NumberFormat.NumberDecimalDigits = 4;

            _nullType          = typeof(NullExtension);
            _namespaceCache    = new NamespaceCache(_culture);
            _dicNamespaceMap   = new Dictionary <string, NamespaceMap>(StringComparer.OrdinalIgnoreCase);
            _contentProperties = new Dictionary <Type, string>();

            _windowsPath = "%WINDIR%";
            _windowsDir  = Environment.ExpandEnvironmentVariables(_windowsPath).ToLower();

            _windowsDir  = _windowsDir.Replace(@"\", "/");
            _wpfSettings = settings;
        }
Example #6
0
        private void WriteObject(object key, object obj, XmlTextWriter writer, bool isRoot)
        {
            MarkupObject markupObj  = MarkupWriter.GetMarkupObjectFor(obj);
            Type         objectType = markupObj.ObjectType;

            _namespaceCache.GetXmlNamespace(objectType);
            string ns     = _namespaceCache.GetXmlNamespace(objectType);
            string prefix = _namespaceCache.GetPrefixForNamespace(ns);

            WriteStartElement(writer, prefix, markupObj.ObjectType.Name);

            if (isRoot)
            {
                foreach (NamespaceMap map in _namespaceMaps.Values)
                {
                    if (string.IsNullOrEmpty(map.Prefix))
                    {
                        writer.WriteAttributeString("xmlns", map.XmlNamespace);
                    }
                    else
                    {
                        writer.WriteAttributeString("xmlns:" + map.Prefix, map.XmlNamespace);
                    }
                }

                if (!_namespaceMaps.ContainsKey(NamespaceCache.XamlNamespace))
                {
                    writer.WriteAttributeString("xmlns:x", NamespaceCache.XamlNamespace);
                }
            }

            if (key != null)
            {
                string keyString = key.ToString();
                if (keyString.Length > 0)
                {
                    writer.WriteAttributeString("x:Key", keyString);
                }
                else
                {
                    //TODO: key may not be a string, what about x:Type...
                    throw new NotImplementedException();
                }
            }

            List <MarkupProperty> propertyElements = new List <MarkupProperty>();
            MarkupProperty        contentProperty  = null;
            string contentString = string.Empty;

            foreach (MarkupProperty markupProperty in markupObj.Properties)
            {
                if (IsContentProperty(markupObj, markupProperty))
                {
                    contentProperty = markupProperty;
                    continue;
                }

                if (markupProperty.IsValueAsString)
                {
                    contentString = markupProperty.Value as string;
                }
                else if (!markupProperty.IsComposite)
                {
                    string temp = markupProperty.Value == null ? string.Empty : _formatterConverter.ToString(markupProperty.Value);

                    if (markupProperty.IsAttached)
                    {
                        string ns1     = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType);
                        string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1);
                        if (string.IsNullOrEmpty(prefix1))
                        {
                            writer.WriteAttributeString(markupProperty.Name, temp);
                        }
                        else
                        {
                            writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp);
                        }
                    }
                    else
                    {
                        if (markupProperty.Name == "Name" && NamespaceCache.GetAssemblyNameFromType(markupProperty.DependencyProperty.OwnerType).Equals("PresentationFramework"))
                        {
                            writer.WriteAttributeString("x:" + markupProperty.Name, temp);
                        }
                        else
                        {
                            writer.WriteAttributeString(markupProperty.Name, temp);
                        }
                    }
                }
                else if (markupProperty.Value.GetType() == typeof(NullExtension))
                {
                    writer.WriteAttributeString(markupProperty.Name, "{x:Null}");
                }
                else
                {
                    propertyElements.Add(markupProperty);
                }
            }

            if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString))
            {
                foreach (MarkupProperty markupProp in propertyElements)
                {
                    string ns2             = _namespaceCache.GetXmlNamespace(markupObj.ObjectType);
                    string prefix2         = _namespaceCache.GetPrefixForNamespace(ns2);
                    string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name;

                    WriteStartElement(writer, prefix2, propElementName);
                    WriteChildren(writer, markupProp);
                    writer.WriteEndElement();
                }

                if (!string.IsNullOrEmpty(contentString))
                {
                    writer.WriteValue(contentString);
                }
                else if (contentProperty != null)
                {
                    if (contentProperty.Value is string)
                    {
                        writer.WriteValue(contentProperty.StringValue);
                    }
                    else
                    {
                        WriteChildren(writer, contentProperty);
                    }
                }
            }

            writer.WriteEndElement();
        }
Example #7
0
        private void WriteProperties(XmlTextWriter writer, MarkupObject markupObj)
        {
            List <MarkupProperty> propertyElements = new List <MarkupProperty>();
            MarkupProperty        contentProperty  = null;
            string contentString = string.Empty;

            foreach (MarkupProperty markupProperty in markupObj.Properties)
            {
                if (IsContentProperty(markupObj, markupProperty))
                {
                    contentProperty = markupProperty;
                    continue;
                }

                if (markupProperty.IsValueAsString)
                {
                    contentString = markupProperty.Value as string;
                }
                else if (!markupProperty.IsComposite)
                {
                    string temp = markupProperty.Value == null ? string.Empty : markupProperty.Value.ToString();

                    if (markupProperty.IsAttached)
                    {
                        string ns1     = _namespaceCache.GetXmlNamespace(markupProperty.DependencyProperty.OwnerType);
                        string prefix1 = _namespaceCache.GetPrefixForNamespace(ns1);
                        if (string.IsNullOrEmpty(prefix1))
                        {
                            writer.WriteAttributeString(markupProperty.Name, temp);
                        }
                        else
                        {
                            writer.WriteAttributeString(prefix1 + ":" + markupProperty.Name, temp);
                        }
                    }
                    else
                    {
                        DependencyProperty dependencyProperty = markupProperty.DependencyProperty;
                        Type ownerType = dependencyProperty == null ? null : dependencyProperty.OwnerType;
                        if (markupProperty.Name == "Name" && ownerType != null && NamespaceCache.GetAssemblyNameFromType(ownerType).Equals("PresentationFramework"))
                        {
                            writer.WriteAttributeString("x:" + markupProperty.Name, temp);
                        }
                        else
                        {
                            writer.WriteAttributeString(markupProperty.Name, temp);
                        }
                    }
                }
                else if (markupProperty.Value.GetType() == typeof(NullExtension))
                {
                    writer.WriteAttributeString(markupProperty.Name, "{x:Null}");
                }
                else
                {
                    propertyElements.Add(markupProperty);
                }
            }

            if (contentProperty != null || propertyElements.Count > 0 || !string.IsNullOrEmpty(contentString))
            {
                foreach (MarkupProperty markupProp in propertyElements)
                {
                    string ns2             = _namespaceCache.GetXmlNamespace(markupObj.ObjectType);
                    string prefix2         = _namespaceCache.GetPrefixForNamespace(ns2);
                    string propElementName = markupObj.ObjectType.Name + "." + markupProp.Name;

                    WriteStartElement(writer, prefix2, propElementName);
                    WriteChildren(writer, markupProp);
                    writer.WriteEndElement();
                }

                if (!string.IsNullOrEmpty(contentString))
                {
                    writer.WriteValue(contentString);
                }
                else if (contentProperty != null)
                {
                    if (contentProperty.Value is string)
                    {
                        writer.WriteValue(contentProperty.StringValue);
                    }
                    else
                    {
                        WriteChildren(writer, contentProperty);
                    }
                }
            }
        }