Пример #1
0
        public IEnumerable <ResultMedia> GetMediaforTest(string path, string mediaLocation, string testNamePrefix, out bool isExceptionCaused)
        {
            var media = new List <ResultMedia>();

            isExceptionCaused = false;

            int index = 1;

            foreach (var filePath in Directory.GetFiles(path))
            {
                try
                {
                    var file = GetforImagefilePath(filePath);

                    if (file.Extension.ToLower().Contains(".jpg") || file.Extension.ToLower().Contains(".jpeg") ||
                        file.Extension.ToLower().Contains(".bmp") || file.Extension.ToLower().Contains(".png"))
                    {
                        media.Add(GetfromImageFile(file, testNamePrefix, mediaLocation));
                    }
                    else if (file.Extension.ToLower().Contains(".avi") || file.Extension.ToLower().Contains(".flv"))
                    {
                        //var videoName = testNamePrefix + "_" + Guid.NewGuid() + "(" + index + ").flv";
                        var videoName = testNamePrefix + "_" + Guid.NewGuid() + "(" + index + ").mp4";

                        var result = SaveVideo(filePath, videoName, mediaLocation);
                        if (!result)
                        {
                            continue;
                        }

                        index++;
                        if (file.Extension.ToLower().Contains(".flv"))
                        {
                            file.MoveTo(mediaLocation + videoName);
                        }

                        var resultMedia = new ResultMedia
                        {
                            File =
                                new Core.Application.Domain.File
                            {
                                FileSize   = file.Length,
                                Path       = videoName,
                                UploadedOn = DateTime.Now,
                                Type       = FileType.Video
                            },
                            Thumbnail = null
                        };

                        media.Add(resultMedia);
                    }
                }
                catch (Exception ex)
                {
                    isExceptionCaused = true;
                    _logger.Error("\n Media Extraction Failed! Error: " + ex.Message + "\n\t\t" + ex.StackTrace);
                }
            }
            return(media);
        }
Пример #2
0
        public void SetSingleMediaForTestResult(ResultMedia media, string sectionName, string testName, HtmlDocument doc)
        {
            string html = "";

            if (media.File.Type != FileType.Image)
            {
                return;
            }

            html += "<table class='result-images-container'><tr><td class='page-title' style='text-align: center; padding-bottom:15px;'> " + testName + " Media </td></tr>";
            html += "<tr><td style='text-align: center;'><img style='height: 850px;' src='" + StringforMediaDirectory + "/" + media.File.Path + "' alt='' /> </td>";
            html += "</tr></table>";

            var selectedMode = doc.DocumentNode.SelectSingleNode("//div[@id='" + sectionName + "']");

            if (selectedMode != null)
            {
                selectedMode.SetAttributeValue("style", "display:block;");
                selectedMode.InnerHtml = html;
            }
        }
