internal static void ScopeValidatorCallback(object scope)
 {
     if ((scope != null) && !((Uri)scope).IsAbsoluteUri)
     {
         throw FxTrace.Exception.AsError(new ArgumentException(SR2.DiscoveryConfigInvalidScopeUri(scope)));
     }
 }
        static DiscoveryEndpoint ValidateAndGetDiscoveryEndpoint(ChannelEndpointElement channelEndpointElement)
        {
            if (string.IsNullOrEmpty(channelEndpointElement.Kind))
            {
                throw FxTrace.Exception.AsError(
                          new ConfigurationErrorsException(
                              SR2.DiscoveryConfigDiscoveryEndpointMissingKind(
                                  typeof(DiscoveryEndpoint).FullName)));
            }

            ServiceEndpoint serviceEndpoint = ConfigLoader.LookupEndpoint(channelEndpointElement, null);

            if (serviceEndpoint == null)
            {
                throw FxTrace.Exception.AsError(
                          new ConfigurationErrorsException(
                              SR2.DiscoveryConfigInvalidEndpointConfiguration(
                                  channelEndpointElement.Kind)));
            }

            DiscoveryEndpoint discoveryEndpoint = serviceEndpoint as DiscoveryEndpoint;

            if (discoveryEndpoint == null)
            {
                throw FxTrace.Exception.AsError(
                          new InvalidOperationException(
                              SR2.DiscoveryConfigInvalidDiscoveryEndpoint(
                                  typeof(DiscoveryEndpoint).FullName,
                                  channelEndpointElement.Kind,
                                  serviceEndpoint.GetType().FullName)));
            }

            return(discoveryEndpoint);
        }
 protected override void OnInitializeAndValidate(ServiceEndpointElement serviceEndpointElement)
 {
     if (!String.IsNullOrEmpty(serviceEndpointElement.Contract))
     {
         throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigContractSpecified(serviceEndpointElement.Kind)));
     }
 }
예제 #4
0
        public static XmlQualifiedName ParseQName(string prefixedQName, XmlReader reader)
        {
            Fx.Assert(prefixedQName != null, "The prefixedQName must be non null.");
            Fx.Assert(reader != null, "The reader must be non null.");
            int index = prefixedQName.IndexOf(':');

            string ns;
            string localname;

            if (index != -1)
            {
                string prefix = prefixedQName.Substring(0, index);
                ns = reader.LookupNamespace(prefix);
                if (ns == null)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlQNamePrefixNotDefined(prefix, prefixedQName)));
                }
                localname = prefixedQName.Substring(index + 1);
                if (localname == string.Empty)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlQNameLocalnameNotDefined(prefixedQName)));
                }
            }
            else
            {
                ns        = string.Empty;
                localname = prefixedQName;
            }

            localname = XmlConvert.DecodeName(localname);
            return(new XmlQualifiedName(localname, ns));
        }
예제 #5
0
        public static void ParseUriList(string listOfUrisAsString, Collection <Uri> uriCollection, UriKind uriKind)
        {
            Fx.Assert(listOfUrisAsString != null, "The listOfUrisAsString must be non null.");
            Fx.Assert(uriCollection != null, "The uriCollection must be non null.");

            string[] uriStrings = listOfUrisAsString.Split(whiteSpaceChars, StringSplitOptions.RemoveEmptyEntries);
            if (uriStrings.Length > 0)
            {
                for (int i = 0; i < uriStrings.Length; i++)
                {
                    try
                    {
                        uriCollection.Add(new Uri(uriStrings[i], uriKind));
                    }
                    catch (FormatException fe)
                    {
                        if (uriKind == UriKind.Absolute)
                        {
                            throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlAbsoluteUriFormatError(uriStrings[i]), fe));
                        }
                        else
                        {
                            throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlUriFormatError(uriStrings[i]), fe));
                        }
                    }
                }
            }
        }
        internal void ReadFrom(XmlReader reader)
        {
            if (reader == null)
            {
                throw FxTrace.Exception.ArgumentNull("reader");
            }

            string instanceIdString = reader.GetAttribute(ProtocolStrings.SchemaNames.AppSequenceInstanceId);

            this.InstanceId = SerializationUtility.ReadUInt(
                instanceIdString,
                SR2.DiscoveryXmlMissingAppSequenceInstanceId,
                SR2.DiscoveryXmlInvalidAppSequenceInstanceId);

            string sequenceIdString = reader.GetAttribute(ProtocolStrings.SchemaNames.AppSequenceSequenceId);

            if (sequenceIdString != null)
            {
                try
                {
                    this.SequenceId = new Uri(sequenceIdString, UriKind.RelativeOrAbsolute);
                }
                catch (FormatException fe)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlUriFormatError(sequenceIdString), fe));
                }
            }

            string messageNumberString = reader.GetAttribute(ProtocolStrings.SchemaNames.AppSequenceMessageNumber);

            this.MessageNumber = SerializationUtility.ReadUInt(
                messageNumberString,
                SR2.DiscoveryXmlMissingAppSequenceMessageNumber,
                SR2.DiscoveryXmlInvalidAppSequenceMessageNumber);
        }
 void ThrowIfOpen()
 {
     if (this.isOpen)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SR2.DiscoverySdmCollectionIsOpen(typeof(T).Name)));
     }
 }
