Пример #1
0
        public void CloudStorageAccountClientMethods()
        {
            CloudStorageAccount account = new CloudStorageAccount(TestBase.StorageCredentials, false);
            CloudBlobClient     blob    = account.CreateCloudBlobClient();
            CloudQueueClient    queue   = account.CreateCloudQueueClient();
            CloudTableClient    table   = account.CreateCloudTableClient();

            // check endpoints
            Assert.AreEqual(account.BlobEndpoint, blob.BaseUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueEndpoint, queue.BaseUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableEndpoint, table.BaseUri, "Table endpoint doesn't match account");

            // check storage uris
            Assert.AreEqual(account.BlobStorageUri, blob.StorageUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueStorageUri, queue.StorageUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableStorageUri, table.StorageUri, "Table endpoint doesn't match account");

            // check creds
            Assert.AreEqual(account.Credentials, blob.Credentials, "Blob creds don't match account");
            Assert.AreEqual(account.Credentials, queue.Credentials, "Queue creds don't match account");
            Assert.AreEqual(account.Credentials, table.Credentials, "Table creds don't match account");
        }
Пример #2
0
        static void QueueTest()
        {
            CloudStorageAccount storageAccount = ValidateConnection();

            if (storageAccount == null)
            {
                return;
            }
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("testqueue");

            queue.CreateIfNotExists();
            Console.WriteLine("Queue created");
            CloudQueueMessage msg = new CloudQueueMessage("Hello, World");

            queue.AddMessage(msg);
            CloudQueueMessage peekedMessage = queue.PeekMessage();

            Console.WriteLine(peekedMessage.AsString);
            CloudQueueMessage message = queue.GetMessage();

            message.SetMessageContent("Updated contents.");
            // Make it invisible for another 60 seconds.
            queue.UpdateMessage(message, TimeSpan.FromSeconds(20.0), MessageUpdateFields.Content | MessageUpdateFields.Visibility);
            msg = new CloudQueueMessage("test1212");
            queue.AddMessage(msg);
            CloudQueueMessage retrievedMessage = queue.GetMessage();

            if (retrievedMessage != null)
            {
                queue.DeleteMessage(retrievedMessage);
            }
            foreach (CloudQueueMessage msg1 in queue.GetMessages(20, TimeSpan.FromMinutes(5)))
            {
                // Process all messages in less than 5 minutes, deleting each message after processing.
                queue.DeleteMessage(msg1);
                Console.WriteLine("Deleted:" + msg1.AsString);
            }
        }
Пример #3
0
        private static async Task ProcessIsues()
        {
            CloudStorageAccount storageAccount = null;
            CloudQueue          queue          = null;

            string storageConnectionString = "provide connection to your string";

            CloudStorageAccount.TryParse(storageConnectionString, out storageAccount);
            try
            {
                CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();
                queue = cloudQueueClient.GetQueueReference("que nane in all lower case");
                bool createdQueue = await queue.CreateIfNotExistsAsync();

                if (createdQueue)
                {
                    Console.WriteLine("The queue was created.");
                }

                Dictionary <string, string> value = new Dictionary <string, string>
                {
                    { "yes", "no" }
                };
                string            json    = JsonConvert.SerializeObject(value, Formatting.Indented);
                CloudQueueMessage message = new CloudQueueMessage(json);
                await queue.AddMessageAsync(message, new TimeSpan(0, 0, 1, 0), null, null, null);

                CloudQueueMessage retrievedMessage = await queue.GetMessageAsync();

                string messagedata = retrievedMessage.AsString;
                Console.WriteLine(messagedata);
                Console.WriteLine();
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error returned from Azure Storage: {0}", ex.Message);
            }
        }
Пример #4
0
        protected EndToEndTestFixture(string rootPath, string testId)
        {
            _settingsManager = ScriptSettingsManager.Instance;
            FixtureId        = testId;
            string connectionString            = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();
            TableClient = storageAccount.CreateCloudTableClient();

            CreateTestStorageEntities();
            TraceWriter = new TestTraceWriter(TraceLevel.Verbose);

            ApiHubTestHelper.SetDefaultConnectionFactory();

            ScriptHostConfiguration config = new ScriptHostConfiguration()
            {
                RootScriptPath  = rootPath,
                TraceWriter     = TraceWriter,
                FileLoggingMode = FileLoggingMode.Always
            };

            RequestConfiguration = new HttpConfiguration();
            RequestConfiguration.Formatters.Add(new PlaintextMediaTypeFormatter());

            EventManager = new ScriptEventManager();
            ScriptHostEnvironmentMock = new Mock <IScriptHostEnvironment>();

            // Reset the timer logs first, since one of the tests will
            // be checking them
            TestHelpers.ClearFunctionLogs("TimerTrigger");
            TestHelpers.ClearFunctionLogs("ListenerStartupException");

            InitializeConfig(config);

            Host = ScriptHost.Create(ScriptHostEnvironmentMock.Object, EventManager, config, _settingsManager);
            Host.Start();
        }
