コード例 #1
0
        public string SalvarImagem(byte[] imagemUpload, string caminhoFisicoDiretorioArquivos, string diretorio, string extensao, string formato)
        {
            try
            {
                extensao = string.IsNullOrEmpty(extensao) ? ".png" : extensao;

                var uploadFolder = $@"{caminhoFisicoDiretorioArquivos}\{diretorio}";
                if (!Directory.Exists(uploadFolder))
                {
                    Directory.CreateDirectory(uploadFolder);
                }

                var guid = Guid.NewGuid();

                var nomeDoArquivo = $"{guid}{extensao}";
                var fullFileName  = Path.Combine(uploadFolder, nomeDoArquivo);

                using (var contexto = new Imageflow.Bindings.JobContext())
                {
                    contexto.AddInputBytesPinned(0, imagemUpload);
                    contexto.AddOutputBuffer(1);
                    var response = contexto.ExecuteImageResizer4CommandString(0, 1, formato);

                    var data         = response.DeserializeDynamic();
                    var outputStream = contexto.GetOutputBuffer(1);

                    byte[] buffer = new byte[16 * 1024];
                    using (MemoryStream ms = new MemoryStream())
                    {
                        int read;
                        while ((read = outputStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }

                        File.WriteAllBytes(fullFileName, ms.ToArray());
                    }
                }

                return($@"{diretorio}/{nomeDoArquivo}");
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #2
0
        private Task <string> GeneratePage(HttpContext context)
        {
            var s   = new StringBuilder(8096);
            var now = DateTime.UtcNow.ToString(NumberFormatInfo.InvariantInfo);

            s.AppendLine($"Diagnostics for Imageflow at {context?.Request.Host.Value} generated {now} UTC");

            try
            {
                using var job = new Imageflow.Bindings.JobContext();
                var version = job.GetVersionInfo();
                s.AppendLine($"libimageflow {version.LongVersionString}");
            }
            catch (Exception e)
            {
                s.AppendLine($"Failed to get libimageflow version: {e.Message}");
            }

            s.AppendLine("Please remember to provide this page when contacting support.");
            var issues = diskCache?.GetIssues().ToList() ?? new List <IIssue>();

            s.AppendLine($"{issues.Count} issues detected:\r\n");
            foreach (var i in issues.OrderBy(i => i?.Severity))
            {
                s.AppendLine($"{i?.Source}({i?.Severity}):\t{i?.Summary}\n\t\t\t{i?.Details?.Replace("\n", "\r\n\t\t\t")}\n");
            }

            s.AppendLine("\nInstalled Plugins");

            if (memoryCache != null)
            {
                s.AppendLine(this.memoryCache.GetType().FullName);
            }
            if (distributedCache != null)
            {
                s.AppendLine(this.distributedCache.GetType().FullName);
            }
            if (diskCache != null)
            {
                s.AppendLine(this.diskCache.GetType().FullName);
            }
            foreach (var provider in blobProviders)
            {
                s.AppendLine(provider.GetType().FullName);
            }


            s.AppendLine("\nAccepted querystring keys:\n");
            s.AppendLine(string.Join(", ", PathHelpers.SupportedQuerystringKeys));

            s.AppendLine("\nAccepted file extensions:\n");
            s.AppendLine(string.Join(", ", PathHelpers.AcceptedImageExtensions));

            s.AppendLine("\nEnvironment information:\n");
            s.AppendLine(
                $"Running on {Environment.OSVersion} and CLR {Environment.Version} and .NET Core {GetNetCoreVersion()}");

            try {
                var wow64 = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
                var arch  = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
                s.AppendLine("OS arch: " + arch + (string.IsNullOrEmpty(wow64)
                    ? ""
                    : " !! Warning, running as 32-bit on a 64-bit OS(" + wow64 +
                                                   "). This will limit ram usage !!"));
            } catch (SecurityException) {
                s.AppendLine(
                    "Failed to detect operating system architecture - security restrictions prevent reading environment variables");
            }
            //Get loaded assemblies for later use
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            //List loaded assemblies, and also detect plugin assemblies that are not being used.
            s.AppendLine("\nLoaded assemblies:\n");

            foreach (var a in assemblies)
            {
                var assemblyName = new AssemblyName(a.FullName);
                var line         = "";
                var error        = a.GetExceptionForReading <AssemblyFileVersionAttribute>();
                if (error != null)
                {
                    line += $"{assemblyName.Name,-40} Failed to read assembly attributes: {error.Message}";
                }
                else
                {
                    var version     = $"{a.GetFileVersion()} ({assemblyName.Version})";
                    var infoVersion = $"{a.GetInformationalVersion()}";
                    line += $"{assemblyName.Name,-40} File: {version,-25} Informational: {infoVersion,-30}";
                }

                s.AppendLine(line);
            }
            return(Task.FromResult(s.ToString()));
        }
コード例 #3
0
 public void TestAccessAbi()
 {
     using (var j = new Imageflow.Bindings.JobContext()) { }
 }