Пример #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        ProcessMedia();
        List <ResultMedia> resultMedia = _resultMedia != null?_resultMedia.ToList() : new List <ResultMedia>();

        string foldername = ImageLocationPrefix.Value;

        if (foldername.IndexOfAny(Path.GetInvalidPathChars()) != -1)
        {
            throw new InvalidDirectoryPathException();
        }

        if (!Directory.Exists(foldername))
        {
            Directory.CreateDirectory(foldername);
        }

        int imgnamecounter = 1;

        foreach (GridViewRow gvrfluploader in gvUploadFiles.Rows)
        {
            var objflupload = (FileUpload)gvrfluploader.FindControl("fluploadImage");
            var fileType    = GetFileTypefortheContentType(objflupload.PostedFile.ContentType);
            if (objflupload.FileName.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
            {
                continue;
            }
            if (objflupload.FileName.Trim().Length < 1)
            {
                continue;
            }


            string fileNamewoExt = Test + "_" + DateTime.Now.ToFileTimeUtc() + "_" + imgnamecounter;
            //var movieFileName = fileNamewoExt + ".flv";
            var    movieFileName     = fileNamewoExt + ".mp4";
            var    fileTypeExtension = Path.GetExtension(objflupload.FileName).ToLower();
            string fileName          = fileNamewoExt + fileTypeExtension;
            string filePath          = foldername + fileName;

            if (filePath.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                continue;
            }


            var settings = IoC.Resolve <ISettings>();

            if (!System.IO.File.Exists(filePath))
            {
                if (Test == TestType.EKG && fileType == FileType.Image && !fileTypeExtension.ToLower().Contains("pdf"))
                {
                    var tempFilePath = foldername + fileNamewoExt + "_" + Guid.NewGuid() + fileTypeExtension;
                    objflupload.SaveAs(tempFilePath);
                    var pdfToImageConverter = IoC.Resolve <IPdftoImageConverter>();

                    /*if (settings.HideEkgSection)
                     * {
                     *  var rectangles = new List<RectangleDimesion>
                     *                       {
                     *                           new RectangleDimesion(0, 230, 1050, 270)
                     *                       };
                     *  pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, rectangles);
                     * }
                     * else
                     * {
                     *  pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, null);
                     * }*/

                    pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, null);
                }
                else if (Test == TestType.QuantaFloABI && fileType == FileType.Image && !fileTypeExtension.ToLower().Contains("pdf"))
                {
                    var tempFilePath = foldername + fileNamewoExt + "_" + Guid.NewGuid() + fileTypeExtension;
                    objflupload.SaveAs(tempFilePath);
                    var pdfToImageConverter = IoC.Resolve <IPdftoImageConverter>();

                    /*if (settings.HideQuantaFloAbiSection)
                     * {
                     *
                     *  var rectangles = new List<RectangleDimesion>
                     *                   {
                     *                       new RectangleDimesion(410, 116, 150, 15)
                     *                   };
                     *  pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, rectangles);
                     * }
                     * else
                     * {
                     *  pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, null);
                     * }*/
                    pdfToImageConverter.HideEcgFinding(tempFilePath, filePath, null, null);
                }
                else
                {
                    objflupload.SaveAs(filePath);

                    if (fileTypeExtension.Contains("svg"))
                    {
                        var imageFilePath = IoC.Resolve <ISvgToImageConverter>().GenerateImage(filePath);
                        if (string.IsNullOrEmpty(imageFilePath) || !System.IO.File.Exists(imageFilePath))
                        {
                            _logger.Info("Svg not converted to Image file.");
                            continue;
                        }
                        filePath = imageFilePath;
                    }
                    else if (fileTypeExtension.Contains("bmp"))
                    {
                        filePath = _mediaHelper.ConvertBmptoJpeg(filePath);
                    }

                    fileName = Path.GetFileName(filePath);
                }
            }

            var     fileSize          = new FileInfo(filePath).Length;
            decimal thumbnailSize     = 0;
            string  thumbnailfilename = string.Empty;

            if (fileTypeExtension.ToLower().Contains("pdf"))
            {
                string imageFileName = filePath.ToLower().Replace(".pdf", ".jpg");
                if (Test == TestType.EKG || Test == TestType.AwvEkg || Test == TestType.AwvEkgIPPE)
                {
                    var pdfToImageConverter = IoC.Resolve <IPdftoImageConverter>();
                    //pdfToImageConverter.ConvertToImage(filePath, imageFileName, IoC.Resolve<ILogManager>().GetLogger<Global>(), settings.HideEkgSection);
                    pdfToImageConverter.ConvertToImage(filePath, imageFileName, IoC.Resolve <ILogManager>().GetLogger <Global>(), false);
                }
                else if (Test == TestType.QuantaFloABI)
                {
                    var pdfToImageConverter = IoC.Resolve <IPdftoImageConverter>();

                    /*var rectangles = new List<RectangleDimesion>
                     *                   {
                     *                       new RectangleDimesion(410, 116, 150, 15)
                     *                   };
                     * pdfToImageConverter.ConvertToImage(filePath, imageFileName, IoC.Resolve<ILogManager>().GetLogger<Global>(), settings.HideQuantaFloAbiSection, rectangles);*/
                    pdfToImageConverter.ConvertToImage(filePath, imageFileName, IoC.Resolve <ILogManager>().GetLogger <Global>(), false, null, null);
                }
                else
                {
                    var fileFound = IoC.Resolve <IPdftoImageConverter>().ConvertToImage(filePath, imageFileName, IoC.Resolve <ILogManager>().GetLogger <Global>(), false);
                    if (!fileFound)
                    {
                        ClientScript.RegisterStartupScript(typeof(string), "jscode", " alert('File could not be uploded!'); parent.ClosePopUp(); ", true);
                    }
                }
                fileType = FileType.Image;
                fileSize = new FileInfo(imageFileName).Length;
                filePath = imageFileName;
                fileName = fileNamewoExt + ".jpg";
            }

            if (fileType == FileType.Image)
            {
                thumbnailfilename = CreateThumbnailImage(filePath, out thumbnailSize);
            }
            else if (fileType == FileType.Video)
            {
                bool result = SaveVideo(filePath, movieFileName);
                if (!result)
                {
                    continue;
                }
                fileName = movieFileName;
            }

            imgnamecounter++;

            var media = new ResultMedia
            {
                File = new File {
                    Path = fileName, FileSize = fileSize, Type = fileType, UploadedOn = DateTime.Now, UploadedBy = new OrganizationRoleUser(0)
                },
                Thumbnail = string.IsNullOrEmpty(thumbnailfilename) ? null : new File {
                    Path = thumbnailfilename, Type = FileType.Image, FileSize = thumbnailSize, UploadedOn = DateTime.Now, UploadedBy = new OrganizationRoleUser(0)
                },
                ReadingSource = ReadingSource.Manual
            };

            if (imgnamecounter == 2 && RestricttoOne)
            {
                resultMedia = new List <ResultMedia>();
            }

            resultMedia.Add(media);
        }

        var jsonSerializer = new JavaScriptSerializer();

        ClientScript.RegisterStartupScript(Page.GetType(), "js_JsonMediaObject", "var jsonMedia = " + jsonSerializer.Serialize(resultMedia) + ";", true);

        if (Test == TestType.AAA)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", " parent.LoadNewImagesAAA(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.Stroke)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesCarotid(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.Lead)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesLead(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.Echocardiogram)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewMediaEcho(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.IMT)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesImt(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.Thyroid)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesThyroid(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.EKG)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesEkg(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.PulmonaryFunction)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesPulmonary(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.Spiro)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesSpiro(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvSpiro)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesAwvSpiro(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.PPAAA)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", " parent.LoadNewImagesPpAAA(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.PPEcho)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewMediaPpEcho(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.HCPAAA)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesHcpAAA(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.HCPCarotid)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesHcpCarotid(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.HCPEcho)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewMediaHcpEcho(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvAAA)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", " parent.LoadNewImagesAwvAaa(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvCarotid)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", " parent.LoadNewImagesAwvCarotid(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvEcho)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewMediaAwvEcho(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvEkgIPPE)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesAwvEkgIppe(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.AwvEkg)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesAwvEkg(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.FloChecABI)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesFloChecABI(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
        else if (Test == TestType.QuantaFloABI)
        {
            ClientScript.RegisterStartupScript(typeof(string), "jscode", "parent.LoadNewImagesQuantaFloABI(jsonMedia, true); parent.ClosePopUp(); ", true);
        }
    }