Пример #5
0
        public void Enqueue(string queueName, string message)
        {
            //Cria uma referência a conta de Armazenamento do Azure
            CloudStorageAccount storageAccountClient =
                CloudStorageAccount.Parse(Properties.Settings.Default
                                          .StorageAccountConnectionString);

            //Cria um objeto cliente de queue/fila a partir da conta de armazenamento
            CloudQueueClient queueClient = storageAccountClient.CreateCloudQueueClient();

            //Crio um objeto que referencia uma determinada queue/fila
            CloudQueue cloudQueue = queueClient.GetQueueReference(queueName);

            //Crio a fila se ela não existir
            cloudQueue.CreateIfNotExists();

            //Crio uma mensagem a partir do objeto serializado
            CloudQueueMessage cloudQueueMessage = new CloudQueueMessage(message);

            //Adiciono a mensagem na queue/fila
            cloudQueue.AddMessage(cloudQueueMessage);
        }
Пример #6
0
        private void ProcessCommandQueue()
        {
            // Retrieve storage account from connection string
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the queue client
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to CommandQueue
            CloudQueue commandQueue = queueClient.GetQueueReference(WebRole.AZURE_COMMAND_QUEUE);

            // Create the queue if it doesn't already exist
            commandQueue.CreateIfNotExists();

            CloudQueueMessage message = commandQueue.GetMessage();

            if (message == null)
            {
                // Exit this function if there is no message
                return;
            }

            if (message.AsString == Commands.CMD_START_CRAWLER.ToString())
            {
                if (statsEntity.CrawlerState == CrawlerStates.Idle)
                {
                    // Start crawling if the current state is 'idle'
                    statsEntity.CrawlerState = CrawlerStates.Loading;
                }
            }
            else if (message.AsString == Commands.CMD_CLEAR_CRAWLER.ToString())
            {
                ClearCrawler();
            }

            // After reading the message, the client should delete it
            commandQueue.DeleteMessage(message);
        }
Пример #7
0
        /// <summary>
        /// Set service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="properties">Service properties</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext)
        {
            CloudStorageAccount account = StorageContext.StorageAccount;

            switch (type)
            {
            case StorageServiceType.Blob:
                account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Queue:
                account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Table:
                account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext);
                break;

            default:
                throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
            }
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of ConnectionSettings using the given storage account name and key as well as
        /// the provided queue name.
        /// </summary>
        /// <param name="storageAccountName">
        /// The name of the Azure Storage Account to connect to.
        /// </param>
        /// <param name="storageAccountKey">
        /// The access key to the Azure Storage Account to connect to.
        /// </param>
        /// <param name="queueName">
        /// The name of the queue to connect to.
        /// </param>
        public ConnectionSettings(string storageAccountName, string storageAccountKey, string queueName)
        {
            if (String.IsNullOrWhiteSpace(storageAccountName))
            {
                throw new ArgumentNullException("storageAccountName");
            }
            else if (String.IsNullOrWhiteSpace(storageAccountKey))
            {
                throw new ArgumentNullException("storageAccountKey");
            }
            else if (String.IsNullOrWhiteSpace(queueName))
            {
                throw new ArgumentNullException("queueName");
            }

            StorageCredentials  credentials    = new StorageCredentials(storageAccountName, storageAccountKey);
            CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true);

            client = storageAccount.CreateCloudQueueClient();

            QueueName = queueName;
        }
Пример #9
0
        /// <inheritdoc />
        public CloudQueue GetCloudQueue(string connectionString, string queueName)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }
            if (queueName == null)
            {
                throw new ArgumentNullException("queueName");
            }

            string queueKey             = GetLookupKey(connectionString, queueName);
            CloudStorageAccount account = QueueAccounts.GetOrAdd(
                queueKey,
                key =>
            {
                CloudStorageAccount storageAccount = GetCloudStorageAccount(connectionString);
                try
                {
                    // Ensure that queue exists
                    CloudQueueClient client = storageAccount.CreateCloudQueueClient();
                    CloudQueue cloudQueue   = client.GetQueueReference(queueName);
                    cloudQueue.CreateIfNotExists();
                }
                catch (Exception ex)
                {
                    string error = GetStorageErrorMessage(ex);
                    string msg   = string.Format(CultureInfo.CurrentCulture, AzureStorageResources.StorageManager_InitializationFailure, error);
                    _logger.Error(msg, ex);
                    throw new InvalidOperationException(msg, ex);
                }

                return(storageAccount);
            });

            CloudQueueClient cloudClient = account.CreateCloudQueueClient();

            return(cloudClient.GetQueueReference(queueName));
        }
