/// <summary>
        ///
        /// </summary>
        /// <param name="clusterNumber"></param>
        /// <returns></returns>
        public async Task <IEnumerable <QueueMessageCheckResult> > QueueCheckAsync(string clusterNumber = null)
        {
            BlobHelper.Setup(operationHelper.StorageConnectionString, "cloudqueueclustersettings");
            var json = clusterNumber.IsEmpty()
                ? BlobHelper.Download($"CloudQueueClusterSettings.{operationHelper.EnvIdentifier}.json")
                : BlobHelper.Download($"CloudQueueClusterSettings.{operationHelper.EnvIdentifier}.{clusterNumber}.json");

            var clusters = JsonConvert.DeserializeObject <QueueCluster[]>(json);

            var results = new List <QueueMessageCheckResult>();

            foreach (var cluster in clusters)
            {
                foreach (var queueNode in cluster.QueueNodes)
                {
                    var result = new QueueMessageCheckResult();

                    var account = CloudStorageAccount.Parse(queueNode.CloudStorageAccount);
                    var client  = account.CreateCloudQueueClient();
                    var queue   = client.GetQueueReference($"{operationHelper.EnvIdentifier}-{queueNode.Name}".ToLower());
                    queue.CreateIfNotExists();

                    result.QueueName    = queue.Name;
                    result.MessageCount = queue.ApproximateMessageCount ?? 0;

                    results.Add(result);
                }
            }

            return(results);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="clusterNumber"></param>
        /// <returns></returns>
        public async Task WarmingupAsync(string clusterNumber = null)
        {
            BlobHelper.Setup(operationHelper.StorageConnectionString, "cloudqueueclustersettings");
            var json = clusterNumber.IsEmpty()
                ? BlobHelper.Download($"CloudQueueClusterSettings.{operationHelper.EnvIdentifier}.json")
                : BlobHelper.Download($"CloudQueueClusterSettings.{operationHelper.EnvIdentifier}.{clusterNumber}.json");

            var clusters = JsonConvert.DeserializeObject <QueueCluster[]>(json);

            foreach (var cluster in clusters)
            {
                foreach (var queueNode in cluster.QueueNodes)
                {
                    await Task.Run(() =>
                    {
                        var account = CloudStorageAccount.Parse(queueNode.CloudStorageAccount);
                        var client  = account.CreateCloudQueueClient();
                        var queue   = client.GetQueueReference($"{operationHelper.EnvIdentifier}-{queueNode.Name}".ToLower());
                        queue.CreateIfNotExists();

                        for (var i = 0; i < 100; i++)
                        {
                            queue.AddMessageAsync(new Microsoft.WindowsAzure.Storage.Queue.CloudQueueMessage("0"));
                            Task.Delay(10);
                        }
                    });
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Anybody downloads a file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public ActionResult Download(string fileName, int maxWidth = 0, int maxHeight = 0)
        {
            if (fileName == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (maxWidth != 0 || maxHeight != 0)
            {
                // Returns thumbnail.
                var bitmap = BlobHelper.DownloadAsBitmap("mediafile", fileName, maxWidth, maxHeight);
                if (bitmap == null)
                {
                    return(HttpNotFound());
                }
                using (var mem = new MemoryStream())
                {
                    bitmap.Save(mem, ImageFormat.Jpeg);
                    return(File(mem.ToArray(), "image/jpeg"));
                }
            }
            else
            {
                // Returns raw file.
                var blob = BlobHelper.Download("mediafile", fileName);
                if (blob == null)
                {
                    return(HttpNotFound());
                }
                return(File(blob.Item1, blob.Item2));
            }
        }