예제 #8
0
 protected override void SetItem(int index, Uri item)
 {
     if (item != null && !item.IsAbsoluteUri)
     {
         throw FxTrace.Exception.Argument("item", SR2.DiscoveryArgumentInvalidScopeUri(item));
     }
     base.SetItem(index, item);
 }
예제 #9
0
 internal static void InitializeAndValidateUdpChannelEndpointElement(ChannelEndpointElement channelEndpointElement)
 {
     if (!(channelEndpointElement.Address == null || String.IsNullOrEmpty(channelEndpointElement.Address.ToString())))
     {
         throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigAddressSpecifiedForUdpDiscoveryEndpoint(channelEndpointElement.Kind)));
     }
     channelEndpointElement.Address = null;
 }
예제 #10
0
 protected override void InsertItem(int index, Uri item)
 {
     if (item != null && !item.IsAbsoluteUri)
     {
         throw FxTrace.Exception.AsError(new ArgumentException(SR2.DiscoveryArgumentInvalidScopeUri(item)));
     }
     base.InsertItem(index, item);
 }
 public void Close(TimeSpan timeout)
 {
     InitializeCloseHandle();
     if (!this.closeHandle.Wait(timeout))
     {
         throw FxTrace.Exception.AsError(new TimeoutException(SR2.TimeoutOnOperation(timeout)));
     }
 }
예제 #12
0
        protected override void OnInitializeAndValidate(ServiceEndpointElement serviceEndpointElement)
        {
            if (!String.IsNullOrEmpty(serviceEndpointElement.Contract))
            {
                throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigContractSpecified(serviceEndpointElement.Kind)));
            }

            if (PropertyValueOrigin.Default == serviceEndpointElement.ElementInformation.Properties[ConfigurationStrings.IsSystemEndpoint].ValueOrigin)
            {
                serviceEndpointElement.IsSystemEndpoint = true;
            }
        }
예제 #13
0
        internal static void InitializeAndValidateUdpServiceEndpointElement(ServiceEndpointElement serviceEndpointElement)
        {
            if (!(serviceEndpointElement.Address == null || String.IsNullOrEmpty(serviceEndpointElement.Address.ToString())))
            {
                throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigAddressSpecifiedForUdpDiscoveryEndpoint(serviceEndpointElement.Kind)));
            }
            serviceEndpointElement.Address = null;

            if (serviceEndpointElement.ListenUri != null)
            {
                throw FxTrace.Exception.AsError(new ConfigurationErrorsException(SR2.DiscoveryConfigListenUriSpecifiedForUdpDiscoveryEndpoint(serviceEndpointElement.Kind)));
            }
        }
예제 #14
0
        public static int ReadMetadataVersion(XmlReader reader)
        {
            reader.ReadStartElement();

            int metadataVersion = reader.ReadContentAsInt();

            if (metadataVersion < 0)
            {
                throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlMetadataVersionLessThanZero(metadataVersion)));
            }

            reader.ReadEndElement();

            return(metadataVersion);
        }
