public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> > UploadAsync(System.String ContainerName, System.String StorageFileName, System.IO.Stream FileContents)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            if (SoftmakeAll.SDK.Helpers.String.Extensions.StringExtensions.IsNullOrWhiteSpace(ContainerName, StorageFileName))
            {
                OperationResult.Message = "The ContainerName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Blobs.BlobContainerClient BlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ContainerName);
                await BlobContainerClient.CreateIfNotExistsAsync();

                global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileName);
                await BlobClient.UploadAsync(FileContents, true);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
        /// <summary>
        /// Creates a OperationResult object based on HTTP Request.
        /// </summary>
        /// <param name="REST">REST object that contains the HTTP Request information.</param>
        /// <param name="RESTResult">The output of Send method.</param>
        /// <returns>A OperationResult with JSON property Data.</returns>
        private static SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> ProcessRESTRequestResult(SoftmakeAll.SDK.Communication.REST REST, System.Text.Json.JsonElement RESTResult)
        {
            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> Result = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();
            if (REST.HasRequestErrors)
            {
                Result.ExitCode = (int)REST.StatusCode;
            }
            else
            {
                Result.ExitCode = RESTResult.GetInt32("ExitCode");
            }

            if (RESTResult.IsValid())
            {
                Result.Message = RESTResult.GetString("Message");
                Result.ID      = RESTResult.GetString("ID");
                Result.Count   = RESTResult.GetInt32("Count");
                Result.Data    = RESTResult.GetJsonElement("Data").ToObject <System.Text.Json.JsonElement>();
            }

            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ExitCode = Result.ExitCode;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Message  = Result.Message;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.Count    = Result.Count;
            SoftmakeAll.SDK.Fluent.SDKContext.LastOperationResult.ID       = Result.ID;

            return(Result);
        }
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> > UploadAsync(System.String ShareName, System.String StorageFileName, System.IO.Stream FileContents)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            if (SoftmakeAll.SDK.Helpers.String.Extensions.StringExtensions.IsNullOrWhiteSpace(ShareName, StorageFileName))
            {
                OperationResult.Message = "The ShareName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Files.Shares.ShareClient          ShareClient          = new global::Azure.Storage.Files.Shares.ShareClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ShareName);
                global::Azure.Storage.Files.Shares.ShareDirectoryClient ShareDirectoryClient = ShareClient.GetRootDirectoryClient();
                global::Azure.Storage.Files.Shares.ShareFileClient      ShareFileClient      = ShareDirectoryClient.GetFileClient(StorageFileName);
                await ShareFileClient.CreateAsync(FileContents.Length);

                await ShareFileClient.UploadAsync(FileContents);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #4
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> > UploadAsync(System.String BucketName, System.String StorageFileName, System.IO.Stream FileContents)
        {
            SoftmakeAll.SDK.CloudStorage.AWS.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            if (SoftmakeAll.SDK.Helpers.String.Extensions.StringExtensions.IsNullOrWhiteSpace(BucketName, StorageFileName))
            {
                OperationResult.Message = "The BucketName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                using (Amazon.S3.Transfer.TransferUtility TransferUtility = new Amazon.S3.Transfer.TransferUtility(SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client))
                    await TransferUtility.UploadAsync(FileContents, BucketName, StorageFileName);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #5
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult> CopyAsync(System.String SourceBucketName, System.String[] SourceStorageFileNames, System.String TargetBucketName, System.String[] TargetStorageFileNames, System.Boolean Overwrite)
        {
            SoftmakeAll.SDK.CloudStorage.AWS.Environment.Validate();

            SoftmakeAll.SDK.OperationResult OperationResult = new SoftmakeAll.SDK.OperationResult();

            if ((System.String.IsNullOrWhiteSpace(SourceBucketName)) || (SourceStorageFileNames == null) || (SourceStorageFileNames.Length == 0) || (System.String.IsNullOrWhiteSpace(TargetBucketName)) || (TargetStorageFileNames == null) || (TargetStorageFileNames.Length == 0))
            {
                OperationResult.Message = "The SourceBucketName, SourceStorageFileNames, TargetBucketName and TargetStorageFileNames cannot be null.";
                return(OperationResult);
            }

            if (SourceStorageFileNames.Length != TargetStorageFileNames.Length)
            {
                OperationResult.Message = "The SourceStorageFileNames and TargetStorageFileNames must be the same length.";
                return(OperationResult);
            }

            try
            {
                using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(SourceStorageFileNames.Length))
                {
                    System.Collections.Generic.List <System.Threading.Tasks.Task> CopyTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                    for (System.Int32 i = 0; i < SourceStorageFileNames.Length; i++)
                    {
                        await SemaphoreSlim.WaitAsync();

                        CopyTasks.Add(System.Threading.Tasks.Task.Run(async() =>
                        {
                            await SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client.CopyObjectAsync(new Amazon.S3.Model.CopyObjectRequest {
                                SourceBucket = SourceBucketName, SourceKey = SourceStorageFileNames[i], DestinationBucket = TargetBucketName, DestinationKey = TargetStorageFileNames[i]
                            });
                            SemaphoreSlim.Release();
                        }));
                    }

                    if (CopyTasks.Any())
                    {
                        await System.Threading.Tasks.Task.WhenAll(CopyTasks);
                    }
                }
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #6
0
        protected virtual async System.Threading.Tasks.Task WriteErrorFileAsync(SoftmakeAll.SDK.OperationResult OperationResult)
        {
            if (OperationResult == null)
            {
                return;
            }

            try
            {
                System.String FileContents = System.String.Format("{0:dd/MM/yyyy HH:mm:ss}: {1} -> {2}{3}", System.DateTimeOffset.Now, OperationResult.ExitCode, OperationResult.Message, System.Environment.NewLine);
                await System.IO.File.AppendAllTextAsync(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "SoftmakeAll_DataAccess.log"), FileContents);
            }
            catch { }
        }
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult> DeleteAsync(System.String ShareName, System.String[] StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult OperationResult = new SoftmakeAll.SDK.OperationResult();

            if ((System.String.IsNullOrWhiteSpace(ShareName)) || (StorageFileNames == null) || (StorageFileNames.Length == 0))
            {
                OperationResult.Message = "The ShareName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Files.Shares.ShareClient          ShareClient          = new global::Azure.Storage.Files.Shares.ShareClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ShareName);
                global::Azure.Storage.Files.Shares.ShareDirectoryClient ShareDirectoryClient = ShareClient.GetRootDirectoryClient();

                using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(StorageFileNames.Length))
                {
                    System.Collections.Generic.List <System.Threading.Tasks.Task> DeleteTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                    foreach (System.String StorageFileName in StorageFileNames)
                    {
                        global::Azure.Storage.Files.Shares.ShareFileClient ShareFileClient = ShareDirectoryClient.GetFileClient(StorageFileName);
                        if (!(await ShareFileClient.ExistsAsync()))
                        {
                            continue;
                        }

                        await SemaphoreSlim.WaitAsync();

                        DeleteTasks.Add(System.Threading.Tasks.Task.Run(async() => { await ShareFileClient.DeleteAsync(); SemaphoreSlim.Release(); }));
                    }

                    if (DeleteTasks.Any())
                    {
                        await System.Threading.Tasks.Task.WhenAll(DeleteTasks);
                    }
                }
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #8
0
        protected virtual SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> ExecuteCommandForJSON(System.String ProcedureNameOrCommandText, System.Collections.Generic.List <System.Data.Common.DbParameter> Parameters, System.Data.CommandType CommandType)
        {
            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> Result = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            SoftmakeAll.SDK.OperationResult <System.Data.DataSet> DatabaseOperationResult = this.ExecuteCommand(ProcedureNameOrCommandText, Parameters, CommandType);
            Result.Count    = DatabaseOperationResult.Count;
            Result.ID       = DatabaseOperationResult.ID;
            Result.Message  = DatabaseOperationResult.Message;
            Result.ExitCode = DatabaseOperationResult.ExitCode;
            if (DatabaseOperationResult.ExitCode != 0)
            {
                return(Result);
            }

            Result.Data = SoftmakeAll.SDK.DataAccess.DatabaseValues.DataSetToJSON(DatabaseOperationResult.Data);

            return(Result);
        }
Beispiel #9
0
        public SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> CompileTo(System.String DirectoryPath)
        {
            if (System.String.IsNullOrWhiteSpace(DirectoryPath))
            {
                throw new System.Exception(System.String.Format(SoftmakeAll.SDK.NetReflector.Compiler.NullOrEmptyMessage, "directory path"));
            }
            if (!(System.IO.Directory.Exists(DirectoryPath)))
            {
                throw new System.Exception("The directory path doesn't exists.");
            }

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> CompileResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();
            using (System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream())
            {
                CompileResult = this.CompileTo(MemoryStream);
                if (CompileResult.ExitCode == 0)
                {
                    System.IO.File.WriteAllBytes(System.IO.Path.Combine(DirectoryPath, this.OutputFileName), MemoryStream.ToArray());
                }
            }
            return(CompileResult);
        }
Beispiel #10
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult> DeleteAsync(System.String BucketName, System.String[] StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.AWS.Environment.Validate();

            SoftmakeAll.SDK.OperationResult OperationResult = new SoftmakeAll.SDK.OperationResult();

            if ((System.String.IsNullOrWhiteSpace(BucketName)) || (StorageFileNames == null) || (StorageFileNames.Length == 0))
            {
                OperationResult.Message = "The BucketName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            System.Collections.Generic.List <Amazon.S3.Model.KeyVersion> Objects = new System.Collections.Generic.List <Amazon.S3.Model.KeyVersion>();
            foreach (System.String StorageFileName in StorageFileNames)
            {
                Objects.Add(new Amazon.S3.Model.KeyVersion()
                {
                    Key = StorageFileName
                });
            }
            Amazon.S3.Model.DeleteObjectsRequest DeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest {
                BucketName = BucketName, Objects = Objects
            };

            try
            {
                await SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client.DeleteObjectsAsync(DeleteObjectsRequest);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #11
0
        public SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> CompileTo(System.IO.Stream Stream)
        {
            if (Stream == null)
            {
                throw new System.Exception(System.String.Format(SoftmakeAll.SDK.NetReflector.Compiler.NullOrEmptyMessage, "Stream"));
            }
            if (System.String.IsNullOrWhiteSpace(this.OutputFileName))
            {
                throw new System.Exception(System.String.Format(SoftmakeAll.SDK.NetReflector.Compiler.NullOrEmptyMessage, "OutputFileName"));
            }
            if ((this.CodeFiles == null) || (!(this.CodeFiles.Any())))
            {
                throw new System.Exception(System.String.Format(SoftmakeAll.SDK.NetReflector.Compiler.NullOrEmptyMessage, "Code"));
            }

            System.Collections.Generic.List <Microsoft.CodeAnalysis.SyntaxTree> SyntaxTrees = new System.Collections.Generic.List <Microsoft.CodeAnalysis.SyntaxTree>();
            foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> CodeFile in this.CodeFiles.Where(c => (!(System.String.IsNullOrWhiteSpace(c.Value)))))
            {
                SyntaxTrees.Add(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.ParseText(CodeFile.Value.Trim()).GetRoot().NormalizeWhitespace(new System.String(' ', this.IndentSize), System.Environment.NewLine, false).ToFullString(), null, CodeFile.Key));
            }
            if (!(SyntaxTrees.Any()))
            {
                throw new System.Exception(System.String.Format(SoftmakeAll.SDK.NetReflector.Compiler.NullOrEmptyMessage, "Code"));
            }

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> CompileResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            System.Collections.Generic.List <Microsoft.CodeAnalysis.MetadataReference> CurrentReferences = new System.Collections.Generic.List <Microsoft.CodeAnalysis.MetadataReference>();
            if (!(System.String.IsNullOrWhiteSpace(this.DefaultReferencesDirectoryPath)))
            {
                if (!(System.IO.Directory.Exists(this.DefaultReferencesDirectoryPath)))
                {
                    throw new System.IO.DirectoryNotFoundException();
                }
                else
                {
                    foreach (System.String ReferencedFile in System.IO.Directory.GetFiles(this.DefaultReferencesDirectoryPath, "*.*", System.IO.SearchOption.AllDirectories))
                    {
                        CurrentReferences.Add(Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(ReferencedFile));
                    }
                }
            }

            if ((this.AdditionalReferences != null) && (this.AdditionalReferences.Any()))
            {
                foreach (System.String ReferencedFile in this.AdditionalReferences)
                {
                    CurrentReferences.Add(Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(ReferencedFile));
                }
            }


            Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions CSharpCompilationOptions = new Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions
                                                                                              (
                optimizationLevel: Microsoft.CodeAnalysis.OptimizationLevel.Release,
                outputKind: (Microsoft.CodeAnalysis.OutputKind) this.OutputKind,
                platform: (Microsoft.CodeAnalysis.Platform) this.Platform
                                                                                              );

            System.IO.FileInfo OutputFileNameInfo = new System.IO.FileInfo(this.OutputFileName);
            System.String      AssemblyName       = OutputFileNameInfo.Name.Substring(0, OutputFileNameInfo.Name.Length - OutputFileNameInfo.Extension.Length);
            Microsoft.CodeAnalysis.CSharp.CSharpCompilation CSharpCompilation = Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(AssemblyName, SyntaxTrees, CurrentReferences, CSharpCompilationOptions);


            Microsoft.CodeAnalysis.Emit.EmitResult EmitResult = CSharpCompilation.Emit(Stream);
            if (EmitResult.Diagnostics.Length > 0)
            {
                System.Collections.Generic.List <System.Text.Json.JsonElement> Diagnostics = new System.Collections.Generic.List <System.Text.Json.JsonElement>();
                foreach (Microsoft.CodeAnalysis.Diagnostic Diagnostic in EmitResult.Diagnostics)
                {
                    if ((this.OmitCompilationHiddenSeverity) && (Diagnostic.Descriptor.DefaultSeverity == Microsoft.CodeAnalysis.DiagnosticSeverity.Hidden))
                    {
                        continue;
                    }
                    if ((this.OmitCompilationInfoSeverity) && (Diagnostic.Descriptor.DefaultSeverity == Microsoft.CodeAnalysis.DiagnosticSeverity.Info))
                    {
                        continue;
                    }
                    if ((this.OmitCompilationWarningSeverity) && (Diagnostic.Descriptor.DefaultSeverity == Microsoft.CodeAnalysis.DiagnosticSeverity.Warning))
                    {
                        continue;
                    }

                    System.String ID = Diagnostic.Descriptor.Id;
                    if (ID == "CS8019") // CS8019 = using directives
                    {
                        continue;
                    }

                    System.String Severity = Diagnostic.Descriptor.DefaultSeverity.ToString();
                    System.String Category = Diagnostic.Descriptor.Category;
                    System.String Message  = Diagnostic.GetMessage();
                    System.Text.Json.JsonElement Location = new System.Text.Json.JsonElement();
                    if ((Diagnostic.Location != null) && (Diagnostic.Location.SourceSpan != null) && (!(Diagnostic.Location.SourceSpan.IsEmpty)))
                    {
                        Microsoft.CodeAnalysis.FileLinePositionSpan FileLinePositionSpan = Diagnostic.Location.GetMappedLineSpan();
                        System.Nullable <System.Int32> Line      = null;
                        System.Nullable <System.Int32> Character = null;
                        if (FileLinePositionSpan.IsValid)
                        {
                            Line      = FileLinePositionSpan.StartLinePosition.Line;
                            Character = FileLinePositionSpan.StartLinePosition.Character;
                        }
                        Location = new { Diagnostic.Location.SourceTree.FilePath, Line, Character, Code = Diagnostic.Location.SourceTree.ToString().Substring(Diagnostic.Location.SourceSpan.Start, Diagnostic.Location.SourceSpan.End - Diagnostic.Location.SourceSpan.Start) }.ToJsonElement();
                    }
                    Diagnostics.Add(new { Severity, Category, ID, Message, Location }.ToJsonElement());
                }
                CompileResult.Data = Diagnostics.ToJsonElement();
            }

            CompileResult.ExitCode = System.Convert.ToInt16((!(EmitResult.Success)) ? -1 : CompileResult.Data.IsValid() ? 1 : 0);

            return(CompileResult);
        }
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Byte[]> > DownloadAsync(System.String ContainerName, System.Collections.Generic.Dictionary <System.String, System.String> StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Byte[]> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Byte[]>();

            if ((System.String.IsNullOrWhiteSpace(ContainerName)) || (StorageFileNames == null) || (StorageFileNames.Count == 0))
            {
                OperationResult.Message = "The ContainerName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Blobs.BlobContainerClient BlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ContainerName);
                if (StorageFileNames.Count == 1)
                {
                    global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileNames.First().Key);
                    if (!(await BlobClient.ExistsAsync()))
                    {
                        OperationResult.Message = "The file could not be found.";
                        return(OperationResult);
                    }

                    using (System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream())
                    {
                        await BlobClient.DownloadToAsync(MemoryStream);

                        OperationResult.Data = MemoryStream.ToArray();
                    }
                }
                else
                {
                    using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(StorageFileNames.Count))
                    {
                        System.Collections.Generic.List <System.Threading.Tasks.Task> DownloadTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                        foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                        {
                            global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileName.Key);
                            if (!(await BlobClient.ExistsAsync()))
                            {
                                continue;
                            }

                            await SemaphoreSlim.WaitAsync();

                            DownloadTasks.Add(System.Threading.Tasks.Task.Run(async() => { await BlobClient.DownloadToAsync(StorageFileName.Key); SemaphoreSlim.Release(); }));
                        }

                        if (DownloadTasks.Any())
                        {
                            await System.Threading.Tasks.Task.WhenAll(DownloadTasks);
                        }
                    }

                    OperationResult.Data = SoftmakeAll.SDK.Files.Compression.CreateZipArchive(StorageFileNames);

                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (StorageFileNames.Count > 0)
                {
                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }

                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult> CopyAsync(System.String SourceContainerName, System.String[] SourceStorageFileNames, System.String TargetContainerName, System.String[] TargetStorageFileNames, System.Boolean Overwrite)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult OperationResult = new SoftmakeAll.SDK.OperationResult();

            if ((System.String.IsNullOrWhiteSpace(SourceContainerName)) || (SourceStorageFileNames == null) || (SourceStorageFileNames.Length == 0) || (System.String.IsNullOrWhiteSpace(TargetContainerName)) || (TargetStorageFileNames == null) || (TargetStorageFileNames.Length == 0))
            {
                OperationResult.Message = "The SourceContainerName, SourceStorageFileNames, TargetContainerName and TargetStorageFileNames cannot be null.";
                return(OperationResult);
            }

            if (SourceStorageFileNames.Length != TargetStorageFileNames.Length)
            {
                OperationResult.Message = "The SourceStorageFileNames and TargetStorageFileNames must be the same length.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Blobs.BlobContainerClient SourceBlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, SourceContainerName);
                global::Azure.Storage.Blobs.BlobContainerClient TargetBlobContainerClient;
                if (SourceContainerName != TargetContainerName)
                {
                    TargetBlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, TargetContainerName);
                }
                else
                {
                    TargetBlobContainerClient = SourceBlobContainerClient;
                }


                using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(SourceStorageFileNames.Length))
                {
                    System.Collections.Generic.List <System.Threading.Tasks.Task> CopyTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                    for (System.Int32 i = 0; i < SourceStorageFileNames.Length; i++)
                    {
                        System.String SourceStorageFileName = SourceStorageFileNames[i];
                        global::Azure.Storage.Blobs.BlobClient SourceBlobClient = SourceBlobContainerClient.GetBlobClient(SourceStorageFileName);
                        if (!(await SourceBlobClient.ExistsAsync()))
                        {
                            continue;
                        }

                        System.String TargetStorageFileName = TargetStorageFileNames[i];
                        global::Azure.Storage.Blobs.BlobClient TargetBlobClient = TargetBlobContainerClient.GetBlobClient(TargetStorageFileName);
                        if ((!(Overwrite)) && (await TargetBlobClient.ExistsAsync()))
                        {
                            continue;
                        }

                        await SemaphoreSlim.WaitAsync();

                        CopyTasks.Add(System.Threading.Tasks.Task.Run(async() => { await TargetBlobClient.StartCopyFromUriAsync(SourceBlobClient.Uri); SemaphoreSlim.Release(); }));
                    }

                    if (CopyTasks.Any())
                    {
                        await System.Threading.Tasks.Task.WhenAll(CopyTasks);
                    }
                }
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Byte[]> > DownloadAsync(System.String ShareName, System.Collections.Generic.Dictionary <System.String, System.String> StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Byte[]> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Byte[]>();

            if ((System.String.IsNullOrWhiteSpace(ShareName)) || (StorageFileNames == null) || (StorageFileNames.Count == 0))
            {
                OperationResult.Message = "The ShareName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Files.Shares.ShareClient          ShareClient          = new global::Azure.Storage.Files.Shares.ShareClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ShareName);
                global::Azure.Storage.Files.Shares.ShareDirectoryClient ShareDirectoryClient = ShareClient.GetRootDirectoryClient();
                if (StorageFileNames.Count == 1)
                {
                    global::Azure.Storage.Files.Shares.ShareFileClient ShareFileClient = ShareDirectoryClient.GetFileClient(StorageFileNames.First().Key);

                    if (!(await ShareFileClient.ExistsAsync()))
                    {
                        OperationResult.Message = "File not found.";
                        return(OperationResult);
                    }

                    global::Azure.Storage.Files.Shares.Models.ShareFileDownloadInfo ShareFileDownloadInfo = await ShareFileClient.DownloadAsync();

                    using (System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream())
                    {
                        ShareFileDownloadInfo.Content.CopyTo(MemoryStream);
                        OperationResult.Data = MemoryStream.ToArray();
                    }
                }
                else
                {
                    System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(StorageFileNames.Count);
                    System.Collections.Generic.List <System.Threading.Tasks.Task> DownloadTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        global::Azure.Storage.Files.Shares.ShareFileClient ShareFileClient = ShareDirectoryClient.GetFileClient(StorageFileName.Key);
                        if (!(await ShareFileClient.ExistsAsync()))
                        {
                            continue;
                        }

                        await SemaphoreSlim.WaitAsync();

                        DownloadTasks.Add(System.Threading.Tasks.Task.Run(async() =>
                        {
                            global::Azure.Storage.Files.Shares.Models.ShareFileDownloadInfo ShareFileDownloadInfo = await ShareFileClient.DownloadAsync();
                            using (System.IO.FileStream FileStream = System.IO.File.OpenWrite(StorageFileName.Key))
                                ShareFileDownloadInfo.Content.CopyTo(FileStream);

                            SemaphoreSlim.Release();
                        }
                                                                          ));
                    }
                    await System.Threading.Tasks.Task.WhenAll(DownloadTasks);

                    SemaphoreSlim.Dispose();

                    OperationResult.Data = SoftmakeAll.SDK.Files.Compression.CreateZipArchive(StorageFileNames);

                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (StorageFileNames.Count > 0)
                {
                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }

                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
Beispiel #15
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Byte[]> > DownloadAsync(System.String BucketName, System.Collections.Generic.Dictionary <System.String, System.String> StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.AWS.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Byte[]> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Byte[]>();

            if ((System.String.IsNullOrWhiteSpace(BucketName)) || (StorageFileNames == null) || (StorageFileNames.Count == 0))
            {
                OperationResult.Message = "The BucketName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                if (StorageFileNames.Count == 1)
                {
                    Amazon.S3.Model.GetObjectRequest GetObjectRequest = new Amazon.S3.Model.GetObjectRequest {
                        BucketName = BucketName, Key = StorageFileNames.First().Key
                    };
                    using (Amazon.S3.Model.GetObjectResponse GetObjectResponse = await SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client.GetObjectAsync(GetObjectRequest))
                        using (System.IO.Stream Stream = GetObjectResponse.ResponseStream)
                            using (System.IO.MemoryStream MemoryStream = new System.IO.MemoryStream())
                            {
                                await Stream.CopyToAsync(MemoryStream);

                                OperationResult.Data = MemoryStream.ToArray();
                            }
                }
                else
                {
                    using (System.Threading.SemaphoreSlim SemaphoreSlim = new System.Threading.SemaphoreSlim(StorageFileNames.Count))
                    {
                        System.Collections.Generic.List <System.Threading.Tasks.Task> DownloadTasks = new System.Collections.Generic.List <System.Threading.Tasks.Task>();
                        foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                        {
                            await SemaphoreSlim.WaitAsync();

                            DownloadTasks.Add(System.Threading.Tasks.Task.Run(async() =>
                            {
                                Amazon.S3.Model.GetObjectRequest GetObjectRequest = new Amazon.S3.Model.GetObjectRequest {
                                    BucketName = BucketName, Key = StorageFileName.Key
                                };
                                using (Amazon.S3.Model.GetObjectResponse GetObjectResponse = await SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client.GetObjectAsync(GetObjectRequest))
                                    await GetObjectResponse.WriteResponseStreamToFileAsync(StorageFileName.Key, false, new System.Threading.CancellationToken());
                                SemaphoreSlim.Release();
                            }));
                        }

                        if (DownloadTasks.Any())
                        {
                            await System.Threading.Tasks.Task.WhenAll(DownloadTasks);
                        }
                    }

                    OperationResult.Data = SoftmakeAll.SDK.Files.Compression.CreateZipArchive(StorageFileNames);

                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                if (StorageFileNames.Count > 0)
                {
                    foreach (System.Collections.Generic.KeyValuePair <System.String, System.String> StorageFileName in StorageFileNames)
                    {
                        if (System.IO.File.Exists(StorageFileName.Key))
                        {
                            try { System.IO.File.Delete(StorageFileName.Key); } catch { }
                        }
                    }
                }

                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }