public static Image DownloadFileFromBlob(string projectName, string fileName, string blobPath = "source/images")
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }

            projectName = projectName.ToUpper();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/" + blobPath);

            System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + projectName + Path.DirectorySeparatorChar + "downloadsource");

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + projectName + Path.DirectorySeparatorChar + "downloadsource" + Path.DirectorySeparatorChar + fileName))
            {
                cloudBlobDirectory.GetBlockBlobReference(fileName).DownloadToFileAsync(AppDomain.CurrentDomain.BaseDirectory + projectName + Path.DirectorySeparatorChar + "downloadsource" + Path.DirectorySeparatorChar + fileName, System.IO.FileMode.Create).GetAwaiter().GetResult();
            }
            var res = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + projectName + Path.DirectorySeparatorChar + "downloadsource" + Path.DirectorySeparatorChar + fileName);

            return(res);
        }
        public static void GetUriAndPermission(string fileName, out string fileUri, out string signUriPara, out DateTime expireDateTime, int keepSeconds, string projectName, string blobPath = "source/images")
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/" + blobPath);

            projectName = projectName.ToUpper();
            var res = CloudBlobContainer.GetPermissionsAsync().Result;

            if (keepSeconds > 0)
            {
                expireDateTime = DateTime.UtcNow.AddSeconds(keepSeconds);
                var sharedPolicy = new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy()
                {
                    SharedAccessExpiryTime = expireDateTime,
                    Permissions            = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Read,
                };

                signUriPara = CloudBlobContainer.GetSharedAccessSignature(sharedPolicy, null);
            }
            else
            {
                expireDateTime = DateTime.UtcNow.Date.AddDays(1).AddSeconds(-1);
                var sharedPolicy = new Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPolicy()
                {
                    SharedAccessExpiryTime = expireDateTime,
                    Permissions            = Microsoft.WindowsAzure.Storage.Blob.SharedAccessBlobPermissions.Read,
                };
                signUriPara = CloudBlobContainer.GetSharedAccessSignature(sharedPolicy, null);
            }

            fileUri = cloudBlobDirectory.GetBlockBlobReference(fileName).Uri.ToString();
        }
Exemple #3
0
        public static bool IsFileExisted(string fileName, string blobPath = "source/images")
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(blobPath);

            return(cloudBlobDirectory.GetBlockBlobReference(fileName).ExistsAsync().Result);
        }
        public static void UpoloadImageSource(string filePath, string projectName, string id)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            projectName = projectName.ToUpper();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/" + "source/images/");



            var bFileInfo = cloudBlobDirectory.GetBlockBlobReference(id + ".gif");

            bFileInfo.Properties.ContentType = "image/gif";

            bFileInfo.UploadFromFileAsync(filePath).GetAwaiter().GetResult();
        }
        public static async Task TriggeredSequenceTask1(
            [BlobTrigger("tasks/step/{iteration}/{instanceId}")] Stream inputStream,
            [Blob("tasks/step")] Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory directory,
            [DurableClient] IDurableClient client,
            string instanceId,
            ILogger logger)
        {
            Input input;

            using (var streamReader = new StreamReader(inputStream))
                input = JsonConvert.DeserializeObject <Input>(await streamReader.ReadToEndAsync());

            input = RunTask(input, logger, instanceId);

            if (input.Position < input.Length)
            {
                // write the blob to trigger the next task
                string content = JsonConvert.SerializeObject(input);
                var    blob    = directory.GetBlockBlobReference($"{input.Position}/{instanceId}");
                await blob.UploadTextAsync(content);
            }
            else
            {
                // notify the waiting orchestrator
                await client.RaiseEventAsync(instanceId, "completed", input);
            }
        }
Exemple #6
0
        public static Models.ImageInfo ReadInfoFromBlob(string id)
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference("source/info");

            var result = cloudBlobDirectory.GetBlockBlobReference(id + ".json").DownloadTextAsync().Result;

            return(JsonConvert.DeserializeObject <Models.ImageInfo>(result));
        }
Exemple #7
0
        public static void UpoloadImageInfoSource(string filePath, string id)
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference("source/info/");

            var bFileInfo = cloudBlobDirectory.GetBlockBlobReference(id + ".json");

            bFileInfo.Properties.ContentType = "application/json; charset=utf-8";
            bFileInfo.UploadTextAsync(System.IO.File.ReadAllText(filePath)).GetAwaiter().GetResult();
        }
Exemple #8
0
        public static void UpoloadImageSource(string filePath, string id)
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference("source/images/");

            var bFileInfo = cloudBlobDirectory.GetBlockBlobReference(id + ".gif");

            bFileInfo.Properties.ContentType = "image/gif";

            bFileInfo.UploadFromFileAsync(filePath).GetAwaiter().GetResult();
        }
        public static async Task SequenceTaskStart(
            [ActivityTrigger] IDurableActivityContext context,
            [Blob("tasks/step/0")] Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory directory,
            ILogger logger)
        {
            Input  input   = context.GetInput <Input>();
            var    blob    = directory.GetBlockBlobReference(context.InstanceId);
            string content = JsonConvert.SerializeObject(input);
            await blob.Container.CreateIfNotExistsAsync();

            await blob.UploadTextAsync(content);
        }
Exemple #10
0
        public static Image DownloadFileFromBlob(string fileName, string blobPath = "source/images")
        {
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(blobPath);

            System.IO.Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "downloadsource");

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "downloadsource" + Path.DirectorySeparatorChar + fileName))
            {
                cloudBlobDirectory.GetBlockBlobReference(fileName).DownloadToFileAsync(AppDomain.CurrentDomain.BaseDirectory + "downloadsource" + Path.DirectorySeparatorChar + fileName, System.IO.FileMode.Create).GetAwaiter().GetResult();
            }
            var res = Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "downloadsource" + Path.DirectorySeparatorChar + fileName);

            return(res);
        }
        public static bool IsFileExisted(string fileName, string projectName, string blobPath = "source/images")
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }

            projectName = projectName.ToUpper();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/" + blobPath);

            return(cloudBlobDirectory.GetBlockBlobReference(fileName).ExistsAsync().Result);
        }
        public static Models.ImageInfo ReadInfoFromBlob(string projectName, string id)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            projectName = projectName.ToUpper();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/source/info");

            var result = cloudBlobDirectory.GetBlockBlobReference(id + ".json").DownloadTextAsync().Result;

            return(JsonConvert.DeserializeObject <Models.ImageInfo>(result));
        }
        public static void UpoloadImageInfoSource(string filePath, string projectName, string id)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                throw new ArgumentNullException("projectName");
            }
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }

            projectName = projectName.ToUpper();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobDirectory cloudBlobDirectory =
                CloudBlobContainer.GetDirectoryReference(projectName + "/" + "source/info/");

            var bFileInfo = cloudBlobDirectory.GetBlockBlobReference(id + ".json");

            bFileInfo.Properties.ContentType = "application/json; charset=utf-8";
            bFileInfo.UploadTextAsync(System.IO.File.ReadAllText(filePath)).GetAwaiter().GetResult();
        }