Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void Submit()
        {
            if (thumbnails != null && thumbnails != "")
            {
                int htmlNameImgIdex = thumbnails.LastIndexOf('\\');

                string NewName = "";
                if (htmlNameImgIdex > 0)
                {
                    string Img = thumbnails.Substring(htmlNameImgIdex + 1);

                    int indexd = Img.LastIndexOf('.');

                    string Expender = Img.Substring(indexd);

                    NewName = Guid.NewGuid().ToString();


                    string ImgName = NewName + "_s" + Expender;

                    string assetpath = Globals.appStartupPath + "\\" + Globals.assetFolder + "\\" + ImgName;
                    FileSecurity.StreamToFileInfo(assetpath, thumbnails);
                    thumbnails = assetpath;
                }

                int htmlNameIdex = path.LastIndexOf('\\');

                if (htmlNameIdex > 0)
                {
                    string pathTmp = path.Substring(htmlNameIdex + 1);


                    int indexd = pathTmp.LastIndexOf('.');

                    string Expender = pathTmp.Substring(indexd);

                    string AssName = "";

                    if (NewName != "")
                    {
                        AssName = NewName + Expender;
                    }
                    else
                    {
                        NewName = Guid.NewGuid().ToString();
                        AssName = NewName + Expender;
                    }
                    string assetpath = Globals.appStartupPath + "\\" + Globals.assetFolder + "\\" + AssName;



                    FileSecurity.StreamToFileInfo(assetpath, path);

                    path = assetpath;
                }



                _AssInfo.AssetPath  = path;
                _AssInfo.AssetName  = NewName;
                _AssInfo.Thumbnails = thumbnails;
            }
        }