示例#1
0
        /// <summary>
        /// Adds the element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>The <see cref="MediaData"/>.</returns>
        public MediaData AddElement(TimelineElement element)
        {
            MediaData media = null;

            if (element.Asset is VideoAsset || element.Asset is AudioAsset)
            {
                media                          = new PlayableMediaData(element);
                media.BufferStart             += this.Media_BufferStart;
                media.BufferEnd               += this.Media_BufferEnd;
                media.DownloadProgressChanged += this.Media_DownloadProgressChanged;
            }
            else if (element.Asset is ImageAsset)
            {
                media = new ImageMediaData(element);
            }
            else if (element.Asset is TitleAsset)
            {
                media = new TitleMediaData(element);
            }

            if (media != null)
            {
                this.mediaData.Add(media);
            }

            return(media);
        }
        public void SetDescriptionImage(AlternateContent altContent, string fullPath)
        {
            Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
            TreeNode node = selection.Item2 ?? selection.Item1;

            if (node == null)
            {
                return;
            }

            var altProp = node.GetAlternateContentProperty();

            if (altProp == null)
            {
                return;
            }

            if (altProp.AlternateContents.IndexOf(altContent) < 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(fullPath))
            {
                if (altContent.Image != null)
                {
                    AlternateContentRemoveManagedMediaCommand cmd1 =
                        node.Presentation.CommandFactory.CreateAlternateContentRemoveManagedMediaCommand(node, altContent,
                                                                                                         altContent.Image);
                    node.Presentation.UndoRedoManager.Execute(cmd1);
                }
            }
            else if (File.Exists(fullPath))
            {
                string extension = Path.GetExtension(fullPath);
                if (string.IsNullOrEmpty(extension))
                {
                    return;
                }

                ManagedImageMedia img1 = node.Presentation.MediaFactory.CreateManagedImageMedia();

                ImageMediaData imgData1 = node.Presentation.MediaDataFactory.CreateImageMediaData(extension);
                if (imgData1 == null)
                {
                    return;
                }

                imgData1.InitializeImage(fullPath, Path.GetFileName(fullPath));
                img1.ImageMediaData = imgData1;

                AlternateContentSetManagedMediaCommand cmd22 =
                    node.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(node, altContent, img1);
                node.Presentation.UndoRedoManager.Execute(cmd22);
            }

            RaisePropertyChanged(() => Descriptions);
        }