예제 #15
0
        public static Uri ReadScopes(Collection <Uri> scopes, XmlReader reader)
        {
            Uri scopeMatchBy = null;

            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    if ((reader.NamespaceURI.Length == 0) &&
                        (reader.Name.Equals(ProtocolStrings.SchemaNames.MatchByAttribute)))
                    {
                        string scopeMatchByStr = reader.Value;
                        try
                        {
                            scopeMatchBy = new Uri(scopeMatchByStr, UriKind.RelativeOrAbsolute);
                        }
                        catch (FormatException fe)
                        {
                            throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlUriFormatError(scopeMatchByStr), fe));
                        }
                        break;
                    }
                }

                reader.MoveToElement();
            }

            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            else
            {
                reader.ReadStartElement();

                string listOfUrisAsString = reader.ReadString();
                if (!string.IsNullOrEmpty(listOfUrisAsString))
                {
                    SerializationUtility.ParseUriList(listOfUrisAsString, scopes, UriKind.Absolute);
                }

                reader.ReadEndElement();
            }

            return(scopeMatchBy);
        }
예제 #16
0
        static CompiledScopeCriteria CompileCriteria(Uri scope, Uri matchBy)
        {
            string compiledScope;
            CompiledScopeCriteriaMatchBy compiledMatchBy;

            if (matchBy.Equals(FindCriteria.ScopeMatchByPrefix))
            {
                compiledScope   = CompileForMatchByRfc2396(scope);
                compiledMatchBy = CompiledScopeCriteriaMatchBy.StartsWith;
            }
            else if (matchBy.Equals(FindCriteria.ScopeMatchByUuid))
            {
                Guid guid;
                if (!TryGetUuidGuid(scope, out guid))
                {
                    throw FxTrace.Exception.AsError(new FormatException(SR2.DiscoveryFormatInvalidScopeUuidUri(scope.ToString())));
                }
                compiledScope   = CompileForMatchByUuid(guid);
                compiledMatchBy = CompiledScopeCriteriaMatchBy.Exact;
            }
            else if (matchBy.Equals(FindCriteria.ScopeMatchByLdap))
            {
                if (string.Compare(scope.Scheme, "ldap", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw FxTrace.Exception.AsError(new FormatException(SR2.DiscoveryFormatInvalidScopeLdapUri(scope.ToString())));
                }
                compiledScope   = CompileForMatchByLdap(scope);
                compiledMatchBy = CompiledScopeCriteriaMatchBy.StartsWith;
            }
            else if (matchBy.Equals(FindCriteria.ScopeMatchByExact))
            {
                compiledScope   = CompileForMatchByStrcmp0(scope);
                compiledMatchBy = CompiledScopeCriteriaMatchBy.Exact;
            }
            else
            {
                throw FxTrace.Exception.ArgumentOutOfRange("matchBy", matchBy,
                                                           SR2.DiscoveryMatchingRuleNotSupported(
                                                               FindCriteria.ScopeMatchByExact,
                                                               FindCriteria.ScopeMatchByPrefix,
                                                               FindCriteria.ScopeMatchByUuid,
                                                               FindCriteria.ScopeMatchByLdap));
            }

            return(new CompiledScopeCriteria(compiledScope, compiledMatchBy));
        }
예제 #17
0
        public static int ReadMaxResults(XmlReader reader)
        {
            int maxResults = int.MaxValue;

            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            else
            {
                reader.ReadStartElement();
                maxResults = reader.ReadContentAsInt();
                if (maxResults <= 0)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlMaxResultsLessThanZero(maxResults)));
                }
                reader.ReadEndElement();
            }
            return(maxResults);
        }
예제 #18
0
        protected internal override object CreateBehavior()
        {
            ServiceDiscoveryBehavior serviceDiscoveryBehavior = new ServiceDiscoveryBehavior();

            AnnouncementEndpoint announcementEndpoint;

            foreach (ChannelEndpointElement channelEndpointElement in this.AnnouncementEndpoints)
            {
                if (string.IsNullOrEmpty(channelEndpointElement.Kind))
                {
                    throw FxTrace.Exception.AsError(
                              new ConfigurationErrorsException(
                                  SR2.DiscoveryConfigAnnouncementEndpointMissingKind(
                                      typeof(AnnouncementEndpoint).FullName)));
                }

                ServiceEndpoint serviceEndpoint = ConfigLoader.LookupEndpoint(channelEndpointElement, null);
                if (serviceEndpoint == null)
                {
                    throw FxTrace.Exception.AsError(
                              new ConfigurationErrorsException(
                                  SR2.DiscoveryConfigInvalidEndpointConfiguration(
                                      channelEndpointElement.Kind)));
                }

                announcementEndpoint = serviceEndpoint as AnnouncementEndpoint;
                if (announcementEndpoint == null)
                {
                    throw FxTrace.Exception.AsError(
                              new InvalidOperationException(
                                  SR2.DiscoveryConfigInvalidAnnouncementEndpoint(
                                      channelEndpointElement.Kind,
                                      serviceEndpoint.GetType().FullName,
                                      typeof(AnnouncementEndpoint).FullName)));
                }

                serviceDiscoveryBehavior.AnnouncementEndpoints.Add(announcementEndpoint);
            }

            return(serviceDiscoveryBehavior);
        }