Пример #10
0
        public ActionResult Index()
        {
            var    kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(PiUiUtil.GetTokenForCurrentApplication));
            string piStorageAccountName                       = kv.GetSecretAsync(CloudConfigurationManager.GetSetting("piStorageAccountName_KvUri")).Result.Value;
            string piStorageAccountSecretKey                  = kv.GetSecretAsync(CloudConfigurationManager.GetSetting("piStorageAccountSecretKey_KvUri")).Result.Value;
            string piStorageAccountCameraContainerName        = kv.GetSecretAsync(CloudConfigurationManager.GetSetting("piStorageAccountCameraContainerName_KvUri")).Result.Value;
            string piStorageAccountCameraStillImagesQueueName = kv.GetSecretAsync(CloudConfigurationManager.GetSetting("piStorageAccountCameraStillImagesQueueName_KvUri")).Result.Value;
            string storageConnection           = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", piStorageAccountName, piStorageAccountSecretKey);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnection);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

            CloudQueue queue = queueClient.GetQueueReference(piStorageAccountCameraStillImagesQueueName);

            queue.EncodeMessage = true;
            // Peek at the next message
            CloudQueueMessage message = queue.GetMessage();


            // Display message.
            Console.WriteLine();

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.GetContainerReference(piStorageAccountCameraContainerName);

            // Retrieve reference to a blob ie "picture.jpg".
            CloudBlockBlob blockBlob = container.GetBlockBlobReference(message.AsString);
            //------

            var newUri = new Uri(blockBlob.Uri.AbsoluteUri);

            ViewBag.ImageUri = newUri;


            return(View());
        }
        public async Task SendMessageAsync <T>(T item)
        {
            #region Commented Code
            //string msgBody = JsonConvert.SerializeObject(item);

            //CloudStorageAccount acct = CloudStorageAccount.Parse(
            //    config[Constants.KEY_STORAGE_CNN]);

            //CloudQueueClient qClient = acct.CreateCloudQueueClient();
            //CloudQueue orderQueue = qClient.GetQueueReference(
            //    config[Constants.KEY_QUEUE]);

            //await orderQueue.CreateIfNotExistsAsync();

            //await orderQueue.AddMessageAsync(
            //    new CloudQueueMessage(msgBody));
            #endregion

            //serialize the object
            string msgBody = JsonConvert.SerializeObject(item);

            //Parse the connection string
            CloudStorageAccount acct = CloudStorageAccount.Parse(
                config[Constants.KEY_STORAGE_CONN]);

            //Create the queue client
            CloudQueueClient qClient = acct.CreateCloudQueueClient();
            //get the queue reference
            CloudQueue orderQueue = qClient.GetQueueReference(
                config[Constants.KEY_QUEUE]);

            //If the queue doesnt exist then create it
            await orderQueue.CreateIfNotExistsAsync();

            //Add the message to the queue
            await orderQueue.AddMessageAsync(
                new CloudQueueMessage(msgBody));
        }
Пример #12
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            CostCenter costCenter = await GetCostCenterAsync(costCenterAPIUrl, Expense.SubmitterEmail);

            if (costCenter != null)
            {
                Expense.CostCenter    = costCenter.CostCenterName;
                Expense.ApproverEmail = costCenter.ApproverEmail;
            }
            else
            {
                Expense.CostCenter    = "Unkown";
                Expense.ApproverEmail = "Unknown";
            }

            // Write to DB, but don't wait right now
            _context.Expense.Add(Expense);
            Task t = _context.SaveChangesAsync();

            // Serialize the expense and write it to the Azure Storage Queue
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_queueInfo.ConnectionString);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();
            CloudQueue          queue          = queueClient.GetQueueReference(_queueInfo.QueueName);
            await queue.CreateIfNotExistsAsync();

            CloudQueueMessage queueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(Expense));
            await queue.AddMessageAsync(queueMessage);

            // Ensure the DB write is complete
            t.Wait();

            return(RedirectToPage("./Index"));
        }
Пример #13
0
        private void OnStarted()
        {
            var connectionString = configuration.GetConnectionString("ImageStore");

            CloudStorageAccount account = null;

            CloudStorageAccount.TryParse(connectionString, out account);

            var blobClient            = account.CreateCloudBlobClient();
            var imageContainer        = blobClient.GetContainerReference("images");
            var imageBlobCreationTask = imageContainer.CreateIfNotExistsAsync();

            var tableClient            = account.CreateCloudTableClient();
            var imageTable             = tableClient.GetTableReference("images");
            var imageTableCreationTask = imageTable.CreateIfNotExistsAsync();

            var queueClient          = account.CreateCloudQueueClient();
            var imgQueue             = queueClient.GetQueueReference("imgprocessing");
            var imgQueueCreationTask = imgQueue.CreateIfNotExistsAsync();

            var thumbnailContainer        = blobClient.GetContainerReference("thumbnails");
            var thumbnailBlobCreationTask = thumbnailContainer
                                            .CreateIfNotExistsAsync()
                                            .ContinueWith
                                            (
                x => {
                thumbnailContainer.SetPermissionsAsync(
                    new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });
                return(true);
            }
                                            );

            Task.WaitAll(imageBlobCreationTask, imageTableCreationTask,
                         imgQueueCreationTask, thumbnailBlobCreationTask);
        }
        /// <summary>
        /// Set service properties
        /// </summary>
        /// <param name="account">Cloud storage account</param>
        /// <param name="type">Service type</param>
        /// <param name="properties">Service properties</param>
        /// <param name="options">Request options</param>
        /// <param name="operationContext">Operation context</param>
        public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext)
        {
            CloudStorageAccount account = StorageContext.StorageAccount;

            switch (type)
            {
            case StorageServiceType.Blob:
                account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Queue:
                account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext);
                break;

            case StorageServiceType.Table:
                account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext);
                break;

            case StorageServiceType.File:
                if (null != properties.Logging)
                {
                    throw new InvalidOperationException(Resources.FileNotSupportLogging);
                }

                if (null != properties.HourMetrics || null != properties.MinuteMetrics)
                {
                    throw new InvalidOperationException(Resources.FileNotSupportMetrics);
                }

                FileServiceProperties fileServiceProperties = new FileServiceProperties();
                fileServiceProperties.Cors = properties.Cors;
                account.CreateCloudFileClient().SetServiceProperties(fileServiceProperties, (FileRequestOptions)options, operationContext);
                break;

            default:
                throw new ArgumentException(Resources.InvalidStorageServiceType, "type");
            }
        }