示例#3
0
        private void diagramXmlParseBody_(XmlNode diagramElementNode, string xmlFilePath, TreeNode treeNode, int objectIndex)
        {
            string diagramElementName = diagramElementNode.Name;

            AlternateContent           altContent     = treeNode.Presentation.AlternateContentFactory.CreateAlternateContent();
            AlternateContentAddCommand cmd_AltContent =
                treeNode.Presentation.CommandFactory.CreateAlternateContentAddCommand(treeNode, altContent);

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent);



            Metadata diagramElementName_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();

            diagramElementName_Metadata.NameContentAttribute              = new MetadataAttribute();
            diagramElementName_Metadata.NameContentAttribute.Name         = DiagramContentModelHelper.DiagramElementName;
            diagramElementName_Metadata.NameContentAttribute.NamespaceUri = null;
            diagramElementName_Metadata.NameContentAttribute.Value        = diagramElementName;
            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementName_Metadata =
                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                    treeNode,
                    null,
                    altContent,
                    diagramElementName_Metadata,
                    null
                    );

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElementName_Metadata);


            if (diagramElementNode.Attributes != null)
            {
                for (int i = 0; i < diagramElementNode.Attributes.Count; i++)
                {
                    XmlAttribute attribute = diagramElementNode.Attributes[i];


                    if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                    {
                        //
                    }
                    else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                    {
                        //
                    }
                    else if (attribute.Name == DiagramContentModelHelper.TOBI_Audio)
                    {
                        string fullPath = null;
                        if (FileDataProvider.isHTTPFile(attribute.Value))
                        {
                            fullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(attribute.Value);
                        }
                        else
                        {
                            fullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), attribute.Value);
                        }
                        if (fullPath != null && File.Exists(fullPath))
                        {
                            string extension = Path.GetExtension(fullPath);

                            bool isWav = extension.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase);

                            AudioLibPCMFormat wavFormat = null;
                            if (isWav)
                            {
                                Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                try
                                {
                                    uint dataLength;
                                    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                }
                                finally
                                {
                                    fileStream.Close();
                                }
                            }
                            string originalFilePath = null;

                            DebugFix.Assert(treeNode.Presentation.MediaDataManager.EnforceSinglePCMFormat);

                            bool wavNeedsConversion = false;
                            if (wavFormat != null)
                            {
                                wavNeedsConversion = !wavFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data);
                            }
                            if (!isWav || wavNeedsConversion)
                            {
                                originalFilePath = fullPath;

                                var audioFormatConvertorSession =
                                    new AudioFormatConvertorSession(
                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                                        treeNode.Presentation.MediaDataManager.DefaultPCMFormat,
                                        false,
                                        m_UrakawaSession.IsAcmCodecsDisabled);

                                //filePath = m_AudioFormatConvertorSession.ConvertAudioFileFormat(filePath);

                                bool cancelled = false;

                                var converter = new AudioClipConverter(audioFormatConvertorSession, fullPath);

                                bool error = ShellView.RunModalCancellableProgressTask(true,
                                                                                       "Converting audio...",
                                                                                       converter,
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion CANCELLED", Category.Debug, Priority.Medium);
                                    cancelled = true;
                                },
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion DONE", Category.Debug, Priority.Medium);
                                    cancelled = false;
                                });

                                if (cancelled)
                                {
                                    //DebugFix.Assert(!result);
                                    break;
                                }

                                fullPath = converter.ConvertedFilePath;
                                if (string.IsNullOrEmpty(fullPath))
                                {
                                    break;
                                }

                                m_Logger.Log(string.Format("Converted audio {0} to {1}", originalFilePath, fullPath),
                                             Category.Debug, Priority.Medium);

                                //Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                //try
                                //{
                                //    uint dataLength;
                                //    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                //}
                                //finally
                                //{
                                //    fileStream.Close();
                                //}
                            }


                            ManagedAudioMedia manAudioMedia  = treeNode.Presentation.MediaFactory.CreateManagedAudioMedia();
                            AudioMediaData    audioMediaData = treeNode.Presentation.MediaDataFactory.CreateAudioMediaData(DataProviderFactory.AUDIO_WAV_EXTENSION);
                            manAudioMedia.AudioMediaData = audioMediaData;

                            FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            dataProv.InitByCopyingExistingFile(fullPath);
                            audioMediaData.AppendPcmData(dataProv);

                            //                            Stream wavStream = null;
                            //                            try
                            //                            {
                            //                                wavStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                            //                                uint dataLength;
                            //                                AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                            //                                if (!treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo))
                            //                                {
                            //#if DEBUG
                            //                                    Debugger.Break();
                            //#endif //DEBUG
                            //                                    wavStream.Close();
                            //                                    wavStream = null;

                            //                                    var audioFormatConvertorSession =
                            //                                        new AudioFormatConvertorSession(
                            //                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                            //                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                            //                                    treeNode.Presentation.MediaDataManager.DefaultPCMFormat, m_UrakawaSession.IsAcmCodecsDisabled);

                            //                                    string newfullWavPath = audioFormatConvertorSession.ConvertAudioFileFormat(fullPath);

                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByMovingExistingFile(newfullWavPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                                else // use original wav file by copying it to data directory
                            //                                {
                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByCopyingExistingFile(fullPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                            }
                            //                            finally
                            //                            {
                            //                                if (wavStream != null) wavStream.Close();
                            //                            }



                            AlternateContentSetManagedMediaCommand cmd_AltContent_diagramElement_Audio =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, manAudioMedia);
                            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElement_Audio);

                            //SetDescriptionAudio(altContent, audio, treeNode);
                        }
                    }
                    else
                    {
                        Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                        diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                        diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                        diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                        diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                        AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                            treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                treeNode,
                                null,
                                altContent,
                                diagramElementAttribute_Metadata,
                                null
                                );
                        treeNode.Presentation.UndoRedoManager.Execute(
                            cmd_AltContent_diagramElementAttribute_Metadata);
                    }
                }
            }

            int nObjects = -1;

            XmlNode textNode = diagramElementNode;

            if (diagramElementName == DiagramContentModelHelper.D_SimplifiedImage ||
                diagramElementName == DiagramContentModelHelper.D_Tactile)
            {
                string  localTourName = DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Tour);
                XmlNode tour          =
                    XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramElementNode, false,
                                                                         localTourName,
                                                                         DiagramContentModelHelper.NS_URL_DIAGRAM);
                textNode = tour;

                IEnumerable <XmlNode> objects = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(diagramElementNode, false,
                                                                                                    DiagramContentModelHelper.
                                                                                                    Object,
                                                                                                    DiagramContentModelHelper.
                                                                                                    NS_URL_ZAI, false);
                nObjects = 0;
                foreach (XmlNode obj in objects)
                {
                    nObjects++;
                }

                int i = -1;
                foreach (XmlNode obj in objects)
                {
                    i++;
                    if (i != objectIndex)
                    {
                        continue;
                    }

                    if (obj.Attributes == null || obj.Attributes.Count <= 0)
                    {
                        break;
                    }

                    for (int j = 0; j < obj.Attributes.Count; j++)
                    {
                        XmlAttribute attribute = obj.Attributes[j];


                        if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                        {
                            //
                        }
                        else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.Src)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.SrcType)
                        {
                            //
                        }
                        else
                        {
                            Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                            diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                            diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                            diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                            diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                    treeNode,
                                    null,
                                    altContent,
                                    diagramElementAttribute_Metadata,
                                    null
                                    );
                            treeNode.Presentation.UndoRedoManager.Execute(
                                cmd_AltContent_diagramElementAttribute_Metadata);
                        }
                    }

                    XmlAttribute srcAttr = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.Src);
                    if (srcAttr != null)
                    {
                        XmlAttribute srcType =
                            (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.SrcType);

                        ManagedImageMedia img = treeNode.Presentation.MediaFactory.CreateManagedImageMedia();

                        string imgFullPath = null;
                        if (FileDataProvider.isHTTPFile(srcAttr.Value))
                        {
                            imgFullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(srcAttr.Value);
                        }
                        else
                        {
                            imgFullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), srcAttr.Value);
                        }
                        if (imgFullPath != null && File.Exists(imgFullPath))
                        {
                            string extension = Path.GetExtension(imgFullPath);

                            ImageMediaData imgData = treeNode.Presentation.MediaDataFactory.CreateImageMediaData(extension);
                            if (imgData != null)
                            {
                                imgData.InitializeImage(imgFullPath, Path.GetFileName(imgFullPath));
                                img.ImageMediaData = imgData;

                                AlternateContentSetManagedMediaCommand cmd_AltContent_Image =
                                    treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(
                                        treeNode, altContent, img);
                                treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Image);
                            }
                        }
                    }
                }
            }

            if (textNode != null)
            {
                string strText = textNode.InnerXml;

                if (!string.IsNullOrEmpty(strText))
                {
                    strText = strText.Trim();
                    strText = Regex.Replace(strText, @"\s+", " ");
                    strText = strText.Replace("\r\n", "\n");
                }

                if (!string.IsNullOrEmpty(strText))
                {
                    TextMedia txtMedia = treeNode.Presentation.MediaFactory.CreateTextMedia();
                    txtMedia.Text = strText;
                    AlternateContentSetManagedMediaCommand cmd_AltContent_Text =
                        treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode,
                                                                                                          altContent,
                                                                                                          txtMedia);
                    treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Text);
                }
            }

            if (nObjects > 0 && ++objectIndex <= nObjects - 1)
            {
                diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, objectIndex);
            }
        }
