Exemplo n.º 1
0
        /// <summary>
        /// 播放器调用方法
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>


        public static ToolboxItem GetToolBoxItemPreview(SaveItemInfo info)
        {
            TransformGroup   transformGroup;
            WindowsFormsHost winformHost;


            string      TempPath = "";
            Image       image;
            ToolboxItem item = null;

            item           = new ToolboxItem();
            item.AssetType = info.assetType;
            item.ItemId    = info.ItemId;
            item.ItemName  = info.ItemName;

            if (!string.IsNullOrEmpty(info.AssetPath))
            {
                TempPath = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp" + info.AssetPath.Substring(info.AssetPath.LastIndexOf("\\"));
                //MessageBox.Show("getitem,"+TempPath);
                try
                {
                    if (System.IO.File.Exists(TempPath))
                    {
                        System.IO.File.Delete(TempPath);
                    }

                    if (!info.IsDescPt || info.assetType == AssetType.HTML5)
                    {
                        FileSecurity.StreamToFileInfo(TempPath, info.AssetPath);
                        if (info.assetType == AssetType.HTML5)
                        {
                            string ItemdisFile = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp" + "\\" + info.ItemsDis.Substring(info.ItemsDis.LastIndexOf("\\"));
                            if (Directory.Exists(ItemdisFile))
                            {
                                DirectoryInfo di = new DirectoryInfo(ItemdisFile);
                                di.Delete(true);
                            }

                            Directory.CreateDirectory(ItemdisFile);
                            string TempFile = ItemdisFile + "\\";

                            string DecFile = info.ItemsDis.Substring(0, info.ItemsDis.LastIndexOf("\\") + 1);


                            GZip.Decompress(DecFile, TempFile, info.ItemsDis.Substring(info.ItemsDis.LastIndexOf("\\") + 1) + ".zip");
                        }
                    }

                    else
                    {
                        FileSecurity.decryptFile(Globals.AssetDecryptKey, TempPath, info.AssetPath);
                    }
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message);
                    //log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    //log.Error(ex.Message + "\r\n" + ex.StackTrace);
                }


                Globals.tempFileList.Add(TempPath);
                //info.AssetPath = TempPath;
            }
            switch (info.assetType)
            {
            case AssetType.Movie:

                Control.ControlMediaElement mediaElement = new Control.ControlMediaElement();
                mediaElement.Source = new Uri(TempPath, UriKind.Absolute);
                mediaElement.mediaElement.LoadedBehavior   = MediaState.Manual;
                mediaElement.mediaElement.UnloadedBehavior = MediaState.Stop;

                //mediaElement.Stop();
                item.Content = mediaElement;

                break;

            case AssetType.Sound:
                MediaPlayer mediaPlayer = new MediaPlayer();
                mediaPlayer.Open(new Uri(TempPath, UriKind.Absolute));
                mediaPlayer.Stop();
                item.Content    = mediaPlayer;
                item.Visibility = Visibility.Hidden;
                break;

            case AssetType.Topic:
                System.Collections.Generic.List <int> answerList = new System.Collections.Generic.List <int>();

                TopicInfo topicInfo = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(((ContentText)info.Content).Text))) as TopicInfo;
                foreach (var v in topicInfo.TopicOptionList)    //记录正确答案。
                {
                    if (v.Right)
                    {
                        answerList.Add(v.Id);
                    }
                }
                TopicControl tc = new TopicControl(false, answerList);
                tc.TopicInfo = topicInfo;
                tc.Clear();
                //tc.TopicInfo.TopicOptionList[0].Right = true;
                //foreach (var v in tc.TopicInfo.TopicOptionList)
                //    v.IsSelected = false;

                SetShowDiv(info, item, tc);
                break;

            case AssetType.TopicDrag:
                ContentTopicDrag contentTopicDrag = info.Content as ContentTopicDrag;
                if (contentTopicDrag == null)
                {
                    break;
                }
                ControlTopicDrag controlTopicDarg = new ControlTopicDrag(contentTopicDrag.topicDragItemAnswerList, contentTopicDrag.topicDragItemList,
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Background)),
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Foreground)), false);
                controlTopicDarg.Score = info.Score;

                SetShowDiv(info, item, controlTopicDarg);
                break;

            case AssetType.Text:
                System.Windows.Controls.RichTextBox richtextbox = new System.Windows.Controls.RichTextBox();
                richtextbox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                richtextbox.BorderThickness             = new Thickness(0);
                richtextbox.IsReadOnly = true;

                richtextbox.Document   = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(jg.HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(((ContentText)info.Content).Text, true)))) as FlowDocument;
                richtextbox.Background = richtextbox.Document.Background;
                if (info.LineHeight != 0)
                {
                    richtextbox.Document.LineHeight = info.LineHeight;
                }
                richtextbox.Document.FontSize   = info.FontSize;
                richtextbox.Document.FontFamily = new FontFamily(info.FontFamily);
                item.LineHeight = info.LineHeight;

                SetShowDiv(info, item, richtextbox);
                break;

            case AssetType.TextGrid:
                ControlTextGrid controlTextGrid = new ControlTextGrid();
                controlTextGrid.IsEdit = false;
                controlTextGrid.Source = (ContentGrid)info.Content;

                SetShowDiv(info, item, controlTextGrid);
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));

                break;

            case AssetType.Shape:
                System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
                path.Style   = path.FindResource(((ContentText)info.Content).Text) as Style;
                path.Stretch = Stretch.Fill;

                SetShowDiv(info, item, path);
                break;

            case AssetType.Image:

                using (FileStream fs = new FileStream(TempPath, FileMode.Open, FileAccess.Read))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, (int)fs.Length);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = new MemoryStream(buffer);
                    bitmapImage.EndInit();
                    image = new Image()
                    {
                        Source = bitmapImage
                    };
                    image.Stretch = Stretch.Fill;

                    SetShowDiv(info, item, image);
                }
                break;

            case AssetType.Document:
                WebBrowser webBrowser = new WebBrowser();
                webBrowser.Source = new Uri(TempPath, UriKind.Absolute);
                SetShowDiv(info, item, webBrowser);
                break;

            case AssetType.Message:
                ControlMessage controlMessage = new ControlMessage(false);
                ContentMessage contentMessage = info.Content as ContentMessage;
                if (contentMessage == null)
                {
                    break;
                }
                controlMessage.Title    = contentMessage.Title;
                controlMessage.Location = new Point(contentMessage.PointX, contentMessage.PointY);
                SetShowDiv(info, item, controlMessage);
                break;

            case AssetType.Line:
                ControlLine controlLine = new ControlLine(false);
                ContentLine contentLine = info.Content as ContentLine;
                if (contentLine == null)
                {
                    break;
                }
                controlLine.Point1 = new Point(contentLine.Point1X, contentLine.Point1Y);
                SetShowDiv(info, item, controlLine);
                break;

            case AssetType.HTML5:
                WebBrowerGecko wbgk = new WebBrowerGecko();
                System.Windows.Forms.Integration.WindowsFormsHost w = new System.Windows.Forms.Integration.WindowsFormsHost();
                w.Child = wbgk;
                wbgk.Navigate(TempPath);
                w.SetValue(Panel.ZIndexProperty, 10);
                w.Width      = info.Width;
                w.Height     = info.Height;
                w.Background = new SolidColorBrush(Colors.Red);
                w.Tag        = TempPath;
                item.Content = w;

                break;

            case AssetType.TPageGroup:
                bool dirInfo = false;
                if (DirectoryAssResInfo.Keys.Count > 0)
                {
                    foreach (var v in DirectoryAssResInfo.Keys)
                    {
                        if (v == item.ItemId.ToString())
                        {
                            dirInfo = true;
                            DirectoryAssResInfo[v].Add(TempPath);
                            UpdateImgGroup(DirectoryAssResInfo[v], DirectoryTpage[v]);
                            break;
                        }
                    }
                }
                if (!dirInfo)
                {
                    TPageControl page = new TPageControl();
                    page.Height = info.Height;
                    page.Width  = info.Width;
                    page.canvasPageContent.Width  = info.Width - 100;
                    page.canvasPageContent.Height = info.Height - 2;
                    System.Collections.ObjectModel.ObservableCollection <string> observableAssResInfo = new System.Collections.ObjectModel.ObservableCollection <string>();
                    observableAssResInfo.Add(TempPath);
                    UpdateImgGroup(observableAssResInfo, page);
                    DirectoryAssResInfo.Add(item.ItemId.ToString(), observableAssResInfo);
                    DirectoryTpage.Add(item.ItemId.ToString(), page);
                    item.Content = DirectoryTpage[item.ItemId.ToString()];
                }
                TPageControl tpage = new TPageControl();
                tpage = DirectoryTpage[item.ItemId.ToString()];
                SetShowDiv(info, item, tpage);
                break;
            }



            //item.Opacity = info.Opacity;
            item.AssetPath  = info.AssetPath;
            item.Thumbnails = info.Thumbnails;

            if (info.Background != null)
            {
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
            }
            if (info.Foreground != null)
            {
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));
            }

            item.IsEdit = false;
            item.ItemId = info.ItemId;
            item.Width  = info.Width;
            item.Height = info.Height;

            Canvas.SetLeft(item, info.X);
            Canvas.SetTop(item, info.Y);

            System.Windows.Controls.Panel.SetZIndex(item, info.ZIndex);

            transformGroup = item.RenderTransform as TransformGroup;
            foreach (var v in transformGroup.Children)
            {
                switch (v.GetType().Name)
                {
                case "RotateTransform":
                    ((RotateTransform)v).Angle = info.Angle;
                    break;

                case "ScaleTransform":
                    ((ScaleTransform)v).ScaleX = info.ScaleX == 0 ? 1 : info.ScaleX;
                    ((ScaleTransform)v).ScaleY = info.ScaleY == 0 ? 1 : info.ScaleY;
                    break;

                case "SkewTransform":
                    ((SkewTransform)v).AngleX = info.SkewX;
                    ((SkewTransform)v).AngleY = info.SkewY;
                    break;

                case "TranslateTransform":
                    ((TranslateTransform)v).X = info.TranslateX;
                    ((TranslateTransform)v).Y = info.TranslateY;
                    break;
                }
            }

            return(item);
        }