Пример #15
0
        public static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("ConnectionString"));

            CloudQueueClient  queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue        queue       = queueClient.GetQueueReference("--process_queue--");
            CloudQueueMessage peekedMsg   = queue.PeekMessage();//get last queue message

            CloudBlobClient    blobClient    = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer blobContainer = blobClient.GetContainerReference("--contenedor_de_registros--");

            blobContainer.CreateIfNotExists();

            //Can not get all message at once.Need to use batch.
            foreach (CloudQueueMessage item in queue.GetMessages(20, TimeSpan.FromSeconds(100)))
            {
                var path = string.Format(@"c:\\Temporal\log{0}.txt", item.Id);

                using (TextWriter tempFile = File.CreateText(path))
                {
                    var msg = queue.GetMessage().AsString;

                    tempFile.WriteLine(msg);
                    Console.WriteLine("CreatedFile");
                }

                using (var fileStream = File.OpenRead(path))
                {
                    CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(string.Format("log{0}", item.Id));
                    blockBlob.UploadFromStream(fileStream);
                    Console.WriteLine("Blob created");
                }

                queue.DeleteMessage(item);
            }

            Console.ReadLine();
        }
        public async Task InitializeAsync()
        {
            _copiedRootPath = Path.Combine(Path.GetTempPath(), "FunctionsE2E", DateTime.UtcNow.ToString("yyMMdd-HHmmss"));
            FileUtility.CopyDirectory(_rootPath, _copiedRootPath);

            var extensionsToInstall = GetExtensionsToInstall();

            if (extensionsToInstall != null && extensionsToInstall.Length > 0)
            {
                TestFunctionHost.WriteNugetPackageSources(_copiedRootPath, "http://www.myget.org/F/azure-appservice/api/v2", "https://www.myget.org/F/azure-appservice-staging/api/v2", "https://api.nuget.org/v3/index.json");
                var options = new OptionsWrapper <ScriptJobHostOptions>(new ScriptJobHostOptions
                {
                    RootScriptPath = _copiedRootPath
                });

                var manager = new ExtensionsManager(options, NullLogger <ExtensionsManager> .Instance);
                await manager.AddExtensions(extensionsToInstall);
            }

            string logPath = Path.Combine(Path.GetTempPath(), @"Functions");

            Host = new TestFunctionHost(_copiedRootPath, logPath, ConfigureJobHost, configureAppConfiguration: s =>
            {
                s.AddInMemoryCollection(new Dictionary <string, string>()
                {
                    { LanguageWorkerConstants.FunctionWorkerRuntimeSettingName, _functionsWorkerRuntime }
                });
            });

            string connectionString            = Host.JobHostServices.GetService <IConfiguration>().GetWebJobsConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();
            TableClient = storageAccount.CreateCloudTableClient();

            await CreateTestStorageEntities();
        }
Пример #17
0
        static void PushPop()
        {
            // Retrieve storage account from connection string.
            CloudStorageAccount storageAccount = CloudStorageAccountHelper.Instance;

            // Create the queue client.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container.
            CloudQueue queue = queueClient.GetQueueReference("myqueue");

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();

            // Create a message and add it to the queue.
            CloudQueueMessage message = new CloudQueueMessage("Hello, World");

            queue.AddMessage(message);

            // Update Message Content
            CloudQueueMessage updateMessage = queue.GetMessage();

            updateMessage.SetMessageContent("Updated contents.");
            queue.UpdateMessage(updateMessage,
                                TimeSpan.FromSeconds(60.0), // Make it invisible for another 60 seconds.
                                MessageUpdateFields.Content | MessageUpdateFields.Visibility);

            // Peek at the next message
            CloudQueueMessage peekedMessage = queue.PeekMessage();

            // Display message.
            Console.WriteLine(peekedMessage.AsString);

            // Delete message
            CloudQueueMessage retrievedMessage = queue.GetMessage();

            queue.DeleteMessage(retrievedMessage);
        }
        public async void QueueWork()
        {
            // Parse the connection string and return a reference to the storage account.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container.
            CloudQueue queue = queueClient.GetQueueReference("myqueue");

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();

            // Create a message and add it to the queue.
            CloudQueueMessage message = new CloudQueueMessage("Hello, World");

            queue.AddMessage(message);

            // Create a message to put in the queue
            CloudQueueMessage cloudQueueMessage = new CloudQueueMessage("My message");

            // Peek at the next message
            CloudQueueMessage peekedMessage = queue.PeekMessage();

            // Get the next message
            CloudQueueMessage retrievedMessage = queue.GetMessage();

            // ASYNC AWAIT
            // Async enqueue the message
            await queue.AddMessageAsync(cloudQueueMessage);

            // Async dequeue the message
            CloudQueueMessage retrievedMessage2 = await queue.GetMessageAsync();

            // QUEUE LENGTH
            int?cachedMessageCount = queue.ApproximateMessageCount;
        }
Пример #19
0
        protected EndToEndTestFixture(string rootPath, string testId, string extensionName = null, string extensionVersion = null)
        {
            FixtureId = testId;
            string connectionString            = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.Storage);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            QueueClient = storageAccount.CreateCloudQueueClient();
            BlobClient  = storageAccount.CreateCloudBlobClient();
            TableClient = storageAccount.CreateCloudTableClient();

            CreateTestStorageEntities().Wait();

            _copiedRootPath = Path.Combine(Path.GetTempPath(), "FunctionsE2E", DateTime.UtcNow.ToString("yyMMdd-HHmmss"));
            FileUtility.CopyDirectory(rootPath, _copiedRootPath);

            // Allow derived classes to limit functions. We'll update host.json in the copied location
            // so it only affects this fixture's instance.
            IEnumerable <string> functions = GetActiveFunctions();
            string  hostJsonPath           = Path.Combine(_copiedRootPath, "host.json");
            JObject hostJson = JObject.Parse(File.ReadAllText(hostJsonPath));

            if (functions != null && functions.Any())
            {
                hostJson["functions"] = JArray.FromObject(functions);
            }
            File.WriteAllText(hostJsonPath, hostJson.ToString());

            Host = new TestFunctionHost(_copiedRootPath);

            // We can currently only support a single extension.
            if (extensionName != null && extensionVersion != null)
            {
                Host.SetNugetPackageSources("http://www.myget.org/F/azure-appservice/api/v2", "https://api.nuget.org/v3/index.json");
                Host.InstallBindingExtension(extensionName, extensionVersion).Wait(TimeSpan.FromSeconds(30));
            }

            Host.StartAsync().Wait(TimeSpan.FromSeconds(30));
        }
Пример #20
0
        public void CloudStorageAccountWithStorageUri()
        {
            StorageUri blobEndpoint = new StorageUri(
                new Uri("http://" + AccountName + BlobService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix));

            StorageUri queueEndpoint = new StorageUri(
                new Uri("http://" + AccountName + QueueService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + QueueService + EndpointSuffix));

            StorageUri fileEndpoint = new StorageUri(
                new Uri("http://" + AccountName + FileService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + FileService + EndpointSuffix));

            CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(), blobEndpoint, queueEndpoint, null, fileEndpoint);

            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = new CloudStorageAccount(new StorageCredentials(AccountName, TestBase.StorageCredentials.ExportBase64EncodedKey()), false);
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = CloudStorageAccount.Parse(string.Format("DefaultEndpointsProtocol=http;AccountName={0};AccountKey=", AccountName));
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            Assert.IsTrue(blobEndpoint.Equals(account.CreateCloudBlobClient().StorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.CreateCloudQueueClient().StorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.CreateCloudFileClient().StorageUri));

            Assert.IsTrue(blobEndpoint.PrimaryUri.Equals(account.BlobEndpoint));
            Assert.IsTrue(queueEndpoint.PrimaryUri.Equals(account.QueueEndpoint));
            Assert.IsTrue(fileEndpoint.PrimaryUri.Equals(account.FileEndpoint));
        }
        public void Run()
        {
            this.storageAccount = CloudStorageAccount.Parse(queueStorageConnectionString);

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container.
            this.queue = queueClient.GetQueueReference(queueName);

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();


            while (true)
            {
                var message = this.queue.GetMessage(TimeSpan.FromSeconds(10));
                if (message == null)
                {
                    Thread.Sleep(1000);
                    continue;
                }
                var msgbytes = message.AsBytes;
                var request  = DeserializeRequest(msgbytes);

                Thread.Sleep(8000);

                //uh ok - we've used almost all our 10 seconds. better ask for more time
                queue.UpdateMessage(message, TimeSpan.FromSeconds(20), MessageUpdateFields.Visibility);

                //System.IO.File.WriteAllBytes(request.Image)

                var result = MakeAnalysisRequest(request.Image).GetAwaiter().GetResult();

                Console.WriteLine(result);

                queue.DeleteMessage(message);
            }
        }
        /// <summary>
        /// Executes the action with the specified <paramref name="data" />.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="formSubmitContext">The form submit context.</param>
        /// <returns>
        ///   <c>true</c> if the action is executed correctly; otherwise <c>false</c>
        /// </returns>
        protected override bool Execute(string data, FormSubmitContext formSubmitContext)
        {
            Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext));
            Assert.ArgumentNotNullOrEmpty(_connectionstring, nameof(_connectionstring));

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_connectionstring);
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

            // Retrieve a reference to a container. use only lowercase!!
            CloudQueue queue = queueClient.GetQueueReference("stockpickformsqueue");

            // Create the queue if it doesn't already exist
            queue.CreateIfNotExists();

            // Create a message
            var message = new FormFields
            {
                FormId = formSubmitContext.FormId.ToString(),
                Fields = new List <FormFieldSmall>()
            };
            List <Guid> filesource = new List <Guid>();

            foreach (var viewModel in formSubmitContext.Fields)
            {
                AddFieldData(viewModel, message);
                filesource.AddRange((IEnumerable <Guid>)GetCommittedFileIds(viewModel));
            }

            if (filesource.Any <Guid>())
            {
                StoreFiles(storageAccount, formSubmitContext, (IEnumerable <Guid>)filesource);
            }
            // Create a queue message with JSON and add it to the queue.
            CloudQueueMessage queuemessage = new CloudQueueMessage(JsonConvert.SerializeObject(message));

            queue.AddMessage(queuemessage);
            return(true);
        }