示例#4
0
        private void ProcessAnalysisResult(ImageAnalysis result, ImageMediaData imageFile)
        {
            if (result == null || imageFile == null)
            {
                return;
            }

            if (result.ImageType != null)
            {
                string clipArtType;
                switch (result.ImageType.ClipArtType)
                {
                case 0:
                    clipArtType = "Non-clipart";
                    break;

                case 1:
                    clipArtType = "Ambiguous";
                    break;

                case 2:
                    clipArtType = "Normal clipart";
                    break;

                case 3:
                    clipArtType = "Good clipart";
                    break;

                default:
                    clipArtType = "Unknown";
                    break;
                }

                imageFile.ClipArtType = clipArtType;

                string lineDrawingType;
                switch (result.ImageType.LineDrawingType)
                {
                case 0:
                    lineDrawingType = "Non-lineDrawing";
                    break;

                case 1:
                    lineDrawingType = "LineDrawing";
                    break;

                default:
                    lineDrawingType = "Unknown";
                    break;
                }

                imageFile.LineDrawingType = lineDrawingType;
            }

            if (result.Adult != null)
            {
                imageFile.IsAdultContent = result.Adult.IsAdultContent;
                imageFile.IsRacyContent  = result.Adult.IsRacyContent;
            }

            if (result.Categories != null && result.Categories.Count > 0)
            {
                imageFile.ImageCategories = result.Categories.Select(c => c.Name).ToArray();
            }

            if (result.Color != null)
            {
                imageFile.AccentColor             = result.Color.AccentColor;
                imageFile.DominantColorBackground = result.Color.DominantColorBackground;
                imageFile.DominantColorForeground = result.Color.DominantColorForeground;
                imageFile.IsBwImg = result.Color.IsBWImg;

                if (result.Color.DominantColors != null && result.Color.DominantColors.Count > 0)
                {
                    imageFile.DominantColors = result.Color.DominantColors;
                }
            }

            if ((imageFile.Tags == null || imageFile.Tags.Count == 0) && result.Tags != null)
            {
                imageFile.Tags = result.Tags.Where(t => t.Confidence > 0.5).Select(t => t.Name).ToArray();
            }

            if (result.Description != null)
            {
                imageFile.Caption = result.Description.Captions.OrderByDescending(c => c.Confidence).FirstOrDefault()?.Text;

                if (imageFile.Tags == null || imageFile.Tags.Count == 0)
                {
                    imageFile.Tags = result.Description.Tags;
                }
            }
        }
