protected ServiceConnectionString(
     ServiceConnectionString parts) : this(
         serviceUri : parts.ServiceUri,
         partitionKind : parts.PartitionKind,
         parts : parts)
 {
 }
Пример #2
0
        public void Parse_Valid_Parses(
            string connectionString,
            string partitionKind,
            string serviceUri)
        {
            var result = ServiceConnectionString.Parse(connectionString);

            Assert.Equal(partitionKind, result.PartitionKind);
            Assert.Equal(serviceUri, result.ServiceUri.ToString());
        }
        protected override void BeginProcessing()
        {
            foreach (var configuration in ServiceConfiguration)
            {
                var parts = configuration.Cast <DictionaryEntry>()
                            .ToDictionary(kv => kv.Key.ToString(), kv => kv.Value.ToString());

                var connectionString = ServiceConnectionString.Parse(parts);

                WriteObject(connectionString.ToString());
            }
        }
 public static bool TryParse(string s, out ServiceConnectionString result)
 {
     try
     {
         result = Parse(s);
         return(true);
     }
     catch (ArgumentException)
     {
         result = default(ServiceConnectionString);
         return(false);
     }
 }
        internal Int64RangeServiceConnectionString(
            long partitionLowKey,
            long partitionHighKey,
            string partitionAlgorithm,
            ServiceConnectionString parts)
            : base(parts)
        {
            PartitionLowKey = partitionLowKey;

            PartitionHighKey = partitionHighKey;

            PartitionAlgorithm = !string.IsNullOrWhiteSpace(partitionAlgorithm)
                ? partitionAlgorithm : throw new ArgumentException("A partition algorithm must be defined");
        }
        private static Int64RangeServiceConnectionString Parse(ServiceConnectionString parts)
        {
            if (parts.PartitionKind != PartitionKindInt64RangeValue)
            {
                throw new ArgumentException($"Connection string is not of type '{PartitionKindInt64RangeValue}'.");
            }

            var partitionLowKey =
                parts.ContainsKey(PartitionLowKeyKey) == false ? throw new ArgumentException($"A {PartitionLowKeyKey} is required when the {nameof(PartitionKind)} is '{PartitionKindInt64RangeValue}'.")
                 : long.TryParse(parts[PartitionLowKeyKey], out var lowKey) == false ? throw new ArgumentException($"'{parts[PartitionLowKeyKey]}' is not a valid long.")
                 : lowKey;

            var partitionHighKey =
                parts.ContainsKey(PartitionHighKeyKey) == false ? throw new ArgumentException($"A {PartitionHighKeyKey} is required when the {nameof(PartitionKind)} is '{PartitionKindInt64RangeValue}'.")
                : long.TryParse(parts[PartitionHighKeyKey], out var highKey) == false ? throw new ArgumentException($"'{parts[PartitionHighKeyKey]}' is not a valid long.")
                : highKey;

            var partitionAlgorithm =
                parts.TryGetValue(PartitionAlgorithmKey, out var algorithm) == false ? default
                : algorithm;

            return(new Int64RangeServiceConnectionString(partitionLowKey, partitionHighKey, partitionAlgorithm, parts));
        }
Пример #7
0
 public void Parse_InvalidPartitionKind_Throws(string connectionString)
 {
     Assert.Throws <ArgumentException>(() => ServiceConnectionString.Parse(connectionString));
 }
Пример #8
0
 internal SingletonServiceConnectionString(
     ServiceConnectionString parts)
     : base(parts)
 {
 }
 private static string CreateConnectionString(ServiceConnectionString connectionString) =>
 string.Join(";", connectionString.Select(kv => kv.Key + "=" + kv.Value));
 public bool Equals(ServiceConnectionString other) =>
 ServiceUri.Equals(other?.ServiceUri) &&
 PartitionKind.Equals(other?.PartitionKind);