Пример #4
0
        public IEnumerable <ResultMedia> GetMediaforTest(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }
            _logger.Info("\nMedia Path: " + path);
            var media    = new List <ResultMedia>();
            var fileName = "Echo_" + Guid.NewGuid() + "(1)";
            var counter  = Directory.GetFiles(path).Select(Path.GetExtension).Where(ext => !string.IsNullOrEmpty(ext)).LongCount(ext => ext.Contains(".jpg") || ext.Contains(".jpeg") || ext.Contains(".bmp") || ext.Contains(".png"));

            try
            {
                if (counter > 1)
                {
                    string fileNameWithoutExtension = fileName;
                    fileName = fileName + ".flv";
                    var returnResult = _movieMaker.GenerateMoviefromImageGroup(path, _mediaLocation, fileName);
                    if (string.IsNullOrEmpty(returnResult))
                    {
                        return(null);
                    }

                    var mp4File = _movieMaker.GenerateMPEG(_mediaLocation + "\\" + returnResult, _mediaLocation, fileNameWithoutExtension);

                    var file = new FileInfo(_mediaLocation + fileName);

                    var resultMedia = new ResultMedia
                    {
                        File =
                            new Core.Application.Domain.File
                        {
                            FileSize   = file.Length,
                            Path       = mp4File,                        //fileName,
                            UploadedOn = DateTime.Now,
                            Type       = FileType.Video
                        }
                    };
                    media.Add(resultMedia);
                }
                else if (counter > 0)
                {
                    var imgFilePath = "";
                    foreach (string filePath in Directory.GetFiles(path))
                    {
                        string ext = Path.GetExtension(filePath);
                        if (!string.IsNullOrEmpty(ext) && (ext.Contains(".jpg") || ext.Contains(".jpeg") || ext.Contains(".bmp") || ext.Contains(".png")))
                        {
                            imgFilePath = filePath;
                            break;
                        }
                    }

                    var imageName = fileName + Path.GetExtension(imgFilePath);
                    var file      = new FileInfo(imgFilePath);
                    file.MoveTo(_mediaLocation + imageName);

                    decimal fileSize;
                    var     thumbnailImageName = CreateThumbnailImage(_mediaLocation + imageName, out fileSize);
                    var     resultMedia        = new ResultMedia
                    {
                        File =
                            new Core.Application.Domain.File
                        {
                            FileSize   = file.Length,
                            Path       = imageName,
                            UploadedOn = DateTime.Now,
                            Type       = FileType.Image
                        },
                        Thumbnail =
                            new Core.Application.Domain.File
                        {
                            FileSize   = fileSize,
                            Path       = thumbnailImageName,
                            UploadedOn = DateTime.Now,
                            Type       = FileType.Image
                        }
                    };
                    media.Add(resultMedia);
                }
            }
            catch (Exception ex)
            {
                _errorSummary += "Media Extraction Failed. ";
                _logger.Error("\n Media Extraction Failed! Error: " + ex.Message + "\n\t\t" + ex.StackTrace);
            }

            return(media);
        }