Exemplo n.º 2
0
        public static ToolboxItem GetToolBoxItem(SaveItemInfo info)
        {
            Image       image;
            ToolboxItem item = null;

            item           = new ToolboxItem();
            item.AssetType = info.assetType;
            item.ItemName  = info.ItemName;
            item.ItemId    = info.ItemId;
            switch (info.assetType)
            {
            case AssetType.Movie:
            case AssetType.Sound:
            case AssetType.HTML5:
            case AssetType.Document:
                image = new Image()
                {
                    Source = new BitmapImage(new Uri(info.Thumbnails, UriKind.Absolute))
                };
                image.Stretch = Stretch.Fill;
                item.Content  = image;
                break;

            case AssetType.Topic:
                TopicControl tc = new TopicControl(true);
                tc.TopicInfo = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(((ContentText)info.Content).Text))) as TopicInfo;
                item.Content = tc;
                break;

            case AssetType.TopicDrag:
                ContentTopicDrag contentTopicDrag = info.Content as ContentTopicDrag;
                if (contentTopicDrag == null)
                {
                    break;
                }

                ControlTopicDrag controlTopicDarg = new ControlTopicDrag(contentTopicDrag.topicDragItemAnswerList, contentTopicDrag.topicDragItemList,
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Background)),
                                                                         new SolidColorBrush((Color)ColorConverter.ConvertFromString(contentTopicDrag.Foreground)), true);
                controlTopicDarg.Score = info.Score;
                item.Content           = controlTopicDarg;
                break;

            case AssetType.Text:
                ControlTextEditor content = new ControlTextEditor();
                if (info.LineHeight != 0)
                {
                    content.mainRTB.Document.LineHeight = info.LineHeight;
                }

                content.mainRTB.Document = XamlReader.Load(XmlReader.Create((TextReader) new StringReader(jg.HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(((ContentText)info.Content).Text, true)))) as FlowDocument;
                //content.mainRTB.Document = XamlReader.Load(XmlReader.Create((TextReader)new StringReader(((ContentText)info.Content).Text))) as FlowDocument;
                if (info.LineHeight != 0)
                {
                    content.mainRTB.Document.LineHeight = info.LineHeight;
                }
                content.mainRTB.Document.FontSize   = info.FontSize;
                content.mainRTB.Document.FontFamily = new FontFamily(info.FontFamily);
                item.LineHeight = info.LineHeight;
                item.FontFamily = new FontFamily(info.FontFamily);
                item.FontSize   = info.FontSize;
                item.Content    = content;
                break;

            case AssetType.TextGrid:
                ControlTextGrid controlTextGrid = new ControlTextGrid();
                controlTextGrid.Source = (ContentGrid)info.Content;
                item.Content           = controlTextGrid;
                break;

            case AssetType.Shape:
                System.Windows.Shapes.Path path = new System.Windows.Shapes.Path()
                {
                    Name = ((ContentText)info.Content).Text
                };
                path.Style   = item.FindResource(((ContentText)info.Content).Text) as Style;
                path.Stretch = Stretch.Fill;
                item.Content = path;
                break;

            case AssetType.Image:
                image = new Image()
                {
                    Source = new BitmapImage(new Uri(info.Thumbnails, UriKind.Absolute))
                };
                image.Stretch = Stretch.Fill;
                item.Content  = image;
                break;

            case AssetType.Message:
                ControlMessage controlMessage = new ControlMessage(true);
                ContentMessage contentMessage = info.Content as ContentMessage;
                if (contentMessage == null)
                {
                    break;
                }
                controlMessage.Title    = contentMessage.Title;
                controlMessage.Location = new Point(contentMessage.PointX, contentMessage.PointY);
                item.Content            = controlMessage;
                break;

            case AssetType.Line:
                ControlLine controlLine = new ControlLine(true);
                ContentLine contentLine = info.Content as ContentLine;
                if (contentLine == null)
                {
                    break;
                }
                controlLine.Point1 = new Point(contentLine.Point1X, contentLine.Point1Y);
                item.Content       = controlLine;
                break;

            case AssetType.TPageGroup:
                bool dirInfo = false;
                if (AssResInfoObser.Keys.Count > 0)
                {
                    foreach (var v in AssResInfoObser.Keys)
                    {
                        if (v == item.ItemId)
                        {
                            dirInfo = true;
                            AssResInfo resInfo = new AssResInfo();
                            resInfo.ArId       = info.ItemId;
                            resInfo.AssetName  = "图片" + (DirectoryTpageLoad[v].Children.Count + 1);
                            resInfo.AssetPath  = info.AssetPath;
                            resInfo.Thumbnails = info.Thumbnails;
                            AssResInfoObser[v].Add(resInfo);
                            DirectoryTpageLoad[v].Children = AssResInfoObser[v];
                            DirectoryTpageLoad[v].UpdateImgGroup();
                            break;
                        }
                    }
                }
                if (!dirInfo)
                {
                    TPageControl page = new TPageControl();
                    page.Height = info.Height;
                    page.Width  = info.Width;
                    page.canvasPageContent.Width  = info.Width - 100;
                    page.canvasPageContent.Height = info.Height - 2;
                    AssResInfo resInfo = new AssResInfo();
                    resInfo.ArId       = info.ItemId;
                    resInfo.AssetName  = "图片1";
                    resInfo.AssetPath  = info.AssetPath;
                    resInfo.Thumbnails = info.Thumbnails;
                    System.Collections.ObjectModel.ObservableCollection <AssResInfo> observableAssResInfo = new System.Collections.ObjectModel.ObservableCollection <AssResInfo>();
                    observableAssResInfo.Add(resInfo);
                    page.Children = observableAssResInfo;
                    page.UpdateImgGroup();
                    AssResInfoObser.Add(item.ItemId, observableAssResInfo);
                    DirectoryTpageLoad.Add(item.ItemId, page);
                    item.Content = DirectoryTpageLoad[item.ItemId];
                }
                break;
            }
            item.IsLongText = info.IsLongText;
            item.IsShowDiv  = info.IsShowDiv;
            item.IsDescPt   = info.IsDescPt;

            item.Opacity = info.Opacity;
            if (info.Background != null)
            {
                item.ItemBackground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Background));
            }
            if (info.Foreground != null)
            {
                item.ItemForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(info.Foreground));
            }

            item.AssetPath  = info.AssetPath;
            item.Thumbnails = info.Thumbnails;

            return(item);
        }