public static bool BuildPreview(string temporaryDirectory, string sourceFile, string mimetype, int width, int height, out string previewMimetype, out string previewPath, out string error)
        {
            IPreview preview = null;
            bool     success = false;

            previewMimetype = null;
            previewPath     = null;
            error           = null;

            if (mimetype.StartsWith("image/") || mimetype.StartsWith("video/") || mimetype.StartsWith("audio/"))
            {
                preview = new ImageVideoPreview(temporaryDirectory);
            }
            else if (Pdf.PdfService.IsPdfCompatible(mimetype))
            {
                preview = new PdfPreview(temporaryDirectory);
            }
            else if (mimetype == "text/uri-list")
            {
                preview = new UrlPreview(temporaryDirectory);
            }
            else if (mimetype.StartsWith("text/plain"))
            {
                preview = new TextPreview(temporaryDirectory);
            }

            if (preview != null)
            {
                PreviewFormat format;
                previewPath = preview.Process(sourceFile, mimetype, width, height, out format, out error);
                if (previewPath != null)
                {
                    if (format == PreviewFormat.PNG)
                    {
                        previewMimetype = "image/png";
                    }
                    else
                    {
                        previewMimetype = "image/jpeg";
                    }
                    success = true;
                }
                else
                {
                    success = false;
                }
            }
            return(success);
        }
        bool BuildPreview(string storage, long file, string filepath, string mimetype, out string previewMimetype, out string previewPath)
        {
            IPreview preview = null;
            bool     success = false;

            previewMimetype = null;
            previewPath     = null;

            if (mimetype.StartsWith("image/") || mimetype.StartsWith("video/") || mimetype.StartsWith("audio/"))
            {
                preview = new ImageVideoPreview(temporaryDirectory);
            }
            else if (Pdf.PdfService.IsPdfCompatible(mimetype))
            {
                preview = new PdfPreview(temporaryDirectory);
            }
            else if (mimetype == "text/uri-list")
            {
                preview = new UrlPreview(temporaryDirectory);
            }
            else if (mimetype.StartsWith("text/plain"))
            {
                preview = new TextPreview(temporaryDirectory);
            }

            if (preview != null)
            {
                PreviewFormat format;
                string        error;
                string        previewFile = preview.Process(filepath, mimetype, width, height, out format, out error);
                if (previewFile != null)
                {
                    if (!Directory.Exists(basePath + "/" + storage))
                    {
                        Directory.CreateDirectory(basePath + "/" + storage);
                    }
                    if (format == PreviewFormat.PNG)
                    {
                        previewMimetype = "image/png";
                    }
                    else
                    {
                        previewMimetype = "image/jpeg";
                    }
                    previewPath = basePath + "/" + storage + "/" + file;
                    try {
                        File.Move(previewFile, previewPath);
                    }
                    catch (IOException) {
                        File.Replace(previewFile, previewPath, null);
                    }
                    success = true;
                }
                else
                {
                    if (error != null)
                    {
                        logger.Log(LogLevel.Error, error);
                    }
                    success = false;
                }
            }
            return(success);
        }