static string GetSubscriptionName(string subscriptionName, string queuePath)
        {
            var subscriptionPath = subscriptionName.Replace("{queuePath}", queuePath);

            string name;

            if (subscriptionPath.Length > 50)
            {
                string hashed;
                using (var hasher = new SHA1Managed())
                {
                    byte[] buffer = Encoding.UTF8.GetBytes(subscriptionPath);
                    byte[] hash   = hasher.ComputeHash(buffer);
                    hashed = _formatter.Format(hash).Substring(0, 6);
                }

                name = $"{subscriptionPath.Substring(0, 43)}-{hashed}";
            }
            else
            {
                name = subscriptionPath;
            }

            return(name);
        }
        static string GetSubscriptionName(NamespaceManager namespaceManager, string queuePath)
        {
            string subscriptionPath =
                $"{queuePath}-{namespaceManager.Address.AbsolutePath.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries).Last()}";

            string name;

            if (subscriptionPath.Length > 50)
            {
                string hashed;
                using (var hasher = new SHA1Managed())
                {
                    byte[] buffer = Encoding.UTF8.GetBytes(subscriptionPath);
                    byte[] hash   = hasher.ComputeHash(buffer);
                    hashed = _formatter.Format(hash).Substring(0, 6);
                }

                name = $"{subscriptionPath.Substring(0, 43)}-{hashed}";
            }
            else
            {
                name = subscriptionPath;
            }
            return(name);
        }
        static string GenerateFilePath(TimeSpan?timeToLive)
        {
            string fileId = _formatter.Format(NewId.Next().ToSequentialGuid().ToByteArray());

            string expiration = timeToLive.HasValue && timeToLive.Value < TimeSpan.MaxValue && timeToLive >= TimeSpan.Zero
                ? (DateTime.UtcNow + timeToLive.Value).ToString("yyyy-MM-dd-HH").Replace('-', Path.DirectorySeparatorChar)
                : "none";

            return(Path.Combine(expiration, fileId));
        }
Esempio n. 4
0
        public string ToString(string format, IFormatProvider formatProvider)
        {
            if (string.IsNullOrEmpty(format))
            {
                format = "D";
            }

            bool sequential = false;

            if (format.Length == 2 && (format[1] == 'S' || format[1] == 's'))
            {
                sequential = true;
            }
            else if (format.Length != 1)
            {
                throw new FormatException("The format string must be exactly one character or null");
            }

            char formatCh = format[0];

            byte[] bytes = sequential ? GetSequentialFormatteryArray() : GetFormatteryArray();

            if (formatCh == 'B' || formatCh == 'b')
            {
                return(_braceFormatter.Format(bytes));
            }
            if (formatCh == 'P' || formatCh == 'p')
            {
                return(_parenFormatter.Format(bytes));
            }
            if (formatCh == 'D' || formatCh == 'd')
            {
                return(_dashedHexFormatter.Format(bytes));
            }
            if (formatCh == 'N' || formatCh == 'n')
            {
                return(_hexFormatter.Format(bytes));
            }

            throw new FormatException("The format string was not valid");
        }
Esempio n. 5
0
        public string ToString(INewIdFormatter formatter, bool sequential = false)
        {
            byte[] bytes = sequential ? GetSequentialFormatteryArray() : GetFormatteryArray();

            return(formatter.Format(bytes));
        }
Esempio n. 6
0
 public string GenerateFileName()
 {
     return(_formatter.Format(NewId.Next().ToSequentialGuid().ToByteArray()));
 }