예제 #19
0
        public static TimeSpan ReadDuration(XmlReader reader)
        {
            TimeSpan timeout = TimeSpan.MaxValue;

            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            else
            {
                reader.ReadStartElement();
                string timeoutString = reader.ReadString();
                timeout = SerializationUtility.ReadTimespan(timeoutString, SR2.DiscoveryXmlDurationDeserializationError(timeoutString));
                if (timeout <= TimeSpan.Zero)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlDurationLessThanZero(timeout)));;
                }
                reader.ReadEndElement();
            }
            return(timeout);
        }
예제 #20
0
        public static DiscoveryVersion FromName(string name)
        {
            if (name == null)
            {
                throw FxTrace.Exception.ArgumentNull("name");
            }

            if (WSDiscovery11.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return(WSDiscovery11);
            }
            else if (WSDiscoveryCD1.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return(WSDiscoveryCD1);
            }
            else if (WSDiscoveryApril2005.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                return(WSDiscoveryApril2005);
            }

            throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException(
                                                SR2.DiscoveryIncorrectVersion(name, WSDiscovery11.Name, WSDiscoveryCD1.Name, WSDiscoveryApril2005.Name)));
        }
예제 #21
0
        internal static TEndpoint LookupEndpointFromClientSection <TEndpoint>(string endpointConfigurationName) where TEndpoint : ServiceEndpoint
        {
            Fx.Assert(endpointConfigurationName != null, "The endpointConfigurationName parameter must be non null.");

            TEndpoint retval = default(TEndpoint);

            bool wildcard = string.Equals(endpointConfigurationName, "*", StringComparison.Ordinal);

            ClientSection clientSection = ClientSection.GetSection();

            foreach (ChannelEndpointElement channelEndpointElement in clientSection.Endpoints)
            {
                if (string.IsNullOrEmpty(channelEndpointElement.Kind))
                {
                    continue;
                }

                if (endpointConfigurationName == channelEndpointElement.Name || wildcard)
                {
                    TEndpoint endpoint = LookupEndpoint <TEndpoint>(channelEndpointElement);
                    if (endpoint != null)
                    {
                        if (retval != null)
                        {
                            if (wildcard)
                            {
                                throw FxTrace.Exception.AsError(
                                          new InvalidOperationException(
                                              SR2.DiscoveryConfigMultipleEndpointsMatchWildcard(
                                                  typeof(TEndpoint).FullName,
                                                  clientSection.SectionInformation.SectionName)));
                            }
                            else
                            {
                                throw FxTrace.Exception.AsError(
                                          new InvalidOperationException(
                                              SR2.DiscoveryConfigMultipleEndpointsMatch(
                                                  typeof(TEndpoint).FullName,
                                                  endpointConfigurationName,
                                                  clientSection.SectionInformation.SectionName)));
                            }
                        }
                        else
                        {
                            retval = endpoint;
                        }
                    }
                }
            }

            if (retval == null)
            {
                if (wildcard)
                {
                    throw FxTrace.Exception.AsError(
                              new InvalidOperationException(
                                  SR2.DiscoveryConfigNoEndpointsMatchWildcard(
                                      typeof(TEndpoint).FullName,
                                      clientSection.SectionInformation.SectionName)));
                }
                else
                {
                    throw FxTrace.Exception.AsError(
                              new InvalidOperationException(
                                  SR2.DiscoveryConfigNoEndpointsMatch(
                                      typeof(TEndpoint).FullName,
                                      endpointConfigurationName,
                                      clientSection.SectionInformation.SectionName)));
                }
            }

            return(retval);
        }