Example #1
0
        public async Task <XchangeFile> Handle(XchangeFile xchangeFile)
        {
            using var cloudFiles = new CloudFilesService(new CloudFilesOptions
            {
                AccessKeyId     = Runner.StartupValueOf(CommonProperties.AccessKeyId),
                SecretAccessKey = Runner.StartupValueOf(CommonProperties.SecretAccessKey),
                ServiceUrl      = Runner.StartupValueOf(CommonProperties.Url),
                BucketName      = Runner.StartupValueOf(CommonProperties.TargetPath),
            });

            var key = "";

            if (Runner.StartupValueOf(CommonProperties.FileName) != "")
            {
                key = Runner.StartupValueOf("FileName");
            }
            else
            {
                key = string.Concat(Runner.StartupValueOf(CommonProperties.FolderName), "/", DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "." + Runner.StartupValueOf(CommonProperties.FileExtension));
            }

            await cloudFiles.WriteTextAsync(xchangeFile.Data, new WriteFileSettings
            {
                Key         = key,
                ContentType = Runner.StartupValueOf(CommonProperties.ContentType),
            });

            return(new XchangeFile(key, xchangeFile.Filename));
        }
Example #2
0
        public async Task <bool> PushToCloudAsync(
            string zipFielPath,
            string adapterId,
            string entryAssembly,
            string accessKeyId,
            string secretAccessKey,
            string serviceUrl,
            string bucketName)
        {
            try
            {
                Console.WriteLine("Pushing to cloud...");


                using var cloudService = new CloudFilesService(new CloudFilesOptions
                {
                    AccessKeyId     = accessKeyId,
                    SecretAccessKey = secretAccessKey,
                    ServiceUrl      = serviceUrl,
                    BucketName      = bucketName
                });

                using var zipFileStream = File.OpenRead(zipFielPath);

                await cloudService.WriteAsync(zipFileStream, new WriteFileSettings
                {
                    ContentType = "application/zip",
                    Key         = $"adapters/{adapterId}".ToLower(),
                    Metadata    = new Dictionary <string, string>
                    {
                        { "EntryAssembly", entryAssembly },
                        { "Lang", "dotnet" }
                    }
                });

                Console.WriteLine("Pushing to cloud succeeded.");
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Pushing to cloud failed: {ex}");
                return(false);
            }
        }