Пример #23
0
        private static void Initialize(string[] args)
        {
            _semaphore = new SemaphoreSlim(1, 1);
            _config    = new Config(args);

            _gs         = $@"{ _config.Get("GS_BIN")}";
            _tempFolder = $@"{ _config.Get("TEMP_FOLDER")}";
            _resolution = (int.Parse(_config.Get("IMAGE_RESOLUTION")) / 10).ToString();

            if (!Directory.Exists(_tempFolder))
            {
                Directory.CreateDirectory(_tempFolder);
            }

            var connectionString = _config.Get("STORAGE_ACCOUNT");

            _queueName = _config.Get("QUEUE_NAME");

            _imageStorageAccount       = _config.Get("IMAGE_STORAGE_ACCOUNT");
            _imageStorageBlobContainer = _config.Get("IMAGE_CONTAINER_NAME");

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException("connectionString is empty");
            }

            try
            {
                _storageAccount = CloudStorageAccount.Parse(connectionString);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error parsing the storage connection string {connectionString}: {ex.Message}");
            }

            _queueClient = _storageAccount.CreateCloudQueueClient();
            _queue       = GetQueueAsync(_queueName).GetAwaiter().GetResult();
        }
Пример #24
0
        public static void Run([QueueTrigger("changeshappened", Connection = "AzureWebJobsStorage")] string myQueueItem, TraceWriter log)
        {
            log.Info($"C# Queue trigger function processed: {myQueueItem}");


            var changeInfo = JsonConvert.DeserializeObject <Common.Models.ChangeInfo>(myQueueItem);


            ClientContext ctx = Common.Helpers.ContextHelper.GetSPContext("https://folkuniversitetetsp2016.sharepoint.com" + changeInfo.SiteUrl).Result;

            // changeInfo.ListId is  list id
            List     list        = ctx.Web.Lists.GetById(new Guid(changeInfo.ListId));
            ListItem changedItem = list.GetItemById(changeInfo.ItemId);

            ctx.Load(changedItem, item => item["Title"], item => item["SiteUrl"], item => item["Owner"]);
            ctx.ExecuteQuery();

            string title = changedItem["Title"].ToString();
            string owner = changedItem["Owner"].ToString();

            GroupHelper.CreateUnifedGroup(title, "groupsite1", "groupsite1", owner);

            //create queue if not exists
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureWebJobsStorage"]);
            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       = queueClient.GetQueueReference("provisionqueue");

            queue.CreateIfNotExists();

            GroupSiteUrl siteUrl = new GroupSiteUrl()
            {
                url = changeInfo.SiteUrl
            };

            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(siteUrl)));
            log.Info("Item was updated id = " + changeInfo.SiteUrl);
        }
Пример #25
0
        /// <summary>
        /// Push the List of to Azure storage Queue
        /// </summary>
        /// <param name="mailList">List<string></param>
        public async Task PushMailInQueue(List <MessageText> mailList)
        {
            ResponseModel response = new ResponseModel();

            if (mailList != null)
            {
                // Retrieve storage account from connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    System.Configuration.ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString);

                foreach (var email in mailList)
                {
                    // Create the queue client.
                    CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

                    if (queueClient != null)
                    {
                        CloudQueue queue = queueClient.GetQueueReference("gmailqueue");
                        //CloudQueue queue = queueClient.GetQueueReference("testqueue");

                        // Create the queue if it doesn't already exist.
                        queue.CreateIfNotExists();

                        // Create a message and add it to the queue.
                        CloudQueueMessage msg = new CloudQueueMessage(email.msgtxt);
                        queue.AddMessage(msg);
                    }
                }


                response.Message = "Following mail will be processing on the Queue";
            }
            else
            {
                response.Message = "No emails found to process";
            }
            //return response;
        }
Пример #26
0
        public FractalForm()
        {
            InitializeComponent();

            ResetColors();

            CloudStorageAccount account      = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccount"]);
            CloudQueueClient    queueStorage = account.CreateCloudQueueClient();

            this.queue = queueStorage.GetQueueReference("fractaltoprocess");
            this.queue.CreateIfNotExist();
            this.inqueue = queueStorage.GetQueueReference("fractalsectors");
            this.inqueue.CreateIfNotExist();
            CloudBlobClient blobClient = account.CreateCloudBlobClient();

            this.blobContainer = blobClient.GetContainerReference("fractalsectors");
            this.blobContainer.CreateIfNotExist();

            Thread thread = new Thread(new ThreadStart(this.ProcessQueue));

            thread.IsBackground = true;
            thread.Start();
        }
Пример #27
0
        public AzureQueue(string connectionString, string queueName)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException("connectionString is empty");
            }
            if (string.IsNullOrWhiteSpace(queueName))
            {
                throw new ArgumentException("queueName is empty");
            }

            try
            {
                _storageAccount = CloudStorageAccount.Parse(connectionString);
            }
            catch (Exception ex)
            {
                throw new Exception($"Error parsing the storage connection string {connectionString}: {ex.Message}");
            }

            _queueClient = _storageAccount.CreateCloudQueueClient();
            _queue       = CreateQueueAsync(queueName).GetAwaiter().GetResult();
        }
        private void InitEnvironment()
        {
            storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));
            queueClient = storageAccount.CreateCloudQueueClient();
            queue       = queueClient.GetQueueReference(CloudConfigurationManager.GetSetting("PhotoQueueName"));
            queue.CreateIfNotExists();

            blobClient = storageAccount.CreateCloudBlobClient();
            container  = blobClient.GetContainerReference(CloudConfigurationManager.GetSetting("TempBlobContainerNamePhoto"));

            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root = HttpContext.Current.Server.MapPath("~/App_Data");

            provider = new MultipartFormDataStreamProvider(root);

            blobPrefixString = CloudConfigurationManager.GetSetting("TempBlobRelativeLocationPhoto");
        }