示例#5
0
        public async Task TagImagesAsync(ImageMediaData imageFile)
        {
            var analysisResult = await DescribeImageFromStreamAsync(imageFile);

            ProcessAnalysisResult(analysisResult, imageFile);
        }
示例#6
0
        protected MediaGalleryData Process_GetMedia(MediaGalleryData media)
        {
            List<ImageMediaData> ImageList = new List<ImageMediaData>();
            if (media == null)
            {
                media = new MediaGalleryData();
            }

            if (ucMedia.ImageData != null)
            {

                for (int i = 0; i <= (ucMedia.ImageData.Count - 1); i++)
                {

                    ImageMediaData image = new ImageMediaData();

                    if (ucMedia.ImageData[i].MarkedForDelete == false && ucMedia.ImageData[i].Id > 0)
                    {
                        image.Id = ucMedia.ImageData[i].Id;
                        image.FileName = (string)(ucMedia.ImageData[i].Title);
                        image.FilePath = (string)(ucMedia.ImageData[i].Path);
                        image.Alt = (string)(ucMedia.ImageData[i].AltText);
                        image.Height = EkFunctions.ReadIntegerValue(ucMedia.ImageData[i].Height);
                        image.Width = EkFunctions.ReadIntegerValue(ucMedia.ImageData[i].Width);
                        image.IncludedInGallery = System.Convert.ToBoolean(ucMedia.ImageData[i].Gallery);
                        if (prod_type_data.DefaultThumbnails.Count > 0)
                        {

                            if (ucMedia.ImageData[i].Thumbnails != null)
                            {

                                for (int j = 0; j <= ucMedia.ImageData[i].Thumbnails.Count - 1; j++)
                                {

                                    image.Thumbnails.Add(new ThumbnailData());

                                    if (ucMedia.ImageData[i].Thumbnails[j].Path.IndexOf(m_refContentApi.SitePath) > -1 && m_refContentApi.SitePath != "/")
                                    {
                                        image.Thumbnails[j].FilePath = (string)(ucMedia.ImageData[i].Thumbnails[j].Path.Substring(ucMedia.ImageData[i].Thumbnails[j].Path.IndexOf(m_refContentApi.SitePath) + m_refContentApi.SitePath.Length));
                                    }
                                    else if (m_refContentApi.SitePath == "/" && ucMedia.ImageData[i].Thumbnails[j].Path.StartsWith("/"))
                                    {
                                        image.Thumbnails[j].FilePath = Strings.Replace((string)(ucMedia.ImageData[i].Thumbnails[j].Path), "/", "", 1, 1, 0);
                                    }
                                    else
                                    {
                                        image.Thumbnails[j].FilePath = (string)(ucMedia.ImageData[i].Thumbnails[j].Path);
                                    }

                                    image.Thumbnails[j].FilePath = (string)(image.Thumbnails[j].FilePath.Replace("\\", "/").TrimEnd(new char[] { '/' }) + "/" + ucMedia.ImageData[i].Thumbnails[j].ImageName);

                                    if (ucMedia.ImageData[i].Thumbnails[j].Path.LastIndexOf("/") > -1)
                                    {
                                        image.Thumbnails[j].FileName = (string)(ucMedia.ImageData[i].Thumbnails[j].ImageName.Substring(ucMedia.ImageData[i].Thumbnails[j].ImageName.LastIndexOf("/") + 1));
                                    }
                                    else
                                    {
                                        image.Thumbnails[j].FileName = (string)(ucMedia.ImageData[i].Thumbnails[j].ImageName);
                                    }
                                    image.Thumbnails[j].Height = (int)(ucMedia.ImageData[i].Thumbnails[j].Height);
                                    image.Thumbnails[j].Width = (int)(ucMedia.ImageData[i].Thumbnails[j].Width);
                                }
                            }
                        }

                        ImageList.Add(image);
                    }
                }
            }

            media.Images = ImageList;
            return media;
        }