Example #1
0
        private async static Task SendQueueMessagesAsync(CancellationToken ct)
        {
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    object msgInfo = msgSendQueue.Take();

                    var commandMessage = new BrokeredMessage(MessageHelper.ToString(msgInfo));

                    Task.Run(async() =>
                    {
                        await _client.SendAsync(commandMessage);
                    });
                }
                catch (Exception ex)
                {
                    if (_feedback != null)
                    {
                        _feedback.OnException(_client, ex);
                    }
                }
            }
        }
Example #2
0
        private async Task ReceiveQueueMessagesAsync(CancellationToken ct)
        {
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    break;
                }

                try
                {
                    object msgInfo = msgReceiveQueue.Take();
                    if (_receiver != null)
                    {
                        _receiver.OnMessage(_client, new ReceivedMessageEventArgs(msgInfo));
                    }
                }
                catch (Exception ex)
                {
                    if (_feedback != null)
                    {
                        _feedback.OnException(_client, ex);
                    }
                }
            }
        }
Example #3
0
        public static bool Initialize(string connectionString, IEventFeedback feedback)
        {
            _connectionString = connectionString;
            _feedback         = feedback;

            try
            {
                storageAccount = CloudStorageAccount.Parse(_connectionString);
                blobClient     = storageAccount.CreateCloudBlobClient();
            }
            catch (Exception ex)
            {
                if (feedback != null)
                {
                    feedback.OnException(null, ex);
                }

                return(false);
            }

            return(true);
        }
Example #4
0
        public static bool Initialize(string shareName, string connectionString, IEventFeedback feedback)
        {
            _connectionString = connectionString;
            _shareName        = shareName;
            _feedback         = feedback;

            try
            {
                storageAccount = CloudStorageAccount.Parse(_connectionString);
                fileClient     = storageAccount.CreateCloudFileClient();
                fileShare      = GetFileShare();
            }
            catch (Exception ex)
            {
                if (_feedback != null)
                {
                    _feedback.OnException(fileClient, ex);
                }

                return(false);
            }

            return(true);
        }
Example #5
0
        private static bool CreateContainer(string name)
        {
            try
            {
                CloudBlobContainer container = blobClient.GetContainerReference(name);

                container.CreateIfNotExists();

                BlobContainerPermissions permissions = new BlobContainerPermissions();
                permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                container.SetPermissions(permissions);
            }
            catch (Exception ex)
            {
                if (_feedback != null)
                {
                    _feedback.OnException(blobClient, ex);
                }

                return(false);
            }

            return(true);
        }
Example #6
0
        public bool Create(string groupName, string region, IDictionary <string, string> tags = null)
        {
            try
            {
                Region regionType = Region.Create(region);
                if (regionType == null)
                {
                    regionType = Region.USCentral;
                }

                bool bExists = false;
                Task.Run(async() =>
                {
                    bExists = await azure.ResourceGroups.CheckExistenceAsync(groupName);
                }).Wait();

                if (bExists)
                {
                    return(true);
                }

                Task.Run(async() =>
                {
                    await azure.ResourceGroups
                    .Define(groupName)
                    .WithRegion(regionType)
                    .CreateAsync();
                }).Wait();
            }
            catch (Exception ex)
            {
                if (feedback != null)
                {
                    feedback.OnException(this, ex);
                }

                return(false);
            }

            return(true);
        }
Example #7
0
        private static bool CreateFileShare()
        {
            try
            {
                CloudFileShare fileShare = fileClient.GetShareReference(_shareName);

                fileShare.CreateIfNotExists();
            }
            catch (Exception ex)
            {
                if (_feedback != null)
                {
                    _feedback.OnException(fileClient, ex);
                }

                return(false);
            }

            return(true);
        }