Пример #29
0
        /// <summary>
        /// Queueへの参照
        /// </summary>
        /// <param name="storageAccount"></param>
        /// <param name="queueName"></param>
        /// <returns></returns>
        private static CloudQueue GetQueueReference(CloudStorageAccount storageAccount, string queueName)
        {
            // queue client を作成
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            // 再試行ポリシーの構成
            QueueRequestOptions interactiveRequestOption = new QueueRequestOptions()
            {
                RetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 5),
                //geo 冗長ストレージ(GRS)の場合、PrimaryThenSecondaryを設定する
                //それ以外は、PrimaryOnlyを設定する
                LocationMode         = LocationMode.PrimaryOnly,
                MaximumExecutionTime = TimeSpan.FromSeconds(10)
            };

            queueClient.DefaultRequestOptions = interactiveRequestOption;

            // queue名に大文字は使えないので小文字に変換する
            queueName = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToLower(queueName);

            // queueへの参照を取得する
            return(queueClient.GetQueueReference(queueName));
        }
        public void AddConfigRequestToQueue(
            string account, string siteUrl, string storageConnectionString)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(storageConnectionString);

            // Get queue... create if does not exist.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CloudQueue       queue       =
                queueClient.GetQueueReference(SiteModificationManager.StorageQueueName);

            queue.CreateIfNotExists();

            // Pass in data for modification
            var newSiteConfigRequest = new SiteModificationData()
            {
                AccountId = account,
                SiteUrl   = siteUrl
            };

            // Add entry to queue
            queue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(newSiteConfigRequest)));
        }
        public void CloudQueueOldSASVersion()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());

            try
            {
                queue.Create();
                string messageContent = Guid.NewGuid().ToString();
                CloudQueueMessage message = new CloudQueueMessage(messageContent);
                queue.AddMessage(message);

                // Prepare SAS authentication with full permissions
                string id = Guid.NewGuid().ToString();
                DateTime start = DateTime.UtcNow;
                DateTime expiry = start.AddMinutes(30);
                QueuePermissions permissions = new QueuePermissions();
                SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
                permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
                {
                    SharedAccessStartTime = start,
                    SharedAccessExpiryTime = expiry,
                    Permissions = queuePerm
                });

                queue.SetPermissions(permissions);
                Thread.Sleep(30 * 1000);

                string sasTokenFromId = queue.GetSharedAccessSignature(null, id, Constants.VersionConstants.February2012);
                StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);

                CloudStorageAccount sasAcc = new CloudStorageAccount(sasCredsFromId, new Uri(TestBase.TargetTenantConfig.BlobServiceEndpoint), new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), new Uri(TestBase.TargetTenantConfig.TableServiceEndpoint));
                CloudQueueClient sasClient = sasAcc.CreateCloudQueueClient();

                CloudQueue sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
                CloudQueueMessage receivedMessage = sasQueueFromSasUri.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage.AsString);

                CloudQueue sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
                CloudQueueMessage receivedMessage1 = sasQueueFromSasUri1.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage1.AsString);

                CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
                CloudQueueMessage receivedMessage2 = sasQueueFromId.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage2.AsString);

                string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
                StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
                CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
                CloudQueueMessage receivedMessage3 = sasQueueFromPolicy.PeekMessage();
                Assert.AreEqual(messageContent, receivedMessage3.AsString);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
Пример #32
0
        public void CloudStorageAccountWithStorageUri()
        {
            StorageUri blobEndpoint = new StorageUri(
                new Uri("http://" + AccountName + BlobService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix));

            StorageUri queueEndpoint = new StorageUri(
                new Uri("http://" + AccountName + QueueService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + QueueService + EndpointSuffix));

            StorageUri tableEndpoint = new StorageUri(
                new Uri("http://" + AccountName + TableService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + TableService + EndpointSuffix));

            StorageUri fileEndpoint = new StorageUri(
                new Uri("http://" + AccountName + FileService + EndpointSuffix),
                new Uri("http://" + AccountName + SecondarySuffix + FileService + EndpointSuffix));

#if WINDOWS_RT || ASPNET_K
            CloudStorageAccount account = CloudStorageAccount.Create(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#else
            CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials(), blobEndpoint, queueEndpoint, tableEndpoint, fileEndpoint);
#endif
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = new CloudStorageAccount(new StorageCredentials(AccountName, TestBase.StorageCredentials.ExportBase64EncodedKey()), false);
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            account = CloudStorageAccount.Parse(string.Format("DefaultEndpointsProtocol=http;AccountName={0};AccountKey=", AccountName));
            Assert.IsTrue(blobEndpoint.Equals(account.BlobStorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.QueueStorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.TableStorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.FileStorageUri));

            Assert.IsTrue(blobEndpoint.Equals(account.CreateCloudBlobClient().StorageUri));
            Assert.IsTrue(queueEndpoint.Equals(account.CreateCloudQueueClient().StorageUri));
            Assert.IsTrue(tableEndpoint.Equals(account.CreateCloudTableClient().StorageUri));
            Assert.IsTrue(fileEndpoint.Equals(account.CreateCloudFileClient().StorageUri));

            Assert.IsTrue(blobEndpoint.PrimaryUri.Equals(account.BlobEndpoint));
            Assert.IsTrue(queueEndpoint.PrimaryUri.Equals(account.QueueEndpoint));
            Assert.IsTrue(tableEndpoint.PrimaryUri.Equals(account.TableEndpoint));
            Assert.IsTrue(fileEndpoint.PrimaryUri.Equals(account.FileEndpoint));
        }
Пример #33
0
        public async Task QueueSASTestAsync()
        {
            CloudQueueClient client = GenerateCloudQueueClient();
            CloudQueue queue = client.GetQueueReference(GenerateNewQueueName());
            await queue.CreateAsync();
            string messageContent = Guid.NewGuid().ToString();
            CloudQueueMessage message = new CloudQueueMessage(messageContent);
            await queue.AddMessageAsync(message);

            // Prepare SAS authentication with full permissions
            string id = Guid.NewGuid().ToString();
            DateTime start = DateTime.UtcNow;
            DateTime expiry = start.AddMinutes(30);
            QueuePermissions permissions = new QueuePermissions();
            SharedAccessQueuePermissions queuePerm = SharedAccessQueuePermissions.Add | SharedAccessQueuePermissions.ProcessMessages | SharedAccessQueuePermissions.Read | SharedAccessQueuePermissions.Update;
            permissions.SharedAccessPolicies.Add(id, new SharedAccessQueuePolicy()
            {
                SharedAccessStartTime = start,
                SharedAccessExpiryTime = expiry,
                Permissions = queuePerm
            });

            await queue.SetPermissionsAsync(permissions);
            await Task.Delay(30 * 1000);

            string sasTokenFromId = queue.GetSharedAccessSignature(null, id);
            StorageCredentials sasCredsFromId = new StorageCredentials(sasTokenFromId);

            CloudStorageAccount sasAcc = new CloudStorageAccount(sasCredsFromId, null /* blobEndpoint */, new Uri(TestBase.TargetTenantConfig.QueueServiceEndpoint), null /* tableEndpoint */, null /* fileEndpoint */);
            CloudQueueClient sasClient = sasAcc.CreateCloudQueueClient();

            CloudQueue sasQueueFromSasUri = new CloudQueue(sasClient.Credentials.TransformUri(queue.Uri));
            CloudQueueMessage receivedMessage = await sasQueueFromSasUri.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage.AsString);

            CloudQueue sasQueueFromSasUri1 = new CloudQueue(new Uri(queue.Uri.ToString() + sasTokenFromId));
            CloudQueueMessage receivedMessage1 = await sasQueueFromSasUri1.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage1.AsString);

            CloudQueue sasQueueFromId = new CloudQueue(queue.Uri, sasCredsFromId);
            CloudQueueMessage receivedMessage2 = await sasQueueFromId.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage2.AsString);

            string sasTokenFromPolicy = queue.GetSharedAccessSignature(permissions.SharedAccessPolicies[id], null);
            StorageCredentials sasCredsFromPolicy = new StorageCredentials(sasTokenFromPolicy);
            CloudQueue sasQueueFromPolicy = new CloudQueue(queue.Uri, sasCredsFromPolicy);
            CloudQueueMessage receivedMessage3 = await sasQueueFromPolicy.PeekMessageAsync();
            Assert.AreEqual(messageContent, receivedMessage3.AsString);
            await queue.DeleteAsync();
        }
        public void CloudStorageAccountClientUriVerify()
        {
            StorageCredentials cred = new StorageCredentials(TestBase.TargetTenantConfig.AccountName, TestBase.TargetTenantConfig.AccountKey);
            CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true);

            CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("container1");
            Assert.AreEqual(cloudStorageAccount.BlobEndpoint.ToString() + "container1", container.Uri.ToString());

            CloudQueueClient queueClient = cloudStorageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueClient.GetQueueReference("queue1");
            Assert.AreEqual(cloudStorageAccount.QueueEndpoint.ToString() + "queue1", queue.Uri.ToString());

            CloudTableClient tableClient = cloudStorageAccount.CreateCloudTableClient();
            CloudTable table = tableClient.GetTableReference("table1");
            Assert.AreEqual(cloudStorageAccount.TableEndpoint.ToString() + "table1", table.Uri.ToString());
        }
        public void CloudStorageAccountClientMethods()
        {
            CloudStorageAccount account = new CloudStorageAccount(TestBase.StorageCredentials, false);
            CloudBlobClient blob = account.CreateCloudBlobClient();
            CloudQueueClient queue = account.CreateCloudQueueClient();
            CloudTableClient table = account.CreateCloudTableClient();

            // check endpoints
            Assert.AreEqual(account.BlobEndpoint, blob.BaseUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueEndpoint, queue.BaseUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableEndpoint, table.BaseUri, "Table endpoint doesn't match account");

            // check storage uris
            Assert.AreEqual(account.BlobStorageUri, blob.StorageUri, "Blob endpoint doesn't match account");
            Assert.AreEqual(account.QueueStorageUri, queue.StorageUri, "Queue endpoint doesn't match account");
            Assert.AreEqual(account.TableStorageUri, table.StorageUri, "Table endpoint doesn't match account");

            // check creds
            Assert.AreEqual(account.Credentials, blob.Credentials, "Blob creds don't match account");
            Assert.AreEqual(account.Credentials, queue.Credentials, "Queue creds don't match account");
            Assert.AreEqual(account.Credentials, table.Credentials, "Table creds don't match account");
        }